v3api.proto 8.6 KB

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