rpc.proto 16 KB

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