fix(codegen): call stack errors when regenerating proto fildes

This commit is contained in:
Connor Peet 2017-10-21 09:08:25 -07:00
Родитель bcf75e1a44
Коммит 268757f51e
4 изменённых файлов: 162 добавлений и 31 удалений

Просмотреть файл

@ -225,14 +225,19 @@ function walk(ast, iterator, path = []) {
}); });
} }
function markResponsesFor(message) { function markResponsesFor(message, seen = []) {
const name = message.node.name;
if (seen.includes(name)) {
return;
}
message.response = true; message.response = true;
_(message.node.fields) _(message.node.fields)
.values() .values()
.map(f => messages.find(f.type)) .map(f => messages.find(f.type))
.filter(Boolean) .filter(Boolean)
.forEach(markResponsesFor); .forEach(m => markResponsesFor(m, seen.concat(name)));
} }
function prepareForGeneration(ast) { function prepareForGeneration(ast) {
@ -256,7 +261,7 @@ function prepareForGeneration(ast) {
.values() .values()
.map(m => messages.find(m.responseType)) .map(m => messages.find(m.responseType))
.filter(Boolean) .filter(Boolean)
.forEach(markResponsesFor); .forEach(m => markResponsesFor(m));
} }
}); });
} }

Просмотреть файл

@ -95,7 +95,13 @@ service Lease {
body: "*" body: "*"
}; };
} }
// TODO(xiangli) List all existing Leases? // LeaseLeases lists all existing leases.
rpc LeaseLeases(LeaseLeasesRequest) returns (LeaseLeasesResponse) {
option (google.api.http) = {
post: "/v3alpha/kv/lease/leases"
body: "*"
};
}
} }
service Cluster { service Cluster {
// MemberAdd adds a member into the cluster. // MemberAdd adds a member into the cluster.
@ -149,7 +155,7 @@ service Maintenance {
body: "*" body: "*"
}; };
} }
// Hash returns the hash of the local KV state for consistency checking purpose. // Hash computes the hash of the KV's backend.
// This is designed for testing; do not use this in production when there // This is designed for testing; do not use this in production when there
// are ongoing transactions. // are ongoing transactions.
rpc Hash(HashRequest) returns (HashResponse) { rpc Hash(HashRequest) returns (HashResponse) {
@ -158,6 +164,13 @@ service Maintenance {
body: "*" body: "*"
}; };
} }
// HashKV computes the hash of all MVCC keys up to a given revision.
rpc HashKV(HashKVRequest) returns (HashKVResponse) {
option (google.api.http) = {
post: "/v3alpha/maintenance/hash"
body: "*"
};
}
// Snapshot sends a snapshot of the entire backend from a member over a stream to a client. // Snapshot sends a snapshot of the entire backend from a member over a stream to a client.
rpc Snapshot(SnapshotRequest) returns (stream SnapshotResponse) { rpc Snapshot(SnapshotRequest) returns (stream SnapshotResponse) {
option (google.api.http) = { option (google.api.http) = {
@ -165,6 +178,13 @@ service Maintenance {
body: "*" body: "*"
}; };
} }
// MoveLeader requests current leader node to transfer its leadership to transferee.
rpc MoveLeader(MoveLeaderRequest) returns (MoveLeaderResponse) {
option (google.api.http) = {
post: "/v3alpha/maintenance/transfer-leadership"
body: "*"
};
}
} }
service Auth { service Auth {
// AuthEnable enables authentication. // AuthEnable enables authentication.
@ -331,7 +351,6 @@ message RangeRequest {
bool serializable = 7; bool serializable = 7;
// keys_only when set returns only the keys and not the values. // keys_only when set returns only the keys and not the values.
bool keys_only = 8; bool keys_only = 8;
// count_only when set returns only the count of the keys in the range. // count_only when set returns only the count of the keys in the range.
bool count_only = 9; bool count_only = 9;
// min_mod_revision is the lower bound for returned key mod revisions; all keys with // min_mod_revision is the lower bound for returned key mod revisions; all keys with
@ -406,6 +425,7 @@ message RequestOp {
RangeRequest request_range = 1; RangeRequest request_range = 1;
PutRequest request_put = 2; PutRequest request_put = 2;
DeleteRangeRequest request_delete_range = 3; DeleteRangeRequest request_delete_range = 3;
TxnRequest request_txn = 4;
} }
} }
message ResponseOp { message ResponseOp {
@ -414,6 +434,7 @@ message ResponseOp {
RangeResponse response_range = 1; RangeResponse response_range = 1;
PutResponse response_put = 2; PutResponse response_put = 2;
DeleteRangeResponse response_delete_range = 3; DeleteRangeResponse response_delete_range = 3;
TxnResponse response_txn = 4;
} }
} }
message Compare { message Compare {
@ -428,6 +449,7 @@ message Compare {
Create = 1; Create = 1;
Mod = 2; Mod = 2;
Value= 3; Value= 3;
Lease = 4;
} }
// result is logical comparison operation for this comparison. // result is logical comparison operation for this comparison.
CompareResult result = 1; CompareResult result = 1;
@ -444,7 +466,14 @@ message Compare {
int64 mod_revision = 6; int64 mod_revision = 6;
// value is the value of the given key, in bytes. // value is the value of the given key, in bytes.
bytes value = 7; bytes value = 7;
// lease is the lease id of the given key.
int64 lease = 8;
// leave room for more target_union field tags, jump to 64
} }
// range_end compares the given target to all keys in the range [key, range_end).
// See RangeRequest for more details on key ranges.
bytes range_end = 64;
// TODO: fill out with most of the rest of RangeRequest fields when needed.
} }
// From google paxosdb paper: // From google paxosdb paper:
// Our implementation hinges around a powerful primitive which we call MultiOp. All other database // Our implementation hinges around a powerful primitive which we call MultiOp. All other database
@ -484,7 +513,7 @@ message TxnResponse {
// CompactionRequest compacts the key-value store up to a given revision. All superseded keys // CompactionRequest compacts the key-value store up to a given revision. All superseded keys
// with a revision less than the compaction revision will be removed. // with a revision less than the compaction revision will be removed.
message CompactionRequest { message CompactionRequest {
// revision is the key-value store revision for the compaction operation. // revision is the key-value store revision for the compaction operation.
int64 revision = 1; int64 revision = 1;
// physical is set so the RPC will wait until the compaction is physically // physical is set so the RPC will wait until the compaction is physically
// applied to the local database such that compacted entries are totally // applied to the local database such that compacted entries are totally
@ -496,9 +525,20 @@ message CompactionResponse {
} }
message HashRequest { message HashRequest {
} }
message HashKVRequest {
// revision is the key-value store revision for the hash operation.
int64 revision = 1;
}
message HashKVResponse {
ResponseHeader header = 1;
// hash is the hash value computed from the responding member's MVCC keys up to a given revision.
uint32 hash = 2;
// compact_revision is the compacted revision of key-value store when hash begins.
int64 compact_revision = 3;
}
message HashResponse { message HashResponse {
ResponseHeader header = 1; ResponseHeader header = 1;
// hash is the hash value computed from the responding member's key-value store. // hash is the hash value computed from the responding member's KV's backend.
uint32 hash = 2; uint32 hash = 2;
} }
message SnapshotRequest { message SnapshotRequest {
@ -567,7 +607,7 @@ message WatchResponse {
// at a compacted index. // at a compacted index.
// //
// This happens when creating a watcher at a compacted revision or the watcher cannot // This happens when creating a watcher at a compacted revision or the watcher cannot
// catch up with the progress of the key-value store. // catch up with the progress of the key-value store.
// //
// The client should treat the watcher as canceled and should not try to create any // The client should treat the watcher as canceled and should not try to create any
// watcher with the same start_revision again. // watcher with the same start_revision again.
@ -625,6 +665,16 @@ message LeaseTimeToLiveResponse {
// Keys is the list of keys attached to this lease. // Keys is the list of keys attached to this lease.
repeated bytes keys = 5; repeated bytes keys = 5;
} }
message LeaseLeasesRequest {
}
message LeaseStatus {
int64 ID = 1;
// TODO: int64 TTL = 2;
}
message LeaseLeasesResponse {
ResponseHeader header = 1;
repeated LeaseStatus leases = 2;
}
message Member { message Member {
// ID is the member ID for this member. // ID is the member ID for this member.
uint64 ID = 1; uint64 ID = 1;
@ -678,9 +728,17 @@ message DefragmentRequest {
message DefragmentResponse { message DefragmentResponse {
ResponseHeader header = 1; ResponseHeader header = 1;
} }
message MoveLeaderRequest {
// targetID is the node ID for the new leader.
uint64 targetID = 1;
}
message MoveLeaderResponse {
ResponseHeader header = 1;
}
enum AlarmType { enum AlarmType {
None = 0; // default, used to query if any alarm is active None = 0; // default, used to query if any alarm is active
Nospace = 1; // space quota is exhausted Nospace = 1; // space quota is exhausted
Corrupt = 2; // kv store corruption detected
} }
message AlarmRequest { message AlarmRequest {
enum AlarmAction { enum AlarmAction {

Просмотреть файл

@ -33,6 +33,7 @@ export const compareTarget: { [key in keyof typeof RPC.CompareTarget]: keyof RPC
Version: 'version', Version: 'version',
Create: 'create_revision', Create: 'create_revision',
Mod: 'mod_revision', Mod: 'mod_revision',
Lease: 'lease',
}; };
/** /**

Просмотреть файл

@ -107,6 +107,12 @@ export class LeaseClient {
public leaseTimeToLive(req: ILeaseTimeToLiveRequest): Promise<ILeaseTimeToLiveResponse> { public leaseTimeToLive(req: ILeaseTimeToLiveRequest): Promise<ILeaseTimeToLiveResponse> {
return this.client.exec('Lease', 'leaseTimeToLive', req); return this.client.exec('Lease', 'leaseTimeToLive', req);
} }
/**
* LeaseLeases lists all existing leases.
*/
public leaseLeases(): Promise<ILeaseLeasesResponse> {
return this.client.exec('Lease', 'leaseLeases', {});
}
} }
export class ClusterClient { export class ClusterClient {
@ -158,19 +164,31 @@ export class MaintenanceClient {
return this.client.exec('Maintenance', 'defragment', {}); return this.client.exec('Maintenance', 'defragment', {});
} }
/** /**
* Hash returns the hash of the local KV state for consistency checking purpose. * Hash computes the hash of the KV's backend.
* This is designed for testing; do not use this in production when there * This is designed for testing; do not use this in production when there
* are ongoing transactions. * are ongoing transactions.
*/ */
public hash(): Promise<IHashResponse> { public hash(): Promise<IHashResponse> {
return this.client.exec('Maintenance', 'hash', {}); return this.client.exec('Maintenance', 'hash', {});
} }
/**
* HashKV computes the hash of all MVCC keys up to a given revision.
*/
public hashKV(req: IHashKVRequest): Promise<IHashKVResponse> {
return this.client.exec('Maintenance', 'hashKV', req);
}
/** /**
* Snapshot sends a snapshot of the entire backend from a member over a stream to a client. * Snapshot sends a snapshot of the entire backend from a member over a stream to a client.
*/ */
public snapshot(): Promise<IResponseStream<ISnapshotResponse>> { public snapshot(): Promise<IResponseStream<ISnapshotResponse>> {
return this.client.getConnection('Maintenance').then(cnx => (<any>cnx.client).snapshot({})); return this.client.getConnection('Maintenance').then(cnx => (<any>cnx.client).snapshot({}));
} }
/**
* MoveLeader requests current leader node to transfer its leadership to transferee.
*/
public moveLeader(req: IMoveLeaderRequest): Promise<IMoveLeaderResponse> {
return this.client.exec('Maintenance', 'moveLeader', req);
}
} }
export class AuthClient { export class AuthClient {
@ -475,11 +493,13 @@ export interface IRequestOp {
request_range?: IRangeRequest; request_range?: IRangeRequest;
request_put?: IPutRequest; request_put?: IPutRequest;
request_delete_range?: IDeleteRangeRequest; request_delete_range?: IDeleteRangeRequest;
request_txn?: ITxnRequest;
} }
export interface IResponseOp { export interface IResponseOp {
response_range: IRangeResponse; response_range: IRangeResponse;
response_put: IPutResponse; response_put: IPutResponse;
response_delete_range: IDeleteRangeResponse; response_delete_range: IDeleteRangeResponse;
response_txn: ITxnResponse;
} }
export enum CompareResult { export enum CompareResult {
Equal = 0, Equal = 0,
@ -492,6 +512,7 @@ export enum CompareTarget {
Create = 1, Create = 1,
Mod = 2, Mod = 2,
Value = 3, Value = 3,
Lease = 4,
} }
export interface ICompare { export interface ICompare {
/** /**
@ -522,6 +543,15 @@ export interface ICompare {
* value is the value of the given key, in bytes. * value is the value of the given key, in bytes.
*/ */
value?: Buffer; value?: Buffer;
/**
* lease is the lease id of the given key.
*/
lease?: string | number;
/**
* range_end compares the given target to all keys in the range [key, range_end).
* See RangeRequest for more details on key ranges.
*/
range_end?: Buffer;
} }
export interface ITxnRequest { export interface ITxnRequest {
/** /**
@ -555,7 +585,7 @@ export interface ITxnResponse {
} }
export interface ICompactionRequest { export interface ICompactionRequest {
/** /**
* revision is the key-value store revision for the compaction operation. * revision is the key-value store revision for the compaction operation.
*/ */
revision?: string | number; revision?: string | number;
/** /**
@ -568,10 +598,27 @@ export interface ICompactionRequest {
export interface ICompactionResponse { export interface ICompactionResponse {
header: IResponseHeader; header: IResponseHeader;
} }
export interface IHashKVRequest {
/**
* revision is the key-value store revision for the hash operation.
*/
revision?: string | number;
}
export interface IHashKVResponse {
header: IResponseHeader;
/**
* hash is the hash value computed from the responding member's MVCC keys up to a given revision.
*/
hash: string;
/**
* compact_revision is the compacted revision of key-value store when hash begins.
*/
compact_revision: string;
}
export interface IHashResponse { export interface IHashResponse {
header: IResponseHeader; header: IResponseHeader;
/** /**
* hash is the hash value computed from the responding member's key-value store. * hash is the hash value computed from the responding member's KV's backend.
*/ */
hash: string; hash: string;
} }
@ -746,6 +793,13 @@ export interface ILeaseTimeToLiveResponse {
*/ */
keys: Buffer[]; keys: Buffer[];
} }
export interface ILeaseStatus {
ID: string;
}
export interface ILeaseLeasesResponse {
header: IResponseHeader;
leases: ILeaseStatus[];
}
export interface IMember { export interface IMember {
/** /**
* ID is the member ID for this member. * ID is the member ID for this member.
@ -821,6 +875,15 @@ export interface IMemberListResponse {
export interface IDefragmentResponse { export interface IDefragmentResponse {
header: IResponseHeader; header: IResponseHeader;
} }
export interface IMoveLeaderRequest {
/**
* targetID is the node ID for the new leader.
*/
targetID?: string | number;
}
export interface IMoveLeaderResponse {
header: IResponseHeader;
}
export enum AlarmType { export enum AlarmType {
/** /**
* default, used to query if any alarm is active * default, used to query if any alarm is active
@ -830,6 +893,10 @@ export enum AlarmType {
* space quota is exhausted * space quota is exhausted
*/ */
Nospace = 1, Nospace = 1,
/**
* kv store corruption detected
*/
Corrupt = 2,
} }
export enum AlarmAction { export enum AlarmAction {
Get = 0, Get = 0,
@ -1017,6 +1084,25 @@ export interface IAuthRoleGrantPermissionResponse {
export interface IAuthRoleRevokePermissionResponse { export interface IAuthRoleRevokePermissionResponse {
header: IResponseHeader; header: IResponseHeader;
} }
export interface IUser {
name?: Buffer;
password?: Buffer;
roles?: string[];
}
export enum Permission {
Read = 0,
Write = 1,
Readwrite = 2,
}
export interface IPermission {
permType: keyof typeof Permission;
key: Buffer;
range_end: Buffer;
}
export interface IRole {
name?: Buffer;
keyPermission?: IPermission[];
}
export interface IKeyValue { export interface IKeyValue {
/** /**
* key is the first key for the range. If range_end is not given, the request only looks up key. * key is the first key for the range. If range_end is not given, the request only looks up key.
@ -1055,25 +1141,6 @@ export interface IEvent {
*/ */
prev_kv: IKeyValue; prev_kv: IKeyValue;
} }
export interface IUser {
name?: Buffer;
password?: Buffer;
roles?: string[];
}
export enum Permission {
Read = 0,
Write = 1,
Readwrite = 2,
}
export interface IPermission {
permType: keyof typeof Permission;
key: Buffer;
range_end: Buffer;
}
export interface IRole {
name?: Buffer;
keyPermission?: IPermission[];
}
export const Services = { export const Services = {
KV: KVClient, KV: KVClient,
Watch: WatchClient, Watch: WatchClient,