rpc.proto 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. }
  53. message PutRequest {
  54. bytes key = 1;
  55. bytes value = 2;
  56. }
  57. message PutResponse {
  58. ResponseHeader header = 1;
  59. }
  60. message DeleteRangeRequest {
  61. // if the range_end is not given, the request deletes the key.
  62. bytes key = 1;
  63. // if the range_end is given, it deletes the keys in range [key, range_end).
  64. bytes range_end = 2;
  65. }
  66. message DeleteRangeResponse {
  67. ResponseHeader header = 1;
  68. }
  69. message RequestUnion {
  70. oneof request {
  71. RangeRequest request_range = 1;
  72. PutRequest request_put = 2;
  73. DeleteRangeRequest request_delete_range = 3;
  74. }
  75. }
  76. message ResponseUnion {
  77. oneof response {
  78. RangeResponse response_range = 1;
  79. PutResponse response_put = 2;
  80. DeleteRangeResponse response_delete_range = 3;
  81. }
  82. }
  83. message Compare {
  84. enum CompareResult {
  85. EQUAL = 0;
  86. GREATER = 1;
  87. LESS = 2;
  88. }
  89. enum CompareTarget {
  90. VERSION = 0;
  91. CREATE = 1;
  92. MOD = 2;
  93. VALUE= 3;
  94. }
  95. CompareResult result = 1;
  96. CompareTarget target = 2;
  97. // key path
  98. bytes key = 3;
  99. oneof target_union {
  100. // version of the given key
  101. int64 version = 4;
  102. // create index of the given key
  103. int64 create_index = 5;
  104. // last modified index of the given key
  105. int64 mod_index = 6;
  106. // value of the given key
  107. bytes value = 7;
  108. }
  109. }
  110. // First all the compare requests are processed.
  111. // If all the compare succeed, all the success
  112. // requests will be processed.
  113. // Or all the failure requests will be processed and
  114. // all the errors in the comparison will be returned.
  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. message CompactionRequest {
  141. int64 index = 1;
  142. }
  143. message CompactionResponse {
  144. ResponseHeader header = 1;
  145. }