v3api.proto 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. syntax = "proto3";
  2. // Interface exported by the server.
  3. service etcd {
  4. // Range gets the keys in the range from the store.
  5. rpc Range(RangeRequest) returns (RangeResponse) {}
  6. // Put puts the given key into the store.
  7. // A put request increases the index of the store,
  8. // and generates one event in the event history.
  9. rpc Put(PutRequest) returns (PutResponse) {}
  10. // Delete deletes the given range from the store.
  11. // A delete request increase the index of the store,
  12. // and generates one event in the event history.
  13. rpc DeleteRange(DeleteRangeRequest) returns (DeleteRangeResponse) {}
  14. // Txn processes all the requests in one transaction.
  15. // A txn request increases the index of the store,
  16. // and generates events with the same index in the event history.
  17. rpc Txn(TxnRequest) returns (TxnResponse) {}
  18. // Watch watches the events happening or happened in etcd. Both input and output
  19. // are stream. One watch rpc can watch for multiple ranges and get a stream of
  20. // events. The whole events history can be watched unless compacted.
  21. rpc WatchRange(stream WatchRangeRequest) returns (stream WatchRangeResponse) {}
  22. // Compact compacts the event history in etcd. User should compact the
  23. // event history periodically, or it will grow infinitely.
  24. rpc Compact(CompactionRequest) returns (CompactionResponse) {}
  25. // LeaseCreate creates a lease. A lease has a TTL. The lease will expire if the
  26. // server does not receive a keepAlive within TTL from the lease holder.
  27. // All keys attached to the lease will be expired and deleted if the lease expires.
  28. // The key expiration generates an event in event history.
  29. rpc LeaseCreate(LeaseCreateRequest) returns (LeaseCreateResponse) {}
  30. // LeaseRevoke revokes a lease. All the key attached to the lease will be expired and deleted.
  31. rpc LeaseRevoke(LeaseRevokeRequest) returns (LeaseRevokeResponse) {}
  32. // LeaseAttach attaches keys with a lease.
  33. rpc LeaseAttach(LeaseAttachRequest) returns (LeaseAttachResponse) {}
  34. // LeaseTxn likes Txn. It has two addition success and failure LeaseAttachRequest list.
  35. // If the Txn is successful, then the success list will be executed. Or the failure list
  36. // will be executed.
  37. rpc LeaseTxn(LeaseTxnRequest) returns (LeaseTxnResponse) {}
  38. // KeepAlive keeps the lease alive.
  39. rpc LeaseKeepAlive(stream LeaseKeepAliveRequest) returns (stream LeaseKeepAliveResponse) {}
  40. }
  41. message ResponseHeader {
  42. // an error type message?
  43. string error = 1;
  44. uint64 cluster_id = 2;
  45. uint64 member_id = 3;
  46. // index of the store when the request was applied.
  47. int64 index = 4;
  48. // term of raft when the request was applied.
  49. uint64 raft_term = 5;
  50. }
  51. message RangeRequest {
  52. // if the range_end is not given, the request returns the key.
  53. bytes key = 1;
  54. // if the range_end is given, it gets the keys in range [key, range_end).
  55. bytes range_end = 2;
  56. // limit the number of keys returned.
  57. int64 limit = 3;
  58. // the response will be consistent with previous request with same token if the token is
  59. // given and is valid.
  60. bytes consistent_token = 4;
  61. }
  62. message RangeResponse {
  63. ResponseHeader header = 1;
  64. repeated storagepb.KeyValue kvs = 2;
  65. bytes consistent_token = 3;
  66. // more indicates if there are more keys to return in the requested range.
  67. bool more = 4;
  68. }
  69. message PutRequest {
  70. bytes key = 1;
  71. bytes value = 2;
  72. }
  73. message PutResponse {
  74. ResponseHeader header = 1;
  75. }
  76. message DeleteRangeRequest {
  77. // if the range_end is not given, the request deletes the key.
  78. bytes key = 1;
  79. // if the range_end is given, it deletes the keys in range [key, range_end).
  80. bytes range_end = 2;
  81. }
  82. message DeleteRangeResponse {
  83. ResponseHeader header = 1;
  84. }
  85. message RequestUnion {
  86. oneof request {
  87. RangeRequest request_range = 1;
  88. PutRequest request_put = 2;
  89. DeleteRangeRequest request_delete_range = 3;
  90. }
  91. }
  92. message ResponseUnion {
  93. oneof response {
  94. RangeResponse response_range = 1;
  95. PutResponse response_put = 2;
  96. DeleteRangeResponse response_delete_range = 3;
  97. }
  98. }
  99. message Compare {
  100. enum CompareResult {
  101. EQUAL = 0;
  102. GREATER = 1;
  103. LESS = 2;
  104. }
  105. enum CompareTarget {
  106. VERSION = 0;
  107. CREATE = 1;
  108. MOD = 2;
  109. VALUE= 3;
  110. }
  111. CompareResult result = 1;
  112. CompareTarget target = 2;
  113. // key path
  114. bytes key = 3;
  115. oneof target_union {
  116. // version of the given key
  117. int64 version = 4;
  118. // create index of the given key
  119. int64 create_index = 5;
  120. // last modified index of the given key
  121. int64 mod_index = 6;
  122. // value of the given key
  123. bytes value = 7;
  124. }
  125. }
  126. // If the comparisons succeed, then the success requests will be processed in order,
  127. // and the response will contain their respective responses in order.
  128. // If the comparisons fail, then the failure requests will be processed in order,
  129. // and the response will contain their respective responses in order.
  130. // From google paxosdb paper:
  131. // Our implementation hinges around a powerful primitive which we call MultiOp. All other database
  132. // operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically
  133. // and consists of three components:
  134. // 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check
  135. // for the absence or presence of a value, or compare with a given value. Two different tests in the guard
  136. // may apply to the same or different entries in the database. All tests in the guard are applied and
  137. // MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise
  138. // it executes f op (see item 3 below).
  139. // 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or
  140. // lookup operation, and applies to a single database entry. Two different operations in the list may apply
  141. // to the same or different entries in the database. These operations are executed
  142. // if guard evaluates to
  143. // true.
  144. // 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false.
  145. message TxnRequest {
  146. repeated Compare compare = 1;
  147. repeated RequestUnion success = 2;
  148. repeated RequestUnion failure = 3;
  149. }
  150. message TxnResponse {
  151. ResponseHeader header = 1;
  152. bool succeeded = 2;
  153. repeated ResponseUnion responses = 3;
  154. }
  155. message KeyValue {
  156. bytes key = 1;
  157. int64 create_index = 2;
  158. // mod_index is the last modified index of the key.
  159. int64 mod_index = 3;
  160. // version is the version of the key. A deletion resets
  161. // the version to zero and any modification of the key
  162. // increases its version.
  163. int64 version = 4;
  164. bytes value = 5;
  165. }
  166. message WatchRangeRequest {
  167. // if the range_end is not given, the request returns the key.
  168. bytes key = 1;
  169. // if the range_end is given, it gets the keys in range [key, range_end).
  170. bytes range_end = 2;
  171. // start_index is an optional index (including) to watch from. No start_index is "now".
  172. int64 start_index = 3;
  173. // end_index is an optional index (excluding) to end watch. No end_index is "forever".
  174. int64 end_index = 4;
  175. bool progress_notification = 5;
  176. }
  177. message WatchRangeResponse {
  178. ResponseHeader header = 1;
  179. repeated Event events = 2;
  180. }
  181. message Event {
  182. enum EventType {
  183. PUT = 0;
  184. DELETE = 1;
  185. EXPIRE = 2;
  186. }
  187. EventType event_type = 1;
  188. // a put event contains the current key-value
  189. // a delete/expire event contains the previous
  190. // key-value
  191. KeyValue kv = 2;
  192. }
  193. // Compaction compacts the kv store upto the given index (including).
  194. // It removes the old versions of a key. It keeps the newest version of
  195. // the key even if its latest modification index is smaller than the given
  196. // index.
  197. message CompactionRequest {
  198. int64 index = 1;
  199. }
  200. message CompactionResponse {
  201. ResponseHeader header = 1;
  202. }
  203. message LeaseCreateRequest {
  204. // advisory ttl in seconds
  205. int64 ttl = 1;
  206. }
  207. message LeaseCreateResponse {
  208. ResponseHeader header = 1;
  209. int64 lease_id = 2;
  210. // server decided ttl in second
  211. int64 ttl = 3;
  212. string error = 4;
  213. }
  214. message LeaseRevokeRequest {
  215. int64 lease_id = 1;
  216. }
  217. message LeaseRevokeResponse {
  218. ResponseHeader header = 1;
  219. }
  220. message LeaseTxnRequest {
  221. TxnRequest request = 1;
  222. repeated LeaseAttachRequest success = 2;
  223. repeated LeaseAttachRequest failure = 3;
  224. }
  225. message LeaseTxnResponse {
  226. ResponseHeader header = 1;
  227. TxnResponse response = 2;
  228. repeated LeaseAttachResponse attach_responses = 3;
  229. }
  230. message LeaseAttachRequest {
  231. int64 lease_id = 1;
  232. bytes key = 2;
  233. }
  234. message LeaseAttachResponse {
  235. ResponseHeader header = 1;
  236. }
  237. message LeaseKeepAliveRequest {
  238. int64 lease_id = 1;
  239. }
  240. message LeaseKeepAliveResponse {
  241. ResponseHeader header = 1;
  242. int64 lease_id = 2;
  243. int64 ttl = 3;
  244. }