rpc.proto 8.9 KB

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