Skip to content

Remove seq_no from bulk response when disabled#143753

Merged
romseygeek merged 11 commits intoelastic:mainfrom
romseygeek:seqno/remove-seq-from-bulk-response
Mar 10, 2026
Merged

Remove seq_no from bulk response when disabled#143753
romseygeek merged 11 commits intoelastic:mainfrom
romseygeek:seqno/remove-seq-from-bulk-response

Conversation

@romseygeek
Copy link
Copy Markdown
Contributor

Sequence number and primary term are retained on the internal
Engine.Result objects, but removed from REST-layer serialization.

Sequence number and primary term are retained on the internal
Engine.Result objects, but removed from REST-layer serialization.
@romseygeek romseygeek requested review from fcofdez, kkrik-es and tlrx March 6, 2026 16:15
@romseygeek romseygeek self-assigned this Mar 6, 2026
@romseygeek romseygeek added >non-issue :Distributed/Engine Anything around managing Lucene and the Translog in an open shard. v9.4.0 labels Mar 6, 2026
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Meta label for distributed team. label Mar 6, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

Copy link
Copy Markdown
Contributor

@fcofdez fcofdez 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 a minor comment that we might want to address.

final BulkItemRequest current = getCurrentItem();
DocWriteRequest<?> docWriteRequest = getRequestToExecute();
switch (result.getResultType()) {
case SUCCESS -> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Apparently we return a sequence number of failures too (I guess it's just the unassigned seq no), but maybe for completeness we should follow the same logic there and ensure that we return the unassigned seq no?

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.

It's kept internally but the serialized XContent doesn't include it.

@romseygeek
Copy link
Copy Markdown
Contributor Author

I ended up having to move the sequence number redaction into the BulkItemResponse handling, rather than in DocWriteResponse, as that's still needed for internal replication correctness. It's sufficiently different that I think it needs another review.

@romseygeek romseygeek requested a review from fcofdez March 9, 2026 15:54
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.

Just to be sure to understand, we remove the seq no/primary term from Bulk responses REST API but we return sentinel values for Searches and GETs? I probably missed a point but this inconsistency looks trappy to me.

.setSettings(
Settings.builder()
.put(IndexSettings.DISABLE_SEQUENCE_NUMBERS.getKey(), true)
.put(IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), "doc_values_only")
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.

nit:

Suggested change
.put(IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), "doc_values_only")
.put(IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), SeqNoFieldMapper.SeqNoIndexOptions.DOC_VALUES_ONLY)


@Override
public SimulateIndexResponse withoutSequenceNumber() {
throw new UnsupportedOperationException("SimulateIndexResponse does not support withoutSequenceNumber");
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.

Looks like we could support this too since SimulateIndexResponse already redacts seq_no/primary term ?

See comment // We don't actually care about most of the IndexResponse fields:

assumeTrue("Test should only run with feature flag", IndexSettings.DISABLE_SEQUENCE_NUMBERS_FEATURE_FLAG);
Settings settings = Settings.builder()
.put(IndexSettings.DISABLE_SEQUENCE_NUMBERS.getKey(), true)
.put(IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), "doc_values_only")
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.

nit:

Suggested change
.put(IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), "doc_values_only")
.put(IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), SeqNoFieldMapper.SeqNoIndexOptions.DOC_VALUES_ONLY)

@fcofdez
Copy link
Copy Markdown
Contributor

fcofdez commented Mar 10, 2026

Just to be sure to understand, we remove the seq no/primary term from Bulk responses REST API but we return sentinel values for Searches and GETs? I probably missed a point but this inconsistency looks trappy to me.

It looks like it's the current behaviour (see

if (getSeqNo() >= 0) {
builder.field(_SEQ_NO, getSeqNo());
builder.field(_PRIMARY_TERM, getPrimaryTerm());
}
). But I agree that this inconsistency can be trappy and I wonder if we could break clients with this change. I think that we should return back the sentinel values indeed.


private void completeBulkOperation() {
BulkItemResponse[] bulkItemResponses = responses.toArray(new BulkItemResponse[responses.length()]);
redactSeqNoFromDisabledIndices(bulkItemResponses);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We iterate over the responses once when a shard responds back (see

BulkItemResponse bulkItemResponse = bulkShardResponse.getResponses()[idx];
) Maybe we should do this transformation there instead?

@romseygeek
Copy link
Copy Markdown
Contributor Author

I think that we should return back the sentinel values indeed.

I can certainly update things to do that. Do you think we should also change it for existing indexes, or just for bulk loads with sequence numbers disabled?

@romseygeek
Copy link
Copy Markdown
Contributor Author

I can certainly update things to do that. Do you think we should also change it for existing indexes, or just for bulk loads with sequence numbers disabled?

Actually, looking again, I think we will have to always return sentinel values if the sequence number isn't assigned. But that should be ok, as the XContent serialization is only used at the REST layer so existing workflows will always have sequence numbers set and the current suppression of values won't have an effect outside of tests.

Copy link
Copy Markdown
Contributor

@fcofdez fcofdez left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for the iterations, I left a few suggestions before approving this.

builder.field(_SEQ_NO, getSeqNo());
builder.field(_PRIMARY_TERM, getPrimaryTerm());
}
builder.field(_SEQ_NO, getSeqNo());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My guess is that this was here for legacy reasons (to support responses before we introduced sequence numbers) so I guess that it's ok to remove the check.

getVersion(),
result
);
copy.setGetResult(getResult);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't we need to copy the shard info here?

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.

It's using the constructor that takes ShardInfo so I think we're good

primary.shardId(),
requestToExecute.id(),
deleteResult.getSeqNo(),
result.getSeqNo(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that we can revert this?

}

private BulkItemResponse maybeRedactSequenceNumber(BulkItemResponse in) {
if (IndexSettings.DISABLE_SEQUENCE_NUMBERS_FEATURE_FLAG == false) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We grab the index metadata in

var indexMetadata = project.getIndexSafe(shardId.getIndex());

maybe we can pass the boolean flag into BulkOperation#executeBulkShardRequest directly so we don't need to go through the project metadata per response?

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 hadn't appreciated that everything would be from a single index, but of course this is per-shard isn't it. Have updated.

Copy link
Copy Markdown
Contributor

@fcofdez fcofdez left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the iterations!

@romseygeek romseygeek merged commit 5a6352b into elastic:main Mar 10, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed/Engine Anything around managing Lucene and the Translog in an open shard. >non-issue Team:Distributed Meta label for distributed team. v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants