v3api.proto 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. // Tnx processes all the requests in one transaction.
  15. // A tnx request increases the index of the store,
  16. // and generates events with the same index in the event history.
  17. rpc Tnx(TnxRequest) returns (TnxResponse) {}
  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. // LeaseTnx likes Tnx. It has two addition success and failure LeaseAttachRequest list.
  35. // If the Tnx is successful, then the success list will be executed. Or the failure list
  36. // will be executed.
  37. rpc LeaseTnx(LeaseTnxRequest) returns (LeaseTnxResponse) {}
  38. // KeepAlive keeps the lease alive.
  39. rpc LeaseKeepAlive(stream LeaseKeepAliveRequest) returns (stream LeaseKeepAliveResponse) {}
  40. }
  41. message ResponseHeader {
  42. // an error type message?
  43. optional string error = 1;
  44. optional uint64 cluster_id = 2;
  45. optional uint64 member_id = 3;
  46. // index of the store when the request was applied.
  47. optional int64 index = 4;
  48. // term of raft when the request was applied.
  49. optional uint64 raft_term = 5;
  50. }
  51. message RangeRequest {
  52. // if the range_end is not given, the request returns the key.
  53. optional bytes key = 1;
  54. // if the range_end is given, it gets the keys in range [key, range_end).
  55. optional bytes range_end = 2;
  56. // limit the number of keys returned.
  57. optional int64 limit = 3;
  58. // the response will be consistent with previous request with same token if the token is
  59. // given and is vaild.
  60. optional bytes consistent_token = 4;
  61. }
  62. message RangeResponse {
  63. optional ResponseHeader header = 1;
  64. repeated KeyValue kvs = 2;
  65. optional bytes consistent_token = 3;
  66. }
  67. message PutRequest {
  68. optional bytes key = 1;
  69. optional bytes value = 2;
  70. }
  71. message PutResponse {
  72. optional ResponseHeader header = 1;
  73. }
  74. message DeleteRangeRequest {
  75. // if the range_end is not given, the request deletes the key.
  76. optional bytes key = 1;
  77. // if the range_end is given, it deletes the keys in range [key, range_end).
  78. optional bytes range_end = 2;
  79. }
  80. message DeleteRangeResponse {
  81. optional ResponseHeader header = 1;
  82. }
  83. message RequestUnion {
  84. oneof request {
  85. RangeRequest request_range = 1;
  86. PutRequest request_put = 2;
  87. DeleteRangeRequest request_delete_range = 3;
  88. }
  89. }
  90. message ResponseUnion {
  91. oneof response {
  92. RangeResponse reponse_range = 1;
  93. PutResponse response_put = 2;
  94. DeleteRangeResponse response_delete_range = 3;
  95. }
  96. }
  97. message Compare {
  98. enum CompareType {
  99. EQUAL = 0;
  100. GREATER = 1;
  101. LESS = 2;
  102. }
  103. optional CompareType type = 1;
  104. // key path
  105. optional bytes key = 2;
  106. oneof target {
  107. // version of the given key
  108. int64 version = 3;
  109. // create index of the given key
  110. int64 create_index = 4;
  111. // last modified index of the given key
  112. int64 mod_index = 5;
  113. // value of the given key
  114. bytes value = 6;
  115. }
  116. }
  117. // First all the compare requests are processed.
  118. // If all the compare succeed, all the success
  119. // requests will be processed.
  120. // Or all the failure requests will be processed and
  121. // all the errors in the comparison will be returned.
  122. // From google paxosdb paper:
  123. // Our implementation hinges around a powerful primitive which we call MultiOp. All other database
  124. // operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically
  125. // and consists of three components:
  126. // 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check
  127. // for the absence or presence of a value, or compare with a given value. Two different tests in the guard
  128. // may apply to the same or different entries in the database. All tests in the guard are applied and
  129. // MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise
  130. // it executes f op (see item 3 below).
  131. // 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or
  132. // lookup operation, and applies to a single database entry. Two different operations in the list may apply
  133. // to the same or different entries in the database. These operations are executed
  134. // if guard evaluates to
  135. // true.
  136. // 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false.
  137. message TnxRequest {
  138. repeated Compare compare = 1;
  139. repeated RequestUnion success = 2;
  140. repeated RequestUnion failure = 3;
  141. }
  142. message TnxResponse {
  143. optional ResponseHeader header = 1;
  144. optional bool succeeded = 2;
  145. repeated ResponseUnion responses = 3;
  146. }
  147. message KeyValue {
  148. optional bytes key = 1;
  149. // mod_index is the last modified index of the key.
  150. optional int64 create_index = 2;
  151. optional int64 mod_index = 3;
  152. // version is the version of the key. A deletion resets
  153. // the version to zero and any modification of the key
  154. // increases its version.
  155. optional int64 version = 4;
  156. optional bytes value = 5;
  157. }
  158. message WatchRangeRequest {
  159. // if the range_end is not given, the request returns the key.
  160. optional bytes key = 1;
  161. // if the range_end is given, it gets the keys in range [key, range_end).
  162. optional bytes range_end = 2;
  163. // start_index is an optional index (including) to watch from. No start_index is "now".
  164. optional int64 start_index = 3;
  165. // end_index is an optional index (excluding) to end watch. No end_index is "forever".
  166. optional int64 end_index = 4;
  167. optional bool progress_notification = 5;
  168. }
  169. message WatchRangeResponse {
  170. optional ResponseHeader header = 1;
  171. repeated Event events = 2;
  172. }
  173. message Event {
  174. enum EventType {
  175. PUT = 0;
  176. DELETE = 1;
  177. EXPIRE = 2;
  178. }
  179. optional EventType event_type = 1;
  180. // a put event contains the current key-value
  181. // a delete/expire event contains the previous
  182. // key-value
  183. optional KeyValue kv = 2;
  184. }
  185. message CompactionRequest {
  186. optional int64 index = 1;
  187. }
  188. message CompactionResponse {
  189. optional ResponseHeader header = 1;
  190. }
  191. message LeaseCreateRequest {
  192. // advisory ttl in seconds
  193. optional int64 ttl = 1;
  194. }
  195. message LeaseCreateResponse {
  196. optional ResponseHeader header = 1;
  197. optional int64 lease_id = 2;
  198. // server decided ttl in second
  199. optional int64 ttl = 3;
  200. optional string error = 4;
  201. }
  202. message LeaseRevokeRequest {
  203. optional int64 lease_id = 1;
  204. }
  205. message LeaseRevokeResponse {
  206. optional ResponseHeader header = 1;
  207. }
  208. message LeaseTnxRequest {
  209. optional TnxRequest request = 1;
  210. repeated LeaseAttachRequest success = 2;
  211. repeated LeaseAttachRequest failure = 3;
  212. }
  213. message LeaseTnxResponse {
  214. optional ResponseHeader header = 1;
  215. optional TnxResponse response = 2;
  216. repeated LeaseAttachResponse attach_responses = 3;
  217. }
  218. message LeaseAttachRequest {
  219. optional int64 lease_id = 1;
  220. optional bytes key = 2;
  221. }
  222. message LeaseAttachResponse {
  223. optional ResponseHeader header = 1;
  224. }
  225. message LeaseKeepAliveRequest {
  226. optional int64 lease_id = 1;
  227. }
  228. message LeaseKeepAliveResponse {
  229. optional ResponseHeader header = 1;
  230. optional int64 lease_id = 2;
  231. optional int64 ttl = 3;
  232. }