-
Notifications
You must be signed in to change notification settings - Fork 58
[Feature] Add warning if crud transactions are not completed #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🦋 Changeset detectedLatest commit: 8a87ec2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
stevensJourney
commented
Aug 6, 2024
stevensJourney
commented
Aug 6, 2024
rkistner
approved these changes
Aug 6, 2024
DominicGBauer
approved these changes
Aug 6, 2024
Chriztiaan
approved these changes
Aug 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
Currently when processing CRUD items the
PowerSyncDatabaseclient will call the backend connector'suploadDatafunction wheneverCrudEntryitems are present in theps_crudinternal table.The
uploadDatacallback has access to thePowerSyncDatabaseclient which it can use to get the pendingCrudEntrys. The connector can consume the CRUD events in numerous different ways.Typically the
uploadDatacallback will either callgetNextCrudTransactionorgetCrudBatchon thePowerSyncDatabase.getNextCrudTransactionwill return the next (Single) group ofCrudEntrys which occurred in the same transaction as an instance ofCrudTransaction. If an operation did not occur in a transaction then only a single operation will be returned.getCrudBatchreturnsnCrudEntrys as an instance ofCrudBatch. These entires are not grouped by transaction.The
CrudBatchandCrudTransactionclasses each have acompletemethod which will remove theCrudEntrys from the CRUD queue. This should be executed in theuploadDatamethod after the items have successfully been uploaded.Given the nature above, there may be more items in the queue than what was consumed by a single invocation of the
uploadDatamethod. In this case the SDK will continuously check ifCrudEntrys are present in the queue and calluploadDatauntil the queue is empty.Issues can occur if the
uploadDatacallback fetches CRUD items and uploads them without calling and awaiting theCrudTransactionorCrudBatchcompletemethod.Failing to
awaitacomplete()call in theuploadDatamethod is mostly guarded in the SDK due to limits on concurrent SQLite operations. Previously theSqliteBucketStorageimplementation used.executemethods for checking if CRUD items were available. Internal queues would (luckily) ensure the next upload iteration would essentially await for thecompleteaction to complete.Failing to call the
complete()method altogether is a much worse scenario. This would result inCrudEntrys not being removed from the queue (after they have been uploaded). The SDK previously would blindly check ifCrudEntrys were still present and immediately calluploadDatato upload them - this will result in an infinite loop of repeated uploads.This PR replaces the use of the
hasCrudcheck with getting theCrudEntrywhich is first in line to be uploaded (the behaviour ofhasCrudis matched if the entry exists). The SDK can then keep track of thisCrudEntryin the upload loop. If it sees the same entry that it already processed previously a warning will be printed and the upload loop will be delayed in order to slow down the infinite loop. This does not currently prevent the loop from continuing.This should help for issues such as #247.