@@ -15,9 +15,9 @@ use futures::future::{BoxFuture, Either, Shared};
1515use futures:: { FutureExt , TryFutureExt } ;
1616use pin_project_lite:: pin_project;
1717use restate_sdk_shared_core:: {
18- CoreVM , DoProgressResponse , Error as CoreError , Header , NonEmptyValue , NotificationHandle ,
19- PayloadOptions , RetryPolicy , RunExitResult , TakeOutputResult , Target , TerminalFailure , VM ,
20- Value ,
18+ AwaitResponse , AwakeableHandle , CoreVM , Error as CoreError , Header , NonEmptyValue ,
19+ NotificationHandle , OnMaxAttempts , PayloadOptions , RetryPolicy , RunExitResult , RunHandle ,
20+ Target , TerminalFailure , UnresolvedFuture , VM , Value ,
2121} ;
2222use std:: borrow:: Cow ;
2323use std:: collections:: HashMap ;
@@ -67,10 +67,10 @@ impl ContextInternalInner {
6767 }
6868
6969 pub ( super ) fn maybe_flip_span_replaying_field ( & mut self ) {
70- if !self . span_replaying_field_state && self . vm . is_replaying ( ) {
70+ if !self . span_replaying_field_state && self . vm . state ( ) . is_replaying ( ) {
7171 tracing:: Span :: current ( ) . record ( "restate.sdk.is_replaying" , true ) ;
7272 self . span_replaying_field_state = true ;
73- } else if self . span_replaying_field_state && !self . vm . is_replaying ( ) {
73+ } else if self . span_replaying_field_state && !self . vm . state ( ) . is_replaying ( ) {
7474 tracing:: Span :: current ( ) . record ( "restate.sdk.is_replaying" , false ) ;
7575 self . span_replaying_field_state = false ;
7676 }
@@ -131,20 +131,26 @@ impl From<RequestTarget> for Target {
131131 handler,
132132 key : None ,
133133 idempotency_key : None ,
134+ scope : None ,
135+ limit_key : None ,
134136 headers : vec ! [ ] ,
135137 } ,
136138 RequestTarget :: Object { name, key, handler } => Target {
137139 service : name,
138140 handler,
139141 key : Some ( key) ,
140142 idempotency_key : None ,
143+ scope : None ,
144+ limit_key : None ,
141145 headers : vec ! [ ] ,
142146 } ,
143147 RequestTarget :: Workflow { name, key, handler } => Target {
144148 service : name,
145149 handler,
146150 key : Some ( key) ,
147151 idempotency_key : None ,
152+ scope : None ,
153+ limit_key : None ,
148154 headers : vec ! [ ] ,
149155 } ,
150156 }
@@ -236,9 +242,10 @@ impl ContextInternal {
236242 syscall : "input" ,
237243 err : err. 0 . clone ( ) . into ( ) ,
238244 } ;
239- let _ = inner_lock
240- . vm
241- . sys_write_output ( NonEmptyValue :: Failure ( err. into ( ) ) , PayloadOptions :: stable ( ) ) ;
245+ let _ = inner_lock. vm . sys_write_output (
246+ NonEmptyValue :: Failure ( err. into ( ) ) ,
247+ PayloadOptions :: stable_serialization ( ) ,
248+ ) ;
242249 let _ = inner_lock. vm . sys_end ( ) ;
243250 // This causes the trap, plus logs the error
244251 inner_lock. handler_state . mark_error ( error_inner. into ( ) ) ;
@@ -261,7 +268,7 @@ impl ContextInternal {
261268 inner_lock,
262269 inner_lock
263270 . vm
264- . sys_state_get( key. to_owned( ) , PayloadOptions :: stable ( ) )
271+ . sys_state_get( key. to_owned( ) , PayloadOptions :: stable_serialization ( ) )
265272 ) ;
266273 inner_lock. maybe_flip_span_replaying_field ( ) ;
267274
@@ -307,9 +314,11 @@ impl ContextInternal {
307314 let mut inner_lock = must_lock ! ( self . inner) ;
308315 match t. serialize ( ) {
309316 Ok ( b) => {
310- let _ = inner_lock
311- . vm
312- . sys_state_set ( key. to_owned ( ) , b, PayloadOptions :: stable ( ) ) ;
317+ let _ = inner_lock. vm . sys_state_set (
318+ key. to_owned ( ) ,
319+ b,
320+ PayloadOptions :: stable_serialization ( ) ,
321+ ) ;
313322 inner_lock. maybe_flip_span_replaying_field ( ) ;
314323 }
315324 Err ( e) => {
@@ -402,7 +411,7 @@ impl ContextInternal {
402411 . and_then ( |input| {
403412 inner_lock
404413 . vm
405- . sys_call ( target, input, None , PayloadOptions :: stable ( ) )
414+ . sys_call ( target, input, None , PayloadOptions :: stable_serialization ( ) )
406415 . map_err ( Into :: into)
407416 } ) ;
408417
@@ -501,7 +510,7 @@ impl ContextInternal {
501510 + delay
502511 } ) ,
503512 None ,
504- PayloadOptions :: stable ( ) ,
513+ PayloadOptions :: stable_serialization ( ) ,
505514 ) {
506515 Ok ( h) => h,
507516 Err ( e) => {
@@ -554,7 +563,7 @@ impl ContextInternal {
554563 inner_lock. maybe_flip_span_replaying_field ( ) ;
555564
556565 let ( awakeable_id, handle) = match maybe_awakeable_id_and_handle {
557- Ok ( ( s , handle) ) => ( s , handle) ,
566+ Ok ( AwakeableHandle { id , handle } ) => ( id , handle) ,
558567 Err ( e) => {
559568 inner_lock. fail ( e. into ( ) ) ;
560569 return (
@@ -597,7 +606,7 @@ impl ContextInternal {
597606 let _ = inner_lock. vm . sys_complete_awakeable (
598607 id. to_owned ( ) ,
599608 NonEmptyValue :: Success ( b) ,
600- PayloadOptions :: stable ( ) ,
609+ PayloadOptions :: stable_serialization ( ) ,
601610 ) ;
602611 }
603612 Err ( e) => {
@@ -610,7 +619,7 @@ impl ContextInternal {
610619 let _ = must_lock ! ( self . inner) . vm . sys_complete_awakeable (
611620 id. to_owned ( ) ,
612621 NonEmptyValue :: Failure ( failure. into ( ) ) ,
613- PayloadOptions :: stable ( ) ,
622+ PayloadOptions :: stable_serialization ( ) ,
614623 ) ;
615624 }
616625
@@ -679,7 +688,7 @@ impl ContextInternal {
679688 let _ = inner_lock. vm . sys_complete_promise (
680689 name. to_owned ( ) ,
681690 NonEmptyValue :: Success ( b) ,
682- PayloadOptions :: stable ( ) ,
691+ PayloadOptions :: stable_serialization ( ) ,
683692 ) ;
684693 }
685694 Err ( e) => {
@@ -698,7 +707,7 @@ impl ContextInternal {
698707 let _ = must_lock ! ( self . inner) . vm . sys_complete_promise (
699708 id. to_owned ( ) ,
700709 NonEmptyValue :: Failure ( failure. into ( ) ) ,
701- PayloadOptions :: stable ( ) ,
710+ PayloadOptions :: stable_serialization ( ) ,
702711 ) ;
703712 }
704713
@@ -744,7 +753,7 @@ impl ContextInternal {
744753
745754 let _ = inner_lock
746755 . vm
747- . sys_write_output ( res_to_write, PayloadOptions :: stable ( ) ) ;
756+ . sys_write_output ( res_to_write, PayloadOptions :: stable_serialization ( ) ) ;
748757 inner_lock. maybe_flip_span_replaying_field ( ) ;
749758 }
750759
@@ -755,11 +764,8 @@ impl ContextInternal {
755764 pub ( crate ) fn consume_to_end ( & self ) {
756765 let mut inner_lock = must_lock ! ( self . inner) ;
757766
758- let out = inner_lock. vm . take_output ( ) ;
759- if let TakeOutputResult :: Buffer ( b) = out
760- && !b. is_empty ( )
761- && !inner_lock. write . send ( b)
762- {
767+ let b = inner_lock. vm . take_output ( ) ;
768+ if !b. is_empty ( ) && !inner_lock. write . send ( b) {
763769 // Nothing we can do anymore here
764770 }
765771 }
@@ -879,6 +885,7 @@ where
879885 max_interval : retry_policy. max_delay ,
880886 max_attempts : retry_policy. max_attempts ,
881887 max_duration : retry_policy. max_duration ,
888+ on_max_attempts : OnMaxAttempts :: FailAsTerminal ,
882889 } ;
883890 self
884891 }
@@ -911,14 +918,14 @@ where
911918 . expect ( "Future should not be polled after returning Poll::Ready" ) ;
912919 let mut inner_ctx = must_lock ! ( ctx) ;
913920
914- let handle = inner_ctx
921+ let RunHandle { handle, .. } = inner_ctx
915922 . vm
916923 . sys_run ( this. name . to_owned ( ) )
917924 . map_err ( ErrorInner :: from) ?;
918925
919926 // Now we do progress once to check whether this closure should be executed or not.
920- match inner_ctx. vm . do_progress ( vec ! [ handle] ) {
921- Ok ( DoProgressResponse :: ExecuteRun ( handle_to_run) ) => {
927+ match inner_ctx. vm . do_await ( UnresolvedFuture :: Single ( handle) ) {
928+ Ok ( AwaitResponse :: ExecuteRun ( handle_to_run) ) => {
922929 // In case it returns ExecuteRun, it must be the handle we just gave it,
923930 // and it means we need to execute the closure
924931 assert_eq ! ( handle, handle_to_run) ;
@@ -931,7 +938,7 @@ where
931938 closure_fut : closure. run ( ) ,
932939 } ) ;
933940 }
934- Ok ( DoProgressResponse :: CancelSignalReceived ) => {
941+ Ok ( AwaitResponse :: CancelSignalReceived ) => {
935942 drop ( inner_ctx) ;
936943 // Got cancellation!
937944 this. state . set ( RunState :: WaitingResultFut {
0 commit comments