rpc.proto 5.4 KB

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