Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions server/src/main/java/org/elasticsearch/cluster/ClusterInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,72 @@ public Builder add(ShardId shardId, long reservedBytes) {
}
}
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
private Map<String, DiskUsage> leastAvailableSpaceUsage = Map.of();
private Map<String, DiskUsage> mostAvailableSpaceUsage = Map.of();
private Map<String, Long> shardSizes = Map.of();
private Map<ShardId, Long> shardDataSetSizes = Map.of();
private Map<NodeAndShard, String> dataPath = Map.of();
private Map<NodeAndPath, ReservedSpace> reservedSpace = Map.of();
private Map<String, EstimatedHeapUsage> estimatedHeapUsages = Map.of();
private Map<String, NodeUsageStatsForThreadPools> nodeUsageStatsForThreadPools = Map.of();

public ClusterInfo build() {
return new ClusterInfo(
leastAvailableSpaceUsage,
mostAvailableSpaceUsage,
shardSizes,
shardDataSetSizes,
dataPath,
reservedSpace,
estimatedHeapUsages,
nodeUsageStatsForThreadPools
);
}

public Builder leastAvailableSpaceUsage(Map<String, DiskUsage> leastAvailableSpaceUsage) {
this.leastAvailableSpaceUsage = leastAvailableSpaceUsage;
return this;
}

public Builder mostAvailableSpaceUsage(Map<String, DiskUsage> mostAvailableSpaceUsage) {
this.mostAvailableSpaceUsage = mostAvailableSpaceUsage;
return this;
}

public Builder shardSizes(Map<String, Long> shardSizes) {
this.shardSizes = shardSizes;
return this;
}

public Builder shardDataSetSizes(Map<ShardId, Long> shardDataSetSizes) {
this.shardDataSetSizes = shardDataSetSizes;
return this;
}

public Builder dataPath(Map<NodeAndShard, String> dataPath) {
this.dataPath = dataPath;
return this;
}

public Builder reservedSpace(Map<NodeAndPath, ReservedSpace> reservedSpace) {
this.reservedSpace = reservedSpace;
return this;
}

public Builder estimatedHeapUsages(Map<String, EstimatedHeapUsage> estimatedHeapUsages) {
this.estimatedHeapUsages = estimatedHeapUsages;
return this;
}

public Builder nodeUsageStatsForThreadPools(Map<String, NodeUsageStatsForThreadPools> nodeUsageStatsForThreadPools) {
this.nodeUsageStatsForThreadPools = nodeUsageStatsForThreadPools;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,7 @@ private static Metadata metadata(IndexMetadata.Builder... indices) {
}

private static ClusterInfo createClusterInfo(ShardRouting shard, Long size) {
return new ClusterInfo(
Map.of(),
Map.of(),
Map.of(ClusterInfo.shardIdentifierFromRouting(shard), size),
Map.of(),
Map.of(),
Map.of(),
Map.of(),
Map.of()
);
return ClusterInfo.builder().shardSizes(Map.of(ClusterInfo.shardIdentifierFromRouting(shard), size)).build();
}

private ClusterState buildRoutingTable(ClusterState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,9 @@ public void testShardStats() {
)
.build();

var clusterInfo = new ClusterInfo(
Map.of(),
Map.of(),
Map.of(ClusterInfo.shardIdentifierFromRouting(shardId, true), currentShardSize),
Map.of(),
Map.of(),
Map.of(),
Map.of(),
Map.of()
);
var clusterInfo = ClusterInfo.builder()
.shardSizes(Map.of(ClusterInfo.shardIdentifierFromRouting(shardId, true), currentShardSize))
.build();

var queue = new DeterministicTaskQueue();
try (var clusterService = ClusterServiceUtils.createClusterService(state, queue.getThreadPool())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ private static ClusterInfo clusterInfo(
Map<String, DiskUsage> diskUsages,
Map<ClusterInfo.NodeAndPath, ClusterInfo.ReservedSpace> reservedSpace
) {
return new ClusterInfo(diskUsages, Map.of(), Map.of(), Map.of(), Map.of(), reservedSpace, Map.of(), Map.of());
return ClusterInfo.builder().leastAvailableSpaceUsage(diskUsages).reservedSpace(reservedSpace).build();
}

private static DiscoveryNode newFrozenOnlyNode(String nodeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,17 @@ public void testExpectedSizeOnMove() {
}

private static ClusterInfo createClusterInfoWith(ShardId shardId, long size) {
return new ClusterInfo(
Map.of(),
Map.of(),
Map.ofEntries(
Map.entry(ClusterInfo.shardIdentifierFromRouting(shardId, true), size),
Map.entry(ClusterInfo.shardIdentifierFromRouting(shardId, false), size)
),
Map.of(),
Map.of(),
Map.of(),
Map.of(),
Map.of()
);
return ClusterInfo.builder()
.shardSizes(
Map.ofEntries(
Map.entry(ClusterInfo.shardIdentifierFromRouting(shardId, true), size),
Map.entry(ClusterInfo.shardIdentifierFromRouting(shardId, false), size)
)
)
.build();
}

private static ClusterInfo createClusterInfo(Map<String, DiskUsage> diskUsage, Map<String, Long> shardSizes) {
return new ClusterInfo(diskUsage, diskUsage, shardSizes, Map.of(), Map.of(), Map.of(), Map.of(), Map.of());
return ClusterInfo.builder().leastAvailableSpaceUsage(diskUsage).mostAvailableSpaceUsage(diskUsage).shardSizes(shardSizes).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -597,21 +597,16 @@ public void testShardSizeDiscrepancyWithinIndex() {

var allocationService = createAllocationService(
Settings.EMPTY,
() -> new ClusterInfo(
Map.of(),
Map.of(),
Map.of(
ClusterInfo.shardIdentifierFromRouting(new ShardId(index, 0), true),
0L,
ClusterInfo.shardIdentifierFromRouting(new ShardId(index, 1), true),
ByteSizeUnit.GB.toBytes(500)
),
Map.of(),
Map.of(),
Map.of(),
Map.of(),
Map.of()
)
() -> ClusterInfo.builder()
.shardSizes(
Map.of(
ClusterInfo.shardIdentifierFromRouting(new ShardId(index, 0), true),
0L,
ClusterInfo.shardIdentifierFromRouting(new ShardId(index, 1), true),
ByteSizeUnit.GB.toBytes(500)
)
)
.build()
);

assertSame(clusterState, reroute(allocationService, clusterState));
Expand Down Expand Up @@ -706,7 +701,7 @@ private RoutingAllocation createRoutingAllocation(ClusterState clusterState) {
}

private static ClusterInfo createClusterInfo(Map<String, Long> indexSizes) {
return new ClusterInfo(Map.of(), Map.of(), indexSizes, Map.of(), Map.of(), Map.of(), Map.of(), Map.of());
return ClusterInfo.builder().shardSizes(indexSizes).build();
}

private static IndexMetadata.Builder anIndex(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,12 @@ public ClusterInfo getClusterInfo() {
dataPath.put(new ClusterInfo.NodeAndShard(shardRouting.currentNodeId(), shardRouting.shardId()), "/data");
}

return new ClusterInfo(diskSpaceUsage, diskSpaceUsage, shardSizes, Map.of(), dataPath, Map.of(), Map.of(), Map.of());
return ClusterInfo.builder()
.leastAvailableSpaceUsage(diskSpaceUsage)
.mostAvailableSpaceUsage(diskSpaceUsage)
.shardSizes(shardSizes)
.dataPath(dataPath)
.build();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,26 +329,21 @@ private static Tuple<IndexMetadata.Builder, String[]> startedIndex(
}

private ClusterInfo createClusterInfo(List<Tuple<String, long[]>> shardSizes) {
return new ClusterInfo(
Map.of(),
Map.of(),
shardSizes.stream()
.flatMap(
entry -> IntStream.range(0, entry.v2().length)
.mapToObj(
index -> Map.entry(
ClusterInfo.shardIdentifierFromRouting(new ShardId(entry.v1(), "_na_", index), true),
entry.v2()[index]
return ClusterInfo.builder()
.shardSizes(
shardSizes.stream()
.flatMap(
entry -> IntStream.range(0, entry.v2().length)
.mapToObj(
index -> Map.entry(
ClusterInfo.shardIdentifierFromRouting(new ShardId(entry.v1(), "_na_", index), true),
entry.v2()[index]
)
)
)
)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)),
Map.of(),
Map.of(),
Map.of(),
Map.of(),
Map.of()
);
)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
)
.build();
}

private static Tuple<String, long[]> indexSizes(String name, long... sizes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,16 +690,12 @@ public ClusterInfoTestBuilder withReservedSpace(String nodeId, String path, long
}

public ClusterInfo build() {
return new ClusterInfo(
leastAvailableSpaceUsage,
mostAvailableSpaceUsage,
shardSizes,
Map.of(),
Map.of(),
reservedSpace,
Map.of(),
Map.of()
);
return ClusterInfo.builder()
.leastAvailableSpaceUsage(leastAvailableSpaceUsage)
.mostAvailableSpaceUsage(mostAvailableSpaceUsage)
.shardSizes(shardSizes)
.reservedSpace(reservedSpace)
.build();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,12 @@ public void testDesiredBalanceShouldConvergeInABigCluster() {
.stream()
.collect(toMap(Map.Entry::getKey, it -> new DiskUsage(it.getKey(), it.getKey(), "/data", diskSize, diskSize - it.getValue())));

var clusterInfo = new ClusterInfo(diskUsage, diskUsage, shardSizes, Map.of(), dataPath, Map.of(), Map.of(), Map.of());
var clusterInfo = ClusterInfo.builder()
.leastAvailableSpaceUsage(diskUsage)
.mostAvailableSpaceUsage(diskUsage)
.shardSizes(shardSizes)
.dataPath(dataPath)
.build();

var settings = Settings.EMPTY;

Expand Down Expand Up @@ -1196,7 +1201,12 @@ public ClusterInfoTestBuilder withReservedSpace(String nodeId, long size, ShardI
}

public ClusterInfo build() {
return new ClusterInfo(diskUsage, diskUsage, shardSizes, Map.of(), Map.of(), reservedSpace, Map.of(), Map.of());
return ClusterInfo.builder()
.leastAvailableSpaceUsage(diskUsage)
.mostAvailableSpaceUsage(diskUsage)
.shardSizes(shardSizes)
.reservedSpace(reservedSpace)
.build();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,16 +843,11 @@ public void testDecidesYesIfWatermarksIgnored() {
allFullUsages.put("node_0", new DiskUsage("node_0", "node_0", "_na_", 100, 0)); // all full
allFullUsages.put("node_1", new DiskUsage("node_1", "node_1", "_na_", 100, 0)); // all full

final ClusterInfo clusterInfo = new ClusterInfo(
allFullUsages,
allFullUsages,
Map.of("[test][0][p]", 10L),
Map.of(),
Map.of(),
Map.of(),
Map.of(),
Map.of()
);
final ClusterInfo clusterInfo = ClusterInfo.builder()
.leastAvailableSpaceUsage(allFullUsages)
.mostAvailableSpaceUsage(allFullUsages)
.shardSizes(Map.of("[test][0][p]", 10L))
.build();
RoutingAllocation allocation = new RoutingAllocation(
new AllocationDeciders(Collections.singleton(decider)),
clusterState,
Expand Down Expand Up @@ -912,16 +907,11 @@ public void testCannotForceAllocateOver100PercentUsage() {
// bigger than available space
final long shardSize = randomIntBetween(1, 10);
shardSizes.put("[test][0][p]", shardSize);
ClusterInfo clusterInfo = new ClusterInfo(
leastAvailableUsages,
mostAvailableUsage,
shardSizes,
Map.of(),
Map.of(),
Map.of(),
Map.of(),
Map.of()
);
ClusterInfo clusterInfo = ClusterInfo.builder()
.leastAvailableSpaceUsage(leastAvailableUsages)
.mostAvailableSpaceUsage(mostAvailableUsage)
.shardSizes(shardSizes)
.build();
RoutingAllocation allocation = new RoutingAllocation(
new AllocationDeciders(Collections.singleton(decider)),
clusterState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void testContext() {
}
}
state = ClusterState.builder(ClusterName.DEFAULT).nodes(nodes).build();
info = new ClusterInfo(leastUsages, mostUsages, Map.of(), Map.of(), Map.of(), Map.of(), Map.of(), Map.of());
info = ClusterInfo.builder().leastAvailableSpaceUsage(leastUsages).mostAvailableSpaceUsage(mostUsages).build();
context = new AutoscalingCalculateCapacityService.DefaultAutoscalingDeciderContext(
roleNames,
state,
Expand Down Expand Up @@ -311,7 +311,7 @@ public void testContext() {
)
);

info = new ClusterInfo(leastUsages, mostUsages, Map.of(), Map.of(), Map.of(), Map.of(), Map.of(), Map.of());
info = ClusterInfo.builder().leastAvailableSpaceUsage(leastUsages).mostAvailableSpaceUsage(mostUsages).build();
context = new AutoscalingCalculateCapacityService.DefaultAutoscalingDeciderContext(
roleNames,
state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public Tuple<Long, ClusterInfo> sizeAndClusterInfo(IndexMetadata indexMetadata)
// add irrelevant shards noise for completeness (should not happen IRL).
sizes.put(new ShardId(index, i), randomLongBetween(0, Integer.MAX_VALUE));
}
ClusterInfo info = new ClusterInfo(Map.of(), Map.of(), Map.of(), sizes, Map.of(), Map.of(), Map.of(), Map.of());
ClusterInfo info = ClusterInfo.builder().shardDataSetSizes(sizes).build();
return Tuple.tuple(totalSize, info);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ private ClusterInfo randomClusterInfo(ProjectState projectState) {
for (var id : projectState.cluster().nodes().getDataNodes().keySet()) {
diskUsage.put(id, new DiskUsage(id, id, "/test", Long.MAX_VALUE, Long.MAX_VALUE));
}
return new ClusterInfo(diskUsage, diskUsage, shardSizes, Map.of(), Map.of(), Map.of(), Map.of(), Map.of());
return ClusterInfo.builder().leastAvailableSpaceUsage(diskUsage).mostAvailableSpaceUsage(diskUsage).shardSizes(shardSizes).build();
}

private ProjectMetadata applyCreatedDates(ProjectMetadata project, DataStream ds, long last, long decrement) {
Expand Down
Loading