rpc.proto 15 KB

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