|
@@ -15,7 +15,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
import org.elasticsearch.common.io.stream.Writeable;
|
|
|
import org.elasticsearch.common.unit.ByteSizeValue;
|
|
|
-import org.elasticsearch.common.util.set.Sets;
|
|
|
import org.elasticsearch.index.shard.ShardId;
|
|
|
import org.elasticsearch.index.store.StoreStats;
|
|
|
import org.elasticsearch.xcontent.ToXContentFragment;
|
|
@@ -36,13 +35,13 @@ import java.util.Set;
|
|
|
*/
|
|
|
public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
|
|
|
+ public static final ClusterInfo EMPTY = new ClusterInfo();
|
|
|
public static final Version DATA_SET_SIZE_SIZE_VERSION = Version.V_7_13_0;
|
|
|
|
|
|
private final Map<String, DiskUsage> leastAvailableSpaceUsage;
|
|
|
private final Map<String, DiskUsage> mostAvailableSpaceUsage;
|
|
|
final Map<String, Long> shardSizes;
|
|
|
final Map<ShardId, Long> shardDataSetSizes;
|
|
|
- public static final ClusterInfo EMPTY = new ClusterInfo();
|
|
|
final Map<ShardRouting, String> routingToDataPath;
|
|
|
final Map<NodeAndPath, ReservedSpace> reservedSpace;
|
|
|
|
|
@@ -236,31 +235,15 @@ public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
/**
|
|
|
* Represents a data path on a node
|
|
|
*/
|
|
|
- public static class NodeAndPath implements Writeable {
|
|
|
- public final String nodeId;
|
|
|
- public final String path;
|
|
|
+ public record NodeAndPath(String nodeId, String path) implements Writeable {
|
|
|
|
|
|
- public NodeAndPath(String nodeId, String path) {
|
|
|
- this.nodeId = Objects.requireNonNull(nodeId);
|
|
|
- this.path = Objects.requireNonNull(path);
|
|
|
+ public NodeAndPath {
|
|
|
+ Objects.requireNonNull(nodeId);
|
|
|
+ Objects.requireNonNull(path);
|
|
|
}
|
|
|
|
|
|
public NodeAndPath(StreamInput in) throws IOException {
|
|
|
- this.nodeId = in.readString();
|
|
|
- this.path = in.readString();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean equals(Object o) {
|
|
|
- if (this == o) return true;
|
|
|
- if (o == null || getClass() != o.getClass()) return false;
|
|
|
- NodeAndPath that = (NodeAndPath) o;
|
|
|
- return nodeId.equals(that.nodeId) && path.equals(that.path);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int hashCode() {
|
|
|
- return Objects.hash(nodeId, path);
|
|
|
+ this(in.readString(), in.readString());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -273,25 +256,12 @@ public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
/**
|
|
|
* Represents the total amount of "reserved" space on a particular data path, together with the set of shards considered.
|
|
|
*/
|
|
|
- public static class ReservedSpace implements Writeable {
|
|
|
+ public record ReservedSpace(long total, Set<ShardId> shardIds) implements Writeable {
|
|
|
|
|
|
public static final ReservedSpace EMPTY = new ReservedSpace(0, new HashSet<>());
|
|
|
|
|
|
- private final long total;
|
|
|
- private final Set<ShardId> shardIds;
|
|
|
-
|
|
|
- private ReservedSpace(long total, HashSet<ShardId> shardIds) {
|
|
|
- this.total = total;
|
|
|
- this.shardIds = shardIds;
|
|
|
- }
|
|
|
-
|
|
|
ReservedSpace(StreamInput in) throws IOException {
|
|
|
- total = in.readVLong();
|
|
|
- final int shardIdCount = in.readVInt();
|
|
|
- shardIds = Sets.newHashSetWithExpectedSize(shardIdCount);
|
|
|
- for (int i = 0; i < shardIdCount; i++) {
|
|
|
- shardIds.add(new ShardId(in));
|
|
|
- }
|
|
|
+ this(in.readVLong(), in.readSet(ShardId::new));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -308,19 +278,6 @@ public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
return shardIds.contains(shardId);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public boolean equals(Object o) {
|
|
|
- if (this == o) return true;
|
|
|
- if (o == null || getClass() != o.getClass()) return false;
|
|
|
- ReservedSpace that = (ReservedSpace) o;
|
|
|
- return total == that.total && shardIds.equals(that.shardIds);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int hashCode() {
|
|
|
- return Objects.hash(total, shardIds);
|
|
|
- }
|
|
|
-
|
|
|
void toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
builder.field("total", total);
|
|
|
builder.startArray("shards");
|
|
@@ -352,5 +309,4 @@ public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|