Skip to content

Commit 5272448

Browse files
authored
feat: add protosocket-rpc cache protocols (#325)
Authored-by: Dylan Abraham <dylan@momentohq.com>
1 parent ea0dde8 commit 5272448

File tree

7 files changed

+144
-2
lines changed

7 files changed

+144
-2
lines changed

proto/protosocket/cache.proto

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
syntax = "proto3";
2+
3+
import "protosocket/common.proto";
4+
5+
// This is the protobuf definition for the Momento Cache service.
6+
// It is available over protosocket-rpc.
7+
package cache;
8+
9+
// All messages sent to the server by a client must be CacheCommands.
10+
message CacheCommand {
11+
// This is the unique identifier used for the command. The server will return this id in the response.
12+
// As protosocket-rpc does not necessarily respond in-order this is used to correlate responses with requests.
13+
uint64 message_id = 2;
14+
// The protosocket-rpc control code.
15+
uint32 control_code = 3;
16+
// The protosocket-rpc rpc kind.
17+
oneof rpc_kind {
18+
Unary unary = 10;
19+
}
20+
}
21+
22+
// These are Unary (single request -> single response) commands.
23+
message Unary {
24+
oneof command {
25+
// Authenticate provides the auth token to be used for all future requests on the connection.
26+
// - It MUST be the first command sent on every cache connection.
27+
// - It MAY be resent later in the connection to provide a different auth token.
28+
// - If sent mid-connection, clients SHOULD wait to pipeline further commands until the corresponding response is received.
29+
// If clients do not wait, it is indeterminate whether the prior or new auth token will be used for those requests.
30+
AuthenticateCommand auth = 1;
31+
// Retrieves an item from cache.
32+
GetCommand get = 2;
33+
// Set an item in cache.
34+
SetCommand set = 3;
35+
// Deletes an item from cache.
36+
DeleteCommand delete = 4;
37+
}
38+
}
39+
40+
// All messages sent by the server to a client will be CacheResponses.
41+
message CacheResponse {
42+
// This is the message id provided in the corresponding command.
43+
uint64 message_id = 1;
44+
// The protosocket-rpc control code.
45+
uint32 control_code = 2;
46+
// The specific response.
47+
oneof kind {
48+
common.CommandError error = 9;
49+
AuthenticateResponse auth = 10;
50+
GetResponse get = 11;
51+
SetResponse set = 12;
52+
DeleteResponse delete = 13;
53+
}
54+
}
55+
56+
message AuthenticateCommand {
57+
string token = 1;
58+
}
59+
60+
message AuthenticateResponse {}
61+
62+
message GetCommand {
63+
string namespace = 1;
64+
bytes key = 2;
65+
}
66+
67+
message GetResponse {
68+
bytes value = 1;
69+
}
70+
71+
message SetCommand {
72+
string namespace = 1;
73+
bytes key = 2;
74+
bytes value = 3;
75+
uint64 ttl_milliseconds = 4;
76+
}
77+
message SetResponse {}
78+
79+
message DeleteCommand {
80+
string namespace = 1;
81+
bytes key = 2;
82+
}
83+
message DeleteResponse {
84+
}

proto/protosocket/common.proto

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
syntax = "proto3";
2+
3+
// This package is for protos we anticipate being used across customer-facing protosocket+protobuf services.
4+
package common;
5+
6+
enum Status {
7+
OK = 0;
8+
CANCELLED = 1;
9+
UNKNOWN = 2;
10+
INVALID_ARGUMENT = 3;
11+
DEADLINE_EXCEEDED = 4;
12+
NOT_FOUND = 5;
13+
ALREADY_EXISTS = 6;
14+
PERMISSION_DENIED = 7;
15+
RESOURCE_EXHAUSTED = 8;
16+
FAILED_PRECONDITION = 9;
17+
ABORTED = 10;
18+
OUT_OF_RANGE = 11;
19+
UNIMPLEMENTED = 12;
20+
INTERNAL = 13;
21+
UNAVAILABLE = 14;
22+
DATA_LOSS = 15;
23+
UNAUTHENTICATED = 16;
24+
}
25+
26+
message CommandError {
27+
Status code = 1;
28+
string message = 2;
29+
}

rust/momento-protos/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ repository = "https://github.com/momentohq/client_protos"
66
license = "Apache-2.0"
77
version = "0.1.0"
88
authors = ["<eng@momentohq.com>"]
9-
edition = "2021"
9+
edition = "2024"
1010
keywords = ["service", "performance", "cache"]
1111
categories = ["web-programming"]
1212
includes = [
1313
"Cargo.toml",
1414
"src/**/*.rs",
15+
"src/**/**/*.rs",
1516
"../proto",
1617
]
1718

rust/momento-protos/src/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
# Need this file to list the proto module imports
55
!lib.rs
6+
!protosocket/mod.rs

rust/momento-protos/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
pub mod protosocket {
2+
pub mod common {
3+
include!("protosocket/common.rs");
4+
}
5+
6+
pub mod cache {
7+
include!("protosocket/cache.rs");
8+
}
9+
}
10+
111
pub mod permission_messages {
212
include!("permission_messages.rs");
313
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory - this is purely generated.
2+
*
3+
# Except this file
4+
!.gitignore

rust/proto_generator/build.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
tonic_build::configure()
1818
.build_client(true)
1919
.build_server(true)
20-
.out_dir(out_dir)
20+
.out_dir(out_dir.clone())
2121
.compile_protos(
2222
&[
2323
format!("{proto_dir}/permissionmessages.proto"),
@@ -34,5 +34,18 @@ fn main() {
3434
)
3535
.unwrap_or_else(|e| panic!("Failed to compile protos {:?}", e));
3636

37+
tonic_build::configure()
38+
.build_client(true)
39+
.build_server(true)
40+
.out_dir(out_dir.join("protosocket"))
41+
.compile_protos(
42+
&[
43+
format!("{proto_dir}/protosocket/common.proto"),
44+
format!("{proto_dir}/protosocket/cache.proto"),
45+
],
46+
&[proto_dir],
47+
)
48+
.unwrap_or_else(|e| panic!("Failed to compile protosocket protos {:?}", e));
49+
3750
println!("cargo:rerun-if-changed=../proto");
3851
}

0 commit comments

Comments
 (0)