-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathclient.proto
492 lines (423 loc) · 13.3 KB
/
client.proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
// Copyright 2023 StreamNative, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* OxiaClient
*/
syntax = "proto3";
package io.streamnative.oxia.proto;
option go_package = "github.com/streamnative/oxia/proto";
option java_multiple_files = true;
/**
* Oxia service that allows clients to discover shard-to-server assignments and
* submit batches of requests.
*
* Clients should connect to a random server to discover the shard-to-server
* assignments and then send the actual batched requests to the appropriate
* shard leader. In the future, this may be handled server-side in a proxy
* layer to allows clients to not be concerned with sharding.
*/
service OxiaClient {
/**
* Gets all shard-to-server assignments as a stream. Each set of assignments
* in the response stream will contain all the assignments to bring the client
* up to date. For example, if a shard is split, the stream will return a
* single response containing all the new shard assignments as opposed to
* multiple stream responses, each containing a single shard assignment.
*
* Clients should connect to a single random server which will stream the
* assignments for all shards on all servers.
*/
rpc GetShardAssignments(ShardAssignmentsRequest)
returns (stream ShardAssignments);
/**
* Batches put, delete and delete_range requests.
*
* Clients should send this request to the shard leader. In the future,
* this may be handled server-side in a proxy layer.
*
* Deprecated
*/
rpc Write(WriteRequest) returns (WriteResponse);
/**
* Batches put, delete and delete_range requests.
*
* Clients should send this request to the shard leader. In the future,
* this may be handled server-side in a proxy layer.
*/
rpc WriteStream(stream WriteRequest) returns (stream WriteResponse);
/**
* Batches get requests.
*
* Clients should send this request to the shard leader. In the future,
* this may be handled server-side in a proxy layer.
*/
rpc Read(ReadRequest) returns (stream ReadResponse);
/**
* Requests all the keys between a range of keys.
*
* Clients should send an equivalent request to all respective shards,
* unless a particular partition key was specified.
*/
rpc List(ListRequest) returns (stream ListResponse);
/**
* Requests all the records between a range of keys.
*
* Clients should send an equivalent request to all respective shards,
* unless a particular partition key was specified.
*/
rpc RangeScan(RangeScanRequest) returns (stream RangeScanResponse);
rpc GetNotifications(NotificationsRequest) returns (stream NotificationBatch);
/*
* Creates a new client session. Sessions are kept alive by regularly sending
* heartbeats via the KeepAlive rpc.
*/
rpc CreateSession(CreateSessionRequest) returns (CreateSessionResponse);
/*
* Sends a heartbeat to prevent the session from timing out.
*/
rpc KeepAlive(SessionHeartbeat) returns (KeepAliveResponse);
/*
* Closes a session and removes all ephemeral values associated with it.
*/
rpc CloseSession(CloseSessionRequest) returns (CloseSessionResponse);
}
/**
* A shard assignments request. Gets all shard-to-server assignments as a
* stream. Each set of assignments in the response stream will contain all the
* assignments to bring the client up to date. For example, if a shard is split,
* the stream will return a single response containing all the new shard
* assignments as opposed to multiple stream responses, each containing a single
* shard assignment.
*/
message ShardAssignmentsRequest {
string namespace = 1;
}
/**
* The response to a shard assignments request.
*/
message ShardAssignments {
map<string, NamespaceShardsAssignment> namespaces = 1;
}
/**
* The shards assignments for a given namespace
*/
message NamespaceShardsAssignment {
// All assignments in the response stream will contain all the
// assignments to bring the client up to date. For example, if a shard is
// split, the stream will return a single response containing all the new
// shard assignments as opposed to multiple stream responses, each containing
// a single shard assignment.
repeated ShardAssignment assignments = 1;
// Indicates the mechanism by which the keys are assigned to the individual
// shards.
ShardKeyRouter shard_key_router = 2;
}
/**
* The assignment of a shard to a server.
*/
message ShardAssignment {
// The shard id
int64 shard = 1;
// The shard leader, e.g. `host:port`
string leader = 2;
// There could be multiple ways to describe the boundaries of a shard
oneof shard_boundaries {
Int32HashRange int32_hash_range = 3;
}
}
enum ShardKeyRouter {
UNKNOWN = 0;
XXHASH3 = 1;
}
/**
* Represents a range of hash values [min, max)
*/
message Int32HashRange {
// The minimum inclusive hash that the shard can contain
fixed32 min_hash_inclusive = 1;
// The maximum inclusive hash that the shard can contain
fixed32 max_hash_inclusive = 2;
}
/**
* A batch write request. Applies the batches of requests. Requests are
* processed in positional order within batches and the batch types are
* processed in the following order: puts, deletes, delete_ranges.
*/
message WriteRequest {
// The shard id. This is optional allow for support for server-side hashing
// and proxying in the future.
optional int64 shard = 1;
// The put requests
repeated PutRequest puts = 2;
// The delete requests
repeated DeleteRequest deletes = 3;
// The delete range requests
repeated DeleteRangeRequest delete_ranges = 4;
}
/**
* The response to a batch write request. Responses of each type respect the
* order of the original requests.
*/
message WriteResponse {
// The put responses
repeated PutResponse puts = 1;
// The delete responses
repeated DeleteResponse deletes = 2;
// The delete range responses
repeated DeleteRangeResponse delete_ranges = 3;
}
/**
* A batch read request. Applies the batches of requests.
*/
message ReadRequest {
// The shard id. This is optional allow for support for server-side hashing
// and proxying in the future.
optional int64 shard = 1;
// The get requests
repeated GetRequest gets = 2;
}
/**
* The response to a batch read request. Responses of each type respect the
* order of the original requests.
*/
message ReadResponse {
// The get responses
repeated GetResponse gets = 1;
}
message SecondaryIndex {
string index_name = 1;
string secondary_key = 2;
}
/**
* A put request. Persists the specified key and value
*/
message PutRequest {
// The key
string key = 1;
// The value
bytes value = 2;
// An optional expected version_id. The put will fail if the server's current version_id
// does not match
optional int64 expected_version_id = 3;
// Optional. Associate the new record with the session (i.e. ephemeral record).
// When the session expires or is explicitly closed, the record will be automatically
// removed
optional int64 session_id = 4;
// Client identifier used to track the client that last modified an
// ephemeral record.
optional string client_identity = 5;
// If a partition key is present, it supersedes the regular record key in determining the routing of
// a record to a particular shard. It is passed to the server because it needs to be persisted as
// part of the record. We would need the partition_key if we're going to do a split of the shards.
optional string partition_key = 6;
// If one or more sequence key are specified. The key will get added suffixes
// based on adding the delta to the current highest key with the same prefix
repeated uint64 sequence_key_delta = 7;
repeated SecondaryIndex secondary_indexes = 8;
}
/**
* The response to a put request.
*/
message PutResponse {
// Includes the error or OK
Status status = 1;
// The version if the put was successful
Version version = 2;
// If the key was generated by Oxia, it will be returned as part
// of the response
optional string key = 3;
}
/**
* A delete request. Deletes the specified key.
*/
message DeleteRequest {
// The key
string key = 1;
// An optional expected version_id. The delete will fail if the server's current version_id
// does not match
optional int64 expected_version_id = 2;
}
/**
* The response to a delete request or an item in a response to the
* delete range request.
*/
message DeleteResponse {
// Includes the error or OK
Status status = 1;
}
/**
* The type of key comparison to apply in a get() request
*/
enum KeyComparisonType {
// The stored key must be equal to the requested key
EQUAL = 0;
// Search for a key that is the highest key that is <= to the requested key
FLOOR = 1;
// Search for a key that is the lowest key that is >= to the requested key
CEILING = 2;
// Search for a key that is the highest key that is < to the requested key
LOWER = 3;
// Search for a key that is the lowest key that is > to the requested key
HIGHER = 4;
}
/**
* A get request. Gets the stat and optionally the value for the specified
* key.
*/
message GetRequest {
// The key
string key = 1;
// Specifies whether the response should include the value
bool include_value = 2;
KeyComparisonType comparison_type = 3;
}
/**
* The response to a get request.
*/
message GetResponse {
// Includes the error or OK
Status status = 1;
// The version of the record
Version version = 2;
// The value, if it was requested and there was no error
optional bytes value = 3;
// In case of non-exact queries (eg. floor, ceiling) the found key will be
// returned in the GetResponse.
optional string key = 4;
}
/**
* Input to a delete range request. Key ranges assume a UTF-8 byte sort order.
*/
message DeleteRangeRequest {
// The start of the range, inclusive
string start_inclusive = 1;
// The end of the range, exclusive
string end_exclusive = 2;
}
/**
* The response for a delete range request.
*/
message DeleteRangeResponse {
// Includes the error or OK
Status status = 1;
}
/**
* Input to a list request. Key ranges assume a UTF-8 byte sort order.
*/
message ListRequest {
// The shard id. This is optional allow for support for server-side hashing
// and proxying in the future.
optional int64 shard = 1;
// The start of the range, inclusive
string start_inclusive = 2;
// The end of the range, exclusive
string end_exclusive = 3;
optional string secondary_index_name = 4;
}
/**
* The response to a list request.
*/
message ListResponse {
// A portion of the keys found within the specified range
repeated string keys = 1;
}
/**
* Input to a range-scan request
*/
message RangeScanRequest {
// The shard id. This is optional allow for support for server-side hashing
// and proxying in the future.
optional int64 shard = 1;
// The start of the range, inclusive
string start_inclusive = 2;
// The end of the range, exclusive
string end_exclusive = 3;
optional string secondary_index_name = 4;
}
/**
* The response to a range-scan request.
*/
message RangeScanResponse {
// A portion of the records found within the specified range
repeated GetResponse records = 1;
}
/**
* Version contains info about the state of a record.
*/
message Version {
// The version identifier of the record
int64 version_id = 1;
// The number of modifications made to the record since
// it was created
int64 modifications_count = 2;
// The creation timestamp of the first version of the record
fixed64 created_timestamp = 3;
// The modified timestamp of the current version of the record
fixed64 modified_timestamp = 4;
// Identifier of the session if the record is ephemeral
optional int64 session_id = 5;
optional string client_identity = 6;
}
/**
* Represents all the possible status.
*/
enum Status {
// Operation was successful
OK = 0;
// The key was not found
KEY_NOT_FOUND = 1;
// The existing version does not match the expected version
UNEXPECTED_VERSION_ID = 2;
// The session that the put request referred to is not alive
SESSION_DOES_NOT_EXIST = 3;
}
message CreateSessionRequest {
int64 shard = 1;
uint32 session_timeout_ms = 2;
string client_identity = 3;
}
message CreateSessionResponse {
int64 session_id = 1;
}
message SessionHeartbeat {
int64 shard = 1;
int64 session_id = 2;
}
message KeepAliveResponse {}
message CloseSessionRequest {
int64 shard = 1;
int64 session_id = 2;
}
message CloseSessionResponse {}
enum NotificationType {
KEY_CREATED = 0;
KEY_MODIFIED = 1;
KEY_DELETED = 2;
KEY_RANGE_DELETED = 3;
}
message NotificationsRequest {
int64 shard = 1;
optional int64 start_offset_exclusive = 2;
}
message NotificationBatch {
int64 shard = 1;
int64 offset = 2;
fixed64 timestamp = 3;
map<string, Notification> notifications = 4;
}
message Notification {
NotificationType type = 1;
optional int64 version_id = 2;
optional string key_range_last = 3;
}