Skip to content

Commit d23fae3

Browse files
committed
envelope-v2: Move ingestion to use V2
Switch the code paths that uses IngestionClient to start ingesting v2 Envelope instead of v1
1 parent b315536 commit d23fae3

18 files changed

Lines changed: 186 additions & 176 deletions

File tree

crates/admin/src/rest_api/invocations.rs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use axum::Json;
1212
use axum::extract::{Path, Query, State};
1313
use axum::http::StatusCode;
1414
use futures::future;
15+
use serde::Deserialize;
1516
use tracing::warn;
1617

1718
use restate_admin_rest_model::invocations::{
@@ -28,12 +29,12 @@ use restate_types::invocation::client::{
2829
};
2930
use restate_types::invocation::{InvocationTermination, PurgeInvocationRequest, TerminationFlavor};
3031
use restate_types::journal_v2::EntryIndex;
31-
use restate_wal_protocol::{Command, Envelope};
32-
use serde::Deserialize;
32+
use restate_types::logs::{BodyWithKeys, Keys};
33+
use restate_wal_protocol::v2;
34+
use restate_wal_protocol::v2::commands;
3335

3436
use super::error::*;
3537
use crate::generate_meta_api_error;
36-
use crate::rest_api::create_envelope_header;
3738
use crate::state::AdminServiceState;
3839

3940
#[derive(Debug, Default, Deserialize, utoipa::ToSchema)]
@@ -88,30 +89,43 @@ where
8889
.parse::<InvocationId>()
8990
.map_err(|e| MetaApiError::InvalidField("invocation_id", e.to_string()))?;
9091

91-
let cmd = match mode.unwrap_or_default() {
92-
DeletionMode::Cancel => Command::TerminateInvocation(InvocationTermination {
93-
invocation_id,
94-
flavor: TerminationFlavor::Cancel,
95-
response_sink: None,
96-
}),
97-
DeletionMode::Kill => Command::TerminateInvocation(InvocationTermination {
98-
invocation_id,
99-
flavor: TerminationFlavor::Kill,
100-
response_sink: None,
101-
}),
102-
DeletionMode::Purge => Command::PurgeInvocation(PurgeInvocationRequest {
103-
invocation_id,
104-
response_sink: None,
105-
}),
92+
let envelope = match mode.unwrap_or_default() {
93+
DeletionMode::Cancel => v2::Envelope::new(
94+
v2::Dedup::None,
95+
commands::TerminateInvocationCommand::from(InvocationTermination {
96+
invocation_id,
97+
flavor: TerminationFlavor::Cancel,
98+
response_sink: None,
99+
}),
100+
)
101+
.into_raw(),
102+
DeletionMode::Kill => v2::Envelope::new(
103+
v2::Dedup::None,
104+
commands::TerminateInvocationCommand::from(InvocationTermination {
105+
invocation_id,
106+
flavor: TerminationFlavor::Kill,
107+
response_sink: None,
108+
}),
109+
)
110+
.into_raw(),
111+
DeletionMode::Purge => v2::Envelope::new(
112+
v2::Dedup::None,
113+
commands::PurgeInvocationCommand::from(PurgeInvocationRequest {
114+
invocation_id,
115+
response_sink: None,
116+
}),
117+
)
118+
.into_raw(),
106119
};
107120

108121
let partition_key = invocation_id.partition_key();
109122

110-
let envelope = Envelope::new(create_envelope_header(partition_key), cmd);
111-
112123
let result = state
113124
.ingestion_client
114-
.ingest(partition_key, envelope)
125+
.ingest(
126+
partition_key,
127+
BodyWithKeys::new(envelope, Keys::Single(partition_key)),
128+
)
115129
.await
116130
.map_err(|err| {
117131
warn!("Could not ingest invocation termination command: {err}");

crates/admin/src/rest_api/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ use utoipa::OpenApi;
2929
use utoipa_axum::{router::OpenApiRouter, routes};
3030

3131
use restate_core::network::TransportConnect;
32-
use restate_types::identifiers::PartitionKey;
3332
use restate_types::invocation::client::InvocationClient;
3433
use restate_types::schema::registry::{DiscoveryClient, MetadataService, TelemetryClient};
35-
use restate_wal_protocol::{Destination, Header, Source};
3634

3735
use crate::state::AdminServiceState;
3836

@@ -187,16 +185,6 @@ where
187185
.with_state(state)
188186
}
189187

190-
fn create_envelope_header(partition_key: PartitionKey) -> Header {
191-
Header {
192-
source: Source::ControlPlane {},
193-
dest: Destination::Processor {
194-
partition_key,
195-
dedup: None,
196-
},
197-
}
198-
}
199-
200188
/// # Error description response
201189
///
202190
/// Error details of the response

crates/admin/src/rest_api/services.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
// the Business Source License, use of this software will be governed
99
// by the Apache License, Version 2.0.
1010

11-
use tracing::{debug, warn};
12-
1311
use axum::Json;
1412
use axum::extract::{Path, State};
1513
use bytes::Bytes;
1614
use http::StatusCode;
15+
use tracing::{debug, warn};
1716

1817
use restate_admin_rest_model::services::ListServicesResponse;
1918
use restate_admin_rest_model::services::*;
@@ -22,13 +21,14 @@ use restate_core::network::TransportConnect;
2221
use restate_errors::warn_it;
2322
use restate_types::config::Configuration;
2423
use restate_types::identifiers::{ServiceId, WithPartitionKey};
24+
use restate_types::logs::{BodyWithKeys, Keys};
2525
use restate_types::schema::registry::MetadataService;
2626
use restate_types::schema::service::ServiceMetadata;
2727
use restate_types::state_mut::ExternalStateMutation;
2828
use restate_types::{Scope, schema};
29-
use restate_wal_protocol::{Command, Envelope};
29+
use restate_wal_protocol::v2;
30+
use restate_wal_protocol::v2::commands;
3031

31-
use super::create_envelope_header;
3232
use super::error::*;
3333
use crate::state::AdminServiceState;
3434

@@ -250,14 +250,17 @@ where
250250
state: new_state,
251251
};
252252

253-
let envelope = Envelope::new(
254-
create_envelope_header(partition_key),
255-
Command::PatchState(patch_state),
253+
let envelop = v2::Envelope::new(
254+
v2::Dedup::None,
255+
commands::PatchStateCommand::from(patch_state),
256256
);
257257

258258
let result = state
259259
.ingestion_client
260-
.ingest(partition_key, envelope)
260+
.ingest(
261+
partition_key,
262+
BodyWithKeys::new(envelop.into_raw(), Keys::Single(partition_key)),
263+
)
261264
.await
262265
.map_err(|err| {
263266
warn!("Could not ingest state patching command: {err}");

crates/admin/src/service.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use std::time::Duration;
1313

1414
use axum::error_handling::HandleErrorLayer;
1515
use http::{Request, Response, StatusCode};
16-
use restate_ingestion_client::IngestionClient;
17-
use restate_wal_protocol::Envelope;
1816
use tower::ServiceBuilder;
1917
use tower_http::classify::ServerErrorsFailureClass;
2018
use tower_http::compression::CompressionLayer;
@@ -24,6 +22,7 @@ use tracing::{Span, debug, info, info_span};
2422
use restate_admin_rest_model::version::AdminApiVersion;
2523
use restate_core::network::{TransportConnect, net_util};
2624
use restate_core::{MetadataWriter, TaskCenter};
25+
use restate_ingestion_client::IngestionClient;
2726
use restate_limiter::rule_book::RuleBookObserver;
2827
use restate_metadata_store::MetadataStoreClient;
2928
use restate_service_client::HttpClient;
@@ -36,6 +35,7 @@ use restate_types::net::address::AdminPort;
3635
use restate_types::net::listener::Listeners;
3736
use restate_types::schema::registry::SchemaRegistry;
3837
use restate_util_time::DurationExt;
38+
use restate_wal_protocol::v2::{Envelope, Raw};
3939

4040
use crate::rest_api::{MAX_ADMIN_API_VERSION, MIN_ADMIN_API_VERSION};
4141
use crate::schema_registry_integration::{MetadataService, TelemetryClient};
@@ -47,7 +47,7 @@ pub struct BuildError(#[from] restate_service_client::BuildError);
4747

4848
pub struct AdminService<Metadata, Discovery, Telemetry, Invocations, Transport> {
4949
listeners: Listeners<AdminPort>,
50-
ingestion_client: IngestionClient<Transport, Envelope>,
50+
ingestion_client: IngestionClient<Transport, Envelope<Raw>>,
5151
schema_registry: SchemaRegistry<Metadata, Discovery, Telemetry>,
5252
serdes_client: SerdesClient,
5353
invocation_client: Invocations,
@@ -65,7 +65,7 @@ where
6565
pub fn new(
6666
listeners: Listeners<AdminPort>,
6767
metadata_writer: MetadataWriter,
68-
ingestion_client: IngestionClient<Transport, Envelope>,
68+
ingestion_client: IngestionClient<Transport, Envelope<Raw>>,
6969
invocation_client: Invocations,
7070
serdes_client: SerdesClient,
7171
service_discovery: ServiceDiscovery,

crates/admin/src/state.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@
88
// the Business Source License, use of this software will be governed
99
// by the Apache License, Version 2.0.
1010

11+
use std::sync::Arc;
12+
1113
use restate_core::network::TransportConnect;
1214
use restate_ingestion_client::IngestionClient;
1315
use restate_limiter::rule_book::RuleBookObserver;
1416
use restate_metadata_store::MetadataStoreClient;
1517
use restate_service_protocol_v4::serdes::SerdesClient;
1618
use restate_storage_query_datafusion::context::QueryContext;
1719
use restate_types::schema::registry::SchemaRegistry;
18-
use restate_wal_protocol::Envelope;
19-
use std::sync::Arc;
20+
use restate_wal_protocol::v2::{Envelope, Raw};
2021

2122
#[derive(Clone, derive_builder::Builder)]
2223
pub struct AdminServiceState<Metadata, Discovery, Telemetry, Invocations, Transport> {
2324
pub schema_registry: SchemaRegistry<Metadata, Discovery, Telemetry>,
2425
pub serdes_client: SerdesClient,
2526
pub invocation_client: Invocations,
26-
pub ingestion_client: IngestionClient<Transport, Envelope>,
27+
pub ingestion_client: IngestionClient<Transport, Envelope<Raw>>,
2728
/// Used by handlers that mutate cluster-global metadata-store keys
2829
/// directly (e.g. the rule book) via `read_modify_write`.
2930
pub metadata_store_client: MetadataStoreClient,
@@ -41,7 +42,7 @@ where
4142
schema_registry: SchemaRegistry<Metadata, Discovery, Telemetry>,
4243
serdes_client: SerdesClient,
4344
invocation_client: Invocations,
44-
ingestion_client: IngestionClient<Transport, Envelope>,
45+
ingestion_client: IngestionClient<Transport, Envelope<Raw>>,
4546
metadata_store_client: MetadataStoreClient,
4647
query_context: Option<QueryContext>,
4748
rule_book_observer: Option<Arc<dyn RuleBookObserver>>,

crates/ingestion-client/src/client.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use restate_core::{
2121
use restate_types::{
2222
identifiers::PartitionKey,
2323
live::Live,
24-
logs::{HasRecordKeys, Keys},
24+
logs::{BodyWithKeys, HasRecordKeys, Keys},
2525
net::ingest::IngestRecord,
2626
partitions::{FindPartition, PartitionTable, PartitionTableError},
2727
storage::{StorageCodec, StorageEncode},
@@ -271,6 +271,16 @@ impl InputRecord<String> {
271271
}
272272
}
273273

274+
impl<T> From<BodyWithKeys<T>> for InputRecord<T>
275+
where
276+
T: StorageEncode,
277+
{
278+
fn from(value: BodyWithKeys<T>) -> Self {
279+
let (keys, record) = value.split();
280+
Self { keys, record }
281+
}
282+
}
283+
274284
#[cfg(test)]
275285
mod test {
276286
use std::{num::NonZeroUsize, time::Duration};

crates/ingress-kafka/src/builder.rs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,20 @@ use opentelemetry::trace::{Span, SpanContext, TraceContextExt};
1818
use opentelemetry_sdk::propagation::TraceContextPropagator;
1919
use rdkafka::Message;
2020
use rdkafka::message::BorrowedMessage;
21-
use tracing::{info_span, trace};
22-
2321
use rdkafka::message::Headers;
22+
use tracing::{info_span, trace};
2423

25-
use restate_storage_api::deduplication_table::DedupInformation;
2624
use restate_types::Scope;
27-
use restate_types::identifiers::{InvocationId, WithPartitionKey, partitioner};
25+
use restate_types::identifiers::{InvocationId, partitioner};
2826
use restate_types::invocation::{Header, InvocationTarget, ServiceInvocation, SpanRelation};
2927
use restate_types::limit_key::LimitKey;
3028
use restate_types::live::Live;
3129
use restate_types::schema::Schema;
3230
use restate_types::schema::invocation_target::{DeploymentStatus, InvocationTargetResolver};
3331
use restate_types::schema::subscriptions::{EventInvocationTargetTemplate, Sink, Subscription};
32+
use restate_types::sharding::{PartitionKey, WithPartitionKey};
3433
use restate_util_string::{ReString, RestateString, RestrictedValueError};
35-
use restate_wal_protocol::{Command, Destination, Envelope, Source};
34+
use restate_wal_protocol::v2::{Dedup, Envelope, commands};
3635

3736
use crate::Error;
3837

@@ -62,7 +61,7 @@ impl EnvelopeBuilder {
6261
producer_id: u128,
6362
consumer_group_id: &str,
6463
msg: BorrowedMessage<'_>,
65-
) -> Result<Envelope, Error> {
64+
) -> Result<(PartitionKey, Envelope<commands::InvokeCommand>), Error> {
6665
// Prepare ingress span
6766
let ingress_span = info_span!(
6867
"kafka_ingress_consume",
@@ -106,7 +105,11 @@ impl EnvelopeBuilder {
106105
(None, LimitKey::None)
107106
};
108107

109-
let dedup = DedupInformation::producer(producer_id, msg.offset() as u64);
108+
let dedup = Dedup::Arbitrary {
109+
prefix: None,
110+
producer_id: producer_id.into(),
111+
seq: msg.offset() as u64,
112+
};
110113

111114
let invocation = InvocationBuilder::create(
112115
&self.subscription,
@@ -130,23 +133,11 @@ impl EnvelopeBuilder {
130133
cause,
131134
})?;
132135

133-
Ok(self.wrap_service_invocation_in_envelope(invocation, dedup))
134-
}
135-
136-
fn wrap_service_invocation_in_envelope(
137-
&self,
138-
service_invocation: Box<ServiceInvocation>,
139-
dedup_information: DedupInformation,
140-
) -> Envelope {
141-
let header = restate_wal_protocol::Header {
142-
source: Source::Ingress {},
143-
dest: Destination::Processor {
144-
partition_key: service_invocation.partition_key(),
145-
dedup: Some(dedup_information),
146-
},
147-
};
148-
149-
Envelope::new(header, Command::Invoke(service_invocation))
136+
let partition_key = invocation.partition_key();
137+
Ok((
138+
partition_key,
139+
Envelope::new(dedup, commands::InvokeCommand::from(invocation)),
140+
))
150141
}
151142

152143
fn generate_events_attributes(msg: &impl Message, subscription_id: &str) -> Vec<Header> {
@@ -225,7 +216,7 @@ impl InvocationBuilder {
225216
topic: &str,
226217
partition: i32,
227218
offset: i64,
228-
) -> Result<Box<ServiceInvocation>, anyhow::Error> {
219+
) -> Result<ServiceInvocation, anyhow::Error> {
229220
let Sink::Invocation {
230221
event_invocation_target_template,
231222
} = subscription.sink();
@@ -325,11 +316,11 @@ impl InvocationBuilder {
325316
);
326317

327318
// Finally generate service invocation
328-
let mut service_invocation = Box::new(ServiceInvocation::initialize(
319+
let mut service_invocation = ServiceInvocation::initialize(
329320
invocation_id,
330321
invocation_target,
331322
restate_types::invocation::Source::Subscription(subscription.id()),
332-
));
323+
);
333324
service_invocation.with_related_span(SpanRelation::parent(ingress_span_context));
334325
service_invocation.argument = payload;
335326
service_invocation.headers = headers;

0 commit comments

Comments
 (0)