@@ -18,21 +18,20 @@ use opentelemetry::trace::{Span, SpanContext, TraceContextExt};
1818use opentelemetry_sdk:: propagation:: TraceContextPropagator ;
1919use rdkafka:: Message ;
2020use rdkafka:: message:: BorrowedMessage ;
21- use tracing:: { info_span, trace} ;
22-
2321use rdkafka:: message:: Headers ;
22+ use tracing:: { info_span, trace} ;
2423
25- use restate_storage_api:: deduplication_table:: DedupInformation ;
2624use restate_types:: Scope ;
27- use restate_types:: identifiers:: { InvocationId , WithPartitionKey , partitioner} ;
25+ use restate_types:: identifiers:: { InvocationId , partitioner} ;
2826use restate_types:: invocation:: { Header , InvocationTarget , ServiceInvocation , SpanRelation } ;
2927use restate_types:: limit_key:: LimitKey ;
3028use restate_types:: live:: Live ;
3129use restate_types:: schema:: Schema ;
3230use restate_types:: schema:: invocation_target:: { DeploymentStatus , InvocationTargetResolver } ;
3331use restate_types:: schema:: subscriptions:: { EventInvocationTargetTemplate , Sink , Subscription } ;
32+ use restate_types:: sharding:: { PartitionKey , WithPartitionKey } ;
3433use 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
3736use 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