|
@@ -8,7 +8,6 @@
|
|
|
|
|
|
package org.elasticsearch.action.admin.cluster.stats;
|
|
|
|
|
|
-import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.admin.indices.stats.ShardStats;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetadata;
|
|
|
import org.elasticsearch.cluster.metadata.Metadata;
|
|
@@ -17,6 +16,7 @@ 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.index.IndexVersion;
|
|
|
import org.elasticsearch.xcontent.ToXContentFragment;
|
|
|
import org.elasticsearch.xcontent.ToXContentObject;
|
|
|
import org.elasticsearch.xcontent.XContentBuilder;
|
|
@@ -42,9 +42,9 @@ public final class VersionStats implements ToXContentFragment, Writeable {
|
|
|
private final Set<SingleVersionStats> versionStats;
|
|
|
|
|
|
public static VersionStats of(Metadata metadata, List<ClusterStatsNodeResponse> nodeResponses) {
|
|
|
- final Map<Version, Integer> indexCounts = new HashMap<>();
|
|
|
- final Map<Version, Integer> primaryShardCounts = new HashMap<>();
|
|
|
- final Map<Version, Long> primaryByteCounts = new HashMap<>();
|
|
|
+ final Map<IndexVersion, Integer> indexCounts = new HashMap<>();
|
|
|
+ final Map<IndexVersion, Integer> primaryShardCounts = new HashMap<>();
|
|
|
+ final Map<IndexVersion, Long> primaryByteCounts = new HashMap<>();
|
|
|
final Map<String, List<ShardStats>> indexPrimaryShardStats = new HashMap<>();
|
|
|
|
|
|
// Build a map from index name to primary shard stats
|
|
@@ -69,38 +69,20 @@ public final class VersionStats implements ToXContentFragment, Writeable {
|
|
|
for (Map.Entry<String, IndexMetadata> cursor : metadata.indices().entrySet()) {
|
|
|
IndexMetadata indexMetadata = cursor.getValue();
|
|
|
// Increment version-specific index counts
|
|
|
- indexCounts.compute(indexMetadata.getCreationVersion(), (v, i) -> {
|
|
|
- if (i == null) {
|
|
|
- return 1;
|
|
|
- } else {
|
|
|
- return i + 1;
|
|
|
- }
|
|
|
- });
|
|
|
+ indexCounts.merge(indexMetadata.getCreationVersion(), 1, Integer::sum);
|
|
|
// Increment version-specific primary shard counts
|
|
|
- primaryShardCounts.compute(indexMetadata.getCreationVersion(), (v, i) -> {
|
|
|
- if (i == null) {
|
|
|
- return indexMetadata.getNumberOfShards();
|
|
|
- } else {
|
|
|
- return i + indexMetadata.getNumberOfShards();
|
|
|
- }
|
|
|
- });
|
|
|
+ primaryShardCounts.merge(indexMetadata.getCreationVersion(), indexMetadata.getNumberOfShards(), Integer::sum);
|
|
|
// Increment version-specific primary shard sizes
|
|
|
- primaryByteCounts.compute(indexMetadata.getCreationVersion(), (v, i) -> {
|
|
|
- String indexName = indexMetadata.getIndex().getName();
|
|
|
- long indexPrimarySize = indexPrimaryShardStats.getOrDefault(indexName, Collections.emptyList())
|
|
|
- .stream()
|
|
|
- .mapToLong(stats -> stats.getStats().getStore().sizeInBytes())
|
|
|
- .sum();
|
|
|
- if (i == null) {
|
|
|
- return indexPrimarySize;
|
|
|
- } else {
|
|
|
- return i + indexPrimarySize;
|
|
|
- }
|
|
|
- });
|
|
|
+ String indexName = indexMetadata.getIndex().getName();
|
|
|
+ long indexPrimarySize = indexPrimaryShardStats.getOrDefault(indexName, Collections.emptyList())
|
|
|
+ .stream()
|
|
|
+ .mapToLong(stats -> stats.getStats().getStore().sizeInBytes())
|
|
|
+ .sum();
|
|
|
+ primaryByteCounts.merge(indexMetadata.getCreationVersion(), indexPrimarySize, Long::sum);
|
|
|
}
|
|
|
List<SingleVersionStats> calculatedStats = new ArrayList<>(indexCounts.size());
|
|
|
- for (Map.Entry<Version, Integer> indexVersionCount : indexCounts.entrySet()) {
|
|
|
- Version v = indexVersionCount.getKey();
|
|
|
+ for (Map.Entry<IndexVersion, Integer> indexVersionCount : indexCounts.entrySet()) {
|
|
|
+ IndexVersion v = indexVersionCount.getKey();
|
|
|
SingleVersionStats singleStats = new SingleVersionStats(
|
|
|
v,
|
|
|
indexVersionCount.getValue(),
|
|
@@ -164,12 +146,12 @@ public final class VersionStats implements ToXContentFragment, Writeable {
|
|
|
|
|
|
static class SingleVersionStats implements ToXContentObject, Writeable, Comparable<SingleVersionStats> {
|
|
|
|
|
|
- public final Version version;
|
|
|
+ public final IndexVersion version;
|
|
|
public final int indexCount;
|
|
|
public final int primaryShardCount;
|
|
|
public final long totalPrimaryByteCount;
|
|
|
|
|
|
- SingleVersionStats(Version version, int indexCount, int primaryShardCount, long totalPrimaryByteCount) {
|
|
|
+ SingleVersionStats(IndexVersion version, int indexCount, int primaryShardCount, long totalPrimaryByteCount) {
|
|
|
this.version = version;
|
|
|
this.indexCount = indexCount;
|
|
|
this.primaryShardCount = primaryShardCount;
|
|
@@ -177,7 +159,7 @@ public final class VersionStats implements ToXContentFragment, Writeable {
|
|
|
}
|
|
|
|
|
|
SingleVersionStats(StreamInput in) throws IOException {
|
|
|
- this.version = Version.readVersion(in);
|
|
|
+ this.version = IndexVersion.readVersion(in);
|
|
|
this.indexCount = in.readVInt();
|
|
|
this.primaryShardCount = in.readVInt();
|
|
|
this.totalPrimaryByteCount = in.readVLong();
|
|
@@ -196,7 +178,7 @@ public final class VersionStats implements ToXContentFragment, Writeable {
|
|
|
|
|
|
@Override
|
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
|
- Version.writeVersion(this.version, out);
|
|
|
+ IndexVersion.writeVersion(this.version, out);
|
|
|
out.writeVInt(this.indexCount);
|
|
|
out.writeVInt(this.primaryShardCount);
|
|
|
out.writeVLong(this.totalPrimaryByteCount);
|