rpc.proto 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. rpc Txn(TxnRequest) returns (TxnResponse) {}
  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. }
  26. service watch {
  27. // Watch watches the events happening or happened. Both input and output
  28. // are stream. One watch rpc can watch for multiple keys or prefixs and
  29. // get a stream of events. The whole events history can be watched unless
  30. // compacted.
  31. rpc Watch(stream WatchRequest) returns (stream WatchResponse) {}
  32. }
  33. message ResponseHeader {
  34. uint64 cluster_id = 1;
  35. uint64 member_id = 2;
  36. // revision of the store when the request was applied.
  37. int64 revision = 3;
  38. // term of raft when the request was applied.
  39. uint64 raft_term = 4;
  40. }
  41. message RangeRequest {
  42. // if the range_end is not given, the request returns the key.
  43. bytes key = 1;
  44. // if the range_end is given, it gets the keys in range [key, range_end).
  45. bytes range_end = 2;
  46. // limit the number of keys returned.
  47. int64 limit = 3;
  48. // range over the store at the given revision.
  49. // if revision is less or equal to zero, range over the newest store.
  50. // if the revision has been compacted, ErrCompaction will be returned in
  51. // response.
  52. int64 revision = 4;
  53. }
  54. message RangeResponse {
  55. ResponseHeader header = 1;
  56. repeated storagepb.KeyValue kvs = 2;
  57. // more indicates if there are more keys to return in the requested range.
  58. bool more = 3;
  59. }
  60. message PutRequest {
  61. bytes key = 1;
  62. bytes value = 2;
  63. }
  64. message PutResponse {
  65. ResponseHeader header = 1;
  66. }
  67. message DeleteRangeRequest {
  68. // if the range_end is not given, the request deletes the key.
  69. bytes key = 1;
  70. // if the range_end is given, it deletes the keys in range [key, range_end).
  71. bytes range_end = 2;
  72. }
  73. message DeleteRangeResponse {
  74. ResponseHeader header = 1;
  75. }
  76. message RequestUnion {
  77. oneof request {
  78. RangeRequest request_range = 1;
  79. PutRequest request_put = 2;
  80. DeleteRangeRequest request_delete_range = 3;
  81. }
  82. }
  83. message ResponseUnion {
  84. oneof response {
  85. RangeResponse response_range = 1;
  86. PutResponse response_put = 2;
  87. DeleteRangeResponse response_delete_range = 3;
  88. }
  89. }
  90. message Compare {
  91. enum CompareResult {
  92. EQUAL = 0;
  93. GREATER = 1;
  94. LESS = 2;
  95. }
  96. enum CompareTarget {
  97. VERSION = 0;
  98. CREATE = 1;
  99. MOD = 2;
  100. VALUE= 3;
  101. }
  102. CompareResult result = 1;
  103. CompareTarget target = 2;
  104. // key path
  105. bytes key = 3;
  106. oneof target_union {
  107. // version of the given key
  108. int64 version = 4;
  109. // create revision of the given key
  110. int64 create_revision = 5;
  111. // last modified revision of the given key
  112. int64 mod_revision = 6;
  113. // value of the given key
  114. bytes value = 7;
  115. }
  116. }
  117. // If the comparisons succeed, then the success requests will be processed in order,
  118. // and the response will contain their respective responses in order.
  119. // If the comparisons fail, then the failure requests will be processed in order,
  120. // and the response will contain their respective responses in order.
  121. // From google paxosdb paper:
  122. // Our implementation hinges around a powerful primitive which we call MultiOp. All other database
  123. // operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically
  124. // and consists of three components:
  125. // 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check
  126. // for the absence or presence of a value, or compare with a given value. Two different tests in the guard
  127. // may apply to the same or different entries in the database. All tests in the guard are applied and
  128. // MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise
  129. // it executes f op (see item 3 below).
  130. // 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or
  131. // lookup operation, and applies to a single database entry. Two different operations in the list may apply
  132. // to the same or different entries in the database. These operations are executed
  133. // if guard evaluates to
  134. // true.
  135. // 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false.
  136. message TxnRequest {
  137. repeated Compare compare = 1;
  138. repeated RequestUnion success = 2;
  139. repeated RequestUnion failure = 3;
  140. }
  141. message TxnResponse {
  142. ResponseHeader header = 1;
  143. bool succeeded = 2;
  144. repeated ResponseUnion responses = 3;
  145. }
  146. // Compaction compacts the kv store upto the given revision (including).
  147. // It removes the old versions of a key. It keeps the newest version of
  148. // the key even if its latest modification revision is smaller than the given
  149. // revision.
  150. message CompactionRequest {
  151. int64 revision = 1;
  152. }
  153. message CompactionResponse {
  154. ResponseHeader header = 1;
  155. }
  156. message WatchRequest {
  157. // the key to be watched
  158. bytes key = 1;
  159. // the prefix to be watched.
  160. bytes prefix = 2;
  161. // start_revision is an optional revision (including) to watch from. No start_revision is "now".
  162. int64 start_revision = 3;
  163. // TODO: support Range watch?
  164. // TODO: support notification every time interval or revision increase?
  165. // TODO: support cancel watch if the server cannot reach with majority?
  166. }
  167. message WatchResponse {
  168. ResponseHeader header = 1;
  169. // TODO: support batched events response?
  170. storagepb.Event event = 2;
  171. }