-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Multi-Writer Prevention : Conditional Upload Flow & Logic #18522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
x-INFiN1TY-x
wants to merge
46
commits into
opensearch-project:main
Choose a base branch
from
x-INFiN1TY-x:pr-branch-MultiWriterMetadataUploadLogic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Multi-Writer Prevention : Conditional Upload Flow & Logic #18522
x-INFiN1TY-x
wants to merge
46
commits into
opensearch-project:main
from
x-INFiN1TY-x:pr-branch-MultiWriterMetadataUploadLogic
+4,230
−332
Conversation
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
Signed-off-by: Tanishq Ranjan <[email protected]>
Signed-off-by: Tanishq Ranjan <[email protected]>
Signed-off-by: Tanishq Ranjan <[email protected]>
Introduces ConditionalWriteOptions and ConditionalWriteResponse classes to support conditional write operations in BlobContainer implementations.
…tainer & AsyncMultiStreamEncryptedBlobContainer
Signed-off-by: Tanishq Ranjan <[email protected]>
….ConditionalWriteResponse
plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3BlobContainer.java plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3BlobStoreContainerTests.java
2. Etag Cache Implementation
Contributor
|
❌ Gradle check result for 4ef0bcd: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Contributor
|
This PR is stalled because it has been open for 30 days with no activity. |
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.
Related Issues/RFCs:
Problem Statement
OpenSearch clusters using remote-backed storage are susceptible to data inconsistencies when multiple primary shards concurrently attempt to upload segment metadata—particularly during network partitions or primary failovers. A stale (previously active) primary might overwrite metadata written by the newly promoted one. This risk undermines cluster safety and complicates automation in recovery flows.
Current multi-writer detection mechanisms are not robust enough to handle this reliably.
Solution Overview
This PR introduces ETag-based conditional writes to the remote segment metadata upload process. ETags (version identifiers from cloud storage systems like S3, GCS, or Azure) allow OpenSearch to safely coordinate access to shared resources. This mechanism ensures only the correct primary shard can write metadata, while stale primaries self-detect and fence themselves.
Key enhancements:
ETag-Based Conditional Writes:
Primary shards attach the known ETag to each metadata upload using the
If-Matchcondition. If the ETag doesn't match the current version in the remote store, the write is rejected (HTTP 412 Precondition Failed).Fixed Metadata Filename:
To enable ETag-based coordination, segment metadata is now always written to a fixed filename (e.g.,
"segment_metadata") instead of legacy dynamic filenames.Stale Primary Self-Fencing:
failShard()operation, fencing off the stale node.ETag Lifecycle Managed at Shard Level:
IndexShardnow caches the ETag for its segment metadata file and updates it based on the success/failure of remote operations.This design shifts writer validation from OpenSearch into the remote store’s atomic operations—improving correctness and simplifying state coordination.
Key Implementation Details
IndexShardIntroduces a
MetadataETagCacheper shard to hold the latest known ETag.Provides methods:
getMetadataETag()updateMetadataETag()clearMetadataETag()On primary promotion, invokes
initiateNonConditionalRemoteMetadataUpload():RemoteStoreRefreshListenerDuring each metadata upload:
uploadMetadata(...)with the ETag and a structuredActionListener.On success: Updates shard’s cached ETag.
On
Precondition Failed: Treats this as a stale primary detection, clears ETag, and callsfailShard()for fencing.Logs other failures without failing the shard.
RemoteSegmentStoreDirectoryAccepts a
versionIdentifier(ETag) and enhancedActionListener.Constructs
ConditionalWriteOptionsbased on the ETag:ifMatchAlways uses
"segment_metadata"as the remote filename.RemoteDirectory&BlobStorecopyFrom()method now takesConditionalWriteOptions.blobContainer.writeBlobConditionally(...)for storage-provider-specific handling.Testing
Unit tests in
RemoteSegmentStoreDirectoryTestshave been expanded to verify:Related Issues
Implements part of RFC #17763
Parent Meta Issue: [META] Implement Conditional APIs for Multi-Writer Detection
Supersedes Introduce Interface changes to Support atomic conditional-writes #18065
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.
Visualizing the Changes
Sequence Diagram: Stale Primary Self-Fencing Mechanism

Demonstrates how an outdated ETag causes a 412 failure, triggering the stale primary’s self-initiated
failShard().Architecture: Core Components for Conditional Metadata Upload

Shows interaction flow between
IndexShard,RemoteStoreRefreshListener,RemoteSegmentStoreDirectory,RemoteDirectory, andBlobStore, including ETag usage.Flowchart: New Primary’s Metadata Ownership Claim

Shows how a new primary clears its ETag cache, performs a non-conditional upload, and updates its local ETag before assuming control.