Skip to content

Commit 9f29f7c

Browse files
committed
delete useless loop in TransportBulkAction$BulkOperation.doRun()
Signed-off-by: kkewwei <kewei.11@bytedance.com> Signed-off-by: kkewwei <kkewwei@163.com>
1 parent c0f7806 commit 9f29f7c

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6060
- Indexed IP field supports `terms_query` with more than 1025 IP masks [#16391](https://github.com/opensearch-project/OpenSearch/pull/16391)
6161
- Make entries for dependencies from server/build.gradle to gradle version catalog ([#16707](https://github.com/opensearch-project/OpenSearch/pull/16707))
6262
- Allow extended plugins to be optional ([#16909](https://github.com/opensearch-project/OpenSearch/pull/16909))
63+
- Delete useless loop in `TransportBulkAction$BulkOperation.doRun`
6364

6465
### Deprecated
6566
- Performing update operation with default pipeline or final pipeline is deprecated ([#16712](https://github.com/opensearch-project/OpenSearch/pull/16712))

server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java

+8-15
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,8 @@ protected void doRun() {
532532
}
533533
final ConcreteIndices concreteIndices = new ConcreteIndices(clusterState, indexNameExpressionResolver);
534534
Metadata metadata = clusterState.metadata();
535+
// go over all the requests and create a ShardId -> Operations mapping
536+
Map<ShardId, List<BulkItemRequest>> requestsByShard = new HashMap<>();
535537
for (int i = 0; i < bulkRequest.requests.size(); i++) {
536538
DocWriteRequest<?> docWriteRequest = bulkRequest.requests.get(i);
537539
// the request can only be null because we set it to null in the previous step, so it gets ignored
@@ -587,6 +589,12 @@ protected void doRun() {
587589
default:
588590
throw new AssertionError("request type not supported: [" + docWriteRequest.opType() + "]");
589591
}
592+
593+
ShardId shardId = clusterService.operationRouting()
594+
.indexShards(clusterState, concreteIndex.getName(), docWriteRequest.id(), docWriteRequest.routing())
595+
.shardId();
596+
List<BulkItemRequest> shardRequests = requestsByShard.computeIfAbsent(shardId, shard -> new ArrayList<>());
597+
shardRequests.add(new BulkItemRequest(i, docWriteRequest));
590598
} catch (OpenSearchParseException | IllegalArgumentException | RoutingMissingException e) {
591599
BulkItemResponse.Failure failure = new BulkItemResponse.Failure(concreteIndex.getName(), docWriteRequest.id(), e);
592600
BulkItemResponse bulkItemResponse = new BulkItemResponse(i, docWriteRequest.opType(), failure);
@@ -596,21 +604,6 @@ protected void doRun() {
596604
}
597605
}
598606

599-
// first, go over all the requests and create a ShardId -> Operations mapping
600-
Map<ShardId, List<BulkItemRequest>> requestsByShard = new HashMap<>();
601-
for (int i = 0; i < bulkRequest.requests.size(); i++) {
602-
DocWriteRequest<?> request = bulkRequest.requests.get(i);
603-
if (request == null) {
604-
continue;
605-
}
606-
String concreteIndex = concreteIndices.getConcreteIndex(request.index()).getName();
607-
ShardId shardId = clusterService.operationRouting()
608-
.indexShards(clusterState, concreteIndex, request.id(), request.routing())
609-
.shardId();
610-
List<BulkItemRequest> shardRequests = requestsByShard.computeIfAbsent(shardId, shard -> new ArrayList<>());
611-
shardRequests.add(new BulkItemRequest(i, request));
612-
}
613-
614607
if (requestsByShard.isEmpty()) {
615608
BulkItemResponse[] response = responses.toArray(new BulkItemResponse[responses.length()]);
616609
long tookMillis = buildTookInMillis(startTimeNanos);

0 commit comments

Comments
 (0)