Repository navigation
Conversation
Replication can deliver a setup document between the read and the write in doSetup. CouchDB then rejects the write with a 409 conflict, and setupDatabase threw. A server that exits on setup errors would restart in a loop until every replicated cluster had the document. On a conflict, run the same read-and-check step again. A document that now matches, or a template that now exists, needs no write. Otherwise write again on top of the new revision, up to 5 attempts in all. Other errors still throw right away.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
none
Description
setupDatabasereads each setup document, compares it with the setup, and writes it if it is missing or different. If replication delivers the same document to that cluster between the read and the write, CouchDB rejects the write with409 conflict("Document update conflict."), and the error escapessetupDatabase.This happens when a server writes a new design document to several clusters in turn and some of those clusters replicate into a later one. edge-login-server exits when setup fails, so the first backend restarted after a release that added a design document crash-looped. Each restart got one database further before the next conflict, until every database on the replicated cluster had the document. Any release that adds or changes a design document can hit the same race.
Both write loops in
doSetupnow run their read, check and write through a newretryOnConflicthelper. On a 409, the step runs again with a fresh read:matchJson) needs no write, so setup moves on. This is the usual case, because replication delivers the same content setup was about to write._rev.After 5 conflicting writes for one document, setup throws the last conflict error. Other errors are thrown right away, as before.
The log lines are unchanged. "Writing document ..." is printed before each write, so a document that needs a second write logs it twice. A dry run never writes, so its output is the same as before.
Testing:
test/couchdb/setup-database.test.ts, with a fake cluster that rejects stale writes with a 409 the way CouchDB does. Four cases fail on master with "Document update conflict." and pass on this branch. Two more check that other errors are not retried and that a dry run only logs.409 conflictin every round. On this branch, all 4 rounds hit the real 409 and finished, and both clusters ended on the same revision with no conflicts.yarn verifypasses.