Skip to content

Allow index requests with explicit ids on seq_no disabled backing indices#144041

Merged
fcofdez merged 8 commits intoelastic:mainfrom
fcofdez:allow-id-writes-on-seq-no-disabled-backing-indices
Mar 13, 2026
Merged

Allow index requests with explicit ids on seq_no disabled backing indices#144041
fcofdez merged 8 commits intoelastic:mainfrom
fcofdez:allow-id-writes-on-seq-no-disabled-backing-indices

Conversation

@fcofdez
Copy link
Copy Markdown
Contributor

@fcofdez fcofdez commented Mar 11, 2026

When sequence numbers are disabled on a data stream backing index,
OCC (if_seq_no/if_primary_term) cannot be used. This relaxes the
append-only restriction for INDEX ops with an explicit document id
targeting backing indices where seq_no is disabled, either on the
target index itself or on any sibling backing index in the data stream.

When sequence numbers are disabled on a data stream backing index,
OCC (if_seq_no/if_primary_term) cannot be used. This relaxes the
append-only restriction for INDEX ops with an explicit document ID
targeting backing indices where seq_no is disabled, either on the
target index itself or on any sibling backing index in the data
stream.
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

}

static boolean hasAnyBackingIndexWithSeqNoDisabled(DataStream dataStream, Function<Index, IndexMetadata> indexMetadataProvider) {
for (Index backingIndex : dataStream.getIndices()) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm exploring the idea of adding a flag into the data stream to tell whether or not it has any backing index with disabled seq nos.

@fcofdez fcofdez changed the title Allow ID writes on seq_no disabled backing indices Allow index requests with explicit ids on seq_no disabled backing indices Mar 11, 2026

@After
public void resetSearchInterceptor() {
public void cleanupInterceptors() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hit a failure in CI with this test and I noticed that the request interceptors weren't cleared after each test, so I went ahead and restricted more when we add the assertions based on the index name and added the clearing between runs to avoid any issues. Happy to extract this into another PR if it's adding noise.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I left some comments.

// to handle mixed data streams where OCC is disabled for the entire operation.
if (writeRequest.id() != null && IndexSettings.DISABLE_SEQUENCE_NUMBERS_FEATURE_FLAG) {
IndexMetadata targetMetadata = indexMetadataProvider.apply(indexAbstraction.getWriteIndex());
if ((targetMetadata != null && IndexSettings.DISABLE_SEQUENCE_NUMBERS.get(targetMetadata.getSettings()))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use targetMetadata.sequenceNumbersDisabled() here? That would be much more efficient.

static boolean hasAnyBackingIndexWithSeqNoDisabled(DataStream dataStream, Function<Index, IndexMetadata> indexMetadataProvider) {
for (Index backingIndex : dataStream.getIndices()) {
IndexMetadata im = indexMetadataProvider.apply(backingIndex);
if (im != null && IndexSettings.DISABLE_SEQUENCE_NUMBERS.get(im.getSettings())) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I think?

var overwriteResponse = client().prepareBulk()
.add(prepareIndex(backingIndex).setId(createdId).setSource(Map.of("@timestamp", "2020-01-01", "value", "overwritten")))
.get();
assertNoFailures(overwriteResponse);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we assert the UPDATED status?


@After
public void resetSearchInterceptor() {
public void cleanupInterceptors() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@fcofdez fcofdez merged commit d2444ea into elastic:main Mar 13, 2026
36 checks passed
@fcofdez
Copy link
Copy Markdown
Contributor Author

fcofdez commented Mar 13, 2026

Thanks for the review Tanguy!

michalborek pushed a commit to michalborek/elasticsearch that referenced this pull request Mar 23, 2026
…ices (elastic#144041)

When sequence numbers are disabled on a data stream backing index,
OCC (if_seq_no/if_primary_term) cannot be used. This relaxes the
append-only restriction for INDEX ops with an explicit document ID
targeting backing indices where seq_no is disabled, either on the
target index itself or on any sibling backing index in the data
stream.

Relates elastic#136305
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants