Reindex Relocation: Prevent source task override task result#145947
Open
samxbr wants to merge 14 commits intoelastic:mainfrom
Open
Reindex Relocation: Prevent source task override task result#145947samxbr wants to merge 14 commits intoelastic:mainfrom
samxbr wants to merge 14 commits intoelastic:mainfrom
Conversation
Collaborator
|
Pinging @elastic/es-distributed (Team:Distributed) |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens reindex relocation task-result persistence by ensuring the relocation destination’s write to .tasks cannot be overwritten by a racing source-node write, preserving the relocation chain even under partial failures (e.g., lost resume response).
Changes:
- Add create-if-absent result storage (
opType(CREATE)) for tasks that must not overwrite an existing.tasksdocument, treating version conflicts as success. - Wire task-specific “create semantics” into
TaskManagerand enable it for reindex source tasks once relocation handoff begins. - Expand unit + integration tests to cover race orderings (destination-first and source-first) and validate stored content/chain behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| server/src/main/java/org/elasticsearch/tasks/TaskResultsService.java | Adds storeResultIfAbsent() using CREATE semantics and version-conflict-as-success handling. |
| server/src/main/java/org/elasticsearch/tasks/TaskManager.java | Routes result persistence through new task-level create/overwrite decision. |
| server/src/main/java/org/elasticsearch/tasks/Task.java | Introduces overridable hook to request create-if-absent result storage. |
| server/src/main/java/org/elasticsearch/index/reindex/BulkByScrollTask.java | Tracks relocation handoff initiation and opts into create-if-absent result storage afterwards. |
| modules/reindex/src/main/java/org/elasticsearch/reindex/Reindexer.java | Sets the handoff flag prior to sending resume request; adds assertion around when source-task results are stored. |
| server/src/main/java/org/elasticsearch/tasks/TaskResult.java | Enforces invariant: cannot have both error and response bytes. |
| server/src/test/java/org/elasticsearch/tasks/TaskResultTests.java | Adds a test validating the new TaskResult invariant. |
| server/src/main/java/org/elasticsearch/index/reindex/ResumeInfo.java | Updates documentation around source task result propagation. |
| modules/reindex/src/test/java/org/elasticsearch/reindex/ReindexerTests.java | Adds coverage ensuring relocation handoff flips the create-semantics flag; strengthens source-task-result assertions. |
| modules/reindex-management/src/test/java/org/elasticsearch/reindex/management/TransportGetReindexActionTests.java | Adjusts relocation-chain test setup consistent with updated chain preservation semantics. |
| modules/reindex-management/src/internalClusterTest/java/org/elasticsearch/reindex/management/ReindexRelocationIT.java | Adds IT coverage for destination-first/source-first write races; extends test plugin to block/defer .tasks writes and capture sources. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...t/src/internalClusterTest/java/org/elasticsearch/reindex/management/ReindexRelocationIT.java
Show resolved
Hide resolved
...t/src/internalClusterTest/java/org/elasticsearch/reindex/management/ReindexRelocationIT.java
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/reindex/ResumeInfo.java
Outdated
Show resolved
Hide resolved
szybia
approved these changes
Apr 10, 2026
Contributor
szybia
left a comment
There was a problem hiding this comment.
LGTM!
only thing, copilot might be cooking with suggestion to use generic threadpool rather than stranded thread
…o.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
This is a follow-up of #145488. This prevents the source reindex task overriding the result written by the destination task, effectively ensuring the destination always wins if there's a race. This is to ensure the relocation chain is preserved in the case where the source task observes another error (eg. network error if the resume response from destination to source is lost).