|
@@ -11,6 +11,7 @@ package org.elasticsearch.cluster;
|
|
|
import com.carrotsearch.hppc.ObjectHashSet;
|
|
|
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
|
|
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
|
|
+import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
|
|
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
@@ -24,6 +25,7 @@ import org.elasticsearch.index.store.StoreStats;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* ClusterInfo is an object representing a map of nodes to {@link DiskUsage}
|
|
@@ -32,15 +34,20 @@ import java.util.Objects;
|
|
|
* for the key used in the shardSizes map
|
|
|
*/
|
|
|
public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
+
|
|
|
+ public static final Version DATA_SET_SIZE_SIZE_VERSION = Version.V_8_0_0; // todo: Version.V_7_13_0;
|
|
|
+
|
|
|
private final ImmutableOpenMap<String, DiskUsage> leastAvailableSpaceUsage;
|
|
|
private final ImmutableOpenMap<String, DiskUsage> mostAvailableSpaceUsage;
|
|
|
final ImmutableOpenMap<String, Long> shardSizes;
|
|
|
+ final ImmutableOpenMap<ShardId, Long> shardDataSetSizes;
|
|
|
public static final ClusterInfo EMPTY = new ClusterInfo();
|
|
|
final ImmutableOpenMap<ShardRouting, String> routingToDataPath;
|
|
|
final ImmutableOpenMap<NodeAndPath, ReservedSpace> reservedSpace;
|
|
|
|
|
|
protected ClusterInfo() {
|
|
|
- this(ImmutableOpenMap.of(), ImmutableOpenMap.of(), ImmutableOpenMap.of(), ImmutableOpenMap.of(), ImmutableOpenMap.of());
|
|
|
+ this(ImmutableOpenMap.of(), ImmutableOpenMap.of(), ImmutableOpenMap.of(), ImmutableOpenMap.of(), ImmutableOpenMap.of(),
|
|
|
+ ImmutableOpenMap.of());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -49,16 +56,18 @@ public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
* @param leastAvailableSpaceUsage a node id to disk usage mapping for the path that has the least available space on the node.
|
|
|
* @param mostAvailableSpaceUsage a node id to disk usage mapping for the path that has the most available space on the node.
|
|
|
* @param shardSizes a shardkey to size in bytes mapping per shard.
|
|
|
+ * @param shardDataSetSizes a shard id to data set size in bytes mapping per shard
|
|
|
* @param routingToDataPath the shard routing to datapath mapping
|
|
|
* @param reservedSpace reserved space per shard broken down by node and data path
|
|
|
* @see #shardIdentifierFromRouting
|
|
|
*/
|
|
|
public ClusterInfo(ImmutableOpenMap<String, DiskUsage> leastAvailableSpaceUsage,
|
|
|
ImmutableOpenMap<String, DiskUsage> mostAvailableSpaceUsage, ImmutableOpenMap<String, Long> shardSizes,
|
|
|
- ImmutableOpenMap<ShardRouting, String> routingToDataPath,
|
|
|
+ ImmutableOpenMap<ShardId, Long> shardDataSetSizes, ImmutableOpenMap<ShardRouting, String> routingToDataPath,
|
|
|
ImmutableOpenMap<NodeAndPath, ReservedSpace> reservedSpace) {
|
|
|
this.leastAvailableSpaceUsage = leastAvailableSpaceUsage;
|
|
|
this.shardSizes = shardSizes;
|
|
|
+ this.shardDataSetSizes = shardDataSetSizes;
|
|
|
this.mostAvailableSpaceUsage = mostAvailableSpaceUsage;
|
|
|
this.routingToDataPath = routingToDataPath;
|
|
|
this.reservedSpace = reservedSpace;
|
|
@@ -68,6 +77,12 @@ public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
Map<String, DiskUsage> leastMap = in.readMap(StreamInput::readString, DiskUsage::new);
|
|
|
Map<String, DiskUsage> mostMap = in.readMap(StreamInput::readString, DiskUsage::new);
|
|
|
Map<String, Long> sizeMap = in.readMap(StreamInput::readString, StreamInput::readLong);
|
|
|
+ Map<ShardId, Long> dataSetSizeMap;
|
|
|
+ if (in.getVersion().onOrAfter(DATA_SET_SIZE_SIZE_VERSION)) {
|
|
|
+ dataSetSizeMap = in.readMap(ShardId::new, StreamInput::readLong);
|
|
|
+ } else {
|
|
|
+ dataSetSizeMap = Map.of();
|
|
|
+ }
|
|
|
Map<ShardRouting, String> routingMap = in.readMap(ShardRouting::new, StreamInput::readString);
|
|
|
Map<NodeAndPath, ReservedSpace> reservedSpaceMap;
|
|
|
if (in.getVersion().onOrAfter(StoreStats.RESERVED_BYTES_VERSION)) {
|
|
@@ -82,6 +97,8 @@ public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
this.mostAvailableSpaceUsage = mostBuilder.putAll(mostMap).build();
|
|
|
ImmutableOpenMap.Builder<String, Long> sizeBuilder = ImmutableOpenMap.builder();
|
|
|
this.shardSizes = sizeBuilder.putAll(sizeMap).build();
|
|
|
+ ImmutableOpenMap.Builder<ShardId, Long> dataSetSizeBuilder = ImmutableOpenMap.builder();
|
|
|
+ this.shardDataSetSizes = dataSetSizeBuilder.putAll(dataSetSizeMap).build();
|
|
|
ImmutableOpenMap.Builder<ShardRouting, String> routingBuilder = ImmutableOpenMap.builder();
|
|
|
this.routingToDataPath = routingBuilder.putAll(routingMap).build();
|
|
|
ImmutableOpenMap.Builder<NodeAndPath, ReservedSpace> reservedSpaceBuilder = ImmutableOpenMap.builder();
|
|
@@ -97,6 +114,9 @@ public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
}
|
|
|
out.writeMap(this.mostAvailableSpaceUsage, StreamOutput::writeString, (o, v) -> v.writeTo(o));
|
|
|
out.writeMap(this.shardSizes, StreamOutput::writeString, (o, v) -> out.writeLong(v == null ? -1 : v));
|
|
|
+ if (out.getVersion().onOrAfter(DATA_SET_SIZE_SIZE_VERSION)) {
|
|
|
+ out.writeMap(this.shardDataSetSizes, (o, s) -> s.writeTo(o), (o, v) -> out.writeLong(v));
|
|
|
+ }
|
|
|
out.writeMap(this.routingToDataPath, (o, k) -> k.writeTo(o), StreamOutput::writeString);
|
|
|
if (out.getVersion().onOrAfter(StoreStats.RESERVED_BYTES_VERSION)) {
|
|
|
out.writeMap(this.reservedSpace);
|
|
@@ -130,6 +150,12 @@ public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
}
|
|
|
}
|
|
|
builder.endObject(); // end "shard_sizes"
|
|
|
+ builder.startObject("shard_data_set_sizes"); {
|
|
|
+ for (ObjectObjectCursor<ShardId, Long> c : this.shardDataSetSizes) {
|
|
|
+ builder.humanReadableField(c.key + "_bytes", c.key.toString(), new ByteSizeValue(c.value));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ builder.endObject(); // end "shard_data_set_sizes"
|
|
|
builder.startObject("shard_paths"); {
|
|
|
for (ObjectObjectCursor<ShardRouting, String> c : this.routingToDataPath) {
|
|
|
builder.field(c.key.toString(), c.value);
|
|
@@ -188,6 +214,9 @@ public class ClusterInfo implements ToXContentFragment, Writeable {
|
|
|
return shardSize == null ? defaultValue : shardSize;
|
|
|
}
|
|
|
|
|
|
+ public Optional<Long> getShardDataSetSize(ShardId shardId) {
|
|
|
+ return Optional.ofNullable(shardDataSetSizes.get(shardId));
|
|
|
+ }
|
|
|
/**
|
|
|
* Returns the reserved space for each shard on the given node/path pair
|
|
|
*/
|