-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Dexie.Observable: startObserving function: remove read-only query in order to avoid TransactionInactiveError #1138
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1ec3e03
Do not re-use current transaction when observation begins
jayaddison 0035e27
Revert "Do not re-use current transaction when observation begins"
jayaddison 5237d33
startObserving: serialize database operations, and ignore current tra…
jayaddison 57b1d07
Revert "startObserving: serialize database operations, and ignore cur…
jayaddison f4de913
Alternative approach: place inner write operations within nested tran…
jayaddison bbd73a0
Use a single, ordered pass over the syncNodes table to modify and set…
jayaddison 76e3c76
Nit: adjust code formatting
jayaddison b645fd1
Add/update explanatory comments
jayaddison 7fc0c88
Assign updated master value to local sync node variable in addition t…
jayaddison 0825fec
Add safety check (with associated TODO)
jayaddison 8c74e39
Add explanatory comment and remove TODO message
jayaddison File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This 'works', but needs a bit of scrutiny as to whether it retains atomicity:
Ideally some test coverage to check & prove atomicity would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another related thought: this is currently essentially performing a get-and-set within a transaction to ensure atomicity.
Would it be possible instead to use a single write operation (
Table.modify
or similar) to perform the required updates?That way there would be no read-only query required within the transaction, and the transaction would not risk becoming inactive as a result of that query completing before any writes occur.
Our requirements are to:
isMaster
flag when no record withisMaster
and an up-to-date heartbeat timestamp is presentisMaster
flag on a record if the heartbeat timestamp is out-of-dateThe challenge is that the value we write for the current node record depends on the contents of a potentially existing (or potentially nonexistent) record with
isMaster
set and potentially out-of-date heartbeat timestamp.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does look like the
isMaster
field is an indexable type (ref: definition asNumber
), so perhaps it would be possible to usedb._syncNodes.orderBy(...).modify(...)
to retrieve existing syncnodes in order, maintain an external variable to store the 'current node should become master' state, and then use a function argument to modify to write the expected object record(s).