rpc.proto 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. service KV {
  8. // Range gets the keys in the range from the store.
  9. rpc Range(RangeRequest) returns (RangeResponse) {}
  10. // Put puts the given key into the store.
  11. // A put request increases the revision of the store,
  12. // and generates one event in the event history.
  13. rpc Put(PutRequest) returns (PutResponse) {}
  14. // Delete deletes the given range from the store.
  15. // A delete request increase the revision of the store,
  16. // and generates one event in the event history.
  17. rpc DeleteRange(DeleteRangeRequest) returns (DeleteRangeResponse) {}
  18. // Txn processes all the requests in one transaction.
  19. // A txn request increases the revision of the store,
  20. // and generates events with the same revision in the event history.
  21. // It is not allowed to modify the same key several times within one txn.
  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. service Watch {
  28. // Watch watches the events happening or happened. Both input and output
  29. // are stream. One watch rpc can watch for multiple keys or prefixs and
  30. // get a stream of events. The whole events history can be watched unless
  31. // compacted.
  32. rpc Watch(stream WatchRequest) returns (stream WatchResponse) {}
  33. }
  34. service Lease {
  35. // LeaseCreate creates a lease. A lease has a TTL. The lease will expire if the
  36. // server does not receive a keepAlive within TTL from the lease holder.
  37. // All keys attached to the lease will be expired and deleted if the lease expires.
  38. // The key expiration generates an event in event history.
  39. rpc LeaseCreate(LeaseCreateRequest) returns (LeaseCreateResponse) {}
  40. // LeaseRevoke revokes a lease. All the key attached to the lease will be expired and deleted.
  41. rpc LeaseRevoke(LeaseRevokeRequest) returns (LeaseRevokeResponse) {}
  42. // KeepAlive keeps the lease alive.
  43. rpc LeaseKeepAlive(stream LeaseKeepAliveRequest) returns (stream LeaseKeepAliveResponse) {}
  44. // TODO(xiangli) List all existing Leases?
  45. // TODO(xiangli) Get details information (expirations, leased keys, etc.) of a lease?
  46. }
  47. service Cluster {
  48. // MemberAdd adds a member into the cluster.
  49. rpc MemberAdd(MemberAddRequest) returns (MemberAddResponse) {}
  50. // MemberRemove removes an existing member from the cluster.
  51. rpc MemberRemove(MemberRemoveRequest) returns (MemberRemoveResponse) {}
  52. // MemberUpdate updates the member configuration.
  53. rpc MemberUpdate(MemberUpdateRequest) returns (MemberUpdateResponse) {}
  54. // MemberList lists all the members in the cluster.
  55. rpc MemberList(MemberListRequest) returns (MemberListResponse) {}
  56. }
  57. message ResponseHeader {
  58. uint64 cluster_id = 1;
  59. uint64 member_id = 2;
  60. // revision of the store when the request was applied.
  61. int64 revision = 3;
  62. // term of raft when the request was applied.
  63. uint64 raft_term = 4;
  64. }
  65. message RangeRequest {
  66. enum SortOrder {
  67. NONE = 0; // default, no sorting
  68. ASCEND = 1; // lowest target value first
  69. DESCEND = 2; // highest target value first
  70. }
  71. enum SortTarget {
  72. KEY = 0;
  73. VERSION = 1;
  74. CREATE = 2;
  75. MOD = 3;
  76. VALUE = 4;
  77. }
  78. // if the range_end is not given, the request returns the key.
  79. bytes key = 1;
  80. // if the range_end is given, it gets the keys in range [key, range_end).
  81. bytes range_end = 2;
  82. // limit the number of keys returned.
  83. int64 limit = 3;
  84. // range over the store at the given revision.
  85. // if revision is less or equal to zero, range over the newest store.
  86. // if the revision has been compacted, ErrCompaction will be returned in
  87. // response.
  88. int64 revision = 4;
  89. // sort_order is the requested order for returned the results
  90. SortOrder sort_order = 5;
  91. // sort_target is the kv field to use for sorting
  92. SortTarget sort_target = 6;
  93. }
  94. message RangeResponse {
  95. ResponseHeader header = 1;
  96. repeated storagepb.KeyValue kvs = 2;
  97. // more indicates if there are more keys to return in the requested range.
  98. bool more = 3;
  99. }
  100. message PutRequest {
  101. bytes key = 1;
  102. bytes value = 2;
  103. int64 lease = 3;
  104. }
  105. message PutResponse {
  106. ResponseHeader header = 1;
  107. }
  108. message DeleteRangeRequest {
  109. // if the range_end is not given, the request deletes the key.
  110. bytes key = 1;
  111. // if the range_end is given, it deletes the keys in range [key, range_end).
  112. bytes range_end = 2;
  113. }
  114. message DeleteRangeResponse {
  115. ResponseHeader header = 1;
  116. }
  117. message RequestUnion {
  118. oneof request {
  119. RangeRequest request_range = 1;
  120. PutRequest request_put = 2;
  121. DeleteRangeRequest request_delete_range = 3;
  122. }
  123. }
  124. message ResponseUnion {
  125. oneof response {
  126. RangeResponse response_range = 1;
  127. PutResponse response_put = 2;
  128. DeleteRangeResponse response_delete_range = 3;
  129. }
  130. }
  131. message Compare {
  132. enum CompareResult {
  133. EQUAL = 0;
  134. GREATER = 1;
  135. LESS = 2;
  136. }
  137. enum CompareTarget {
  138. VERSION = 0;
  139. CREATE = 1;
  140. MOD = 2;
  141. VALUE= 3;
  142. }
  143. CompareResult result = 1;
  144. CompareTarget target = 2;
  145. // key path
  146. bytes key = 3;
  147. oneof target_union {
  148. // version of the given key
  149. int64 version = 4;
  150. // create revision of the given key
  151. int64 create_revision = 5;
  152. // last modified revision of the given key
  153. int64 mod_revision = 6;
  154. // value of the given key
  155. bytes value = 7;
  156. }
  157. }
  158. // If the comparisons succeed, then the success requests will be processed in order,
  159. // and the response will contain their respective responses in order.
  160. // If the comparisons fail, then the failure requests will be processed in order,
  161. // and the response will contain their respective responses in order.
  162. // From google paxosdb paper:
  163. // Our implementation hinges around a powerful primitive which we call MultiOp. All other database
  164. // operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically
  165. // and consists of three components:
  166. // 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check
  167. // for the absence or presence of a value, or compare with a given value. Two different tests in the guard
  168. // may apply to the same or different entries in the database. All tests in the guard are applied and
  169. // MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise
  170. // it executes f op (see item 3 below).
  171. // 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or
  172. // lookup operation, and applies to a single database entry. Two different operations in the list may apply
  173. // to the same or different entries in the database. These operations are executed
  174. // if guard evaluates to
  175. // true.
  176. // 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false.
  177. message TxnRequest {
  178. repeated Compare compare = 1;
  179. repeated RequestUnion success = 2;
  180. repeated RequestUnion failure = 3;
  181. }
  182. message TxnResponse {
  183. ResponseHeader header = 1;
  184. bool succeeded = 2;
  185. repeated ResponseUnion responses = 3;
  186. }
  187. // Compaction compacts the kv store upto the given revision (including).
  188. // It removes the old versions of a key. It keeps the newest version of
  189. // the key even if its latest modification revision is smaller than the given
  190. // revision.
  191. message CompactionRequest {
  192. int64 revision = 1;
  193. }
  194. message CompactionResponse {
  195. ResponseHeader header = 1;
  196. }
  197. message WatchRequest {
  198. oneof request_union {
  199. WatchCreateRequest create_request = 1;
  200. WatchCancelRequest cancel_request = 2;
  201. }
  202. }
  203. message WatchCreateRequest {
  204. // the key to be watched
  205. bytes key = 1;
  206. // the prefix to be watched.
  207. bytes prefix = 2;
  208. // start_revision is an optional revision (including) to watch from. No start_revision is "now".
  209. int64 start_revision = 3;
  210. // TODO: support Range watch?
  211. }
  212. message WatchCancelRequest {
  213. int64 watch_id = 1;
  214. }
  215. message WatchResponse {
  216. ResponseHeader header = 1;
  217. // watch_id is the ID of the watching the response sent to.
  218. int64 watch_id = 2;
  219. // If the response is for a create watch request, created is set to true.
  220. // Client should record the watch_id and prepare for receiving events for
  221. // that watching from the same stream.
  222. // All events sent to the created watching will attach with the same watch_id.
  223. bool created = 3;
  224. // If the response is for a cancel watch request, cancel is set to true.
  225. // No further events will be sent to the canceled watching.
  226. bool canceled = 4;
  227. // If a watching tries to watch at a compacted index, compacted will be set to true.
  228. //
  229. // This happens when creating a watching at a compacted revision or the watching cannot
  230. // catch up with the progress of the KV.
  231. //
  232. // Client should treat the watching as canceled and should not try to create any
  233. // watching with same start_revision again.
  234. bool compacted = 5;
  235. repeated storagepb.Event events = 11;
  236. }
  237. message LeaseCreateRequest {
  238. // advisory ttl in seconds
  239. int64 TTL = 1;
  240. // requested ID to create; 0 lets lessor choose
  241. int64 ID = 2;
  242. }
  243. message LeaseCreateResponse {
  244. ResponseHeader header = 1;
  245. int64 ID = 2;
  246. // server decided ttl in second
  247. int64 TTL = 3;
  248. string error = 4;
  249. }
  250. message LeaseRevokeRequest {
  251. int64 ID = 1;
  252. }
  253. message LeaseRevokeResponse {
  254. ResponseHeader header = 1;
  255. }
  256. message LeaseKeepAliveRequest {
  257. int64 ID = 1;
  258. }
  259. message LeaseKeepAliveResponse {
  260. ResponseHeader header = 1;
  261. int64 ID = 2;
  262. int64 TTL = 3;
  263. }
  264. message Member {
  265. uint64 ID = 1;
  266. // If the member is not started, name will be an empty string.
  267. string name = 2;
  268. repeated string peerURLs = 3;
  269. // If the member is not started, client_URLs will be an zero length
  270. // string array.
  271. repeated string clientURLs = 4;
  272. }
  273. message MemberAddRequest {
  274. repeated string peerURLs = 1;
  275. }
  276. message MemberAddResponse {
  277. ResponseHeader header = 1;
  278. Member member = 2;
  279. }
  280. message MemberRemoveRequest {
  281. uint64 ID = 1;
  282. }
  283. message MemberRemoveResponse {
  284. ResponseHeader header = 1;
  285. }
  286. message MemberUpdateRequest {
  287. uint64 ID = 1;
  288. repeated string peerURLs = 2;
  289. }
  290. message MemberUpdateResponse{
  291. ResponseHeader header = 1;
  292. }
  293. message MemberListRequest {
  294. }
  295. message MemberListResponse {
  296. ResponseHeader header = 1;
  297. repeated Member members = 2;
  298. }