1- use core:: { cell :: RefCell , fmt:: Write } ;
1+ use core:: fmt:: Write ;
22
33use alloc:: {
44 borrow:: Cow ,
@@ -136,7 +136,7 @@ struct StreamingSyncIteration {
136136 // A checkpoint that has been fully received and validated, but couldn't be applied due to
137137 // pending local data. We will retry applying this checkpoint when the client SDK informs us
138138 // that it has finished uploading changes.
139- validated_but_not_applied : RefCell < Option < OwnedCheckpoint > > ,
139+ validated_but_not_applied : Option < OwnedCheckpoint > ,
140140 diagnostics : Option < DiagnosticsCollector > ,
141141}
142142
@@ -156,7 +156,7 @@ impl StreamingSyncIteration {
156156 Ok ( Self {
157157 state,
158158 adapter,
159- status : SyncStatusContainer :: new ( ) ,
159+ status,
160160 options,
161161 target : SyncTarget :: BeforeCheckpoint ( prepared_request) ,
162162 validated_but_not_applied : Default :: default ( ) ,
@@ -289,9 +289,7 @@ impl StreamingSyncIteration {
289289 SyncLocalResult :: PendingLocalChanges => {
290290 // If we have pending uploads, we can't complete new checkpoints outside
291291 // of priority 0. We'll resolve this for a complete checkpoint later.
292- SyncStateMachineTransition :: Empty {
293- contains_line : true ,
294- }
292+ SyncStateMachineTransition :: EmptyAndConnected
295293 }
296294 SyncLocalResult :: ChangesApplied { timestamp } => {
297295 SyncStateMachineTransition :: SyncLocalChangesApplied {
@@ -322,9 +320,7 @@ impl StreamingSyncIteration {
322320 event
323321 . instructions
324322 . push ( Instruction :: FetchCredentials { did_expire : false } ) ;
325- SyncStateMachineTransition :: Empty {
326- contains_line : true ,
327- }
323+ SyncStateMachineTransition :: EmptyAndConnected
328324 } else {
329325 // Periodically check whether any subscriptions that are part of this stream
330326 // are expired. We currently do this by re-creating the request and aborting the
@@ -339,9 +335,7 @@ impl StreamingSyncIteration {
339335 hide_disconnect : true ,
340336 } )
341337 } else {
342- SyncStateMachineTransition :: Empty {
343- contains_line : true ,
344- }
338+ SyncStateMachineTransition :: EmptyAndConnected
345339 }
346340 }
347341 }
@@ -350,9 +344,7 @@ impl StreamingSyncIteration {
350344 severity : LogSeverity :: DEBUG ,
351345 line : "Unknown sync line" . into ( ) ,
352346 } ) ;
353- SyncStateMachineTransition :: Empty {
354- contains_line : true ,
355- }
347+ SyncStateMachineTransition :: EmptyAndConnected
356348 }
357349 } )
358350 }
@@ -379,7 +371,7 @@ impl StreamingSyncIteration {
379371 // pending checkpoint, so we'd have to take the oplog state at the time we've
380372 // originally received the validated-but-not-applied checkpoint. This is likely not
381373 // something worth doing.
382- * self . validated_but_not_applied . get_mut ( ) = None ;
374+ self . validated_but_not_applied = None ;
383375 self . target = updated_target;
384376
385377 if let Some ( diagnostics) = & self . diagnostics {
@@ -406,13 +398,15 @@ impl StreamingSyncIteration {
406398 SyncStateMachineTransition :: SyncLocalFailedDueToPendingCrud {
407399 validated_but_not_applied,
408400 } => {
409- * self . validated_but_not_applied . get_mut ( ) = Some ( validated_but_not_applied) ;
401+ self . validated_but_not_applied = Some ( validated_but_not_applied) ;
410402 }
411403 SyncStateMachineTransition :: SyncLocalChangesApplied {
412404 applied_checkpoint_request_id,
413405 partial,
414406 timestamp,
415407 } => {
408+ self . validated_but_not_applied = None ;
409+
416410 if let Some ( priority) = partial {
417411 self . status . update (
418412 |status| {
@@ -427,16 +421,11 @@ impl StreamingSyncIteration {
427421 SyncStateMachineTransition :: ChangeActiveStreams ( streams) => {
428422 self . options . active_streams = streams;
429423 }
430- SyncStateMachineTransition :: MarkConnected
431- | SyncStateMachineTransition :: Empty {
432- contains_line : true ,
433- } => {
424+ SyncStateMachineTransition :: EmptyAndConnected => {
434425 self . status
435426 . update ( |s| s. mark_connected ( ) , & mut event. instructions ) ;
436427 }
437- SyncStateMachineTransition :: Empty {
438- contains_line : false ,
439- } => { }
428+ SyncStateMachineTransition :: Empty => { }
440429 } ;
441430
442431 false
@@ -479,7 +468,7 @@ impl StreamingSyncIteration {
479468 SyncStateMachineTransition :: ChangeActiveStreams ( Rc :: clone ( active_streams) )
480469 }
481470 }
482- SyncEvent :: ConnectionEstablished => SyncStateMachineTransition :: MarkConnected ,
471+ SyncEvent :: ConnectionEstablished => SyncStateMachineTransition :: EmptyAndConnected ,
483472 SyncEvent :: DidRefreshToken => {
484473 // Break so that the client SDK starts another iteration.
485474 SyncStateMachineTransition :: CloseIteration ( CloseSyncStream {
@@ -517,20 +506,16 @@ impl StreamingSyncIteration {
517506 & ' _ self ,
518507 event : & mut ActiveEvent < ' a > ,
519508 ) -> Result < SyncStateMachineTransition < ' a > > {
520- let Some ( checkpoint) = self . validated_but_not_applied . take ( ) else {
521- return Ok ( SyncStateMachineTransition :: Empty {
522- contains_line : false ,
523- } ) ;
509+ let Some ( checkpoint) = & self . validated_but_not_applied else {
510+ return Ok ( SyncStateMachineTransition :: Empty ) ;
524511 } ;
525512
526513 let target_write = self . adapter . target_checkpoint_request_id ( ) ?;
527514 if checkpoint. write_checkpoint < target_write {
528515 // Note: None < Some(x). The pending checkpoint does not contain the write
529516 // checkpoint created during the upload, so we don't have to try applying it, it's
530517 // guaranteed to be outdated.
531- return Ok ( SyncStateMachineTransition :: Empty {
532- contains_line : false ,
533- } ) ;
518+ return Ok ( SyncStateMachineTransition :: Empty ) ;
534519 }
535520
536521 let result = self . sync_local ( & checkpoint, None ) ?;
@@ -557,9 +542,7 @@ impl StreamingSyncIteration {
557542 line : "Could not apply pending checkpoint even after completed upload" . into ( ) ,
558543 } ) ;
559544
560- SyncStateMachineTransition :: Empty {
561- contains_line : false ,
562- }
545+ SyncStateMachineTransition :: Empty
563546 }
564547 } )
565548 }
@@ -1057,8 +1040,6 @@ enum SyncStateMachineTransition<'a> {
10571040 } ,
10581041 CloseIteration ( CloseSyncStream ) ,
10591042 ChangeActiveStreams ( Rc < Vec < StreamKey > > ) ,
1060- MarkConnected ,
1061- Empty {
1062- contains_line : bool ,
1063- } ,
1043+ EmptyAndConnected ,
1044+ Empty ,
10641045}
0 commit comments