-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 latter updates should take precedent on a slow network #6363
Comments
@mauerbac Thanks for parking this under feature-request, but isn't this more like an issue with DataStore rather than a feature request? |
I can reproduce in React too. Repo link & Local data/mutations seems to be working fine, it's the appsync graphql request that is returning the previous data when For example I'm sending 5 saves A B C D E: https://github.com/wei/aws-amplify-react/blob/6363/src/App.js#L21-L27 2 Appsync graphql requests can be observed:
I tried to replay the second request as well sending the same When setting When setting The second request in my screenshots is updating Update |
Clients never update the version in DataStore. The consistency model is to have a central authority and therefore only AppSync updates the version. This is outlined in the AppSync documentation as well. Up-leveling to the original question: If I make a local mutation, then change the data again before going online, the final state is what should be represented in the system. If that's not happening then this is a bug and should be looked into. DataStore's offline queue is a hashmap which operates in the following mechanism:
With this information lets go back to the original question:
Based on this description I suspect a bug exists in the React Native implementation for draining the hashmap after a successful service confirmation of a write. We should review this in bugbash. |
@undefobj Thanks for sharing your insights. I performed some tests on react-native. Take my example of updating titles to There are two different scenarios:
To summarize: This issue arises when a request is enroute and another mutation on the same model is triggered in the meantime (with the same @nubpro One solution I can think of is to use a custom LAMBA conflict resolver to basically ignore _version and always update the field, not ideal but doable. |
Thanks for the detailed investigation. I don't think this problem is exclusive to React Native only is it? We are using a custom conflict resolver setup for the particular mutation to address this pain-point in prod. |
@nubpro yeah I believe it's across the board. |
Please don't do this, let AppSync handle updates to the version. Modifying it could lead to data loss. I've spoken with @iartemiev and I think there is an improvement to the hashmap implementation for slow networks that we can make by not allowing the write to the record when the item is in flight. He's tracking the issue internally. |
Would the solution be throwing an error when user is trying to save a model meeting the following condition?
Users can then catch this error on |
I haven't been following this thread in detail, but @undefobj 's suggestion at first glance concerns me because the whole point of DataStore in my view is that it insulates the developer from having to worry about online-offline connectivity - things are queued on the way out and on the way in. What @undefobj suggests appears to deviate from this. I don't know the internals here, but it appears to me that every local mutation should either increase the (This ever-increasing versioning stategy is normally derived using the current time, but I've forgotten the exact name of this versioning strategy - something to do with atomic clocks but my brain and google-fu is failing me). The summary of my concern is I wouldn't want local writes to be blocked because the network is either unavailable, slow, or intermittently available, as that would be a terrible user experience and also brings up questions like what @wei said in that we'd want to fail fast in those situations, but in a slow network situation, that's kind of a paradox. /cc @iartemiev |
@danrivett I think you're reading too much into the phrasing of my comment. The library should handle all of these implementations internally, not force the developer to think about them. @wei is one of the Amplify team fellows working with @iartemiev |
same issue with react |
@nubpro and @laclance Note that this problem is exclusive to Automerge. Optimistic Concurrency abides by last-write-wins, so it will correctly keep the latter update. |
Hi, is there any update please? |
We just deployed changes that should fix this. |
I'm having an issue that seems similar to this on the latest version (#8012), if it's the same bug this issue is not fixed. |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Describe the bug
Say you have a button to update a Post title.
With that you change the post title to 'Hairy Potter'. This mutation is queued in the outbox.
However before this mutation is processed, you decides to update the post title again to 'Marry in the Soberland'.
As a user, you would expect your post title to be permanently change to the latter title as the local updates reflects that.
Once the both mutations are processed, the post title would return to 'Hairy Potter' which isn't correct.
To Reproduce
Expected behavior
The expected post title should be 'Title B'.
What is Configured?
We are using 'Auto merge' as the Conflict Handler, however it shouldn't matter for this case. As I would expect DataStore to give precedent to the second mutation because the first mutation is not processed yet. Personally, I think the solution would be to increment the version number by 1 to the second mutation after knowing that the first mutation is processed.
Environment
Smartphone (please complete the following information):
The text was updated successfully, but these errors were encountered: