rpc.proto 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. // Interface exported by the server.
  6. service etcd {
  7. // Range gets the keys in the range from the store.
  8. rpc Range(RangeRequest) returns (RangeResponse) {}
  9. // Put puts the given key into the store.
  10. // A put request increases the index of the store,
  11. // and generates one event in the event history.
  12. rpc Put(PutRequest) returns (PutResponse) {}
  13. // Delete deletes the given range from the store.
  14. // A delete request increase the index of the store,
  15. // and generates one event in the event history.
  16. rpc DeleteRange(DeleteRangeRequest) returns (DeleteRangeResponse) {}
  17. // Tnx processes all the requests in one transaction.
  18. // A tnx request increases the index of the store,
  19. // and generates events with the same index in the event history.
  20. rpc Tnx(TnxRequest) returns (TnxResponse) {}
  21. // Compact compacts the event history in etcd. User should compact the
  22. // event history periodically, or it will grow infinitely.
  23. rpc Compact(CompactionRequest) returns (CompactionResponse) {}
  24. }
  25. message ResponseHeader {
  26. // an error type message?
  27. string error = 1;
  28. uint64 cluster_id = 2;
  29. uint64 member_id = 3;
  30. // index of the store when the request was applied.
  31. int64 index = 4;
  32. // term of raft when the request was applied.
  33. uint64 raft_term = 5;
  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. // the response will be consistent with previous request with same token if the token is
  43. // given and is vaild.
  44. bytes consistent_token = 4;
  45. }
  46. message RangeResponse {
  47. ResponseHeader header = 1;
  48. repeated storagepb.KeyValue kvs = 2;
  49. bytes consistent_token = 3;
  50. }
  51. message PutRequest {
  52. bytes key = 1;
  53. bytes value = 2;
  54. }
  55. message PutResponse {
  56. ResponseHeader header = 1;
  57. }
  58. message DeleteRangeRequest {
  59. // if the range_end is not given, the request deletes the key.
  60. bytes key = 1;
  61. // if the range_end is given, it deletes the keys in range [key, range_end).
  62. bytes range_end = 2;
  63. }
  64. message DeleteRangeResponse {
  65. ResponseHeader header = 1;
  66. }
  67. message RequestUnion {
  68. oneof request {
  69. RangeRequest request_range = 1;
  70. PutRequest request_put = 2;
  71. DeleteRangeRequest request_delete_range = 3;
  72. }
  73. }
  74. message ResponseUnion {
  75. oneof response {
  76. RangeResponse reponse_range = 1;
  77. PutResponse response_put = 2;
  78. DeleteRangeResponse response_delete_range = 3;
  79. }
  80. }
  81. message Compare {
  82. enum CompareType {
  83. EQUAL = 0;
  84. GREATER = 1;
  85. LESS = 2;
  86. }
  87. CompareType type = 1;
  88. // key path
  89. bytes key = 2;
  90. oneof target {
  91. // version of the given key
  92. int64 version = 3;
  93. // create index of the given key
  94. int64 create_index = 4;
  95. // last modified index of the given key
  96. int64 mod_index = 5;
  97. // value of the given key
  98. bytes value = 6;
  99. }
  100. }
  101. // First all the compare requests are processed.
  102. // If all the compare succeed, all the success
  103. // requests will be processed.
  104. // Or all the failure requests will be processed and
  105. // all the errors in the comparison will be returned.
  106. // From google paxosdb paper:
  107. // Our implementation hinges around a powerful primitive which we call MultiOp. All other database
  108. // operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically
  109. // and consists of three components:
  110. // 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check
  111. // for the absence or presence of a value, or compare with a given value. Two different tests in the guard
  112. // may apply to the same or different entries in the database. All tests in the guard are applied and
  113. // MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise
  114. // it executes f op (see item 3 below).
  115. // 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or
  116. // lookup operation, and applies to a single database entry. Two different operations in the list may apply
  117. // to the same or different entries in the database. These operations are executed
  118. // if guard evaluates to
  119. // true.
  120. // 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false.
  121. message TnxRequest {
  122. repeated Compare compare = 1;
  123. repeated RequestUnion success = 2;
  124. repeated RequestUnion failure = 3;
  125. }
  126. message TnxResponse {
  127. ResponseHeader header = 1;
  128. bool succeeded = 2;
  129. repeated ResponseUnion responses = 3;
  130. }
  131. message CompactionRequest {
  132. int64 index = 1;
  133. }
  134. message CompactionResponse {
  135. ResponseHeader header = 1;
  136. }