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

Updating a document using Update() unexpectedly results in a conflict #388

Closed
zgramana opened this issue Mar 6, 2015 · 1 comment · Fixed by #402
Closed

Updating a document using Update() unexpectedly results in a conflict #388

zgramana opened this issue Mar 6, 2015 · 1 comment · Fixed by #402
Assignees
Labels
Milestone

Comments

@zgramana
Copy link
Contributor

zgramana commented Mar 6, 2015

From @jonlipsky:

For each user that has had this problem, it only occurs after they make a change to an existing document, and when it happens, I get hundreds of error reports about the issue, which leads me to believe this is getting caused during executing the puller.

If they restart the app, the exceptions go away; however the users lose their latest changes and they get replaced by a previous revision.

Description: [Database] Couchbase.Lite.CouchbaseLiteException: Conflicts not allowed and there is already an existing doc with id: f4fe2fb4-e8fe-4fc1-a4b0-82ae1a3726de
at Couchbase.Lite.Database+c_AnonStorey5.<>m_0 () [0x00000] in :0
at Couchbase.Lite.Database+c_AnonStorey0.<>m_0 () [0x00000] in :0

@zgramana zgramana added the bug label Mar 6, 2015
@zgramana zgramana changed the title Updating a document unexpectedly results in a conflict Updating a document using Update unexpectedly results in a conflict Mar 6, 2015
@zgramana zgramana changed the title Updating a document using Update unexpectedly results in a conflict Updating a document using Update() unexpectedly results in a conflict Mar 6, 2015
@zgramana
Copy link
Contributor Author

zgramana commented Mar 6, 2015

The large number of counts of exceptions likely happens because Update runs the delegate inside of a do...while loop. If another process is simultaneously updating that doc, then a conflict is raised. This is caught, and the loop will abandon that failed revision and start over again. Consider this example, where foo is the document Id:

                       foo 1-aaaaaaaaaaa
                          /        \
                         /          \
Update > Create new rev: 'foo 2-'    \
                      /        Puller > Insert 'foo 2-bbbbbbbbbbb'
                     /
         Save > Insert 'foo 2-ccccccccccccc'
                    |
                 Conflict!
                    |
Update > Create new rev: 'foo 3-'
                    |
         Save > Insert 'foo 3-ccccccccccccc'
                    |
                 Success!

What's puzzling in this case is that the call to Save is always throwing an exception.

I believe I found the issue. The Java version of Update is missing a critical line from the iOS version which forces the current revision to be reloaded from disk before any subsequent iteration of the loop. I'll commit this fix in a minute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants