rpc.proto 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. syntax = "proto3";
  2. package etcdserverpb;
  3. import "gogoproto/gogo.proto";
  4. import "etcd/storage/storagepb/kv.proto";
  5. import "etcd/auth/authpb/auth.proto";
  6. option (gogoproto.marshaler_all) = true;
  7. option (gogoproto.unmarshaler_all) = true;
  8. service KV {
  9. // Range gets the keys in the range from the store.
  10. rpc Range(RangeRequest) returns (RangeResponse) {}
  11. // Put puts the given key into the store.
  12. // A put request increases the revision of the store,
  13. // and generates one event in the event history.
  14. rpc Put(PutRequest) returns (PutResponse) {}
  15. // Delete deletes the given range from the store.
  16. // A delete request increase the revision of the store,
  17. // and generates one event in the event history.
  18. rpc DeleteRange(DeleteRangeRequest) returns (DeleteRangeResponse) {}
  19. // Txn processes all the requests in one transaction.
  20. // A txn request increases the revision of the store,
  21. // and generates events with the same revision in the event history.
  22. // It is not allowed to modify the same key several times within one txn.
  23. rpc Txn(TxnRequest) returns (TxnResponse) {}
  24. // Compact compacts the event history in etcd. User should compact the
  25. // event history periodically, or it will grow infinitely.
  26. rpc Compact(CompactionRequest) returns (CompactionResponse) {}
  27. }
  28. service Watch {
  29. // Watch watches the events happening or happened. Both input and output
  30. // are stream. One watch rpc can watch for multiple keys or prefixs and
  31. // get a stream of events. The whole events history can be watched unless
  32. // compacted.
  33. rpc Watch(stream WatchRequest) returns (stream WatchResponse) {}
  34. }
  35. service Lease {
  36. // LeaseGrant creates a lease. A lease has a TTL. The lease will expire if the
  37. // server does not receive a keepAlive within TTL from the lease holder.
  38. // All keys attached to the lease will be expired and deleted if the lease expires.
  39. // The key expiration generates an event in event history.
  40. rpc LeaseGrant(LeaseGrantRequest) returns (LeaseGrantResponse) {}
  41. // LeaseRevoke revokes a lease. All the key attached to the lease will be expired and deleted.
  42. rpc LeaseRevoke(LeaseRevokeRequest) returns (LeaseRevokeResponse) {}
  43. // KeepAlive keeps the lease alive.
  44. rpc LeaseKeepAlive(stream LeaseKeepAliveRequest) returns (stream LeaseKeepAliveResponse) {}
  45. // TODO(xiangli) List all existing Leases?
  46. // TODO(xiangli) Get details information (expirations, leased keys, etc.) of a lease?
  47. }
  48. service Cluster {
  49. // MemberAdd adds a member into the cluster.
  50. rpc MemberAdd(MemberAddRequest) returns (MemberAddResponse) {}
  51. // MemberRemove removes an existing member from the cluster.
  52. rpc MemberRemove(MemberRemoveRequest) returns (MemberRemoveResponse) {}
  53. // MemberUpdate updates the member configuration.
  54. rpc MemberUpdate(MemberUpdateRequest) returns (MemberUpdateResponse) {}
  55. // MemberList lists all the members in the cluster.
  56. rpc MemberList(MemberListRequest) returns (MemberListResponse) {}
  57. }
  58. service Maintenance {
  59. // Alarm activates, deactivates, and queries alarms regarding cluster health.
  60. rpc Alarm(AlarmRequest) returns (AlarmResponse) {}
  61. // Status gets the status of the member.
  62. rpc Status(StatusRequest) returns (StatusResponse) {}
  63. rpc Defragment(DefragmentRequest) returns (DefragmentResponse) {}
  64. // Hash returns the hash of the local KV state for consistency checking purpose.
  65. // This is designed for testing; do not use this in production when there
  66. // are ongoing transactions.
  67. rpc Hash(HashRequest) returns (HashResponse) {}
  68. // Snapshot sends a snapshot of the entire backend
  69. rpc Snapshot(SnapshotRequest) returns (stream SnapshotResponse) {}
  70. }
  71. service Auth {
  72. // AuthEnable enables authentication.
  73. rpc AuthEnable(AuthEnableRequest) returns (AuthEnableResponse) {}
  74. // AuthDisable disables authentication.
  75. rpc AuthDisable(AuthDisableRequest) returns (AuthDisableResponse) {}
  76. // Authenticate processes authenticate request.
  77. rpc Authenticate(AuthenticateRequest) returns (AuthenticateResponse) {}
  78. // UserAdd adds a new user.
  79. rpc UserAdd(AuthUserAddRequest) returns (AuthUserAddResponse) {}
  80. // UserGet gets a detailed information of a user or lists entire users.
  81. rpc UserGet(AuthUserGetRequest) returns (AuthUserGetResponse) {}
  82. // UserDelete deletes a specified user.
  83. rpc UserDelete(AuthUserDeleteRequest) returns (AuthUserDeleteResponse) {}
  84. // UserChangePassword changes password of a specified user.
  85. rpc UserChangePassword(AuthUserChangePasswordRequest) returns (AuthUserChangePasswordResponse) {}
  86. // UserGrant grants a role to a specified user.
  87. rpc UserGrant(AuthUserGrantRequest) returns (AuthUserGrantResponse) {}
  88. // UserRevoke revokes a role of specified user.
  89. rpc UserRevoke(AuthUserRevokeRequest) returns (AuthUserRevokeResponse) {}
  90. // RoleAdd adds a new role.
  91. rpc RoleAdd(AuthRoleAddRequest) returns (AuthRoleAddResponse) {}
  92. // RoleGet gets a detailed information of a role or lists entire roles.
  93. rpc RoleGet(AuthRoleGetRequest) returns (AuthRoleGetResponse) {}
  94. // RoleDelete deletes a specified role.
  95. rpc RoleDelete(AuthRoleDeleteRequest) returns (AuthRoleDeleteResponse) {}
  96. // RoleGrant grants a permission of a specified key or range to a specified role.
  97. rpc RoleGrant(AuthRoleGrantRequest) returns (AuthRoleGrantResponse) {}
  98. // RoleRevoke revokes a key or range permission of a specified role.
  99. rpc RoleRevoke(AuthRoleRevokeRequest) returns (AuthRoleRevokeResponse) {}
  100. }
  101. message ResponseHeader {
  102. uint64 cluster_id = 1;
  103. uint64 member_id = 2;
  104. // revision of the store when the request was applied.
  105. int64 revision = 3;
  106. // term of raft when the request was applied.
  107. uint64 raft_term = 4;
  108. }
  109. message RangeRequest {
  110. enum SortOrder {
  111. NONE = 0; // default, no sorting
  112. ASCEND = 1; // lowest target value first
  113. DESCEND = 2; // highest target value first
  114. }
  115. enum SortTarget {
  116. KEY = 0;
  117. VERSION = 1;
  118. CREATE = 2;
  119. MOD = 3;
  120. VALUE = 4;
  121. }
  122. // if the range_end is not given, the request returns the key.
  123. bytes key = 1;
  124. // if the range_end is given, it gets the keys in range [key, range_end)
  125. // if range_end is nonempty, otherwise it returns all keys >= key.
  126. bytes range_end = 2;
  127. // limit the number of keys returned.
  128. int64 limit = 3;
  129. // range over the store at the given revision.
  130. // if revision is less or equal to zero, range over the newest store.
  131. // if the revision has been compacted, ErrCompaction will be returned in
  132. // response.
  133. int64 revision = 4;
  134. // sort_order is the requested order for returned the results
  135. SortOrder sort_order = 5;
  136. // sort_target is the kv field to use for sorting
  137. SortTarget sort_target = 6;
  138. // range request is linearizable by default. Linearizable requests has a higher
  139. // latency and lower throughput than serializable request.
  140. // To reduce latency, serializable can be set. If serializable is set, range request
  141. // will be serializable, but not linearizable with other requests.
  142. // Serializable range can be served locally without waiting for other nodes in the cluster.
  143. bool serializable = 7;
  144. }
  145. message RangeResponse {
  146. ResponseHeader header = 1;
  147. repeated storagepb.KeyValue kvs = 2;
  148. // more indicates if there are more keys to return in the requested range.
  149. bool more = 3;
  150. }
  151. message PutRequest {
  152. bytes key = 1;
  153. bytes value = 2;
  154. int64 lease = 3;
  155. }
  156. message PutResponse {
  157. ResponseHeader header = 1;
  158. }
  159. message DeleteRangeRequest {
  160. // if the range_end is not given, the request deletes the key.
  161. bytes key = 1;
  162. // if the range_end is given, it deletes the keys in range [key, range_end).
  163. bytes range_end = 2;
  164. }
  165. message DeleteRangeResponse {
  166. ResponseHeader header = 1;
  167. // Deleted is the number of keys that got deleted.
  168. int64 deleted = 2;
  169. }
  170. message RequestUnion {
  171. oneof request {
  172. RangeRequest request_range = 1;
  173. PutRequest request_put = 2;
  174. DeleteRangeRequest request_delete_range = 3;
  175. }
  176. }
  177. message ResponseUnion {
  178. oneof response {
  179. RangeResponse response_range = 1;
  180. PutResponse response_put = 2;
  181. DeleteRangeResponse response_delete_range = 3;
  182. }
  183. }
  184. message Compare {
  185. enum CompareResult {
  186. EQUAL = 0;
  187. GREATER = 1;
  188. LESS = 2;
  189. }
  190. enum CompareTarget {
  191. VERSION = 0;
  192. CREATE = 1;
  193. MOD = 2;
  194. VALUE= 3;
  195. }
  196. CompareResult result = 1;
  197. CompareTarget target = 2;
  198. // key path
  199. bytes key = 3;
  200. oneof target_union {
  201. // version of the given key
  202. int64 version = 4;
  203. // create revision of the given key
  204. int64 create_revision = 5;
  205. // last modified revision of the given key
  206. int64 mod_revision = 6;
  207. // value of the given key
  208. bytes value = 7;
  209. }
  210. }
  211. // If the comparisons succeed, then the success requests will be processed in order,
  212. // and the response will contain their respective responses in order.
  213. // If the comparisons fail, then the failure requests will be processed in order,
  214. // and the response will contain their respective responses in order.
  215. // From google paxosdb paper:
  216. // Our implementation hinges around a powerful primitive which we call MultiOp. All other database
  217. // operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically
  218. // and consists of three components:
  219. // 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check
  220. // for the absence or presence of a value, or compare with a given value. Two different tests in the guard
  221. // may apply to the same or different entries in the database. All tests in the guard are applied and
  222. // MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise
  223. // it executes f op (see item 3 below).
  224. // 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or
  225. // lookup operation, and applies to a single database entry. Two different operations in the list may apply
  226. // to the same or different entries in the database. These operations are executed
  227. // if guard evaluates to
  228. // true.
  229. // 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false.
  230. message TxnRequest {
  231. repeated Compare compare = 1;
  232. repeated RequestUnion success = 2;
  233. repeated RequestUnion failure = 3;
  234. }
  235. message TxnResponse {
  236. ResponseHeader header = 1;
  237. bool succeeded = 2;
  238. repeated ResponseUnion responses = 3;
  239. }
  240. // Compaction compacts the kv store upto the given revision (including).
  241. // It removes the old versions of a key. It keeps the newest version of
  242. // the key even if its latest modification revision is smaller than the given
  243. // revision.
  244. message CompactionRequest {
  245. int64 revision = 1;
  246. // physical is set so the RPC will wait until the compaction is physically
  247. // applied to the local database such that compacted entries are totally
  248. // removed from the backing store.
  249. bool physical = 2;
  250. }
  251. message CompactionResponse {
  252. ResponseHeader header = 1;
  253. }
  254. message HashRequest {
  255. }
  256. message HashResponse {
  257. ResponseHeader header = 1;
  258. uint32 hash = 2;
  259. }
  260. message SnapshotRequest {
  261. }
  262. message SnapshotResponse {
  263. // header has the current store information. The first header in the snapshot
  264. // stream indicates the point in time of the snapshot.
  265. ResponseHeader header = 1;
  266. // remaining_bytes is the number of blob bytes to be sent after this message
  267. uint64 remaining_bytes = 2;
  268. // blob has the next chunk of the snapshot in the snapshot stream.
  269. bytes blob = 3;
  270. }
  271. message WatchRequest {
  272. oneof request_union {
  273. WatchCreateRequest create_request = 1;
  274. WatchCancelRequest cancel_request = 2;
  275. }
  276. }
  277. message WatchCreateRequest {
  278. // the key to be watched
  279. bytes key = 1;
  280. // if the range_end is given, keys in [key, range_end) are watched
  281. // NOTE: only range_end == prefixEnd(key) is accepted now
  282. bytes range_end = 2;
  283. // start_revision is an optional revision (including) to watch from. No start_revision is "now".
  284. int64 start_revision = 3;
  285. // if progress_notify is set, etcd server sends WatchResponse with empty events to the
  286. // created watcher when there are no recent events. It is useful when clients want always to be
  287. // able to recover a disconnected watcher from a recent known revision.
  288. // etcdsever can decide how long it should send a notification based on current load.
  289. bool progress_notify = 4;
  290. }
  291. message WatchCancelRequest {
  292. int64 watch_id = 1;
  293. }
  294. message WatchResponse {
  295. ResponseHeader header = 1;
  296. // watch_id is the ID of the watching the response sent to.
  297. int64 watch_id = 2;
  298. // If the response is for a create watch request, created is set to true.
  299. // Client should record the watch_id and prepare for receiving events for
  300. // that watching from the same stream.
  301. // All events sent to the created watching will attach with the same watch_id.
  302. bool created = 3;
  303. // If the response is for a cancel watch request, cancel is set to true.
  304. // No further events will be sent to the canceled watching.
  305. bool canceled = 4;
  306. // CompactRevision is set to the minimum index if a watching tries to watch
  307. // at a compacted index.
  308. //
  309. // This happens when creating a watching at a compacted revision or the watching cannot
  310. // catch up with the progress of the KV.
  311. //
  312. // Client should treat the watching as canceled and should not try to create any
  313. // watching with same start_revision again.
  314. int64 compact_revision = 5;
  315. repeated storagepb.Event events = 11;
  316. }
  317. message LeaseGrantRequest {
  318. // advisory ttl in seconds
  319. int64 TTL = 1;
  320. // requested ID to create; 0 lets lessor choose
  321. int64 ID = 2;
  322. }
  323. message LeaseGrantResponse {
  324. ResponseHeader header = 1;
  325. int64 ID = 2;
  326. // server decided ttl in second
  327. int64 TTL = 3;
  328. string error = 4;
  329. }
  330. message LeaseRevokeRequest {
  331. int64 ID = 1;
  332. }
  333. message LeaseRevokeResponse {
  334. ResponseHeader header = 1;
  335. }
  336. message LeaseKeepAliveRequest {
  337. int64 ID = 1;
  338. }
  339. message LeaseKeepAliveResponse {
  340. ResponseHeader header = 1;
  341. int64 ID = 2;
  342. int64 TTL = 3;
  343. }
  344. message Member {
  345. uint64 ID = 1;
  346. // If the member is not started, name will be an empty string.
  347. string name = 2;
  348. bool IsLeader = 3;
  349. repeated string peerURLs = 4;
  350. // If the member is not started, client_URLs will be an zero length
  351. // string array.
  352. repeated string clientURLs = 5;
  353. }
  354. message MemberAddRequest {
  355. repeated string peerURLs = 1;
  356. }
  357. message MemberAddResponse {
  358. ResponseHeader header = 1;
  359. Member member = 2;
  360. }
  361. message MemberRemoveRequest {
  362. uint64 ID = 1;
  363. }
  364. message MemberRemoveResponse {
  365. ResponseHeader header = 1;
  366. }
  367. message MemberUpdateRequest {
  368. uint64 ID = 1;
  369. repeated string peerURLs = 2;
  370. }
  371. message MemberUpdateResponse{
  372. ResponseHeader header = 1;
  373. }
  374. message MemberListRequest {
  375. }
  376. message MemberListResponse {
  377. ResponseHeader header = 1;
  378. repeated Member members = 2;
  379. }
  380. message DefragmentRequest {
  381. }
  382. message DefragmentResponse {
  383. ResponseHeader header = 1;
  384. }
  385. enum AlarmType {
  386. NONE = 0; // default, used to query if any alarm is active
  387. NOSPACE = 1;
  388. }
  389. message AlarmRequest {
  390. enum AlarmAction {
  391. GET = 0;
  392. ACTIVATE = 1;
  393. DEACTIVATE = 2;
  394. }
  395. AlarmAction action = 1;
  396. // MemberID is the member raising the alarm request
  397. uint64 memberID = 2;
  398. AlarmType alarm = 3;
  399. }
  400. message AlarmMember {
  401. uint64 memberID = 1;
  402. AlarmType alarm = 2;
  403. }
  404. message AlarmResponse {
  405. ResponseHeader header = 1;
  406. repeated AlarmMember alarms = 2;
  407. }
  408. message StatusRequest {
  409. }
  410. message StatusResponse {
  411. ResponseHeader header = 1;
  412. string version = 2;
  413. int64 dbSize = 3;
  414. uint64 leader = 4;
  415. uint64 raftIndex = 5;
  416. uint64 raftTerm = 6;
  417. }
  418. message AuthEnableRequest {
  419. }
  420. message AuthDisableRequest {
  421. }
  422. message AuthenticateRequest {
  423. }
  424. message AuthUserAddRequest {
  425. string name = 1;
  426. string password = 2;
  427. }
  428. message AuthUserGetRequest {
  429. }
  430. message AuthUserDeleteRequest {
  431. string name = 1;
  432. }
  433. message AuthUserChangePasswordRequest {
  434. string name = 1;
  435. string password = 2;
  436. }
  437. message AuthUserGrantRequest {
  438. string user = 1;
  439. string role = 2;
  440. }
  441. message AuthUserRevokeRequest {
  442. }
  443. message AuthRoleAddRequest {
  444. string name = 1;
  445. }
  446. message AuthRoleGetRequest {
  447. }
  448. message AuthRoleDeleteRequest {
  449. }
  450. message AuthRoleGrantRequest {
  451. string name = 1;
  452. authpb.Permission perm = 2;
  453. }
  454. message AuthRoleRevokeRequest {
  455. }
  456. message AuthEnableResponse {
  457. ResponseHeader header = 1;
  458. }
  459. message AuthDisableResponse {
  460. ResponseHeader header = 1;
  461. }
  462. message AuthenticateResponse {
  463. ResponseHeader header = 1;
  464. }
  465. message AuthUserAddResponse {
  466. ResponseHeader header = 1;
  467. }
  468. message AuthUserGetResponse {
  469. ResponseHeader header = 1;
  470. }
  471. message AuthUserDeleteResponse {
  472. ResponseHeader header = 1;
  473. }
  474. message AuthUserChangePasswordResponse {
  475. ResponseHeader header = 1;
  476. }
  477. message AuthUserGrantResponse {
  478. ResponseHeader header = 1;
  479. }
  480. message AuthUserRevokeResponse {
  481. ResponseHeader header = 1;
  482. }
  483. message AuthRoleAddResponse {
  484. ResponseHeader header = 1;
  485. }
  486. message AuthRoleGetResponse {
  487. ResponseHeader header = 1;
  488. }
  489. message AuthRoleDeleteResponse {
  490. ResponseHeader header = 1;
  491. }
  492. message AuthRoleGrantResponse {
  493. ResponseHeader header = 1;
  494. }
  495. message AuthRoleRevokeResponse {
  496. ResponseHeader header = 1;
  497. }