From cd05cf91f01759dc5955354b275128661a66fe0b Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 24 Mar 2016 15:09:47 +0100 Subject: [PATCH] remove PROTOTYPE from DiscoveryNode --- .../cluster/node/tasks/list/TaskInfo.java | 2 +- .../verify/VerifyRepositoryResponse.java | 2 +- .../shards/ClusterSearchShardsResponse.java | 2 +- .../shards/IndicesShardStoresResponse.java | 2 +- .../support/nodes/BaseNodeResponse.java | 2 +- .../cluster/node/DiscoveryNode.java | 37 +++++++++---------- .../cluster/node/DiscoveryNodes.java | 4 +- .../allocation/AllocationExplanation.java | 2 +- .../discovery/zen/fd/NodesFaultDetection.java | 2 +- .../zen/membership/MembershipAction.java | 4 +- .../discovery/zen/ping/ZenPing.java | 5 +-- .../gateway/LocalAllocateDangledIndices.java | 2 +- .../indices/recovery/RecoveryState.java | 4 +- .../recovery/StartRecoveryRequest.java | 4 +- .../indices/store/IndicesStore.java | 2 +- .../transport/ConnectTransportException.java | 2 +- 16 files changed, 37 insertions(+), 41 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TaskInfo.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TaskInfo.java index c027bfa7ab4..f7455463d5a 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TaskInfo.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/TaskInfo.java @@ -73,7 +73,7 @@ public class TaskInfo implements Writeable, ToXContent { } public TaskInfo(StreamInput in) throws IOException { - node = DiscoveryNode.readNode(in); + node = new DiscoveryNode(in); taskId = new TaskId(node.getId(), in.readLong()); type = in.readString(); action = in.readString(); diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java index 451ef21f632..ba62002c1c6 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java @@ -55,7 +55,7 @@ public class VerifyRepositoryResponse extends ActionResponse implements ToXConte clusterName = ClusterName.readClusterName(in); nodes = new DiscoveryNode[in.readVInt()]; for (int i=0; i, ToXContent { - private static final DiscoveryNode PROTOTYPE = new DiscoveryNode("prototype", DummyTransportAddress.INSTANCE, Version.CURRENT); - public static boolean localNode(Settings settings) { if (Node.NODE_LOCAL_SETTING.exists(settings)) { return Node.NODE_LOCAL_SETTING.get(settings); @@ -95,6 +92,22 @@ public class DiscoveryNode implements Writeable, ToXContent { private final Version version; private final Set roles; + public DiscoveryNode(StreamInput in) throws IOException { + this.nodeName = in.readString().intern(); + this.nodeId = in.readString().intern(); + this.hostName = in.readString().intern(); + this.hostAddress = in.readString().intern(); + this.address = TransportAddressSerializers.addressFromStream(in); + int size = in.readVInt(); + ImmutableOpenMap.Builder attributesBuilder = ImmutableOpenMap.builder(size); + for (int i = 0; i < size; i++) { + attributesBuilder.put(in.readString().intern(), in.readString().intern()); + } + this.attributes = attributesBuilder.build(); + this.version = Version.readVersion(in); + this.roles = resolveRoles(this.attributes); + } + /** * Creates a new {@link DiscoveryNode} *

@@ -335,25 +348,9 @@ public class DiscoveryNode implements Writeable, ToXContent { return this.version; } - public static DiscoveryNode readNode(StreamInput in) throws IOException { - return PROTOTYPE.readFrom(in); - } - @Override public DiscoveryNode readFrom(StreamInput in) throws IOException { - String nodeName = in.readString().intern(); - String nodeId = in.readString().intern(); - String hostName = in.readString().intern(); - String hostAddress = in.readString().intern(); - TransportAddress address = TransportAddressSerializers.addressFromStream(in); - int size = in.readVInt(); - ImmutableOpenMap.Builder attributesBuilder = ImmutableOpenMap.builder(size); - for (int i = 0; i < size; i++) { - attributesBuilder.put(in.readString().intern(), in.readString().intern()); - } - ImmutableOpenMap attributes = attributesBuilder.build(); - Version version = Version.readVersion(in); - return new DiscoveryNode(nodeName, nodeId, hostName, hostAddress, address, attributes, version); + return new DiscoveryNode(in); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index a1562a42842..a6eaf73929e 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -599,7 +599,7 @@ public class DiscoveryNodes extends AbstractDiffable implements } } - public DiscoveryNodes readFrom(StreamInput in, DiscoveryNode localNode) throws IOException { + private DiscoveryNodes readFrom(StreamInput in, DiscoveryNode localNode) throws IOException { Builder builder = new Builder(); if (in.readBoolean()) { builder.masterNodeId(in.readString()); @@ -609,7 +609,7 @@ public class DiscoveryNodes extends AbstractDiffable implements } int size = in.readVInt(); for (int i = 0; i < size; i++) { - DiscoveryNode node = DiscoveryNode.readNode(in); + DiscoveryNode node = new DiscoveryNode(in); if (localNode != null && node.id().equals(localNode.id())) { // reuse the same instance of our address and local node id for faster equality node = localNode; diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationExplanation.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationExplanation.java index 68110130829..e2b5de9b52d 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationExplanation.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationExplanation.java @@ -125,7 +125,7 @@ public class AllocationExplanation implements Streamable { for (int j = 0; j < size2; j++) { DiscoveryNode node = null; if (in.readBoolean()) { - node = DiscoveryNode.readNode(in); + node = new DiscoveryNode(in); } ne.add(new NodeExplanation(node, in.readString())); } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java b/core/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java index 9386ff6356e..4b1077cc1b2 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java @@ -314,7 +314,7 @@ public class NodesFaultDetection extends FaultDetection { super.readFrom(in); nodeId = in.readString(); clusterName = ClusterName.readClusterName(in); - masterNode = DiscoveryNode.readNode(in); + masterNode = new DiscoveryNode(in); clusterStateVersion = in.readLong(); } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java b/core/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java index de4caf664ea..bec5abccd24 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java @@ -121,7 +121,7 @@ public class MembershipAction extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - node = DiscoveryNode.readNode(in); + node = new DiscoveryNode(in); } @Override @@ -204,7 +204,7 @@ public class MembershipAction extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - node = DiscoveryNode.readNode(in); + node = new DiscoveryNode(in); } @Override diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java b/core/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java index f97b31861ec..e28efa044d6 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java @@ -33,7 +33,6 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import static org.elasticsearch.cluster.ClusterName.readClusterName; -import static org.elasticsearch.cluster.node.DiscoveryNode.readNode; /** * @@ -120,9 +119,9 @@ public interface ZenPing extends LifecycleComponent { @Override public void readFrom(StreamInput in) throws IOException { clusterName = readClusterName(in); - node = readNode(in); + node = new DiscoveryNode(in); if (in.readBoolean()) { - master = readNode(in); + master = new DiscoveryNode(in); } this.hasJoinedOnce = in.readBoolean(); this.id = in.readLong(); diff --git a/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java b/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java index b14dcc6d1a4..face4c62ca7 100644 --- a/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java +++ b/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java @@ -212,7 +212,7 @@ public class LocalAllocateDangledIndices extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - fromNode = DiscoveryNode.readNode(in); + fromNode = new DiscoveryNode(in); indices = new IndexMetaData[in.readVInt()]; for (int i = 0; i < indices.length; i++) { indices[i] = IndexMetaData.Builder.readFrom(in); diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java index d1c41d4b932..604879452ba 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java @@ -270,9 +270,9 @@ public class RecoveryState implements ToXContent, Streamable { stage = Stage.fromId(in.readByte()); shardId = ShardId.readShardId(in); restoreSource = RestoreSource.readOptionalRestoreSource(in); - targetNode = DiscoveryNode.readNode(in); + targetNode = new DiscoveryNode(in); if (in.readBoolean()) { - sourceNode = DiscoveryNode.readNode(in); + sourceNode = new DiscoveryNode(in); } index.readFrom(in); translog.readFrom(in); diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java b/core/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java index 49dd70a73f7..ba2e1f42a57 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java @@ -92,8 +92,8 @@ public class StartRecoveryRequest extends TransportRequest { super.readFrom(in); recoveryId = in.readLong(); shardId = ShardId.readShardId(in); - sourceNode = DiscoveryNode.readNode(in); - targetNode = DiscoveryNode.readNode(in); + sourceNode = new DiscoveryNode(in); + targetNode = new DiscoveryNode(in); metadataSnapshot = new Store.MetadataSnapshot(in); recoveryType = RecoveryState.Type.fromId(in.readByte()); diff --git a/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java b/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java index d2db41a7a0c..fcca5769ddd 100644 --- a/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java +++ b/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java @@ -418,7 +418,7 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe public void readFrom(StreamInput in) throws IOException { super.readFrom(in); shardActive = in.readBoolean(); - node = DiscoveryNode.readNode(in); + node = new DiscoveryNode(in); } @Override diff --git a/core/src/main/java/org/elasticsearch/transport/ConnectTransportException.java b/core/src/main/java/org/elasticsearch/transport/ConnectTransportException.java index 75bf3cd9148..515cdcc941f 100644 --- a/core/src/main/java/org/elasticsearch/transport/ConnectTransportException.java +++ b/core/src/main/java/org/elasticsearch/transport/ConnectTransportException.java @@ -52,7 +52,7 @@ public class ConnectTransportException extends ActionTransportException { public ConnectTransportException(StreamInput in) throws IOException { super(in); if (in.readBoolean()) { - node = DiscoveryNode.readNode(in); + node = new DiscoveryNode(in); } else { node = null; }