rpc.proto 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. message ResponseHeader {
  62. uint64 cluster_id = 1;
  63. uint64 member_id = 2;
  64. // revision of the store when the request was applied.
  65. int64 revision = 3;
  66. // term of raft when the request was applied.
  67. uint64 raft_term = 4;
  68. }
  69. message RangeRequest {
  70. enum SortOrder {
  71. NONE = 0; // default, no sorting
  72. ASCEND = 1; // lowest target value first
  73. DESCEND = 2; // highest target value first
  74. }
  75. enum SortTarget {
  76. KEY = 0;
  77. VERSION = 1;
  78. CREATE = 2;
  79. MOD = 3;
  80. VALUE = 4;
  81. }
  82. // if the range_end is not given, the request returns the key.
  83. bytes key = 1;
  84. // if the range_end is given, it gets the keys in range [key, range_end).
  85. bytes range_end = 2;
  86. // limit the number of keys returned.
  87. int64 limit = 3;
  88. // range over the store at the given revision.
  89. // if revision is less or equal to zero, range over the newest store.
  90. // if the revision has been compacted, ErrCompaction will be returned in
  91. // response.
  92. int64 revision = 4;
  93. // sort_order is the requested order for returned the results
  94. SortOrder sort_order = 5;
  95. // sort_target is the kv field to use for sorting
  96. SortTarget sort_target = 6;
  97. }
  98. message RangeResponse {
  99. ResponseHeader header = 1;
  100. repeated storagepb.KeyValue kvs = 2;
  101. // more indicates if there are more keys to return in the requested range.
  102. bool more = 3;
  103. }
  104. message PutRequest {
  105. bytes key = 1;
  106. bytes value = 2;
  107. int64 lease = 3;
  108. }
  109. message PutResponse {
  110. ResponseHeader header = 1;
  111. }
  112. message DeleteRangeRequest {
  113. // if the range_end is not given, the request deletes the key.
  114. bytes key = 1;
  115. // if the range_end is given, it deletes the keys in range [key, range_end).
  116. bytes range_end = 2;
  117. }
  118. message DeleteRangeResponse {
  119. ResponseHeader header = 1;
  120. }
  121. message RequestUnion {
  122. oneof request {
  123. RangeRequest request_range = 1;
  124. PutRequest request_put = 2;
  125. DeleteRangeRequest request_delete_range = 3;
  126. }
  127. }
  128. message ResponseUnion {
  129. oneof response {
  130. RangeResponse response_range = 1;
  131. PutResponse response_put = 2;
  132. DeleteRangeResponse response_delete_range = 3;
  133. }
  134. }
  135. message Compare {
  136. enum CompareResult {
  137. EQUAL = 0;
  138. GREATER = 1;
  139. LESS = 2;
  140. }
  141. enum CompareTarget {
  142. VERSION = 0;
  143. CREATE = 1;
  144. MOD = 2;
  145. VALUE= 3;
  146. }
  147. CompareResult result = 1;
  148. CompareTarget target = 2;
  149. // key path
  150. bytes key = 3;
  151. oneof target_union {
  152. // version of the given key
  153. int64 version = 4;
  154. // create revision of the given key
  155. int64 create_revision = 5;
  156. // last modified revision of the given key
  157. int64 mod_revision = 6;
  158. // value of the given key
  159. bytes value = 7;
  160. }
  161. }
  162. // If the comparisons succeed, then the success requests will be processed in order,
  163. // and the response will contain their respective responses in order.
  164. // If the comparisons fail, then the failure requests will be processed in order,
  165. // and the response will contain their respective responses in order.
  166. // From google paxosdb paper:
  167. // Our implementation hinges around a powerful primitive which we call MultiOp. All other database
  168. // operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically
  169. // and consists of three components:
  170. // 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check
  171. // for the absence or presence of a value, or compare with a given value. Two different tests in the guard
  172. // may apply to the same or different entries in the database. All tests in the guard are applied and
  173. // MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise
  174. // it executes f op (see item 3 below).
  175. // 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or
  176. // lookup operation, and applies to a single database entry. Two different operations in the list may apply
  177. // to the same or different entries in the database. These operations are executed
  178. // if guard evaluates to
  179. // true.
  180. // 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false.
  181. message TxnRequest {
  182. repeated Compare compare = 1;
  183. repeated RequestUnion success = 2;
  184. repeated RequestUnion failure = 3;
  185. }
  186. message TxnResponse {
  187. ResponseHeader header = 1;
  188. bool succeeded = 2;
  189. repeated ResponseUnion responses = 3;
  190. }
  191. // Compaction compacts the kv store upto the given revision (including).
  192. // It removes the old versions of a key. It keeps the newest version of
  193. // the key even if its latest modification revision is smaller than the given
  194. // revision.
  195. message CompactionRequest {
  196. int64 revision = 1;
  197. }
  198. message CompactionResponse {
  199. ResponseHeader header = 1;
  200. }
  201. message HashRequest {
  202. }
  203. message HashResponse {
  204. uint32 hash = 1;
  205. }
  206. message WatchRequest {
  207. oneof request_union {
  208. WatchCreateRequest create_request = 1;
  209. WatchCancelRequest cancel_request = 2;
  210. }
  211. }
  212. message WatchCreateRequest {
  213. // the key to be watched
  214. bytes key = 1;
  215. // the prefix to be watched.
  216. bytes prefix = 2;
  217. // start_revision is an optional revision (including) to watch from. No start_revision is "now".
  218. int64 start_revision = 3;
  219. // TODO: support Range watch?
  220. }
  221. message WatchCancelRequest {
  222. int64 watch_id = 1;
  223. }
  224. message WatchResponse {
  225. ResponseHeader header = 1;
  226. // watch_id is the ID of the watching the response sent to.
  227. int64 watch_id = 2;
  228. // If the response is for a create watch request, created is set to true.
  229. // Client should record the watch_id and prepare for receiving events for
  230. // that watching from the same stream.
  231. // All events sent to the created watching will attach with the same watch_id.
  232. bool created = 3;
  233. // If the response is for a cancel watch request, cancel is set to true.
  234. // No further events will be sent to the canceled watching.
  235. bool canceled = 4;
  236. // If a watching tries to watch at a compacted index, compacted will be set to true.
  237. //
  238. // This happens when creating a watching at a compacted revision or the watching cannot
  239. // catch up with the progress of the KV.
  240. //
  241. // Client should treat the watching as canceled and should not try to create any
  242. // watching with same start_revision again.
  243. bool compacted = 5;
  244. repeated storagepb.Event events = 11;
  245. }
  246. message LeaseCreateRequest {
  247. // advisory ttl in seconds
  248. int64 TTL = 1;
  249. // requested ID to create; 0 lets lessor choose
  250. int64 ID = 2;
  251. }
  252. message LeaseCreateResponse {
  253. ResponseHeader header = 1;
  254. int64 ID = 2;
  255. // server decided ttl in second
  256. int64 TTL = 3;
  257. string error = 4;
  258. }
  259. message LeaseRevokeRequest {
  260. int64 ID = 1;
  261. }
  262. message LeaseRevokeResponse {
  263. ResponseHeader header = 1;
  264. }
  265. message LeaseKeepAliveRequest {
  266. int64 ID = 1;
  267. }
  268. message LeaseKeepAliveResponse {
  269. ResponseHeader header = 1;
  270. int64 ID = 2;
  271. int64 TTL = 3;
  272. }
  273. message Member {
  274. uint64 ID = 1;
  275. // If the member is not started, name will be an empty string.
  276. string name = 2;
  277. repeated string peerURLs = 3;
  278. // If the member is not started, client_URLs will be an zero length
  279. // string array.
  280. repeated string clientURLs = 4;
  281. }
  282. message MemberAddRequest {
  283. repeated string peerURLs = 1;
  284. }
  285. message MemberAddResponse {
  286. ResponseHeader header = 1;
  287. Member member = 2;
  288. }
  289. message MemberRemoveRequest {
  290. uint64 ID = 1;
  291. }
  292. message MemberRemoveResponse {
  293. ResponseHeader header = 1;
  294. }
  295. message MemberUpdateRequest {
  296. uint64 ID = 1;
  297. repeated string peerURLs = 2;
  298. }
  299. message MemberUpdateResponse{
  300. ResponseHeader header = 1;
  301. }
  302. message MemberListRequest {
  303. }
  304. message MemberListResponse {
  305. ResponseHeader header = 1;
  306. repeated Member members = 2;
  307. }