From 5fe2615ba7d41dd6596c020db4bd7fb7f248d58f Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 3 Feb 2011 00:50:24 +0200 Subject: [PATCH] Index Status: Add primary store size to include only primary shards store sizes, also move index store and translog into their own elements, closes #666. --- .../admin/cluster/node/stats/NodeStats.java | 12 +++---- .../indices/status/IndexShardStatus.java | 36 +++++++++++++++++++ .../admin/indices/status/IndexStatus.java | 32 +++++++++++++++++ .../elasticsearch/indices/IndicesService.java | 2 +- .../indices/InternalIndicesService.java | 4 +-- ...ndicesStats.java => NodeIndicesStats.java} | 12 +++---- .../status/RestIndicesStatusAction.java | 12 +++++-- 7 files changed, 92 insertions(+), 18 deletions(-) rename modules/elasticsearch/src/main/java/org/elasticsearch/indices/{IndicesStats.java => NodeIndicesStats.java} (91%) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java index a99a1b803b0..5255ce65b9a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java @@ -23,7 +23,7 @@ import org.elasticsearch.action.support.nodes.NodeOperationResponse; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.indices.IndicesStats; +import org.elasticsearch.indices.NodeIndicesStats; import org.elasticsearch.monitor.jvm.JvmStats; import org.elasticsearch.monitor.network.NetworkStats; import org.elasticsearch.monitor.os.OsStats; @@ -40,7 +40,7 @@ import java.io.IOException; */ public class NodeStats extends NodeOperationResponse { - private IndicesStats indices; + private NodeIndicesStats indices; private OsStats os; @@ -57,7 +57,7 @@ public class NodeStats extends NodeOperationResponse { NodeStats() { } - public NodeStats(DiscoveryNode node, IndicesStats indices, + public NodeStats(DiscoveryNode node, NodeIndicesStats indices, OsStats os, ProcessStats process, JvmStats jvm, NetworkStats network, ThreadPoolStats threadPool, TransportStats transport) { super(node); @@ -73,14 +73,14 @@ public class NodeStats extends NodeOperationResponse { /** * Indices level stats. */ - public IndicesStats indices() { + public NodeIndicesStats indices() { return this.indices; } /** * Indices level stats. */ - public IndicesStats getIndices() { + public NodeIndicesStats getIndices() { return indices(); } @@ -171,7 +171,7 @@ public class NodeStats extends NodeOperationResponse { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); if (in.readBoolean()) { - indices = IndicesStats.readIndicesStats(in); + indices = NodeIndicesStats.readIndicesStats(in); } if (in.readBoolean()) { os = OsStats.readOsStats(in); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexShardStatus.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexShardStatus.java index 812327eadd7..67efcdd7d3c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexShardStatus.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexShardStatus.java @@ -59,6 +59,39 @@ public class IndexShardStatus implements Iterable { return shards[position]; } + /** + * Returns only the primary shards store size in bytes. + */ + public ByteSizeValue primaryStoreSize() { + long bytes = -1; + for (ShardStatus shard : shards()) { + if (!shard.shardRouting().primary()) { + // only sum docs for the primaries + continue; + } + if (shard.storeSize() != null) { + if (bytes == -1) { + bytes = 0; + } + bytes += shard.storeSize().bytes(); + } + } + if (bytes == -1) { + return null; + } + return new ByteSizeValue(bytes); + } + + /** + * Returns only the primary shards store size in bytes. + */ + public ByteSizeValue getPrimaryStoreSize() { + return primaryStoreSize(); + } + + /** + * Returns the full store size in bytes, of both primaries and replicas. + */ public ByteSizeValue storeSize() { long bytes = -1; for (ShardStatus shard : shards()) { @@ -75,6 +108,9 @@ public class IndexShardStatus implements Iterable { return new ByteSizeValue(bytes); } + /** + * Returns the full store size in bytes, of both primaries and replicas. + */ public ByteSizeValue getStoreSize() { return storeSize(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexStatus.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexStatus.java index d59a0c7f6eb..39e9b730f5a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexStatus.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexStatus.java @@ -87,6 +87,35 @@ public class IndexStatus implements Iterable { return settings(); } + /** + * Returns only the primary shards store size in bytes. + */ + public ByteSizeValue primaryStoreSize() { + long bytes = -1; + for (IndexShardStatus shard : this) { + if (shard.primaryStoreSize() != null) { + if (bytes == -1) { + bytes = 0; + } + bytes += shard.primaryStoreSize().bytes(); + } + } + if (bytes == -1) { + return null; + } + return new ByteSizeValue(bytes); + } + + /** + * Returns only the primary shards store size in bytes. + */ + public ByteSizeValue getPrimaryStoreSize() { + return primaryStoreSize(); + } + + /** + * Returns the full store size in bytes, of both primaries and replicas. + */ public ByteSizeValue storeSize() { long bytes = -1; for (IndexShardStatus shard : this) { @@ -103,6 +132,9 @@ public class IndexStatus implements Iterable { return new ByteSizeValue(bytes); } + /** + * Returns the full store size in bytes, of both primaries and replicas. + */ public ByteSizeValue getStoreSize() { return storeSize(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesService.java index ac3faeb87ee..8bb0e9bbd66 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -38,7 +38,7 @@ public interface IndicesService extends Iterable, LifecycleCompone */ public boolean changesAllowed(); - IndicesStats stats(); + NodeIndicesStats stats(); boolean hasIndex(String index); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java index 254afc5d50f..cfb17860c29 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java @@ -157,7 +157,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent