Remove seq_no from bulk response when disabled#143753
Remove seq_no from bulk response when disabled#143753romseygeek merged 11 commits intoelastic:mainfrom
Conversation
Sequence number and primary term are retained on the internal Engine.Result objects, but removed from REST-layer serialization.
|
Pinging @elastic/es-distributed (Team:Distributed) |
fcofdez
left a comment
There was a problem hiding this comment.
LGTM. I left a minor comment that we might want to address.
| final BulkItemRequest current = getCurrentItem(); | ||
| DocWriteRequest<?> docWriteRequest = getRequestToExecute(); | ||
| switch (result.getResultType()) { | ||
| case SUCCESS -> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
It's kept internally but the serialized XContent doesn't include it.
|
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. |
tlrx
left a comment
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
nit:
| .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"); |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
nit:
| .put(IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), "doc_values_only") | |
| .put(IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), SeqNoFieldMapper.SeqNoIndexOptions.DOC_VALUES_ONLY) |
It looks like it's the current behaviour (see ). 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); |
There was a problem hiding this comment.
We iterate over the responses once when a shard responds back (see
) Maybe we should do this transformation there instead?
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. |
…esponse' into seqno/remove-seq-from-bulk-response
fcofdez
left a comment
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
don't we need to copy the shard info here?
There was a problem hiding this comment.
It's using the constructor that takes ShardInfo so I think we're good
| primary.shardId(), | ||
| requestToExecute.id(), | ||
| deleteResult.getSeqNo(), | ||
| result.getSeqNo(), |
There was a problem hiding this comment.
I think that we can revert this?
| } | ||
|
|
||
| private BulkItemResponse maybeRedactSequenceNumber(BulkItemResponse in) { | ||
| if (IndexSettings.DISABLE_SEQUENCE_NUMBERS_FEATURE_FLAG == false) { |
There was a problem hiding this comment.
We grab the index metadata in
maybe we can pass the boolean flag into
BulkOperation#executeBulkShardRequest directly so we don't need to go through the project metadata per response?
There was a problem hiding this comment.
I hadn't appreciated that everything would be from a single index, but of course this is per-shard isn't it. Have updated.
fcofdez
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the iterations!
Sequence number and primary term are retained on the internal
Engine.Result objects, but removed from REST-layer serialization.