-
Notifications
You must be signed in to change notification settings - Fork 26
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
[Feature] Add warning if crud transactions are not completed #254
Merged
Conversation
This file contains 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
PowerSyncDatabase
client will call the backend connector'suploadData
function wheneverCrudEntry
items are present in theps_crud
internal table.The
uploadData
callback has access to thePowerSyncDatabase
client which it can use to get the pendingCrudEntry
s. The connector can consume the CRUD events in numerous different ways.Typically the
uploadData
callback will either callgetNextCrudTransaction
orgetCrudBatch
on thePowerSyncDatabase
.getNextCrudTransaction
will return the next (Single) group ofCrudEntry
s 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.getCrudBatch
returnsn
CrudEntry
s as an instance ofCrudBatch
. These entires are not grouped by transaction.The
CrudBatch
andCrudTransaction
classes each have acomplete
method which will remove theCrudEntry
s from the CRUD queue. This should be executed in theuploadData
method 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
uploadData
method. In this case the SDK will continuously check ifCrudEntry
s are present in the queue and calluploadData
until the queue is empty.Issues can occur if the
uploadData
callback fetches CRUD items and uploads them without calling and awaiting theCrudTransaction
orCrudBatch
complete
method.Failing to
await
acomplete()
call in theuploadData
method is mostly guarded in the SDK due to limits on concurrent SQLite operations. Previously theSqliteBucketStorage
implementation used.execute
methods for checking if CRUD items were available. Internal queues would (luckily) ensure the next upload iteration would essentially await for thecomplete
action to complete.Failing to call the
complete()
method altogether is a much worse scenario. This would result inCrudEntry
s not being removed from the queue (after they have been uploaded). The SDK previously would blindly check ifCrudEntry
s were still present and immediately calluploadData
to upload them - this will result in an infinite loop of repeated uploads.This PR replaces the use of the
hasCrud
check with getting theCrudEntry
which is first in line to be uploaded (the behaviour ofhasCrud
is matched if the entry exists). The SDK can then keep track of thisCrudEntry
in 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.