diff options
Diffstat (limited to 'core/src/main/java/org/elasticsearch/cluster/ClusterState.java')
-rw-r--r-- | core/src/main/java/org/elasticsearch/cluster/ClusterState.java | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/core/src/main/java/org/elasticsearch/cluster/ClusterState.java b/core/src/main/java/org/elasticsearch/cluster/ClusterState.java index e6cc335a47..1ac379555a 100644 --- a/core/src/main/java/org/elasticsearch/cluster/ClusterState.java +++ b/core/src/main/java/org/elasticsearch/cluster/ClusterState.java @@ -63,7 +63,7 @@ import java.util.Set; /** * Represents the current state of the cluster. - * + * <p> * The cluster state object is immutable with an * exception of the {@link RoutingNodes} structure, which is built on demand from the {@link RoutingTable}, * and cluster state {@link #status}, which is updated during cluster state publishing and applying @@ -74,7 +74,7 @@ import java.util.Set; * the type of discovery. For example, for local discovery it is implemented by the {@link LocalDiscovery#publish} * method. In the Zen Discovery it is handled in the {@link PublishClusterStateAction#publish} method. The * publishing mechanism can be overridden by other discovery. - * + * <p> * The cluster state implements the {@link Diffable} interface in order to support publishing of cluster state * differences instead of the entire state on each change. The publishing mechanism should only send differences * to a node if this node was present in the previous version of the cluster state. If a node is not present was @@ -135,7 +135,7 @@ public class ClusterState implements ToXContent, Diffable<ClusterState> { public static <T extends Custom> T lookupPrototypeSafe(String type) { @SuppressWarnings("unchecked") - T proto = (T)customPrototypes.get(type); + T proto = (T) customPrototypes.get(type); if (proto == null) { throw new IllegalArgumentException("No custom state prototype registered for type [" + type + "], node likely missing plugins"); } @@ -281,6 +281,16 @@ public class ClusterState implements ToXContent, Diffable<ClusterState> { sb.append("state uuid: ").append(stateUUID).append("\n"); sb.append("from_diff: ").append(wasReadFromDiff).append("\n"); sb.append("meta data version: ").append(metaData.version()).append("\n"); + for (IndexMetaData indexMetaData : metaData) { + final String TAB = " "; + sb.append(TAB).append(indexMetaData.getIndex()); + sb.append(": v[").append(indexMetaData.getVersion()).append("]\n"); + for (int shard = 0; shard < indexMetaData.getNumberOfShards(); shard++) { + sb.append(TAB).append(TAB).append(shard).append(": "); + sb.append("p_term [").append(indexMetaData.primaryTerm(shard)).append("], "); + sb.append("a_ids ").append(indexMetaData.activeAllocationIds(shard)).append("\n"); + } + } sb.append(blocks().prettyPrint()); sb.append(nodes().prettyPrint()); sb.append(routingTable().prettyPrint()); @@ -477,6 +487,12 @@ public class ClusterState implements ToXContent, Diffable<ClusterState> { } builder.endArray(); + builder.startObject(IndexMetaData.KEY_PRIMARY_TERMS); + for (int shard = 0; shard < indexMetaData.getNumberOfShards(); shard++) { + builder.field(Integer.toString(shard), indexMetaData.primaryTerm(shard)); + } + builder.endObject(); + builder.startObject(IndexMetaData.KEY_ACTIVE_ALLOCATIONS); for (IntObjectCursor<Set<String>> cursor : indexMetaData.getActiveAllocationIds()) { builder.startArray(String.valueOf(cursor.key)); @@ -487,6 +503,7 @@ public class ClusterState implements ToXContent, Diffable<ClusterState> { } builder.endObject(); + // index metadata builder.endObject(); } builder.endObject(); @@ -683,16 +700,16 @@ public class ClusterState implements ToXContent, Diffable<ClusterState> { } /** - * @param data input bytes - * @param localNode used to set the local node in the cluster state. + * @param data input bytes + * @param localNode used to set the local node in the cluster state. */ public static ClusterState fromBytes(byte[] data, DiscoveryNode localNode) throws IOException { return readFrom(StreamInput.wrap(data), localNode); } /** - * @param in input stream - * @param localNode used to set the local node in the cluster state. can be null. + * @param in input stream + * @param localNode used to set the local node in the cluster state. can be null. */ public static ClusterState readFrom(StreamInput in, @Nullable DiscoveryNode localNode) throws IOException { return PROTO.readFrom(in, localNode); @@ -791,17 +808,17 @@ public class ClusterState implements ToXContent, Diffable<ClusterState> { metaData = proto.metaData.readDiffFrom(in); blocks = proto.blocks.readDiffFrom(in); customs = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), - new DiffableUtils.DiffableValueSerializer<String, Custom>() { - @Override - public Custom read(StreamInput in, String key) throws IOException { - return lookupPrototypeSafe(key).readFrom(in); - } + new DiffableUtils.DiffableValueSerializer<String, Custom>() { + @Override + public Custom read(StreamInput in, String key) throws IOException { + return lookupPrototypeSafe(key).readFrom(in); + } - @Override - public Diff<Custom> readDiff(StreamInput in, String key) throws IOException { - return lookupPrototypeSafe(key).readDiffFrom(in); - } - }); + @Override + public Diff<Custom> readDiff(StreamInput in, String key) throws IOException { + return lookupPrototypeSafe(key).readDiffFrom(in); + } + }); } @Override |