Skip to content
Open
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
9 changes: 9 additions & 0 deletions crates/core/src/sync/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ pub enum Instruction {
#[serde_as(as = "Option<DisplayFromStr>")]
applied_checkpoint_request_id: Option<i64>,
},
/// The sync client has received a `checkpoint_complete` message that couldn't be applied due to
/// pending local writes that have not been uploaded yet.
///
/// SDKs notify the sync client (via [SyncEvent::UploadFinished]) once writes have been
/// uploaded, which the client uses as a signal to try applying the checkpoint again.
///
/// SDKs connected in download-only mode raise this as an error, since these sync-preventing
/// writes would never be uploaded. Otherwise, handling this instruction is a noop.
CheckpointDelayedDueToLocalData {},

/// Handle a diagnostic event.
///
Expand Down
7 changes: 7 additions & 0 deletions crates/core/src/sync/streaming_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ impl StreamingSyncIteration {
severity: LogSeverity::INFO,
line: "Could not apply checkpoint due to local data. Will retry at completed upload or next checkpoint.".into(),
});
event
.instructions
.push(Instruction::CheckpointDelayedDueToLocalData {});

SyncStateMachineTransition::SyncLocalFailedDueToPendingCrud {
validated_but_not_applied: target.clone(),
Expand Down Expand Up @@ -287,6 +290,10 @@ impl StreamingSyncIteration {
SyncStateMachineTransition::CloseIteration(Default::default())
}
SyncLocalResult::PendingLocalChanges => {
event
.instructions
.push(Instruction::CheckpointDelayedDueToLocalData {});

// If we have pending uploads, we can't complete new checkpoints outside
// of priority 0. We'll resolve this for a complete checkpoint later.
SyncStateMachineTransition::EmptyAndConnected
Expand Down
15 changes: 12 additions & 3 deletions dart/test/sync_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,10 @@ void _syncTests<T>({
containsPair('LogLine', {
'severity': 'INFO',
'line': contains('Will retry at completed upload')
})
}),
{
'CheckpointDelayedDueToLocalData': {},
},
]);

// Now complete the upload process.
Expand Down Expand Up @@ -1364,7 +1367,10 @@ void _syncTests<T>({
containsPair('LogLine', {
'severity': 'INFO',
'line': contains('Will retry at completed upload')
})
}),
{
'CheckpointDelayedDueToLocalData': {},
},
]);

// Now the upload is complete and requests a write checkpoint
Expand Down Expand Up @@ -1398,7 +1404,10 @@ void _syncTests<T>({
containsPair('LogLine', {
'severity': 'INFO',
'line': contains('Will retry at completed upload')
})
}),
{
'CheckpointDelayedDueToLocalData': {},
},
]);

// Second local write during sync
Expand Down
Loading