rpc.proto 5.4 KB

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