rpc.proto 16 KB

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