Closed ghost closed 9 years ago
Hi @noonedoes can you please post a simplified version of the code, which consists only of logic needed to reproduce the problem?
@jo I did some additional testing. I believe this issue is related to the the the 202 return code during a create of the cloudant document.
https://docs.cloudant.com/api.html#documentCreate32
202 - Accepted
Request has been accepted, but the corresponding operation may not have completed. This is used for background operations, such as database compaction or for bulk operations where some updates might have led to a conflict. This code can also be returned following an attempt to create or update a document.
It appears the insert request was successful but the operation wasn't completed, so when a subsequent insert request happens with the same rev id, it overwrites it. I might be able to get around it by using the header returned during the insert.
Thanks
Closing now, feel free to reopen.
I have code that is trying to concurrently update a document to reserve a free port. I followed the guide to get the document and then do an insert. If the insert fails it'll retry do a recursive call on the method and gets the document and trys inserting again.
It works for the most part, but on a few occasions...a double insert happens so it overwrites the an entry.
Here is my calling code:
and for the the PortList.js:
When it executes, the document before inserting has the same _rev id as another another doc: [2015-04-21 13:43:04.477] [INFO] portlist - Doc to insert = { _id: 'test/portlist', _rev: '265-1c0ca8a768551c43a8043c4c4ae071f6', start: 1, end: 50, available: 44, inuse: { '1': 'test_3', '2': 'test_1', '3': 'test_5', '4': 'test_2', '5': 'test_0' },
[2015-04-21 13:43:04.432] [INFO] portlist - Doc to insert = { _id: 'test/portlist', _rev: '265-1c0ca8a768551c43a8043c4c4ae071f6', start: 1, end: 50, available: 44, inuse: { '1': 'test_3', '2': 'test_1', '3': 'test_5', '4': 'test_2', '5': 'test_4' }, free:
but both of them are are inserted:
[2015-04-21 13:43:05.475] [INFO] portlist - { ok: true, id: 'test/portlist', rev: '266-0d56476019fc3d3eca8315e8f7954bc5' } [2015-04-21 13:43:05.479] [INFO] portlist - Successfully updated doc: 5 for key test/portlist [2015-04-21 13:43:05.484] [INFO] portlist - { ok: true, id: 'test/portlist', rev: '266-488e8bd6a767a8fef06ef33883f5f2f4' } [2015-04-21 13:43:05.487] [INFO] portlist - Successfully updated doc: 5 for key test/portlist
and in the resultant doc in the database:
{ "_id": "test/portlist", "_rev": "266-488e8bd6a767a8fef06ef33883f5f2f4", "start": 1, "end": 50, "available": 44, "inuse": { "1": "test_3", "2": "test_1", "3": "test_5", "4": "test_2", "5": "test_0" },
so rev 266-488e8bd6a767a8fef06ef33883f5f2f4 overwrote 266-0d56476019fc3d3eca8315e8f7954bc5