Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Core: create operation on replica should not throw DocumentAlreadyExistsException #7142
For a create operation, today we (by design) throw DAEE if the given _uid is already present in the index, even if its version is "old".
But when there are concurrent operations in flight against the same _uid this can be wrong, and was causing [rare] failures in SimpleVersioningTests.testRandomIDsAndVersions... the specific case was a given _uid was already in the index, and then a delete op (with higher version), and a create op (with higher version still) were issued concurrently.
On primary, the delete came first, succeeded, and then the create came second, and it succeeded. But on the replica, the create came first, and it threw DAEE (which we intentionally suppress & don't throw back to user), then the delete came, and it succeeded, leaving primary & replica silently out-of-sync.
To fix this, for a create op, if we are a replica, we should not throw DAEE: it means the primary has already decided the document should be indexed. Instead, we should fallback to the same logic index operation does, making sure the version is newer, and we must use IW.updateDocument/s in this case since the doc is in the index with an older version. We can still use the auto-gen'd ID optimization...