Skip to content

Commit c09e270

Browse files
Protocol v6 (#49)
* Update protocol version * Protocol V6 and random seed support
1 parent e667018 commit c09e270

File tree

9 files changed

+73
-47
lines changed

9 files changed

+73
-47
lines changed

service-protocol/dev/restate/service/protocol.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ enum ServiceProtocolVersion {
3333
// * New command to attach to existing invocation
3434
// * New command to get output of existing invocation
3535
V5 = 5;
36+
// Added:
37+
// * StartMessage.random_seed
38+
V6 = 6;
3639
}
3740

3841
// --- Core frames ---
@@ -74,6 +77,10 @@ message StartMessage {
7477
// Please note this duration might not be accurate,
7578
// and might change depending on which Restate replica executes the request.
7679
uint64 duration_since_last_stored_entry = 8;
80+
81+
// Random seed to use to seed the deterministic RNG exposed in the context API.
82+
// This will be stable across restarts.
83+
uint64 random_seed = 9;
7784
}
7885

7986
// Type: 0x0000 + 1

src/service_protocol/encoding.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ mod tests {
220220
key: "key".to_string(),
221221
retry_count_since_last_stored_entry: 0,
222222
duration_since_last_stored_entry: 0,
223+
random_seed: 0,
223224
};
224225

225226
let expected_msg_1 = messages::InputCommandMessage {

src/service_protocol/generated/dev.restate.service.protocol.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ pub struct StartMessage {
3333
/// and might change depending on which Restate replica executes the request.
3434
#[prost(uint64, tag = "8")]
3535
pub duration_since_last_stored_entry: u64,
36+
/// Random seed to use to seed the deterministic RNG exposed in the context API.
37+
/// This will be stable across restarts.
38+
#[prost(uint64, tag = "9")]
39+
pub random_seed: u64,
3640
}
3741
/// Nested message and enum types in `StartMessage`.
3842
pub mod start_message {
@@ -925,6 +929,9 @@ pub enum ServiceProtocolVersion {
925929
/// * New command to attach to existing invocation
926930
/// * New command to get output of existing invocation
927931
V5 = 5,
932+
/// Added:
933+
/// * StartMessage.random_seed
934+
V6 = 6,
928935
}
929936
impl ServiceProtocolVersion {
930937
/// String value of the enum field names used in the ProtoBuf definition.
@@ -939,6 +946,7 @@ impl ServiceProtocolVersion {
939946
Self::V3 => "V3",
940947
Self::V4 => "V4",
941948
Self::V5 => "V5",
949+
Self::V6 => "V6",
942950
}
943951
}
944952
/// Creates an enum from field names used in the ProtoBuf definition.
@@ -950,6 +958,7 @@ impl ServiceProtocolVersion {
950958
"V3" => Some(Self::V3),
951959
"V4" => Some(Self::V4),
952960
"V5" => Some(Self::V5),
961+
"V6" => Some(Self::V6),
953962
_ => None,
954963
}
955964
}

src/service_protocol/version.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ pub enum Version {
88
V3 = 3,
99
V4 = 4,
1010
V5 = 5,
11+
V6 = 6,
1112
}
1213

1314
const CONTENT_TYPE_V1: &str = "application/vnd.restate.invocation.v1";
1415
const CONTENT_TYPE_V2: &str = "application/vnd.restate.invocation.v2";
1516
const CONTENT_TYPE_V3: &str = "application/vnd.restate.invocation.v3";
1617
const CONTENT_TYPE_V4: &str = "application/vnd.restate.invocation.v4";
1718
const CONTENT_TYPE_V5: &str = "application/vnd.restate.invocation.v5";
19+
const CONTENT_TYPE_V6: &str = "application/vnd.restate.invocation.v6";
1820

1921
impl Version {
2022
pub const fn content_type(&self) -> &'static str {
@@ -24,6 +26,7 @@ impl Version {
2426
Version::V3 => CONTENT_TYPE_V3,
2527
Version::V4 => CONTENT_TYPE_V4,
2628
Version::V5 => CONTENT_TYPE_V5,
29+
Version::V6 => CONTENT_TYPE_V6,
2730
}
2831
}
2932

@@ -32,7 +35,7 @@ impl Version {
3235
}
3336

3437
pub const fn maximum_supported_version() -> Self {
35-
Version::V5
38+
Version::V6
3639
}
3740
}
3841

@@ -61,6 +64,7 @@ impl FromStr for Version {
6164
CONTENT_TYPE_V3 => Ok(Version::V3),
6265
CONTENT_TYPE_V4 => Ok(Version::V4),
6366
CONTENT_TYPE_V5 => Ok(Version::V5),
67+
CONTENT_TYPE_V6 => Ok(Version::V6),
6468
s if s.starts_with("application/vnd.restate.invocation.") => {
6569
Err(ContentTypeError::RestateContentType(s.to_owned()))
6670
}

src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ pub fn start_message(known_entries: u32) -> StartMessage {
201201
key: "".to_string(),
202202
retry_count_since_last_stored_entry: 0,
203203
duration_since_last_stored_entry: 0,
204+
random_seed: 0,
204205
}
205206
}
206207

src/vm/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub(crate) struct StartInfo {
1818
pub(crate) entries_to_replay: u32,
1919
pub(crate) retry_count_since_last_stored_entry: u32,
2020
pub(crate) duration_since_last_stored_entry: u64,
21+
pub(crate) random_seed: Option<u64>,
2122
}
2223

2324
pub(crate) struct Journal {
@@ -434,6 +435,7 @@ pub(crate) struct Context {
434435
// It's not very Rusty I know, but it makes much more reasonable handling failure cases.
435436
pub(crate) start_info: Option<StartInfo>,
436437
pub(crate) journal: Journal,
438+
pub(crate) negotiated_protocol_version: Version,
437439

438440
pub(crate) input_is_closed: bool,
439441
pub(crate) output: Output,

0 commit comments

Comments
 (0)