Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/bifrost/benches/replicated_loglet_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use pprof::flamegraph::Options;
use prost::Message as _;
use rand::distr::Alphanumeric;
use rand::{Rng, RngCore, random};
use restate_types::ReString;

use restate_bifrost::InputRecord;
use restate_core::network::protobuf::network::message::Body;
Expand Down Expand Up @@ -68,7 +69,7 @@ fn invoke_cmd() -> Command {
let idempotency_key: ByteString = rand_string(15).into();
let request_id = PartitionProcessorRpcRequestId::new();
let inv_source = restate_types::invocation::Source::Ingress(request_id);
let handler: ByteString = format!("aFunction_{}", rand_string(10)).into();
let handler: ReString = format!("aFunction_{}", rand_string(10)).into();

Command::Invoke(Box::new(ServiceInvocation {
invocation_id: InvocationId::generate(
Expand Down Expand Up @@ -104,7 +105,7 @@ fn invoke_cmd() -> Command {

fn invoker_effect_cmd() -> Command {
let idempotency_key: ByteString = rand_string(15).into();
let handler: ByteString = format!("aFunction_{}", rand_string(10)).into();
let handler: ReString = format!("aFunction_{}", rand_string(10)).into();

let mut data = [0u8; 128];
rand::rng().fill_bytes(&mut data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ where
self.invocation_task
.invocation_target
.key()
.map(|bs| bs.as_bytes().clone()),
.cloned()
.map(Into::into),
journal_size,
partial_state,
state_map,
Expand Down
100 changes: 63 additions & 37 deletions crates/invoker-impl/src/invocation_task/service_protocol_runner_v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,32 @@ const RATE_LIMITED_CODES: [StatusCode; 2] = [
StatusCode::TOO_MANY_REQUESTS,
];

/// Convert prost-decoded bytes from the SDK into an `InvokeRequest`, validating UTF-8.
#[allow(clippy::too_many_arguments)]
fn try_invoke_request_from_call(
service_name: Bytes,
handler_name: Bytes,
key: Bytes,
parameter: Bytes,
headers: Vec<Header>,
idempotency_key: Option<ByteString>,
scope: Option<Bytes>,
limit_key: Option<Bytes>,
span_relation: SpanRelation,
) -> Result<InvokeRequest, CommandPreconditionError> {
Ok(InvokeRequest {
service_name: ReString::try_from(service_name)?,
handler_name: ReString::try_from(handler_name)?,
parameter,
headers,
key: ReString::try_from(key)?,
idempotency_key,
scope: scope.map(ReString::try_from).transpose()?,
limit_key: limit_key.map(ReString::try_from).transpose()?,
span_relation,
})
}

/// Runs the interaction between the server and the service endpoint.
pub struct ServiceProtocolRunner<'a, EE, Schemas> {
invocation_task: &'a mut InvocationTask<EE, Schemas>,
Expand Down Expand Up @@ -706,7 +732,8 @@ where
self.invocation_task
.invocation_target
.key()
.map(|bs| bs.as_bytes().clone()),
.cloned()
.map(Into::into),
journal_size,
partial_state,
state_map,
Expand All @@ -724,7 +751,8 @@ where
self.invocation_task
.invocation_target
.key()
.map(|bs| bs.as_bytes().clone()),
.cloned()
.map(Into::into),
journal_size,
partial_state,
state_map,
Expand Down Expand Up @@ -1063,22 +1091,21 @@ where
let name = cmd.name;
let entry: Entry = OneWayCallCommand {
request: shortcircuit!(
resolve_call_request(
self.invocation_task.schemas.live_load(),
InvokeRequest {
service_name: cmd.service_name.into(),
handler_name: cmd.handler_name.into(),
parameter: cmd.parameter,
headers: cmd.headers.into_iter().map(Into::into).collect(),
key: cmd.key.into(),
idempotency_key: cmd.idempotency_key.map(|s| s.into()),
scope: cmd.scope,
limit_key: cmd.limit_key,
span_relation: SpanRelation::Linked(
attempt_span.span_context().clone().into()
)
}
try_invoke_request_from_call(
cmd.service_name,
cmd.handler_name,
cmd.key,
cmd.parameter,
cmd.headers.into_iter().map(Into::into).collect(),
cmd.idempotency_key.map(|s| s.into()),
cmd.scope,
cmd.limit_key,
SpanRelation::Linked(attempt_span.span_context().clone().into()),
)
.and_then(|req| resolve_call_request(
self.invocation_task.schemas.live_load(),
req
))
.map_err(|e| InvokerError::CommandPrecondition(
self.command_index,
EntryType::Command(CommandType::OneWayCall),
Expand All @@ -1105,22 +1132,21 @@ where
let name = cmd.name;
let entry: Entry = CallCommand {
request: shortcircuit!(
resolve_call_request(
self.invocation_task.schemas.live_load(),
InvokeRequest {
service_name: cmd.service_name.into(),
handler_name: cmd.handler_name.into(),
parameter: cmd.parameter,
headers: cmd.headers.into_iter().map(Into::into).collect(),
key: cmd.key.into(),
idempotency_key: cmd.idempotency_key.map(|s| s.into()),
scope: cmd.scope,
limit_key: cmd.limit_key,
span_relation: SpanRelation::Parent(
attempt_span.span_context().clone().into()
)
}
try_invoke_request_from_call(
cmd.service_name,
cmd.handler_name,
cmd.key,
cmd.parameter,
cmd.headers.into_iter().map(Into::into).collect(),
cmd.idempotency_key.map(|s| s.into()),
cmd.scope,
cmd.limit_key,
SpanRelation::Parent(attempt_span.span_context().clone().into()),
)
.and_then(|req| resolve_call_request(
self.invocation_task.schemas.live_load(),
req
))
.map_err(|e| InvokerError::CommandPrecondition(
self.command_index,
EntryType::Command(CommandType::Call),
Expand Down Expand Up @@ -1476,16 +1502,16 @@ where
}

pub struct InvokeRequest {
service_name: ByteString,
handler_name: ByteString,
service_name: ReString,
handler_name: ReString,
headers: Vec<Header>,
/// Empty if service call.
/// The reason this is not Option<ByteString> is that it cannot be distinguished purely from the message
/// whether the key is none or empty.
key: ByteString,
key: ReString,
idempotency_key: Option<ByteString>,
scope: Option<String>,
limit_key: Option<String>,
scope: Option<ReString>,
limit_key: Option<ReString>,
span_relation: SpanRelation,
parameter: Bytes,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::collections::HashSet;
use std::sync::LazyLock;
use std::time::Duration;

use bytestring::ByteString;
use restate_util_string::ReString;

use restate_storage_api::invocation_status_table::{
InFlightInvocationMetadata, InvocationStatus, JournalMetadata, ReadInvocationStatusTable,
Expand All @@ -33,39 +33,39 @@ use restate_types::journal_v2::UnresolvedFuture;
use restate_types::time::MillisSinceEpoch;

const INVOCATION_TARGET_1: InvocationTarget = InvocationTarget::VirtualObject {
name: ByteString::from_static("abc"),
key: ByteString::from_static("1"),
handler: ByteString::from_static("myhandler"),
name: ReString::from_static("abc"),
key: ReString::from_static("1"),
handler: ReString::from_static("myhandler"),
handler_ty: VirtualObjectHandlerType::Exclusive,
scope: None,
};
static INVOCATION_ID_1: LazyLock<InvocationId> =
LazyLock::new(|| InvocationId::mock_generate(&INVOCATION_TARGET_1));

const INVOCATION_TARGET_2: InvocationTarget = InvocationTarget::VirtualObject {
name: ByteString::from_static("abc"),
key: ByteString::from_static("2"),
handler: ByteString::from_static("myhandler"),
name: ReString::from_static("abc"),
key: ReString::from_static("2"),
handler: ReString::from_static("myhandler"),
handler_ty: VirtualObjectHandlerType::Exclusive,
scope: None,
};
static INVOCATION_ID_2: LazyLock<InvocationId> =
LazyLock::new(|| InvocationId::mock_generate(&INVOCATION_TARGET_2));

const INVOCATION_TARGET_3: InvocationTarget = InvocationTarget::VirtualObject {
name: ByteString::from_static("abc"),
key: ByteString::from_static("3"),
handler: ByteString::from_static("myhandler"),
name: ReString::from_static("abc"),
key: ReString::from_static("3"),
handler: ReString::from_static("myhandler"),
handler_ty: VirtualObjectHandlerType::Exclusive,
scope: None,
};
static INVOCATION_ID_3: LazyLock<InvocationId> =
LazyLock::new(|| InvocationId::mock_generate(&INVOCATION_TARGET_3));

const INVOCATION_TARGET_4: InvocationTarget = InvocationTarget::VirtualObject {
name: ByteString::from_static("abc"),
key: ByteString::from_static("4"),
handler: ByteString::from_static("myhandler"),
name: ReString::from_static("abc"),
key: ReString::from_static("4"),
handler: ReString::from_static("myhandler"),
handler_ty: VirtualObjectHandlerType::Exclusive,
scope: None,
};
Expand Down
6 changes: 3 additions & 3 deletions crates/partition-store/src/tests/journal_table_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::sync::LazyLock;
use std::time::Duration;

use bytes::Bytes;
use bytestring::ByteString;
use futures_util::StreamExt;
use restate_util_string::ReString;

use restate_rocksdb::RocksDbManager;
use restate_storage_api::Transaction;
Expand Down Expand Up @@ -43,8 +43,8 @@ static MOCK_INVOKE_JOURNAL_ENTRY: LazyLock<JournalEntry> = LazyLock::new(|| {
enrichment_result: Some(CallEnrichmentResult {
invocation_id: InvocationId::from_parts(789, InvocationUuid::from_u128(456)),
invocation_target: InvocationTarget::Service {
name: ByteString::from_static("MySvc"),
handler: ByteString::from_static("MyHandler"),
name: ReString::from_static("MySvc"),
handler: ReString::from_static("MyHandler"),
scope: None,
},
completion_retention_time: Some(Duration::from_secs(10)),
Expand Down
9 changes: 5 additions & 4 deletions crates/partition-store/src/tests/journal_table_v2_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use restate_types::journal_v2::{
};
use restate_types::storage::{StoredRawEntry, StoredRawEntryHeader};
use restate_types::time::MillisSinceEpoch;
use restate_util_string::ReString;

const MOCK_INVOCATION_ID_1: InvocationId =
InvocationId::from_parts(1, InvocationUuid::from_u128(12345678900001));
Expand All @@ -55,8 +56,8 @@ fn mock_call_command(
request: CallRequest {
invocation_id: InvocationId::from_parts(789, InvocationUuid::from_u128(456)),
invocation_target: InvocationTarget::Service {
name: ByteString::from_static("MySvc"),
handler: ByteString::from_static("MyHandler"),
name: ReString::from_static("MySvc"),
handler: ReString::from_static("MyHandler"),
scope: None,
},
span_context: ServiceInvocationSpanContext::empty(),
Expand All @@ -78,8 +79,8 @@ fn mock_one_way_call_command(invocation_id_completion_id: CompletionId) -> Entry
request: CallRequest {
invocation_id: InvocationId::from_parts(789, InvocationUuid::from_u128(456)),
invocation_target: InvocationTarget::Service {
name: ByteString::from_static("MySvc"),
handler: ByteString::from_static("MyHandler"),
name: ReString::from_static("MySvc"),
handler: ReString::from_static("MyHandler"),
scope: None,
},
span_context: ServiceInvocationSpanContext::empty(),
Expand Down
Loading
Loading