Repository navigation
fix: send if_seq_no/if_primary_term in bulk index, create and update actions - #2336
Open
caioocesar wants to merge 2 commits into
Open
caioocesar wants to merge 2 commits into
caioocesar wants to merge 2 commits into
Conversation
…actions Bulk IndexDocument (and CreateDocument/UpdateDocument, which extend it) left the optimistic concurrency control options out of the action metadata, so they were silently ignored. DeleteDocument included them but read them through getOptions(), which filters falsy values and dropped if_seq_no = 0 (the first document in a shard). Fixes ruflin#2058 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #2058
Problem
Document::setSequenceNumber()/setPrimaryTerm()(and the same setters on scripts) are ignored when the document goes throughBulk:Bulk\Action\IndexDocument::_getMetadata()does not listif_seq_no/if_primary_term.CreateDocumentandUpdateDocumentextend it, so bulkindex,createandupdateactions all send the write unconditionally. A stale document overwrites the newer one instead of failing with a version conflict.Bulk\Action\DeleteDocumentlists both keys, but reads them throughgetOptions(), which runsarray_filter()and dropsif_seq_no = 0, the sequence number of the first document written to a shard.Index::addDocument()already handles this case explicitly (Add support for seq_no_primary_term search option and if_seq_no/if_primary_term index options #2284).Change
AbstractDocument::_addConcurrencyControlMetadata()adds both options withhasSequenceNumber()/hasPrimaryTerm(), so0is kept.IndexDocument(and thereforeCreateDocumentandUpdateDocument) andDeleteDocumentuse it.Elasticsearch accepts
if_seq_no/if_primary_termon bulkindex,updateanddeleteactions. It rejects them oncreate("create operations do not support compare and set"). Acreateaction with these options now gets that error back instead of silently creating the document without the check, which matches whatIndex::addDocument()does withop_type=create.Tests
tests/Bulk/Action/AbstractDocumentTest.php. They check the action metadata forindex,create,updateanddeletewith sequence numbers5and0, for a script-based update, and for a document without the options.src/reverted to9.xand the tests kept, 8 of the 12 cases fail, for exampletestDocumentConcurrencyControlMetadata with data set "update" ('update', 5):Failed asserting that two arrays are identical(the expected'if_seq_no' => 5, 'if_primary_term' => 2are missing). With the fix all 12 pass.vendor/bin/phpunit --group=uniton PHP 8.4: 506 tests pass, 1 skipped.tests/DocumentTest.php, which the same run also reports on unmodified9.x.AI disclosure
The code, tests and this description were written by an AI agent (Claude Code, model Claude Opus 5.5) following this repository's
AGENTS.md, and published from my account.🤖 Generated with Claude Code