v3api.proto 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. // 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. // revision of the store when the request was applied.
  47. int64 revision = 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. // range over the store at the given revision.
  59. // if revision is less or equal to zero, range over the newest store.
  60. // if the revision has been compacted, ErrCompaction will be returned in
  61. // response.
  62. int64 revision = 4;
  63. }
  64. message RangeResponse {
  65. ResponseHeader header = 1;
  66. repeated storagepb.KeyValue kvs = 2;
  67. // more indicates if there are more keys to return in the requested range.
  68. bool more = 3;
  69. }
  70. message PutRequest {
  71. bytes key = 1;
  72. bytes value = 2;
  73. }
  74. message PutResponse {
  75. ResponseHeader header = 1;
  76. }
  77. message DeleteRangeRequest {
  78. // if the range_end is not given, the request deletes the key.
  79. bytes key = 1;
  80. // if the range_end is given, it deletes the keys in range [key, range_end).
  81. bytes range_end = 2;
  82. }
  83. message DeleteRangeResponse {
  84. ResponseHeader header = 1;
  85. }
  86. message RequestUnion {
  87. oneof request {
  88. RangeRequest request_range = 1;
  89. PutRequest request_put = 2;
  90. DeleteRangeRequest request_delete_range = 3;
  91. }
  92. }
  93. message ResponseUnion {
  94. oneof response {
  95. RangeResponse response_range = 1;
  96. PutResponse response_put = 2;
  97. DeleteRangeResponse response_delete_range = 3;
  98. }
  99. }
  100. message Compare {
  101. enum CompareResult {
  102. EQUAL = 0;
  103. GREATER = 1;
  104. LESS = 2;
  105. }
  106. enum CompareTarget {
  107. VERSION = 0;
  108. CREATE = 1;
  109. MOD = 2;
  110. VALUE= 3;
  111. }
  112. CompareResult result = 1;
  113. CompareTarget target = 2;
  114. // key path
  115. bytes key = 3;
  116. oneof target_union {
  117. // version of the given key
  118. int64 version = 4;
  119. // create revision of the given key
  120. int64 create_revision = 5;
  121. // last modified revision of the given key
  122. int64 mod_revision = 6;
  123. // value of the given key
  124. bytes value = 7;
  125. }
  126. }
  127. // If the comparisons succeed, then the success requests will be processed in order,
  128. // and the response will contain their respective responses in order.
  129. // If the comparisons fail, then the failure requests will be processed in order,
  130. // and the response will contain their respective responses in order.
  131. // From google paxosdb paper:
  132. // Our implementation hinges around a powerful primitive which we call MultiOp. All other database
  133. // operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically
  134. // and consists of three components:
  135. // 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check
  136. // for the absence or presence of a value, or compare with a given value. Two different tests in the guard
  137. // may apply to the same or different entries in the database. All tests in the guard are applied and
  138. // MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise
  139. // it executes f op (see item 3 below).
  140. // 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or
  141. // lookup operation, and applies to a single database entry. Two different operations in the list may apply
  142. // to the same or different entries in the database. These operations are executed
  143. // if guard evaluates to
  144. // true.
  145. // 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false.
  146. message TxnRequest {
  147. repeated Compare compare = 1;
  148. repeated RequestUnion success = 2;
  149. repeated RequestUnion failure = 3;
  150. }
  151. message TxnResponse {
  152. ResponseHeader header = 1;
  153. bool succeeded = 2;
  154. repeated ResponseUnion responses = 3;
  155. }
  156. message KeyValue {
  157. bytes key = 1;
  158. int64 create_revision = 2;
  159. // mod_revision is the last modified revision of the key.
  160. int64 mod_revision = 3;
  161. // version is the version of the key. A deletion resets
  162. // the version to zero and any modification of the key
  163. // increases its version.
  164. int64 version = 4;
  165. bytes value = 5;
  166. }
  167. message WatchRangeRequest {
  168. // if the range_end is not given, the request returns the key.
  169. bytes key = 1;
  170. // if the range_end is given, it gets the keys in range [key, range_end).
  171. bytes range_end = 2;
  172. // start_revision is an optional revision (including) to watch from. No start_revision is "now".
  173. int64 start_revision = 3;
  174. // end_revision is an optional revision (excluding) to end watch. No end_revision is "forever".
  175. int64 end_revision = 4;
  176. bool progress_notification = 5;
  177. }
  178. message WatchRangeResponse {
  179. ResponseHeader header = 1;
  180. repeated Event events = 2;
  181. }
  182. message Event {
  183. enum EventType {
  184. PUT = 0;
  185. DELETE = 1;
  186. EXPIRE = 2;
  187. }
  188. EventType event_type = 1;
  189. // a put event contains the current key-value
  190. // a delete/expire event contains the previous
  191. // key-value
  192. KeyValue kv = 2;
  193. }
  194. // Compaction compacts the kv store upto the given revision (including).
  195. // It removes the old versions of a key. It keeps the newest version of
  196. // the key even if its latest modification revision is smaller than the given
  197. // revision.
  198. message CompactionRequest {
  199. int64 revision = 1;
  200. }
  201. message CompactionResponse {
  202. ResponseHeader header = 1;
  203. }
  204. message LeaseCreateRequest {
  205. // advisory ttl in seconds
  206. int64 ttl = 1;
  207. }
  208. message LeaseCreateResponse {
  209. ResponseHeader header = 1;
  210. int64 lease_id = 2;
  211. // server decided ttl in second
  212. int64 ttl = 3;
  213. string error = 4;
  214. }
  215. message LeaseRevokeRequest {
  216. int64 lease_id = 1;
  217. }
  218. message LeaseRevokeResponse {
  219. ResponseHeader header = 1;
  220. }
  221. message LeaseTxnRequest {
  222. TxnRequest request = 1;
  223. repeated LeaseAttachRequest success = 2;
  224. repeated LeaseAttachRequest failure = 3;
  225. }
  226. message LeaseTxnResponse {
  227. ResponseHeader header = 1;
  228. TxnResponse response = 2;
  229. repeated LeaseAttachResponse attach_responses = 3;
  230. }
  231. message LeaseAttachRequest {
  232. int64 lease_id = 1;
  233. bytes key = 2;
  234. }
  235. message LeaseAttachResponse {
  236. ResponseHeader header = 1;
  237. }
  238. message LeaseKeepAliveRequest {
  239. int64 lease_id = 1;
  240. }
  241. message LeaseKeepAliveResponse {
  242. ResponseHeader header = 1;
  243. int64 lease_id = 2;
  244. int64 ttl = 3;
  245. }