|
| 1 | +syntax = "proto3"; |
| 2 | +package etcdserverpb; |
| 3 | + |
| 4 | +import "gogoproto/gogo.proto"; |
| 5 | +import "etcd/storage/storagepb/kv.proto"; |
| 6 | + |
| 7 | +option (gogoproto.marshaler_all) = true; |
| 8 | +option (gogoproto.unmarshaler_all) = true; |
| 9 | + |
| 10 | +service KV { |
| 11 | + // Range gets the keys in the range from the store. |
| 12 | + rpc Range(RangeRequest) returns (RangeResponse) {} |
| 13 | + |
| 14 | + // Put puts the given key into the store. |
| 15 | + // A put request increases the revision of the store, |
| 16 | + // and generates one event in the event history. |
| 17 | + rpc Put(PutRequest) returns (PutResponse) {} |
| 18 | + |
| 19 | + // Delete deletes the given range from the store. |
| 20 | + // A delete request increase the revision of the store, |
| 21 | + // and generates one event in the event history. |
| 22 | + rpc DeleteRange(DeleteRangeRequest) returns (DeleteRangeResponse) {} |
| 23 | + |
| 24 | + // Txn processes all the requests in one transaction. |
| 25 | + // A txn request increases the revision of the store, |
| 26 | + // and generates events with the same revision in the event history. |
| 27 | + rpc Txn(TxnRequest) returns (TxnResponse) {} |
| 28 | + |
| 29 | + // Compact compacts the event history in etcd. User should compact the |
| 30 | + // event history periodically, or it will grow infinitely. |
| 31 | + rpc Compact(CompactionRequest) returns (CompactionResponse) {} |
| 32 | +} |
| 33 | + |
| 34 | +service watch { |
| 35 | + // Watch watches the events happening or happened. Both input and output |
| 36 | + // are stream. One watch rpc can watch for multiple keys or prefixs and |
| 37 | + // get a stream of events. The whole events history can be watched unless |
| 38 | + // compacted. |
| 39 | + rpc Watch(stream WatchRequest) returns (stream WatchResponse) {} |
| 40 | +} |
| 41 | + |
| 42 | +message ResponseHeader { |
| 43 | + uint64 cluster_id = 1; |
| 44 | + uint64 member_id = 2; |
| 45 | + // revision of the store when the request was applied. |
| 46 | + int64 revision = 3; |
| 47 | + // term of raft when the request was applied. |
| 48 | + uint64 raft_term = 4; |
| 49 | +} |
| 50 | + |
| 51 | +message RangeRequest { |
| 52 | + // if the range_end is not given, the request returns the key. |
| 53 | + bytes key = 1; |
| 54 | + // if the range_end is given, it gets the keys in range [key, range_end). |
| 55 | + bytes range_end = 2; |
| 56 | + // limit the number of keys returned. |
| 57 | + int64 limit = 3; |
| 58 | + // range over the store at the given revision. |
| 59 | + // if revision is less or equal to zero, range over the newest store. |
| 60 | + // if the revision has been compacted, ErrCompaction will be returned in |
| 61 | + // response. |
| 62 | + int64 revision = 4; |
| 63 | +} |
| 64 | + |
| 65 | +message RangeResponse { |
| 66 | + ResponseHeader header = 1; |
| 67 | + repeated storagepb.KeyValue kvs = 2; |
| 68 | + // more indicates if there are more keys to return in the requested range. |
| 69 | + bool more = 3; |
| 70 | +} |
| 71 | + |
| 72 | +message PutRequest { |
| 73 | + bytes key = 1; |
| 74 | + bytes value = 2; |
| 75 | +} |
| 76 | + |
| 77 | +message PutResponse { |
| 78 | + ResponseHeader header = 1; |
| 79 | +} |
| 80 | + |
| 81 | +message DeleteRangeRequest { |
| 82 | + // if the range_end is not given, the request deletes the key. |
| 83 | + bytes key = 1; |
| 84 | + // if the range_end is given, it deletes the keys in range [key, range_end). |
| 85 | + bytes range_end = 2; |
| 86 | +} |
| 87 | + |
| 88 | +message DeleteRangeResponse { |
| 89 | + ResponseHeader header = 1; |
| 90 | +} |
| 91 | + |
| 92 | +message RequestUnion { |
| 93 | + oneof request { |
| 94 | + RangeRequest request_range = 1; |
| 95 | + PutRequest request_put = 2; |
| 96 | + DeleteRangeRequest request_delete_range = 3; |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +message ResponseUnion { |
| 101 | + oneof response { |
| 102 | + RangeResponse response_range = 1; |
| 103 | + PutResponse response_put = 2; |
| 104 | + DeleteRangeResponse response_delete_range = 3; |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +message Compare { |
| 109 | + enum CompareResult { |
| 110 | + EQUAL = 0; |
| 111 | + GREATER = 1; |
| 112 | + LESS = 2; |
| 113 | + } |
| 114 | + enum CompareTarget { |
| 115 | + VERSION = 0; |
| 116 | + CREATE = 1; |
| 117 | + MOD = 2; |
| 118 | + VALUE= 3; |
| 119 | + } |
| 120 | + CompareResult result = 1; |
| 121 | + CompareTarget target = 2; |
| 122 | + // key path |
| 123 | + bytes key = 3; |
| 124 | + oneof target_union { |
| 125 | + // version of the given key |
| 126 | + int64 version = 4; |
| 127 | + // create revision of the given key |
| 128 | + int64 create_revision = 5; |
| 129 | + // last modified revision of the given key |
| 130 | + int64 mod_revision = 6; |
| 131 | + // value of the given key |
| 132 | + bytes value = 7; |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +// If the comparisons succeed, then the success requests will be processed in order, |
| 137 | +// and the response will contain their respective responses in order. |
| 138 | +// If the comparisons fail, then the failure requests will be processed in order, |
| 139 | +// and the response will contain their respective responses in order. |
| 140 | + |
| 141 | +// From google paxosdb paper: |
| 142 | +// Our implementation hinges around a powerful primitive which we call MultiOp. All other database |
| 143 | +// operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically |
| 144 | +// and consists of three components: |
| 145 | +// 1. A list of tests called guard. Each test in guard checks a single entry in the database. It may check |
| 146 | +// for the absence or presence of a value, or compare with a given value. Two different tests in the guard |
| 147 | +// may apply to the same or different entries in the database. All tests in the guard are applied and |
| 148 | +// MultiOp returns the results. If all tests are true, MultiOp executes t op (see item 2 below), otherwise |
| 149 | +// it executes f op (see item 3 below). |
| 150 | +// 2. A list of database operations called t op. Each operation in the list is either an insert, delete, or |
| 151 | +// lookup operation, and applies to a single database entry. Two different operations in the list may apply |
| 152 | +// to the same or different entries in the database. These operations are executed |
| 153 | +// if guard evaluates to |
| 154 | +// true. |
| 155 | +// 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false. |
| 156 | +message TxnRequest { |
| 157 | + repeated Compare compare = 1; |
| 158 | + repeated RequestUnion success = 2; |
| 159 | + repeated RequestUnion failure = 3; |
| 160 | +} |
| 161 | + |
| 162 | +message TxnResponse { |
| 163 | + ResponseHeader header = 1; |
| 164 | + bool succeeded = 2; |
| 165 | + repeated ResponseUnion responses = 3; |
| 166 | +} |
| 167 | + |
| 168 | +// Compaction compacts the kv store upto the given revision (including). |
| 169 | +// It removes the old versions of a key. It keeps the newest version of |
| 170 | +// the key even if its latest modification revision is smaller than the given |
| 171 | +// revision. |
| 172 | +message CompactionRequest { |
| 173 | + int64 revision = 1; |
| 174 | +} |
| 175 | + |
| 176 | +message CompactionResponse { |
| 177 | + ResponseHeader header = 1; |
| 178 | +} |
| 179 | + |
| 180 | +message WatchRequest { |
| 181 | + // the key to be watched |
| 182 | + bytes key = 1; |
| 183 | + // the prefix to be watched. |
| 184 | + bytes prefix = 2; |
| 185 | + // start_revision is an optional revision (including) to watch from. No start_revision is "now". |
| 186 | + int64 start_revision = 3; |
| 187 | + // TODO: support Range watch? |
| 188 | + // TODO: support notification every time interval or revision increase? |
| 189 | + // TODO: support cancel watch if the server cannot reach with majority? |
| 190 | +} |
| 191 | + |
| 192 | +message WatchResponse { |
| 193 | + ResponseHeader header = 1; |
| 194 | + // TODO: support batched events response? |
| 195 | + storagepb.Event event = 2; |
| 196 | +} |
0 commit comments