Skip to content

Commit 102bdc1

Browse files
committed
Removing the allocationId
1 parent 0c7bf62 commit 102bdc1

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

server/src/main/java/org/elasticsearch/action/search/load/ShardSearchLoadStats.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@
1919

2020
/**
2121
* ShardSearchLoadStats class represents the statistics of a shard in an index.
22-
* It contains information such as the index name, shard ID, allocation ID, and EWMA rate.
22+
* It contains information such as the index name, shard ID, and search load.
2323
*/
2424
public class ShardSearchLoadStats implements Writeable {
2525

2626
private final String indexName;
2727

2828
private final Integer shardId;
2929

30-
private final String allocationId;
31-
3230
private final Double searchLoad;
3331

3432
/**
@@ -41,7 +39,6 @@ public ShardSearchLoadStats(StreamInput in) throws IOException {
4139
assert Transports.assertNotTransportThread("O(#shards) work must always fork to an appropriate executor");
4240
this.indexName = in.readString();
4341
this.shardId = in.readVInt();
44-
this.allocationId = in.readString();
4542
this.searchLoad = in.readDouble();
4643
}
4744

@@ -50,13 +47,11 @@ public ShardSearchLoadStats(StreamInput in) throws IOException {
5047
*
5148
* @param indexName the name of the index
5249
* @param shardId the ID of the shard
53-
* @param allocationId the allocation ID of the shard
5450
* @param searchLoad the search load of the shard
5551
*/
56-
public ShardSearchLoadStats(String indexName, Integer shardId, String allocationId, Double searchLoad) {
52+
public ShardSearchLoadStats(String indexName, Integer shardId, Double searchLoad) {
5753
this.indexName = indexName;
5854
this.shardId = shardId;
59-
this.allocationId = allocationId;
6055
this.searchLoad = searchLoad;
6156
}
6257

@@ -67,13 +62,12 @@ public boolean equals(Object o) {
6762
ShardSearchLoadStats that = (ShardSearchLoadStats) o;
6863
return Objects.equals(indexName, that.indexName)
6964
&& Objects.equals(shardId, that.shardId)
70-
&& Objects.equals(allocationId, that.allocationId)
7165
&& Objects.equals(searchLoad, that.searchLoad);
7266
}
7367

7468
@Override
7569
public int hashCode() {
76-
return Objects.hash(indexName, shardId, allocationId, searchLoad);
70+
return Objects.hash(indexName, shardId, searchLoad);
7771
}
7872

7973
/**
@@ -94,15 +88,6 @@ public Integer getShardId() {
9488
return this.shardId;
9589
}
9690

97-
/**
98-
* Returns the allocation ID of the shard.
99-
*
100-
* @return the allocation ID
101-
*/
102-
public String getAllocationId() {
103-
return this.allocationId;
104-
}
105-
10691
/**
10792
* Returns the search load of the shard.
10893
*
@@ -116,7 +101,6 @@ public Double getSearchLoad() {
116101
public void writeTo(StreamOutput out) throws IOException {
117102
out.writeString(indexName);
118103
out.writeVInt(shardId);
119-
out.writeString(allocationId);
120104
out.writeDouble(searchLoad);
121105
}
122106
}

server/src/main/java/org/elasticsearch/action/search/load/ShardSearchLoadStatsResponse.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@
1616
import org.elasticsearch.xcontent.ToXContent;
1717

1818
import java.io.IOException;
19+
import java.util.Arrays;
20+
import java.util.Collections;
21+
import java.util.HashMap;
1922
import java.util.Iterator;
2023
import java.util.List;
24+
import java.util.Map;
2125
import java.util.Objects;
26+
import java.util.Optional;
2227

2328
/**
2429
* Response to a shard stats request.
@@ -39,7 +44,7 @@ public class ShardSearchLoadStatsResponse extends ChunkedBroadcastResponse {
3944
}
4045

4146
/**
42-
* Constructor to create a ShardStatsResponse object with the given parameters.
47+
* Constructor to create a ShardSearchLoadStatsResponse object with the given parameters.
4348
*
4449
* @param shards the array of shard stats
4550
* @param totalShards the total number of shards
@@ -55,17 +60,18 @@ public class ShardSearchLoadStatsResponse extends ChunkedBroadcastResponse {
5560
List<DefaultShardOperationFailedException> shardFailures
5661
) {
5762
super(totalShards, successfulShards, failedShards, shardFailures);
58-
this.shards = shards;
59-
Objects.requireNonNull(shards);
63+
this.shards = aggregateSearchLoadByShard(Objects.requireNonNull(shards));
6064
}
6165

66+
67+
6268
/**
63-
* Returns the array of shard stats.
69+
* Returns a copy of the array of shard stats.
6470
*
6571
* @return the array of shard stats
6672
*/
6773
public ShardSearchLoadStats[] getShards() {
68-
return shards;
74+
return Arrays.copyOf(shards, shards.length);
6975
}
7076

7177
@Override
@@ -76,6 +82,26 @@ public void writeTo(StreamOutput out) throws IOException {
7682

7783
@Override
7884
protected Iterator<ToXContent> customXContentChunks(ToXContent.Params params) {
79-
return null;
85+
return Collections.emptyIterator();
8086
}
87+
88+
private ShardSearchLoadStats[] aggregateSearchLoadByShard(ShardSearchLoadStats[] shards) {
89+
Map<ShardKey, Double> aggregated = new HashMap<>();
90+
91+
for (var stat : shards) {
92+
var key = new ShardKey(stat.getIndexName(), stat.getShardId());
93+
var load = Optional.ofNullable(stat.getSearchLoad()).orElse(0.0);
94+
aggregated.merge(key, load, Double::sum);
95+
}
96+
97+
return aggregated.entrySet().stream()
98+
.map(e -> new ShardSearchLoadStats(
99+
e.getKey().indexName(),
100+
e.getKey().shardId(),
101+
e.getValue()
102+
))
103+
.toArray(ShardSearchLoadStats[]::new);
104+
}
105+
106+
private record ShardKey(String indexName, int shardId) {}
81107
}

server/src/main/java/org/elasticsearch/action/search/load/TransportShardSearchLoadStatsAction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ protected void shardOperation(Request request, ShardRouting shardRouting, Task t
171171
return new ShardSearchLoadStats(
172172
shardId.getIndex().getName(),
173173
shardId.getId(),
174-
shardRouting.allocationId().getId(),
175174
indexShard.getSearchLoadRate()
176175
);
177176
});

0 commit comments

Comments
 (0)