v3api.proto 8.6 KB

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