rpc.proto 7.6 KB

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