Recover from some errors within sync iteration #97
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the
can_retry
method to the newPowerSyncError
type (#96). Then, in the sync iteration, we catch errors for each sync line and check whether the error is fatal or whether we allow retrying the operation.When retrying isn't necessary, we keep the sync iteration future active.
powersync_control
will still return an error, but the invocation can be retried after e.g. unlocking a database or waiting for a WA-sqlite VFS to settle.To implement this in a sound way, handling sync lines is split across two functions:
StreamingSyncIteration::prepare_handling_sync_line
: This method is responsible for writing data to the database, but it does not mutate the internal sync client state. It returns aSyncStateMachineTransition
, which describes pending changes to be applied if the call has succeeded.StreamingSyncIteration::apply_transition
then updates the internal client state.The reason for this split is that it makes it easy to argue that we cannot possibly update in-memory state before completing writes to SQLite (thanks Rust!). This ensures that handling sync lines is idempotent wrt. underlying SQLite failures, the property we need.
This also adds tests to block the database in different stages of the sync iteration.