Skip to content
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

DataStore batch reconciliation bug when changelist for models include delete #2727

Closed
lawmicha opened this issue Mar 7, 2024 · 3 comments
Closed
Assignees
Labels
bug Something isn't working datastore DataStore category/plugins

Comments

@lawmicha
Copy link
Member

lawmicha commented Mar 7, 2024

Let me try to summarize this, the reconciliation path for DataStore takes the sync query remote model results and decides to apply the remote model to the local database or drop it. Previously the logic processed one model at a time. We changed this to a batch operation by putting the reconciliation logic under a transaction block, operating on the entire list of remote models. The necessary logic updates to perform the SQL operations more efficiently included constructing a predicate of all the model identifiers as a filter criteria for querying local data that is used for the reconciliation logic. There exists a bug with this optimization when having multiple entries of remote model belong to the same identifier and the changes to the remote model ends up as a deleted model on the latest version.

Bug example
remoteModels = [id=111 version=1 deleted=false, id=111 version=2 deleted=true]

When the disposition of the model is calculated for the create model, it is to create the model with the local database, because there is no local model, nor is there a local model with version less than the remote model.
When the disposition of the model is calculated for the delete model, it is to drop it because no local model yet to exist, so it thinks there is nothing to delete.

The end result is the model is created but not deleted. The fix we are applying in the PR is to optimize the reconciliation by only taking the latest versions of the remote model. In the example, this becomes [id=111 version=2, deleted=true]. The latest version represents the final state of the model that we want applied to the local database. In this case, the remote model will be dropped. There is no create disposition so it will not be created either.

Originally posted by @lawmicha in aws-amplify/amplify-swift#3554 (comment)

@github-actions github-actions bot added the pending-triage Issue is pending triage label Mar 7, 2024
Copy link
Contributor

github-actions bot commented Mar 7, 2024

This issue was opened by a maintainer of this repository; updates will be posted here. If you are also experiencing this issue, please comment here with any relevant information so that we're aware and can prioritize accordingly.

@tylerjroach tylerjroach added datastore DataStore category/plugins bug Something isn't working and removed pending-triage Issue is pending triage labels Mar 11, 2024
joon-won added a commit that referenced this issue May 3, 2024
@joon-won
Copy link
Member

joon-won commented May 3, 2024

This issue is resolved with Amplify Android 2.16.1

@joon-won joon-won closed this as completed May 3, 2024
Copy link
Contributor

github-actions bot commented May 3, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datastore DataStore category/plugins
Projects
None yet
Development

No branches or pull requests

3 participants