Skip to content

Commit

Permalink
remove the flags
Browse files Browse the repository at this point in the history
  • Loading branch information
pgomulka committed Jul 9, 2024
1 parent 410111f commit 6c13ca7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ static TransportVersion def(int id) {
public static final TransportVersion ML_INFERENCE_GOOGLE_VERTEX_AI_RERANKING_ADDED = def(8_700_00_0);
public static final TransportVersion VERSIONED_MASTER_NODE_REQUESTS = def(8_701_00_0);
public static final TransportVersion ML_INFERENCE_AMAZON_BEDROCK_ADDED = def(8_702_00_0);
public static final TransportVersion INDEX_REQUEST_UPDATE_BY_SCRIPT_ORIGIN = def(8_704_00_0);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public class IndexRequest extends ReplicatedWriteRequest<IndexRequest> implement
*/
private Object rawTimestamp;
private long normalisedBytesParsed = -1;
private boolean originatesFromUpdateByScript;

public IndexRequest(StreamInput in) throws IOException {
this(null, in);
Expand Down Expand Up @@ -197,6 +198,12 @@ public IndexRequest(@Nullable ShardId shardId, StreamInput in) throws IOExceptio
} else {
requireDataStream = false;
}

if (in.getTransportVersion().onOrAfter(TransportVersions.INDEX_REQUEST_UPDATE_BY_SCRIPT_ORIGIN)) {
originatesFromUpdateByScript = in.readBoolean();
} else {
originatesFromUpdateByScript = false;
}
}

public IndexRequest() {
Expand Down Expand Up @@ -757,6 +764,10 @@ private void writeBody(StreamOutput out) throws IOException {
out.writeBoolean(requireDataStream);
out.writeZLong(normalisedBytesParsed);
}

if (out.getTransportVersion().onOrAfter(TransportVersions.INDEX_REQUEST_UPDATE_BY_SCRIPT_ORIGIN)) {
out.writeBoolean(originatesFromUpdateByScript);
}
}

@Override
Expand Down Expand Up @@ -959,4 +970,13 @@ public List<String> getExecutedPipelines() {
return Collections.unmodifiableList(executedPipelines);
}
}

public IndexRequest setOriginatesFromUpdateByScript(boolean originatesFromUpdateByScript) {
this.originatesFromUpdateByScript = originatesFromUpdateByScript;
return this;
}

public boolean originatesFromUpdateByScript() {
return this.originatesFromUpdateByScript;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ Result prepareUpdateIndexRequest(ShardId shardId, UpdateRequest request, GetResu
.timeout(request.timeout())
.setRefreshPolicy(request.getRefreshPolicy());
documentSizeObserver.setNormalisedBytesParsedOn(finalIndexRequest);

return new Result(finalIndexRequest, DocWriteResponse.Result.UPDATED, updatedSourceAsMap, updateSourceContentType);
}
}
Expand All @@ -237,8 +238,6 @@ Result prepareUpdateIndexRequest(ShardId shardId, UpdateRequest request, GetResu
* primary and replicas.
*/
Result prepareUpdateScriptRequest(ShardId shardId, UpdateRequest request, GetResult getResult, LongSupplier nowInMillis) {
final DocumentSizeObserver documentSizeObserver = documentParsingProvider.newDocumentSizeObserver(request);

final IndexRequest currentRequest = request.doc();
final String routing = calculateRouting(getResult, currentRequest);
final Tuple<XContentType, Map<String, Object>> sourceAndContent = XContentHelper.convertToMap(getResult.internalSourceRef(), true);
Expand Down Expand Up @@ -270,8 +269,8 @@ Result prepareUpdateScriptRequest(ShardId shardId, UpdateRequest request, GetRes
.setIfPrimaryTerm(getResult.getPrimaryTerm())
.waitForActiveShards(request.waitForActiveShards())
.timeout(request.timeout())
.setRefreshPolicy(request.getRefreshPolicy());
documentSizeObserver.setNormalisedBytesParsedOn(indexRequest);
.setRefreshPolicy(request.getRefreshPolicy())
.setOriginatesFromUpdateByScript(true);
return new Result(indexRequest, DocWriteResponse.Result.UPDATED, updatedSourceAsMap, updateSourceContentType);
}
case DELETE -> {
Expand Down

0 comments on commit 6c13ca7

Please sign in to comment.