rpc.proto 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. syntax = "proto3";
  2. package etcdserverpb;
  3. import "github.com/gogo/protobuf/gogoproto/gogo.proto";
  4. import "github.com/coreos/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 index 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 index 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 index of the store,
  21. // and generates events with the same index 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. message ResponseHeader {
  28. // an error type message?
  29. string error = 1;
  30. uint64 cluster_id = 2;
  31. uint64 member_id = 3;
  32. // index of the store when the request was applied.
  33. int64 index = 4;
  34. // term of raft when the request was applied.
  35. uint64 raft_term = 5;
  36. }
  37. message RangeRequest {
  38. // if the range_end is not given, the request returns the key.
  39. bytes key = 1;
  40. // if the range_end is given, it gets the keys in range [key, range_end).
  41. bytes range_end = 2;
  42. // limit the number of keys returned.
  43. int64 limit = 3;
  44. // the response will be consistent with previous request with same token if the token is
  45. // given and is valid.
  46. bytes consistent_token = 4;
  47. }
  48. message RangeResponse {
  49. ResponseHeader header = 1;
  50. repeated storagepb.KeyValue kvs = 2;
  51. bytes consistent_token = 3;
  52. // more indicates if there are more keys to return in the requested range.
  53. bool more = 4;
  54. }
  55. message PutRequest {
  56. bytes key = 1;
  57. bytes value = 2;
  58. }
  59. message PutResponse {
  60. ResponseHeader header = 1;
  61. }
  62. message DeleteRangeRequest {
  63. // if the range_end is not given, the request deletes the key.
  64. bytes key = 1;
  65. // if the range_end is given, it deletes the keys in range [key, range_end).
  66. bytes range_end = 2;
  67. }
  68. message DeleteRangeResponse {
  69. ResponseHeader header = 1;
  70. }
  71. message RequestUnion {
  72. oneof request {
  73. RangeRequest request_range = 1;
  74. PutRequest request_put = 2;
  75. DeleteRangeRequest request_delete_range = 3;
  76. }
  77. }
  78. message ResponseUnion {
  79. oneof response {
  80. RangeResponse response_range = 1;
  81. PutResponse response_put = 2;
  82. DeleteRangeResponse response_delete_range = 3;
  83. }
  84. }
  85. message Compare {
  86. enum CompareResult {
  87. EQUAL = 0;
  88. GREATER = 1;
  89. LESS = 2;
  90. }
  91. enum CompareTarget {
  92. VERSION = 0;
  93. CREATE = 1;
  94. MOD = 2;
  95. VALUE= 3;
  96. }
  97. CompareResult result = 1;
  98. CompareTarget target = 2;
  99. // key path
  100. bytes key = 3;
  101. oneof target_union {
  102. // version of the given key
  103. int64 version = 4;
  104. // create index of the given key
  105. int64 create_index = 5;
  106. // last modified index of the given key
  107. int64 mod_index = 6;
  108. // value of the given key
  109. bytes value = 7;
  110. }
  111. }
  112. // If the comparisons succeed, then the success requests will be processed in order,
  113. // and the response will contain their respective responses in order.
  114. // If the comparisons fail, then the failure requests will be processed in order,
  115. // and the response will contain their respective responses in order.
  116. // From google paxosdb paper:
  117. // Our implementation hinges around a powerful primitive which we call MultiOp. All other database
  118. // operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically
  119. // and consists of three components:
  120. // 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check
  121. // for the absence or presence of a value, or compare with a given value. Two different tests in the guard
  122. // may apply to the same or different entries in the database. All tests in the guard are applied and
  123. // MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise
  124. // it executes f op (see item 3 below).
  125. // 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or
  126. // lookup operation, and applies to a single database entry. Two different operations in the list may apply
  127. // to the same or different entries in the database. These operations are executed
  128. // if guard evaluates to
  129. // true.
  130. // 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false.
  131. message TxnRequest {
  132. repeated Compare compare = 1;
  133. repeated RequestUnion success = 2;
  134. repeated RequestUnion failure = 3;
  135. }
  136. message TxnResponse {
  137. ResponseHeader header = 1;
  138. bool succeeded = 2;
  139. repeated ResponseUnion responses = 3;
  140. }
  141. // Compaction compacts the kv store upto the given index (including).
  142. // It removes the old versions of a key. It keeps the newest version of
  143. // the key even if its latest modification index is smaller than the given
  144. // index.
  145. message CompactionRequest {
  146. int64 index = 1;
  147. }
  148. message CompactionResponse {
  149. ResponseHeader header = 1;
  150. }