rpc.proto 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. // Interface exported by the server.
  8. service etcd {
  9. // Range gets the keys in the range from the store.
  10. rpc Range(RangeRequest) returns (RangeResponse) {}
  11. // Put puts the given key into the store.
  12. // A put request increases the revision of the store,
  13. // and generates one event in the event history.
  14. rpc Put(PutRequest) returns (PutResponse) {}
  15. // Delete deletes the given range from the store.
  16. // A delete request increase the revision of the store,
  17. // and generates one event in the event history.
  18. rpc DeleteRange(DeleteRangeRequest) returns (DeleteRangeResponse) {}
  19. // Txn processes all the requests in one transaction.
  20. // A txn request increases the revision of the store,
  21. // and generates events with the same revision in the event history.
  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. message ResponseHeader {
  35. uint64 cluster_id = 1;
  36. uint64 member_id = 2;
  37. // revision of the store when the request was applied.
  38. int64 revision = 3;
  39. // term of raft when the request was applied.
  40. uint64 raft_term = 4;
  41. }
  42. message RangeRequest {
  43. // if the range_end is not given, the request returns the key.
  44. bytes key = 1;
  45. // if the range_end is given, it gets the keys in range [key, range_end).
  46. bytes range_end = 2;
  47. // limit the number of keys returned.
  48. int64 limit = 3;
  49. // range over the store at the given revision.
  50. // if revision is less or equal to zero, range over the newest store.
  51. // if the revision has been compacted, ErrCompaction will be returned in
  52. // response.
  53. int64 revision = 4;
  54. }
  55. message RangeResponse {
  56. ResponseHeader header = 1;
  57. repeated storagepb.KeyValue kvs = 2;
  58. // more indicates if there are more keys to return in the requested range.
  59. bool more = 3;
  60. }
  61. message PutRequest {
  62. bytes key = 1;
  63. bytes value = 2;
  64. }
  65. message PutResponse {
  66. ResponseHeader header = 1;
  67. }
  68. message DeleteRangeRequest {
  69. // if the range_end is not given, the request deletes the key.
  70. bytes key = 1;
  71. // if the range_end is given, it deletes the keys in range [key, range_end).
  72. bytes range_end = 2;
  73. }
  74. message DeleteRangeResponse {
  75. ResponseHeader header = 1;
  76. }
  77. message RequestUnion {
  78. oneof request {
  79. RangeRequest request_range = 1;
  80. PutRequest request_put = 2;
  81. DeleteRangeRequest request_delete_range = 3;
  82. }
  83. }
  84. message ResponseUnion {
  85. oneof response {
  86. RangeResponse response_range = 1;
  87. PutResponse response_put = 2;
  88. DeleteRangeResponse response_delete_range = 3;
  89. }
  90. }
  91. message Compare {
  92. enum CompareResult {
  93. EQUAL = 0;
  94. GREATER = 1;
  95. LESS = 2;
  96. }
  97. enum CompareTarget {
  98. VERSION = 0;
  99. CREATE = 1;
  100. MOD = 2;
  101. VALUE= 3;
  102. }
  103. CompareResult result = 1;
  104. CompareTarget target = 2;
  105. // key path
  106. bytes key = 3;
  107. oneof target_union {
  108. // version of the given key
  109. int64 version = 4;
  110. // create revision of the given key
  111. int64 create_revision = 5;
  112. // last modified revision of the given key
  113. int64 mod_revision = 6;
  114. // value of the given key
  115. bytes value = 7;
  116. }
  117. }
  118. // If the comparisons succeed, then the success requests will be processed in order,
  119. // and the response will contain their respective responses in order.
  120. // If the comparisons fail, then the failure requests will be processed in order,
  121. // and the response will contain their respective responses in order.
  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 TxnRequest {
  138. repeated Compare compare = 1;
  139. repeated RequestUnion success = 2;
  140. repeated RequestUnion failure = 3;
  141. }
  142. message TxnResponse {
  143. ResponseHeader header = 1;
  144. bool succeeded = 2;
  145. repeated ResponseUnion responses = 3;
  146. }
  147. // Compaction compacts the kv store upto the given revision (including).
  148. // It removes the old versions of a key. It keeps the newest version of
  149. // the key even if its latest modification revision is smaller than the given
  150. // revision.
  151. message CompactionRequest {
  152. int64 revision = 1;
  153. }
  154. message CompactionResponse {
  155. ResponseHeader header = 1;
  156. }
  157. message WatchRequest {
  158. // the key to be watched
  159. bytes key = 1;
  160. // the prefix to be watched.
  161. bytes prefix = 2;
  162. // start_revision is an optional revision (including) to watch from. No start_revision is "now".
  163. int64 start_revision = 3;
  164. // TODO: support Range watch?
  165. // TODO: support notification every time interval or revision increase?
  166. // TODO: support cancel watch if the server cannot reach with majority?
  167. }
  168. message WatchResponse {
  169. ResponseHeader header = 1;
  170. // TODO: support batched events response?
  171. storagepb.Event event = 2;
  172. }