зеркало из https://github.com/microsoft/etcd3.git
feat: apply update grpc module
This commit is contained in:
Родитель
5c638a6867
Коммит
6d67af2e24
|
@ -201,10 +201,6 @@ function generateMethodCalls(node, name) {
|
|||
|
||||
function generateInterface(node, name) {
|
||||
const message = messages.find(name);
|
||||
if (message.empty) {
|
||||
return;
|
||||
}
|
||||
|
||||
template('interface', { name, node, message });
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
|
||||
// AUTOGENERATED CODE, DO NOT EDIT
|
||||
|
||||
import * as grpc from 'grpc';
|
||||
import { StatusMessage } from './grpcTypes';
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
export interface ICallable<T> {
|
||||
exec<T>(
|
||||
|
@ -25,7 +26,7 @@ export interface ICallable<T> {
|
|||
export interface IResponseStream<T> {
|
||||
on(event: 'data', fn: (item: T) => void): this;
|
||||
on(event: 'end', fn: () => void): this;
|
||||
on(event: 'status', fn: (status: StatusMessage) => void): this;
|
||||
on(event: 'status', fn: (status: grpc.StatusObject) => void): this;
|
||||
on(event: 'error', fn: (err: Error) => void): this;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
## 1.0.0 TBA
|
||||
|
||||
- **breaking**: Node < 10 is no longer supported
|
||||
- **breaking**: `bignumber.js`, used to handle 64-bit numbers returned from etcd, updated from 5.x to 9.0.0
|
||||
- **breaking**: TypeScript is updated to 3.9, and the types of some function signatures have been narrowed
|
||||
- **breaking**: **chore:**: Node < 10 is no longer supported
|
||||
- **breaking**: **chore:**: `bignumber.js`, used to handle 64-bit numbers returned from etcd, updated from 5.x to 9.0.0
|
||||
- **breaking**: **chore:**: TypeScript is updated to 3.9, and the types of some function signatures have been narrowed
|
||||
- **breaking**: **chore:** grpc has been updated from `grpc@1.24` to `@grpc/grpc-js@1.0.05`. This affects the optional `grpcOptions` that the client can be configured with. The previous package was a couple years old, so you may additionally see different behavior of grpc on your network.
|
||||
|
||||
Thank you to [@pauliusuza](https://github.com/pauliusuza) for his help updating everything
|
||||
|
||||
## 0.2.13 2019-07-03
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
"test:cover": "nyc mocha",
|
||||
"test:lint": "eslint \"src/**/*.ts\"",
|
||||
"watch": "tsc --watch",
|
||||
"build:proto": "node ./bin/update-proto ./proto && node bin/generate-methods.js ./proto/rpc.proto > src/rpc.ts && npm run fmt:ts",
|
||||
"build:proto": "node ./bin/update-proto ./proto && node bin/generate-methods.js ./proto/rpc.proto > src/rpc.ts && npm run fmt",
|
||||
"build:doc": "rimraf docs && typedoc --gitRevision `git describe --abbrev=0 --tags` --exclude \"**/test/*\" --excludePrivate --out ./docs ./src/index.ts && node bin/tame-typedoc",
|
||||
"build:ts": "tsc",
|
||||
"fmt": "prettier --write \"src/**/*.{ts,js}\" && npm run -s test:lint -- --fix",
|
||||
|
@ -73,8 +73,8 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@grpc/proto-loader": "^0.5.4",
|
||||
"bignumber.js": "^9.0.0",
|
||||
"grpc": "^1.24.3"
|
||||
"@grpc/grpc-js": "^1.0.5",
|
||||
"bignumber.js": "^9.0.0"
|
||||
},
|
||||
"prettier": {
|
||||
"singleQuote": true,
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
syntax = "proto3";
|
||||
package authpb;
|
||||
|
||||
message UserAddOptions {
|
||||
bool no_password = 1;
|
||||
};
|
||||
// User is a single entry in the bucket authUsers
|
||||
message User {
|
||||
bytes name = 1;
|
||||
bytes password = 2;
|
||||
repeated string roles = 3;
|
||||
UserAddOptions options = 4;
|
||||
}
|
||||
// Permission is a single entity
|
||||
message Permission {
|
||||
|
|
214
proto/rpc.proto
214
proto/rpc.proto
|
@ -8,7 +8,7 @@ service KV {
|
|||
// Range gets the keys in the range from the key-value store.
|
||||
rpc Range(RangeRequest) returns (RangeResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/kv/range"
|
||||
post: "/v3/kv/range"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ service KV {
|
|||
// and generates one event in the event history.
|
||||
rpc Put(PutRequest) returns (PutResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/kv/put"
|
||||
post: "/v3/kv/put"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ service KV {
|
|||
// and generates a delete event in the event history for every deleted key.
|
||||
rpc DeleteRange(DeleteRangeRequest) returns (DeleteRangeResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/kv/deleterange"
|
||||
post: "/v3/kv/deleterange"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ service KV {
|
|||
// It is not allowed to modify the same key several times within one txn.
|
||||
rpc Txn(TxnRequest) returns (TxnResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/kv/txn"
|
||||
post: "/v3/kv/txn"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ service KV {
|
|||
// indefinitely.
|
||||
rpc Compact(CompactionRequest) returns (CompactionResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/kv/compaction"
|
||||
post: "/v3/kv/compaction"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ service Watch {
|
|||
// last compaction revision.
|
||||
rpc Watch(stream WatchRequest) returns (stream WatchResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/watch"
|
||||
post: "/v3/watch"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
@ -69,37 +69,49 @@ service Lease {
|
|||
// deleted if the lease expires. Each expired key generates a delete event in the event history.
|
||||
rpc LeaseGrant(LeaseGrantRequest) returns (LeaseGrantResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/lease/grant"
|
||||
post: "/v3/lease/grant"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// LeaseRevoke revokes a lease. All keys attached to the lease will expire and be deleted.
|
||||
rpc LeaseRevoke(LeaseRevokeRequest) returns (LeaseRevokeResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/kv/lease/revoke"
|
||||
post: "/v3/lease/revoke"
|
||||
body: "*"
|
||||
additional_bindings {
|
||||
post: "/v3/kv/lease/revoke"
|
||||
body: "*"
|
||||
}
|
||||
};
|
||||
}
|
||||
// LeaseKeepAlive keeps the lease alive by streaming keep alive requests from the client
|
||||
// to the server and streaming keep alive responses from the server to the client.
|
||||
rpc LeaseKeepAlive(stream LeaseKeepAliveRequest) returns (stream LeaseKeepAliveResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/lease/keepalive"
|
||||
post: "/v3/lease/keepalive"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// LeaseTimeToLive retrieves lease information.
|
||||
rpc LeaseTimeToLive(LeaseTimeToLiveRequest) returns (LeaseTimeToLiveResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/kv/lease/timetolive"
|
||||
post: "/v3/lease/timetolive"
|
||||
body: "*"
|
||||
additional_bindings {
|
||||
post: "/v3/kv/lease/timetolive"
|
||||
body: "*"
|
||||
}
|
||||
};
|
||||
}
|
||||
// LeaseLeases lists all existing leases.
|
||||
rpc LeaseLeases(LeaseLeasesRequest) returns (LeaseLeasesResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/kv/lease/leases"
|
||||
post: "/v3/lease/leases"
|
||||
body: "*"
|
||||
additional_bindings {
|
||||
post: "/v3/kv/lease/leases"
|
||||
body: "*"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -107,28 +119,35 @@ service Cluster {
|
|||
// MemberAdd adds a member into the cluster.
|
||||
rpc MemberAdd(MemberAddRequest) returns (MemberAddResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/cluster/member/add"
|
||||
post: "/v3/cluster/member/add"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// MemberRemove removes an existing member from the cluster.
|
||||
rpc MemberRemove(MemberRemoveRequest) returns (MemberRemoveResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/cluster/member/remove"
|
||||
post: "/v3/cluster/member/remove"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// MemberUpdate updates the member configuration.
|
||||
rpc MemberUpdate(MemberUpdateRequest) returns (MemberUpdateResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/cluster/member/update"
|
||||
post: "/v3/cluster/member/update"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// MemberList lists all the members in the cluster.
|
||||
rpc MemberList(MemberListRequest) returns (MemberListResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/cluster/member/list"
|
||||
post: "/v3/cluster/member/list"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// MemberPromote promotes a member from raft learner (non-voting) to raft voting member.
|
||||
rpc MemberPromote(MemberPromoteRequest) returns (MemberPromoteResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3/cluster/member/promote"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
@ -137,51 +156,62 @@ service Maintenance {
|
|||
// Alarm activates, deactivates, and queries alarms regarding cluster health.
|
||||
rpc Alarm(AlarmRequest) returns (AlarmResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/maintenance/alarm"
|
||||
post: "/v3/maintenance/alarm"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// Status gets the status of the member.
|
||||
rpc Status(StatusRequest) returns (StatusResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/maintenance/status"
|
||||
post: "/v3/maintenance/status"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// Defragment defragments a member's backend database to recover storage space.
|
||||
rpc Defragment(DefragmentRequest) returns (DefragmentResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/maintenance/defragment"
|
||||
post: "/v3/maintenance/defragment"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// Hash computes the hash of the KV's backend.
|
||||
// This is designed for testing; do not use this in production when there
|
||||
// are ongoing transactions.
|
||||
// Hash computes the hash of whole backend keyspace,
|
||||
// including key, lease, and other buckets in storage.
|
||||
// This is designed for testing ONLY!
|
||||
// Do not rely on this in production with ongoing transactions,
|
||||
// since Hash operation does not hold MVCC locks.
|
||||
// Use "HashKV" API instead for "key" bucket consistency checks.
|
||||
rpc Hash(HashRequest) returns (HashResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/maintenance/hash"
|
||||
post: "/v3/maintenance/hash"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// HashKV computes the hash of all MVCC keys up to a given revision.
|
||||
// It only iterates "key" bucket in backend storage.
|
||||
rpc HashKV(HashKVRequest) returns (HashKVResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/maintenance/hash"
|
||||
post: "/v3/maintenance/hash"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// Snapshot sends a snapshot of the entire backend from a member over a stream to a client.
|
||||
rpc Snapshot(SnapshotRequest) returns (stream SnapshotResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/maintenance/snapshot"
|
||||
post: "/v3/maintenance/snapshot"
|
||||
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"
|
||||
post: "/v3/maintenance/transfer-leadership"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// Downgrade requests downgrade, cancel downgrade on the cluster version.
|
||||
rpc Downgrade(DowngradeRequest) returns (DowngradeResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3/maintenance/downgrade"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
@ -190,112 +220,119 @@ service Auth {
|
|||
// AuthEnable enables authentication.
|
||||
rpc AuthEnable(AuthEnableRequest) returns (AuthEnableResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/enable"
|
||||
post: "/v3/auth/enable"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// AuthDisable disables authentication.
|
||||
rpc AuthDisable(AuthDisableRequest) returns (AuthDisableResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/disable"
|
||||
post: "/v3/auth/disable"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// AuthStatus displays authentication status.
|
||||
rpc AuthStatus(AuthStatusRequest) returns (AuthStatusResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3/auth/status"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// Authenticate processes an authenticate request.
|
||||
rpc Authenticate(AuthenticateRequest) returns (AuthenticateResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/authenticate"
|
||||
post: "/v3/auth/authenticate"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// UserAdd adds a new user.
|
||||
// UserAdd adds a new user. User name cannot be empty.
|
||||
rpc UserAdd(AuthUserAddRequest) returns (AuthUserAddResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/user/add"
|
||||
post: "/v3/auth/user/add"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// UserGet gets detailed user information.
|
||||
rpc UserGet(AuthUserGetRequest) returns (AuthUserGetResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/user/get"
|
||||
post: "/v3/auth/user/get"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// UserList gets a list of all users.
|
||||
rpc UserList(AuthUserListRequest) returns (AuthUserListResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/user/list"
|
||||
post: "/v3/auth/user/list"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// UserDelete deletes a specified user.
|
||||
rpc UserDelete(AuthUserDeleteRequest) returns (AuthUserDeleteResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/user/delete"
|
||||
post: "/v3/auth/user/delete"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// UserChangePassword changes the password of a specified user.
|
||||
rpc UserChangePassword(AuthUserChangePasswordRequest) returns (AuthUserChangePasswordResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/user/changepw"
|
||||
post: "/v3/auth/user/changepw"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// UserGrant grants a role to a specified user.
|
||||
rpc UserGrantRole(AuthUserGrantRoleRequest) returns (AuthUserGrantRoleResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/user/grant"
|
||||
post: "/v3/auth/user/grant"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// UserRevokeRole revokes a role of specified user.
|
||||
rpc UserRevokeRole(AuthUserRevokeRoleRequest) returns (AuthUserRevokeRoleResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/user/revoke"
|
||||
post: "/v3/auth/user/revoke"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// RoleAdd adds a new role.
|
||||
// RoleAdd adds a new role. Role name cannot be empty.
|
||||
rpc RoleAdd(AuthRoleAddRequest) returns (AuthRoleAddResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/role/add"
|
||||
post: "/v3/auth/role/add"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// RoleGet gets detailed role information.
|
||||
rpc RoleGet(AuthRoleGetRequest) returns (AuthRoleGetResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/role/get"
|
||||
post: "/v3/auth/role/get"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// RoleList gets lists of all roles.
|
||||
rpc RoleList(AuthRoleListRequest) returns (AuthRoleListResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/role/list"
|
||||
post: "/v3/auth/role/list"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// RoleDelete deletes a specified role.
|
||||
rpc RoleDelete(AuthRoleDeleteRequest) returns (AuthRoleDeleteResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/role/delete"
|
||||
post: "/v3/auth/role/delete"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// RoleGrantPermission grants a permission of a specified key or range to a specified role.
|
||||
rpc RoleGrantPermission(AuthRoleGrantPermissionRequest) returns (AuthRoleGrantPermissionResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/role/grant"
|
||||
post: "/v3/auth/role/grant"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// RoleRevokePermission revokes a key or range permission of a specified role.
|
||||
rpc RoleRevokePermission(AuthRoleRevokePermissionRequest) returns (AuthRoleRevokePermissionResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v3alpha/auth/role/revoke"
|
||||
post: "/v3/auth/role/revoke"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
@ -306,6 +343,9 @@ message ResponseHeader {
|
|||
// member_id is the ID of the member which sent the response.
|
||||
uint64 member_id = 2;
|
||||
// revision is the key-value store revision when the request was applied.
|
||||
// For watch progress responses, the header.revision indicates progress. All future events
|
||||
// recieved in this stream are guaranteed to have a higher revision number than the
|
||||
// header.revision number.
|
||||
int64 revision = 3;
|
||||
// raft_term is the raft term when the request was applied.
|
||||
uint64 raft_term = 4;
|
||||
|
@ -360,7 +400,7 @@ message RangeRequest {
|
|||
// greater mod revisions will be filtered away.
|
||||
int64 max_mod_revision = 11;
|
||||
// min_create_revision is the lower bound for returned key create revisions; all keys with
|
||||
// lesser create trevisions will be filtered away.
|
||||
// lesser create revisions will be filtered away.
|
||||
int64 min_create_revision = 12;
|
||||
// max_create_revision is the upper bound for returned key create revisions; all keys with
|
||||
// greater create revisions will be filtered away.
|
||||
|
@ -557,6 +597,7 @@ message WatchRequest {
|
|||
oneof request_union {
|
||||
WatchCreateRequest create_request = 1;
|
||||
WatchCancelRequest cancel_request = 2;
|
||||
WatchProgressRequest progress_request = 3;
|
||||
}
|
||||
}
|
||||
message WatchCreateRequest {
|
||||
|
@ -586,11 +627,23 @@ message WatchCreateRequest {
|
|||
// If prev_kv is set, created watcher gets the previous KV before the event happens.
|
||||
// If the previous KV is already compacted, nothing will be returned.
|
||||
bool prev_kv = 6;
|
||||
// If watch_id is provided and non-zero, it will be assigned to this watcher.
|
||||
// Since creating a watcher in etcd is not a synchronous operation,
|
||||
// this can be used ensure that ordering is correct when creating multiple
|
||||
// watchers on the same stream. Creating a watcher with an ID already in
|
||||
// use on the stream will cause an error to be returned.
|
||||
int64 watch_id = 7;
|
||||
// fragment enables splitting large revisions into multiple watch responses.
|
||||
bool fragment = 8;
|
||||
}
|
||||
message WatchCancelRequest {
|
||||
// watch_id is the watcher id to cancel so that no more events are transmitted.
|
||||
int64 watch_id = 1;
|
||||
}
|
||||
// Requests the a watch stream progress status be sent in the watch response stream as soon as
|
||||
// possible.
|
||||
message WatchProgressRequest {
|
||||
}
|
||||
message WatchResponse {
|
||||
ResponseHeader header = 1;
|
||||
// watch_id is the ID of the watcher that corresponds to the response.
|
||||
|
@ -614,10 +667,12 @@ message WatchResponse {
|
|||
int64 compact_revision = 5;
|
||||
// cancel_reason indicates the reason for canceling the watcher.
|
||||
string cancel_reason = 6;
|
||||
// framgment is true if large watch response was split over multiple responses.
|
||||
bool fragment = 7;
|
||||
repeated mvccpb.Event events = 11;
|
||||
}
|
||||
message LeaseGrantRequest {
|
||||
// TTL is the advisory time-to-live in seconds.
|
||||
// TTL is the advisory time-to-live in seconds. Expired lease will return -1.
|
||||
int64 TTL = 1;
|
||||
// ID is the requested ID for the lease. If ID is set to 0, the lessor chooses an ID.
|
||||
int64 ID = 2;
|
||||
|
@ -637,6 +692,18 @@ message LeaseRevokeRequest {
|
|||
message LeaseRevokeResponse {
|
||||
ResponseHeader header = 1;
|
||||
}
|
||||
message LeaseCheckpoint {
|
||||
// ID is the lease ID to checkpoint.
|
||||
int64 ID = 1;
|
||||
// Remaining_TTL is the remaining time until expiry of the lease.
|
||||
int64 remaining_TTL = 2;
|
||||
}
|
||||
message LeaseCheckpointRequest {
|
||||
repeated LeaseCheckpoint checkpoints = 1;
|
||||
}
|
||||
message LeaseCheckpointResponse {
|
||||
ResponseHeader header = 1;
|
||||
}
|
||||
message LeaseKeepAliveRequest {
|
||||
// ID is the lease ID for the lease to keep alive.
|
||||
int64 ID = 1;
|
||||
|
@ -684,10 +751,14 @@ message Member {
|
|||
repeated string peerURLs = 3;
|
||||
// clientURLs is the list of URLs the member exposes to clients for communication. If the member is not started, clientURLs will be empty.
|
||||
repeated string clientURLs = 4;
|
||||
// isLearner indicates if the member is raft learner.
|
||||
bool isLearner = 5;
|
||||
}
|
||||
message MemberAddRequest {
|
||||
// peerURLs is the list of URLs the added member will use to communicate with the cluster.
|
||||
repeated string peerURLs = 1;
|
||||
// isLearner indicates if the added member is raft learner.
|
||||
bool isLearner = 2;
|
||||
}
|
||||
message MemberAddResponse {
|
||||
ResponseHeader header = 1;
|
||||
|
@ -717,12 +788,22 @@ message MemberUpdateResponse{
|
|||
repeated Member members = 2;
|
||||
}
|
||||
message MemberListRequest {
|
||||
bool linearizable = 1;
|
||||
}
|
||||
message MemberListResponse {
|
||||
ResponseHeader header = 1;
|
||||
// members is a list of all members associated with the cluster.
|
||||
repeated Member members = 2;
|
||||
}
|
||||
message MemberPromoteRequest {
|
||||
// ID is the member ID of the member to promote.
|
||||
uint64 ID = 1;
|
||||
}
|
||||
message MemberPromoteResponse {
|
||||
ResponseHeader header = 1;
|
||||
// members is a list of all members after promoting the member.
|
||||
repeated Member members = 2;
|
||||
}
|
||||
message DefragmentRequest {
|
||||
}
|
||||
message DefragmentResponse {
|
||||
|
@ -767,25 +848,53 @@ message AlarmResponse {
|
|||
// alarms is a list of alarms associated with the alarm request.
|
||||
repeated AlarmMember alarms = 2;
|
||||
}
|
||||
message DowngradeRequest {
|
||||
enum DowngradeAction {
|
||||
Validate = 0;
|
||||
Enable = 1;
|
||||
Cancel = 2;
|
||||
}
|
||||
// action is the kind of downgrade request to issue. The action may
|
||||
// VALIDATE the target version, DOWNGRADE the cluster version,
|
||||
// or CANCEL the current downgrading job.
|
||||
DowngradeAction action = 1;
|
||||
// version is the target version to downgrade.
|
||||
string version = 2;
|
||||
}
|
||||
message DowngradeResponse {
|
||||
ResponseHeader header = 1;
|
||||
// version is the current cluster version.
|
||||
string version = 2;
|
||||
}
|
||||
message StatusRequest {
|
||||
}
|
||||
message StatusResponse {
|
||||
ResponseHeader header = 1;
|
||||
// version is the cluster protocol version used by the responding member.
|
||||
string version = 2;
|
||||
// dbSize is the size of the backend database, in bytes, of the responding member.
|
||||
// dbSize is the size of the backend database physically allocated, in bytes, of the responding member.
|
||||
int64 dbSize = 3;
|
||||
// leader is the member ID which the responding member believes is the current leader.
|
||||
uint64 leader = 4;
|
||||
// raftIndex is the current raft index of the responding member.
|
||||
// raftIndex is the current raft committed index of the responding member.
|
||||
uint64 raftIndex = 5;
|
||||
// raftTerm is the current raft term of the responding member.
|
||||
uint64 raftTerm = 6;
|
||||
// raftAppliedIndex is the current raft applied index of the responding member.
|
||||
uint64 raftAppliedIndex = 7;
|
||||
// errors contains alarm/health information and status.
|
||||
repeated string errors = 8;
|
||||
// dbSizeInUse is the size of the backend database logically in use, in bytes, of the responding member.
|
||||
int64 dbSizeInUse = 9;
|
||||
// isLearner indicates if the member is raft learner.
|
||||
bool isLearner = 10;
|
||||
}
|
||||
message AuthEnableRequest {
|
||||
}
|
||||
message AuthDisableRequest {
|
||||
}
|
||||
message AuthStatusRequest {
|
||||
}
|
||||
message AuthenticateRequest {
|
||||
string name = 1;
|
||||
string password = 2;
|
||||
|
@ -793,6 +902,7 @@ message AuthenticateRequest {
|
|||
message AuthUserAddRequest {
|
||||
string name = 1;
|
||||
string password = 2;
|
||||
authpb.UserAddOptions options = 3;
|
||||
}
|
||||
message AuthUserGetRequest {
|
||||
string name = 1;
|
||||
|
@ -839,8 +949,8 @@ message AuthRoleGrantPermissionRequest {
|
|||
}
|
||||
message AuthRoleRevokePermissionRequest {
|
||||
string role = 1;
|
||||
string key = 2;
|
||||
string range_end = 3;
|
||||
bytes key = 2;
|
||||
bytes range_end = 3;
|
||||
}
|
||||
message AuthEnableResponse {
|
||||
ResponseHeader header = 1;
|
||||
|
@ -848,6 +958,12 @@ message AuthEnableResponse {
|
|||
message AuthDisableResponse {
|
||||
ResponseHeader header = 1;
|
||||
}
|
||||
message AuthStatusResponse {
|
||||
ResponseHeader header = 1;
|
||||
bool enabled = 2;
|
||||
// authRevision is the current revision of auth store
|
||||
uint64 authRevision = 3;
|
||||
}
|
||||
message AuthenticateResponse {
|
||||
ResponseHeader header = 1;
|
||||
// token is an authorized token that can be used in succeeding RPCs
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
import * as grpc from 'grpc';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
import { Range } from './range';
|
||||
import { AuthClient, Permission } from './rpc';
|
||||
|
@ -69,8 +69,8 @@ export class Role {
|
|||
return this.client
|
||||
.roleRevokePermission({
|
||||
role: this.name,
|
||||
key: range.start.toString(),
|
||||
range_end: range.end.toString(),
|
||||
key: range.start,
|
||||
range_end: range.end,
|
||||
})
|
||||
.then(() => this);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
import * as grpc from 'grpc';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
import { Rangable, Range } from './range';
|
||||
import * as RPC from './rpc';
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
import { loadSync } from '@grpc/proto-loader';
|
||||
import * as grpc from 'grpc';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
import { ExponentialBackoff } from './backoff/exponential';
|
||||
import { castGrpcError, EtcdInvalidAuthTokenError, GRPCGenericError } from './errors';
|
||||
import { ChannelOptions } from './grpcTypes';
|
||||
import { IOptions } from './options';
|
||||
import { ICallable, Services } from './rpc';
|
||||
import { SharedPool } from './shared-pool';
|
||||
import { forOwn } from './util';
|
||||
import { ChannelOptions } from '@grpc/grpc-js/build/src/channel-options';
|
||||
|
||||
const packageDefinition = loadSync(`${__dirname}/../proto/rpc.proto`, {
|
||||
keepCase: true,
|
||||
|
@ -50,7 +50,7 @@ function runServiceCall(
|
|||
payload: unknown,
|
||||
): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
(client as any)[method](payload, metadata, options, (err: Error | null, res: any) => {
|
||||
(client as any)[method](payload, metadata, options || {}, (err: Error | null, res: any) => {
|
||||
if (err) {
|
||||
reject(castGrpcError(err));
|
||||
} else {
|
||||
|
|
|
@ -212,6 +212,7 @@ type IErrorCtor = new (message: string) => Error;
|
|||
const grpcMessageToError = new Map<string, IErrorCtor>([
|
||||
['Connect Failed', GRPCConnectFailedError],
|
||||
['Channel Disconnected', GRPCConnectFailedError],
|
||||
['No connection established', GRPCConnectFailedError],
|
||||
['failed to connect to all addresses', GRPCConnectFailedError],
|
||||
['Endpoint read failed', GRPCProtocolError],
|
||||
['Got config after disconnection', GRPCProtocolError],
|
||||
|
|
347
src/grpcTypes.ts
347
src/grpcTypes.ts
|
@ -1,347 +0,0 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
import * as grpc from 'grpc';
|
||||
|
||||
/**
|
||||
* ChannelOptions may be passed into the Client to configure GRPC internals.
|
||||
*/
|
||||
// tslint:disable-next-line: interface-name
|
||||
export interface ChannelOptions {
|
||||
/**
|
||||
* If non-zero, allow the use of SO_REUSEPORT if it's available (default 1)
|
||||
*/
|
||||
'grpc.so_reuseport'?: number;
|
||||
|
||||
/**
|
||||
* Default authority to pass if none specified on call construction.
|
||||
*/
|
||||
'grpc.default_authority'?: string;
|
||||
|
||||
/**
|
||||
* If non-zero, enable census for tracing and stats collection.
|
||||
*/
|
||||
'grpc.census'?: number;
|
||||
|
||||
/**
|
||||
* Enable/disable support for deadline checking.
|
||||
*
|
||||
* Defaults to 1, unless GRPC_ARG_MINIMAL_STACK is enabled
|
||||
* in which case it defaults to 0
|
||||
*/
|
||||
'grpc.enable_deadline_checking'?: number;
|
||||
|
||||
/**
|
||||
* If non-zero, enable load reporting.
|
||||
*/
|
||||
'grpc.loadreporting'?: number;
|
||||
|
||||
/**
|
||||
* Enable/disable support for per-message compression.
|
||||
*
|
||||
* Defaults to 1, unless GRPC_ARG_MINIMAL_STACK is enabled, in which
|
||||
* case it defaults to 0.
|
||||
*/
|
||||
'grpc.per_message_compression'?: number;
|
||||
|
||||
/**
|
||||
* If non-zero, expand wildcard addresses to a list of local addresses.
|
||||
*/
|
||||
'grpc.expand_wildcard_addrs'?: number;
|
||||
|
||||
/**
|
||||
* (Not Documented)
|
||||
*/
|
||||
'grpc.grpclb_timeout_ms'?: number;
|
||||
|
||||
/**
|
||||
* Should BDP probing be performed?
|
||||
*/
|
||||
'grpc.http2.bdp_probe'?: number;
|
||||
|
||||
/**
|
||||
* Should we allow receipt of true-binary data on http2 connections
|
||||
* Defaults to on (1)
|
||||
*/
|
||||
'grpc.http2.true_binary'?: number;
|
||||
|
||||
/**
|
||||
* How much memory to use for hpack decoding.
|
||||
*
|
||||
* Int valued, bytes.
|
||||
*/
|
||||
'grpc.http2.hpack_table_size.decoder'?: number;
|
||||
|
||||
/**
|
||||
* How much memory to use for hpack encoding.
|
||||
*
|
||||
* Int valued, bytes.
|
||||
*/
|
||||
'grpc.http2.hpack_table_size.encoder'?: number;
|
||||
|
||||
/**
|
||||
* Initial stream ID for http2 transports.
|
||||
*
|
||||
* Int valued.
|
||||
*/
|
||||
'grpc.http2.initial_sequence_number'?: number;
|
||||
|
||||
/**
|
||||
* How big a frame are we willing to receive via HTTP2.
|
||||
*
|
||||
* Min 16384, max 16777215. Larger values give lower CPU usage for large
|
||||
* messages, but more head of line blocking for small messages.
|
||||
*/
|
||||
'grpc.http2.max_frame_size'?: number;
|
||||
|
||||
/**
|
||||
* How many misbehaving pings the server can bear before sending goaway and
|
||||
* closing the transport? (0 indicates that the server can bear an infinit
|
||||
* number of misbehaving pings)
|
||||
*/
|
||||
'grpc.http2.max_ping_strikes'?: number;
|
||||
|
||||
/**
|
||||
* How many pings can we send before needing to send a data frame or header
|
||||
* frame? (0 indicates that an infinite number of pings can be sent without
|
||||
* sending a data frame or header frame)
|
||||
*/
|
||||
'grpc.http2.max_pings_without_data'?: number;
|
||||
|
||||
/**
|
||||
* Minimum allowed time between two pings without sending any data frame.
|
||||
*
|
||||
* Int valued, seconds
|
||||
*/
|
||||
'grpc.http2.min_ping_interval_without_data_ms'?: number;
|
||||
|
||||
/**
|
||||
* Minimum time (in milliseconds) between successive ping frames being sent.
|
||||
*/
|
||||
'grpc.http2.min_time_between_pings_ms'?: number;
|
||||
|
||||
/**
|
||||
* Channel arg to override the http2 :scheme header.
|
||||
*/
|
||||
'grpc.http2_scheme'?: string;
|
||||
|
||||
/**
|
||||
* Amount to read ahead on individual streams.
|
||||
*
|
||||
* Defaults to 64kb, larger values can help throughput on high-latency
|
||||
* connections. NOTE: at some point we'd like to auto-tune this,
|
||||
* and this parameter will become a no-op. Int valued, bytes.
|
||||
*/
|
||||
'grpc.http2.lookahead_bytes'?: number;
|
||||
|
||||
/**
|
||||
* How much data are we willing to queue up per stream i
|
||||
* GRPC_WRITE_BUFFER_HINT is set? This is an upper bound.
|
||||
*/
|
||||
'grpc.http2.write_buffer_size'?: number;
|
||||
|
||||
/**
|
||||
* The time between the first and second connection attempts, in ms.
|
||||
*/
|
||||
'grpc.initial_reconnect_backoff_ms'?: number;
|
||||
|
||||
/**
|
||||
* Is it permissible to send keepalive pings without any outstanding streams.
|
||||
*
|
||||
* Int valued, 0(false)/1(true).
|
||||
*/
|
||||
'grpc.keepalive_permit_without_calls'?: number;
|
||||
|
||||
/**
|
||||
* After a duration of this time the client/server pings its peer to
|
||||
* see if the transport is still alive.
|
||||
*
|
||||
* Int valued, milliseconds.
|
||||
*/
|
||||
'grpc.keepalive_time_ms'?: number;
|
||||
|
||||
/**
|
||||
* After waiting for a duration of this time, if the keepalive ping sender
|
||||
* does not receive the ping ack, it will close the transport.
|
||||
*
|
||||
* Int valued, milliseconds.
|
||||
*/
|
||||
'grpc.keepalive_timeout_ms'?: number;
|
||||
|
||||
/**
|
||||
* LB policy name.
|
||||
*/
|
||||
'grpc.lb_policy_name'?: string;
|
||||
|
||||
/**
|
||||
* Maximum number of concurrent incoming streams to allow on a http2 connection.
|
||||
*
|
||||
* Int valued.
|
||||
*/
|
||||
'grpc.max_concurrent_streams'?: number;
|
||||
|
||||
/**
|
||||
* Grace period after the chennel reaches its max age.
|
||||
*
|
||||
* Int valued, milliseconds. INT_MAX means unlimited.
|
||||
*/
|
||||
'grpc.max_connection_age_grace_ms'?: number;
|
||||
|
||||
/**
|
||||
* Maximum time that a channel may exist.
|
||||
*
|
||||
* Int valued, milliseconds. INT_MAX means unlimited.
|
||||
*/
|
||||
'grpc.max_connection_age_ms'?: number;
|
||||
|
||||
/**
|
||||
* Maximum time that a channel may have no outstanding rpcs.
|
||||
*
|
||||
* Int valued, milliseconds. INT_MAX means unlimited.
|
||||
*/
|
||||
'grpc.max_connection_idle_ms'?: number;
|
||||
|
||||
/**
|
||||
* Maximum metadata size, in bytes.
|
||||
*
|
||||
* Note this limit applies to the max sum of all metadata key-value
|
||||
* entries in a batch of headers.
|
||||
*/
|
||||
'grpc.max_metadata_size'?: number;
|
||||
|
||||
/**
|
||||
* Maximum message length that the channel can receive.
|
||||
*
|
||||
* Int valued, bytes. -1 means unlimited.
|
||||
*/
|
||||
'grpc.max_receive_message_length'?: number;
|
||||
|
||||
/**
|
||||
* The maximum time between subsequent connection attempts, in ms.
|
||||
*/
|
||||
'grpc.max_reconnect_backoff_ms'?: number;
|
||||
|
||||
/**
|
||||
* Maximum message length that the channel can send.
|
||||
*
|
||||
* Int valued, bytes. -1 means unlimited.
|
||||
*/
|
||||
'grpc.max_send_message_length'?: number;
|
||||
|
||||
/**
|
||||
* The minimum time between subsequent connection attempts, in ms.
|
||||
*/
|
||||
'grpc.min_reconnect_backoff_ms'?: number;
|
||||
|
||||
/**
|
||||
* Request that optional features default to off (regardless of what they
|
||||
* usually default to) - to enable tight control over what gets enabled.
|
||||
*/
|
||||
'grpc.minimal_stack'?: boolean;
|
||||
|
||||
/**
|
||||
* String defining the optimization target for a channel.
|
||||
*
|
||||
* Can be:
|
||||
* "latency" - attempt to minimize latency at the cost of throughput
|
||||
* "blend" - try to balance latency and throughput
|
||||
* "throughput" - attempt to maximize throughput at the expense of latency
|
||||
*
|
||||
* Defaults to "blend". In the current implementation "blend"
|
||||
* is equivalent to "latency".
|
||||
*/
|
||||
'grpc.optimization_target'?: 'latency' | 'blend' | 'throughput';
|
||||
|
||||
/**
|
||||
* Primary user agent: goes at the start of the user-agent metadata sent on each request.
|
||||
*/
|
||||
'grpc.primary_user_agent'?: string;
|
||||
|
||||
/**
|
||||
* Secondary user agent: goes at the end of the user-agent metadata sent on each request.
|
||||
*/
|
||||
'grpc.secondary_user_agent'?: string;
|
||||
|
||||
/**
|
||||
* Service config data in JSON form.
|
||||
*
|
||||
* This value will be ignored if the name resolver returns a service config.
|
||||
*/
|
||||
'grpc.service_config'?: string;
|
||||
|
||||
/**
|
||||
* Disable looking up the service config via the name resolver.
|
||||
*/
|
||||
'grpc.service_config_disable_resolution'?: boolean;
|
||||
|
||||
/**
|
||||
* (Not Documented)
|
||||
*/
|
||||
'grpc.experimental.tcp_max_read_chunk_size'?: number;
|
||||
|
||||
/**
|
||||
* (Not Documented)
|
||||
*/
|
||||
'grpc.experimental.tcp_min_read_chunk_size'?: number;
|
||||
|
||||
/**
|
||||
* Channel arg (integer) setting how large a slice to try and read from the wire each time recvmsg (or equivalent) is called.
|
||||
*/
|
||||
'grpc.experimental.tcp_read_chunk_size'?: number;
|
||||
|
||||
/**
|
||||
* If non-zero, Cronet transport will coalesce packets to fewer frames when possible.
|
||||
*/
|
||||
'grpc.use_cronet_packet_coalescing'?: number;
|
||||
|
||||
/**
|
||||
* If non-zero, grpc server's cronet compression workaround will be enabled.
|
||||
*/
|
||||
'grpc.workaround.cronet_compression'?: number;
|
||||
|
||||
/**
|
||||
* Default compression algorithm for the channel.
|
||||
*
|
||||
* Its value is an int from the grpc_compression_algorithm enum.
|
||||
*/
|
||||
'grpc.default_compression_algorithm'?: number;
|
||||
|
||||
/**
|
||||
* Default compression level for the channel.
|
||||
*
|
||||
* Its value is an int from the grpc_compression_level enum.
|
||||
* @see https://grpc.io/grpc/cpp/compression__types_8h.html#a14a79ed6b5ebd7e1dda7c2684f499cc7
|
||||
*/
|
||||
'grpc.default_compression_level'?: number;
|
||||
|
||||
/**
|
||||
* Compression algorithms supported by the channel.
|
||||
*
|
||||
* Its value is a bitset (an int). Bits correspond to algorithms in
|
||||
* grpc_compression_algorithm. For example, its LSB corresponds to
|
||||
* GRPC_COMPRESS_NONE, the next bit to GRPC_COMPRESS_DEFLATE, etc. Unset bits
|
||||
* disable support for the algorithm. By default all algorithms are
|
||||
* supported. It's not possible to disable GRPC_COMPRESS_NONE
|
||||
* (the attempt will be ignored).
|
||||
*/
|
||||
'grpc.compression_enabled_algorithms_bitset'?: number;
|
||||
|
||||
/**
|
||||
* This should be used for testing only.
|
||||
*
|
||||
* The caller of the secure_channel_create functions may override the target
|
||||
* name used for SSL host name checking using this channel argument which is
|
||||
* of type GRPC_ARG_STRING. If this argument is not specified, the name used
|
||||
* for SSL host name checking will be the target parameter (assuming that the
|
||||
* secure channel is an SSL channel). If this parameter is specified and the
|
||||
* underlying is not an SSL channel, it will just be ignored.
|
||||
*/
|
||||
'grpc.ssl_target_name_override'?: string;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line: interface-name
|
||||
export interface StatusMessage {
|
||||
code: number;
|
||||
details: string;
|
||||
metadata: grpc.Metadata;
|
||||
}
|
|
@ -17,7 +17,6 @@ export * from './options';
|
|||
export * from './range';
|
||||
export * from './rpc';
|
||||
export * from './stm';
|
||||
export * from './grpcTypes';
|
||||
export { WatchBuilder, Watcher } from './watch';
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
import { EventEmitter } from 'events';
|
||||
import * as grpc from 'grpc';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
import { PutBuilder } from './builder';
|
||||
import { ConnectionPool, Host } from './connection-pool';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
import * as grpc from 'grpc';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
import { ComparatorBuilder, PutBuilder } from './builder';
|
||||
import { ConnectionPool } from './connection-pool';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
import * as grpc from 'grpc';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
import * as Builder from './builder';
|
||||
import { ConnectionPool, defaultBackoffStrategy } from './connection-pool';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
import { ChannelOptions } from './grpcTypes';
|
||||
import { ChannelOptions } from '@grpc/grpc-js/build/src/channel-options';
|
||||
|
||||
import { IBackoffStrategy } from './backoff/backoff';
|
||||
|
||||
|
|
236
src/rpc.ts
236
src/rpc.ts
|
@ -4,8 +4,9 @@
|
|||
|
||||
// AUTOGENERATED CODE, DO NOT EDIT
|
||||
|
||||
import * as grpc from 'grpc';
|
||||
import { StatusMessage } from './grpcTypes';
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
export interface ICallable<T> {
|
||||
exec<T>(
|
||||
|
@ -25,7 +26,7 @@ export interface ICallable<T> {
|
|||
export interface IResponseStream<T> {
|
||||
on(event: 'data', fn: (item: T) => void): this;
|
||||
on(event: 'end', fn: () => void): this;
|
||||
on(event: 'status', fn: (status: StatusMessage) => void): this;
|
||||
on(event: 'status', fn: (status: grpc.StatusObject) => void): this;
|
||||
on(event: 'error', fn: (err: Error) => void): this;
|
||||
}
|
||||
|
||||
|
@ -189,8 +190,20 @@ export class ClusterClient {
|
|||
/**
|
||||
* MemberList lists all the members in the cluster.
|
||||
*/
|
||||
public memberList(options?: grpc.CallOptions): Promise<IMemberListResponse> {
|
||||
return this.client.exec('Cluster', 'memberList', {}, options);
|
||||
public memberList(
|
||||
req: IMemberListRequest,
|
||||
options?: grpc.CallOptions,
|
||||
): Promise<IMemberListResponse> {
|
||||
return this.client.exec('Cluster', 'memberList', req, options);
|
||||
}
|
||||
/**
|
||||
* MemberPromote promotes a member from raft learner (non-voting) to raft voting member.
|
||||
*/
|
||||
public memberPromote(
|
||||
req: IMemberPromoteRequest,
|
||||
options?: grpc.CallOptions,
|
||||
): Promise<IMemberPromoteResponse> {
|
||||
return this.client.exec('Cluster', 'memberPromote', req, options);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,15 +228,19 @@ export class MaintenanceClient {
|
|||
return this.client.exec('Maintenance', 'defragment', {}, options);
|
||||
}
|
||||
/**
|
||||
* Hash computes the hash of the KV's backend.
|
||||
* This is designed for testing; do not use this in production when there
|
||||
* are ongoing transactions.
|
||||
* Hash computes the hash of whole backend keyspace,
|
||||
* including key, lease, and other buckets in storage.
|
||||
* This is designed for testing ONLY!
|
||||
* Do not rely on this in production with ongoing transactions,
|
||||
* since Hash operation does not hold MVCC locks.
|
||||
* Use "HashKV" API instead for "key" bucket consistency checks.
|
||||
*/
|
||||
public hash(options?: grpc.CallOptions): Promise<IHashResponse> {
|
||||
return this.client.exec('Maintenance', 'hash', {}, options);
|
||||
}
|
||||
/**
|
||||
* HashKV computes the hash of all MVCC keys up to a given revision.
|
||||
* It only iterates "key" bucket in backend storage.
|
||||
*/
|
||||
public hashKV(req: IHashKVRequest, options?: grpc.CallOptions): Promise<IHashKVResponse> {
|
||||
return this.client.exec('Maintenance', 'hashKV', req, options);
|
||||
|
@ -248,6 +265,15 @@ export class MaintenanceClient {
|
|||
): Promise<IMoveLeaderResponse> {
|
||||
return this.client.exec('Maintenance', 'moveLeader', req, options);
|
||||
}
|
||||
/**
|
||||
* Downgrade requests downgrade, cancel downgrade on the cluster version.
|
||||
*/
|
||||
public downgrade(
|
||||
req: IDowngradeRequest,
|
||||
options?: grpc.CallOptions,
|
||||
): Promise<IDowngradeResponse> {
|
||||
return this.client.exec('Maintenance', 'downgrade', req, options);
|
||||
}
|
||||
}
|
||||
|
||||
export class AuthClient {
|
||||
|
@ -264,6 +290,12 @@ export class AuthClient {
|
|||
public authDisable(options?: grpc.CallOptions): Promise<IAuthDisableResponse> {
|
||||
return this.client.exec('Auth', 'authDisable', {}, options);
|
||||
}
|
||||
/**
|
||||
* AuthStatus displays authentication status.
|
||||
*/
|
||||
public authStatus(options?: grpc.CallOptions): Promise<IAuthStatusResponse> {
|
||||
return this.client.exec('Auth', 'authStatus', {}, options);
|
||||
}
|
||||
/**
|
||||
* Authenticate processes an authenticate request.
|
||||
*/
|
||||
|
@ -274,7 +306,7 @@ export class AuthClient {
|
|||
return this.client.exec('Auth', 'authenticate', req, options);
|
||||
}
|
||||
/**
|
||||
* UserAdd adds a new user.
|
||||
* UserAdd adds a new user. User name cannot be empty.
|
||||
*/
|
||||
public userAdd(
|
||||
req: IAuthUserAddRequest,
|
||||
|
@ -334,7 +366,7 @@ export class AuthClient {
|
|||
return this.client.exec('Auth', 'userRevokeRole', req, options);
|
||||
}
|
||||
/**
|
||||
* RoleAdd adds a new role.
|
||||
* RoleAdd adds a new role. Role name cannot be empty.
|
||||
*/
|
||||
public roleAdd(
|
||||
req: IAuthRoleAddRequest,
|
||||
|
@ -397,6 +429,9 @@ export interface IResponseHeader {
|
|||
member_id: string;
|
||||
/**
|
||||
* revision is the key-value store revision when the request was applied.
|
||||
* For watch progress responses, the header.revision indicates progress. All future events
|
||||
* recieved in this stream are guaranteed to have a higher revision number than the
|
||||
* header.revision number.
|
||||
*/
|
||||
revision: string;
|
||||
/**
|
||||
|
@ -486,7 +521,7 @@ export interface IRangeRequest {
|
|||
max_mod_revision?: string | number;
|
||||
/**
|
||||
* min_create_revision is the lower bound for returned key create revisions; all keys with
|
||||
* lesser create trevisions will be filtered away.
|
||||
* lesser create revisions will be filtered away.
|
||||
*/
|
||||
min_create_revision?: string | number;
|
||||
/**
|
||||
|
@ -687,6 +722,7 @@ export interface ICompactionRequest {
|
|||
export interface ICompactionResponse {
|
||||
header: IResponseHeader;
|
||||
}
|
||||
export interface IHashRequest {}
|
||||
export interface IHashKVRequest {
|
||||
/**
|
||||
* revision is the key-value store revision for the hash operation.
|
||||
|
@ -711,6 +747,7 @@ export interface IHashResponse {
|
|||
*/
|
||||
hash: string;
|
||||
}
|
||||
export interface ISnapshotRequest {}
|
||||
export interface ISnapshotResponse {
|
||||
/**
|
||||
* header has the current key-value store information. The first header in the snapshot
|
||||
|
@ -729,6 +766,7 @@ export interface ISnapshotResponse {
|
|||
export interface IWatchRequest {
|
||||
create_request?: IWatchCreateRequest;
|
||||
cancel_request?: IWatchCancelRequest;
|
||||
progress_request?: IWatchProgressRequest;
|
||||
}
|
||||
export enum FilterType {
|
||||
/**
|
||||
|
@ -773,6 +811,18 @@ export interface IWatchCreateRequest {
|
|||
* If the previous KV is already compacted, nothing will be returned.
|
||||
*/
|
||||
prev_kv?: boolean;
|
||||
/**
|
||||
* If watch_id is provided and non-zero, it will be assigned to this watcher.
|
||||
* Since creating a watcher in etcd is not a synchronous operation,
|
||||
* this can be used ensure that ordering is correct when creating multiple
|
||||
* watchers on the same stream. Creating a watcher with an ID already in
|
||||
* use on the stream will cause an error to be returned.
|
||||
*/
|
||||
watch_id?: string | number;
|
||||
/**
|
||||
* fragment enables splitting large revisions into multiple watch responses.
|
||||
*/
|
||||
fragment?: boolean;
|
||||
}
|
||||
export interface IWatchCancelRequest {
|
||||
/**
|
||||
|
@ -780,6 +830,7 @@ export interface IWatchCancelRequest {
|
|||
*/
|
||||
watch_id?: string | number;
|
||||
}
|
||||
export interface IWatchProgressRequest {}
|
||||
export interface IWatchResponse {
|
||||
header: IResponseHeader;
|
||||
/**
|
||||
|
@ -798,16 +849,30 @@ export interface IWatchResponse {
|
|||
* No further events will be sent to the canceled watcher.
|
||||
*/
|
||||
canceled: boolean;
|
||||
/**
|
||||
* compact_revision is set to the minimum index if a watcher tries to watch
|
||||
* at a compacted index.
|
||||
*
|
||||
* This happens when creating a watcher at a compacted revision or the watcher cannot
|
||||
* 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
|
||||
* watcher with the same start_revision again.
|
||||
*/
|
||||
compact_revision: string;
|
||||
/**
|
||||
* cancel_reason indicates the reason for canceling the watcher.
|
||||
*/
|
||||
cancel_reason: string;
|
||||
/**
|
||||
* framgment is true if large watch response was split over multiple responses.
|
||||
*/
|
||||
fragment: boolean;
|
||||
events: IEvent[];
|
||||
}
|
||||
export interface ILeaseGrantRequest {
|
||||
/**
|
||||
* TTL is the advisory time-to-live in seconds.
|
||||
* TTL is the advisory time-to-live in seconds. Expired lease will return -1.
|
||||
*/
|
||||
TTL?: string | number;
|
||||
/**
|
||||
|
@ -836,6 +901,22 @@ export interface ILeaseRevokeRequest {
|
|||
export interface ILeaseRevokeResponse {
|
||||
header: IResponseHeader;
|
||||
}
|
||||
export interface ILeaseCheckpoint {
|
||||
/**
|
||||
* ID is the lease ID to checkpoint.
|
||||
*/
|
||||
ID?: string | number;
|
||||
/**
|
||||
* Remaining_TTL is the remaining time until expiry of the lease.
|
||||
*/
|
||||
remaining_TTL?: string | number;
|
||||
}
|
||||
export interface ILeaseCheckpointRequest {
|
||||
checkpoints?: ILeaseCheckpoint[];
|
||||
}
|
||||
export interface ILeaseCheckpointResponse {
|
||||
header?: IResponseHeader;
|
||||
}
|
||||
export interface ILeaseKeepAliveRequest {
|
||||
/**
|
||||
* ID is the lease ID for the lease to keep alive.
|
||||
|
@ -882,6 +963,7 @@ export interface ILeaseTimeToLiveResponse {
|
|||
*/
|
||||
keys: Buffer[];
|
||||
}
|
||||
export interface ILeaseLeasesRequest {}
|
||||
export interface ILeaseStatus {
|
||||
ID: string;
|
||||
}
|
||||
|
@ -906,12 +988,20 @@ export interface IMember {
|
|||
* clientURLs is the list of URLs the member exposes to clients for communication. If the member is not started, clientURLs will be empty.
|
||||
*/
|
||||
clientURLs: string[];
|
||||
/**
|
||||
* isLearner indicates if the member is raft learner.
|
||||
*/
|
||||
isLearner: boolean;
|
||||
}
|
||||
export interface IMemberAddRequest {
|
||||
/**
|
||||
* peerURLs is the list of URLs the added member will use to communicate with the cluster.
|
||||
*/
|
||||
peerURLs?: string[];
|
||||
/**
|
||||
* isLearner indicates if the added member is raft learner.
|
||||
*/
|
||||
isLearner?: boolean;
|
||||
}
|
||||
export interface IMemberAddResponse {
|
||||
header: IResponseHeader;
|
||||
|
@ -954,6 +1044,9 @@ export interface IMemberUpdateResponse {
|
|||
*/
|
||||
members: IMember[];
|
||||
}
|
||||
export interface IMemberListRequest {
|
||||
linearizable?: boolean;
|
||||
}
|
||||
export interface IMemberListResponse {
|
||||
header: IResponseHeader;
|
||||
/**
|
||||
|
@ -961,6 +1054,20 @@ export interface IMemberListResponse {
|
|||
*/
|
||||
members: IMember[];
|
||||
}
|
||||
export interface IMemberPromoteRequest {
|
||||
/**
|
||||
* ID is the member ID of the member to promote.
|
||||
*/
|
||||
ID?: string | number;
|
||||
}
|
||||
export interface IMemberPromoteResponse {
|
||||
header: IResponseHeader;
|
||||
/**
|
||||
* members is a list of all members after promoting the member.
|
||||
*/
|
||||
members: IMember[];
|
||||
}
|
||||
export interface IDefragmentRequest {}
|
||||
export interface IDefragmentResponse {
|
||||
header: IResponseHeader;
|
||||
}
|
||||
|
@ -1026,6 +1133,31 @@ export interface IAlarmResponse {
|
|||
*/
|
||||
alarms: IAlarmMember[];
|
||||
}
|
||||
export enum DowngradeAction {
|
||||
Validate = 0,
|
||||
Enable = 1,
|
||||
Cancel = 2,
|
||||
}
|
||||
export interface IDowngradeRequest {
|
||||
/**
|
||||
* action is the kind of downgrade request to issue. The action may
|
||||
* VALIDATE the target version, DOWNGRADE the cluster version,
|
||||
* or CANCEL the current downgrading job.
|
||||
*/
|
||||
action?: DowngradeAction | keyof typeof DowngradeAction;
|
||||
/**
|
||||
* version is the target version to downgrade.
|
||||
*/
|
||||
version?: string;
|
||||
}
|
||||
export interface IDowngradeResponse {
|
||||
header: IResponseHeader;
|
||||
/**
|
||||
* version is the current cluster version.
|
||||
*/
|
||||
version: string;
|
||||
}
|
||||
export interface IStatusRequest {}
|
||||
export interface IStatusResponse {
|
||||
header: IResponseHeader;
|
||||
/**
|
||||
|
@ -1033,7 +1165,7 @@ export interface IStatusResponse {
|
|||
*/
|
||||
version: string;
|
||||
/**
|
||||
* dbSize is the size of the backend database, in bytes, of the responding member.
|
||||
* dbSize is the size of the backend database physically allocated, in bytes, of the responding member.
|
||||
*/
|
||||
dbSize: string;
|
||||
/**
|
||||
|
@ -1041,14 +1173,33 @@ export interface IStatusResponse {
|
|||
*/
|
||||
leader: string;
|
||||
/**
|
||||
* raftIndex is the current raft index of the responding member.
|
||||
* raftIndex is the current raft committed index of the responding member.
|
||||
*/
|
||||
raftIndex: string;
|
||||
/**
|
||||
* raftTerm is the current raft term of the responding member.
|
||||
*/
|
||||
raftTerm: string;
|
||||
/**
|
||||
* raftAppliedIndex is the current raft applied index of the responding member.
|
||||
*/
|
||||
raftAppliedIndex: string;
|
||||
/**
|
||||
* errors contains alarm/health information and status.
|
||||
*/
|
||||
errors: string[];
|
||||
/**
|
||||
* dbSizeInUse is the size of the backend database logically in use, in bytes, of the responding member.
|
||||
*/
|
||||
dbSizeInUse: string;
|
||||
/**
|
||||
* isLearner indicates if the member is raft learner.
|
||||
*/
|
||||
isLearner: boolean;
|
||||
}
|
||||
export interface IAuthEnableRequest {}
|
||||
export interface IAuthDisableRequest {}
|
||||
export interface IAuthStatusRequest {}
|
||||
export interface IAuthenticateRequest {
|
||||
name?: string;
|
||||
password?: string;
|
||||
|
@ -1056,6 +1207,7 @@ export interface IAuthenticateRequest {
|
|||
export interface IAuthUserAddRequest {
|
||||
name?: string;
|
||||
password?: string;
|
||||
options?: IUserAddOptions;
|
||||
}
|
||||
export interface IAuthUserGetRequest {
|
||||
name?: string;
|
||||
|
@ -1099,6 +1251,8 @@ export interface IAuthRoleAddRequest {
|
|||
export interface IAuthRoleGetRequest {
|
||||
role?: string;
|
||||
}
|
||||
export interface IAuthUserListRequest {}
|
||||
export interface IAuthRoleListRequest {}
|
||||
export interface IAuthRoleDeleteRequest {
|
||||
role?: string;
|
||||
}
|
||||
|
@ -1114,8 +1268,8 @@ export interface IAuthRoleGrantPermissionRequest {
|
|||
}
|
||||
export interface IAuthRoleRevokePermissionRequest {
|
||||
role?: string;
|
||||
key?: string;
|
||||
range_end?: string;
|
||||
key?: Buffer;
|
||||
range_end?: Buffer;
|
||||
}
|
||||
export interface IAuthEnableResponse {
|
||||
header: IResponseHeader;
|
||||
|
@ -1123,6 +1277,14 @@ export interface IAuthEnableResponse {
|
|||
export interface IAuthDisableResponse {
|
||||
header: IResponseHeader;
|
||||
}
|
||||
export interface IAuthStatusResponse {
|
||||
header: IResponseHeader;
|
||||
enabled: boolean;
|
||||
/**
|
||||
* authRevision is the current revision of auth store
|
||||
*/
|
||||
authRevision: string;
|
||||
}
|
||||
export interface IAuthenticateResponse {
|
||||
header: IResponseHeader;
|
||||
/**
|
||||
|
@ -1173,25 +1335,6 @@ export interface IAuthRoleGrantPermissionResponse {
|
|||
export interface IAuthRoleRevokePermissionResponse {
|
||||
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 {
|
||||
/**
|
||||
* key is the first key for the range. If range_end is not given, the request only looks up key.
|
||||
|
@ -1230,6 +1373,29 @@ export interface IEvent {
|
|||
*/
|
||||
prev_kv: IKeyValue;
|
||||
}
|
||||
export interface IUserAddOptions {
|
||||
no_password?: boolean;
|
||||
}
|
||||
export interface IUser {
|
||||
name?: Buffer;
|
||||
password?: Buffer;
|
||||
roles?: string[];
|
||||
options?: IUserAddOptions;
|
||||
}
|
||||
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 = {
|
||||
KV: KVClient,
|
||||
Watch: WatchClient,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as grpc from 'grpc';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
import * as Builder from './builder';
|
||||
import { ClientRuntimeError, STMConflictError } from './errors';
|
||||
|
@ -89,12 +89,17 @@ function keyValueToResponse(key: string | Buffer, value?: Buffer): RPC.IRangeRes
|
|||
} as any;
|
||||
}
|
||||
|
||||
interface CompletedReads {
|
||||
key: Buffer;
|
||||
res: RPC.IRangeResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* ReadSet records a set of reads in a SoftwareTransaction.
|
||||
*/
|
||||
class ReadSet {
|
||||
private readonly reads: { [key: string]: Promise<RPC.IRangeResponse> } = Object.create(null);
|
||||
private readonly completedReads: { key: Buffer; res: RPC.IRangeResponse }[] = [];
|
||||
private readonly completedReads: CompletedReads[] = [];
|
||||
private earliestMod = new BigNumber(Infinity);
|
||||
|
||||
/**
|
||||
|
|
|
@ -151,7 +151,9 @@ describe('lease()', () => {
|
|||
let clock: sinon.SinonFakeTimers;
|
||||
|
||||
beforeEach(async () => {
|
||||
clock = sinon.useFakeTimers();
|
||||
clock = sinon.useFakeTimers({
|
||||
shouldAdvanceTime: true,
|
||||
});
|
||||
lease = client.lease(60);
|
||||
await onceEvent(lease, 'keepaliveEstablished');
|
||||
});
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
import { expect } from 'chai';
|
||||
import * as grpc from 'grpc';
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
|
||||
import {
|
||||
Etcd3,
|
||||
|
|
|
@ -211,6 +211,6 @@ export async function createTestKeys(client: Namespace) {
|
|||
* Destroys the etcd client and wipes all keys.
|
||||
*/
|
||||
export async function tearDownTestClient(client: Etcd3) {
|
||||
await client.delete().all();
|
||||
await client?.delete().all();
|
||||
client.close();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче