From 3942c9e4df6b55dbd5e28535bd89de35f1e9fb9b Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 30 Mar 2016 14:56:15 +0200 Subject: [PATCH] Remove DiscoveryNode#version in favour of existing DiscoveryNode#getVersion --- .../cluster/node/DiscoveryNode.java | 6 +----- .../cluster/node/DiscoveryNodes.java | 6 +++--- .../decider/NodeVersionAllocationDecider.java | 12 +++++------ .../publish/PublishClusterStateAction.java | 20 +++++++++---------- .../transport/local/LocalTransport.java | 2 +- .../transport/netty/NettyTransport.java | 4 ++-- .../org/elasticsearch/tribe/TribeService.java | 2 +- .../cluster/ClusterStateDiffIT.java | 2 +- .../NodeVersionAllocationDeciderTests.java | 18 ++++++++--------- .../discovery/zen/ZenDiscoveryIT.java | 2 +- 10 files changed, 35 insertions(+), 39 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index c3a7d2a44dc..340e00a71f3 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -264,7 +264,7 @@ public class DiscoveryNode implements Writeable, ToXContent { return roles; } - public Version version() { + public Version getVersion() { return this.version; } @@ -276,10 +276,6 @@ public class DiscoveryNode implements Writeable, ToXContent { return this.hostAddress; } - public Version getVersion() { - return this.version; - } - @Override public DiscoveryNode readFrom(StreamInput in) throws IOException { return new DiscoveryNode(in); 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 37cbbc95af1..f41e3c50682 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -677,16 +677,16 @@ public class DiscoveryNodes extends AbstractDiffable implements for (ObjectObjectCursor nodeEntry : nodes) { if (nodeEntry.value.isDataNode()) { dataNodesBuilder.put(nodeEntry.key, nodeEntry.value); - minNonClientNodeVersion = Version.smallest(minNonClientNodeVersion, nodeEntry.value.version()); + minNonClientNodeVersion = Version.smallest(minNonClientNodeVersion, nodeEntry.value.getVersion()); } if (nodeEntry.value.isMasterNode()) { masterNodesBuilder.put(nodeEntry.key, nodeEntry.value); - minNonClientNodeVersion = Version.smallest(minNonClientNodeVersion, nodeEntry.value.version()); + minNonClientNodeVersion = Version.smallest(minNonClientNodeVersion, nodeEntry.value.getVersion()); } if (nodeEntry.value.isIngestNode()) { ingestNodesBuilder.put(nodeEntry.key, nodeEntry.value); } - minNodeVersion = Version.smallest(minNodeVersion, nodeEntry.value.version()); + minNodeVersion = Version.smallest(minNodeVersion, nodeEntry.value.getVersion()); } return new DiscoveryNodes( diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeVersionAllocationDecider.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeVersionAllocationDecider.java index 95540d89a6f..17ac486a8ce 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeVersionAllocationDecider.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeVersionAllocationDecider.java @@ -73,26 +73,26 @@ public class NodeVersionAllocationDecider extends AllocationDecider { private Decision isVersionCompatible(final RoutingNodes routingNodes, final String sourceNodeId, final RoutingNode target, RoutingAllocation allocation) { final RoutingNode source = routingNodes.node(sourceNodeId); - if (target.node().version().onOrAfter(source.node().version())) { + if (target.node().getVersion().onOrAfter(source.node().getVersion())) { /* we can allocate if we can recover from a node that is younger or on the same version * if the primary is already running on a newer version that won't work due to possible * differences in the lucene index format etc.*/ return allocation.decision(Decision.YES, NAME, "target node version [%s] is the same or newer than source node version [%s]", - target.node().version(), source.node().version()); + target.node().getVersion(), source.node().getVersion()); } else { return allocation.decision(Decision.NO, NAME, "target node version [%s] is older than the source node version [%s]", - target.node().version(), source.node().version()); + target.node().getVersion(), source.node().getVersion()); } } private Decision isVersionCompatible(RestoreSource restoreSource, final RoutingNode target, RoutingAllocation allocation) { - if (target.node().version().onOrAfter(restoreSource.version())) { + if (target.node().getVersion().onOrAfter(restoreSource.version())) { /* we can allocate if we can restore from a snapshot that is older or on the same version */ return allocation.decision(Decision.YES, NAME, "target node version [%s] is the same or newer than snapshot version [%s]", - target.node().version(), restoreSource.version()); + target.node().getVersion(), restoreSource.version()); } else { return allocation.decision(Decision.NO, NAME, "target node version [%s] is older than the snapshot version [%s]", - target.node().version(), restoreSource.version()); + target.node().getVersion(), restoreSource.version()); } } } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java b/core/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java index 64b77588726..0c8d16c2cb8 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java @@ -212,16 +212,16 @@ public class PublishClusterStateAction extends AbstractComponent { try { if (sendFullVersion || !previousState.nodes().nodeExists(node.getId())) { // will send a full reference - if (serializedStates.containsKey(node.version()) == false) { - serializedStates.put(node.version(), serializeFullClusterState(clusterState, node.version())); + if (serializedStates.containsKey(node.getVersion()) == false) { + serializedStates.put(node.getVersion(), serializeFullClusterState(clusterState, node.getVersion())); } } else { // will send a diff if (diff == null) { diff = clusterState.diff(previousState); } - if (serializedDiffs.containsKey(node.version()) == false) { - serializedDiffs.put(node.version(), serializeDiffClusterState(diff, node.version())); + if (serializedDiffs.containsKey(node.getVersion()) == false) { + serializedDiffs.put(node.getVersion(), serializeDiffClusterState(diff, node.getVersion())); } } } catch (IOException e) { @@ -232,11 +232,11 @@ public class PublishClusterStateAction extends AbstractComponent { private void sendFullClusterState(ClusterState clusterState, Map serializedStates, DiscoveryNode node, TimeValue publishTimeout, SendingController sendingController) { - BytesReference bytes = serializedStates.get(node.version()); + BytesReference bytes = serializedStates.get(node.getVersion()); if (bytes == null) { try { - bytes = serializeFullClusterState(clusterState, node.version()); - serializedStates.put(node.version(), bytes); + bytes = serializeFullClusterState(clusterState, node.getVersion()); + serializedStates.put(node.getVersion(), bytes); } catch (Throwable e) { logger.warn("failed to serialize cluster_state before publishing it to node {}", e, node); sendingController.onNodeSendFailed(node, e); @@ -249,8 +249,8 @@ public class PublishClusterStateAction extends AbstractComponent { private void sendClusterStateDiff(ClusterState clusterState, Map serializedDiffs, Map serializedStates, DiscoveryNode node, TimeValue publishTimeout, SendingController sendingController) { - BytesReference bytes = serializedDiffs.get(node.version()); - assert bytes != null : "failed to find serialized diff for node " + node + " of version [" + node.version() + "]"; + BytesReference bytes = serializedDiffs.get(node.getVersion()); + assert bytes != null : "failed to find serialized diff for node " + node + " of version [" + node.getVersion() + "]"; sendClusterStateToNode(clusterState, bytes, node, publishTimeout, sendingController, true, serializedStates); } @@ -266,7 +266,7 @@ public class PublishClusterStateAction extends AbstractComponent { // -> no need to compress, we already compressed the bytes TransportRequestOptions options = TransportRequestOptions.builder().withType(TransportRequestOptions.Type.STATE).withCompress(false).build(); transportService.sendRequest(node, SEND_ACTION_NAME, - new BytesTransportRequest(bytes, node.version()), + new BytesTransportRequest(bytes, node.getVersion()), options, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) { diff --git a/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java b/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java index aed46a56f96..8585e54f50d 100644 --- a/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java +++ b/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java @@ -202,7 +202,7 @@ public class LocalTransport extends AbstractLifecycleComponent implem @Override public void sendRequest(final DiscoveryNode node, final long requestId, final String action, final TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { - final Version version = Version.smallest(node.version(), this.version); + final Version version = Version.smallest(node.getVersion(), this.version); try (BytesStreamOutput stream = new BytesStreamOutput()) { stream.setVersion(version); diff --git a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java index 84da18b2a09..5b9029fa03e 100644 --- a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java +++ b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java @@ -887,7 +887,7 @@ public class NettyTransport extends AbstractLifecycleComponent implem // we pick the smallest of the 2, to support both backward and forward compatibility // note, this is the only place we need to do this, since from here on, we use the serialized version // as the version to use also when the node receiving this request will send the response with - Version version = Version.smallest(this.version, node.version()); + Version version = Version.smallest(this.version, node.getVersion()); stream.setVersion(version); threadPool.getThreadContext().writeTo(stream); @@ -900,7 +900,7 @@ public class NettyTransport extends AbstractLifecycleComponent implem // more explicit). if (request instanceof BytesTransportRequest) { BytesTransportRequest bRequest = (BytesTransportRequest) request; - assert node.version().equals(bRequest.version()); + assert node.getVersion().equals(bRequest.version()); bRequest.writeThin(stream); stream.close(); bytes = bStream.bytes(); diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeService.java b/core/src/main/java/org/elasticsearch/tribe/TribeService.java index 0802ed64099..a6cfec81126 100644 --- a/core/src/main/java/org/elasticsearch/tribe/TribeService.java +++ b/core/src/main/java/org/elasticsearch/tribe/TribeService.java @@ -367,7 +367,7 @@ public class TribeService extends AbstractLifecycleComponent { Map tribeAttr = new HashMap<>(tribe.getAttributes()); tribeAttr.put(TRIBE_NAME_SETTING.getKey(), tribeName); DiscoveryNode discoNode = new DiscoveryNode(tribe.getName(), tribe.getId(), tribe.getHostName(), tribe.getHostAddress(), - tribe.getAddress(), unmodifiableMap(tribeAttr), tribe.getRoles(), tribe.version()); + tribe.getAddress(), unmodifiableMap(tribeAttr), tribe.getRoles(), tribe.getVersion()); clusterStateChanged = true; logger.info("[{}] adding node [{}]", tribeName, discoNode); nodes.put(discoNode); diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java b/core/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java index 059bda8082d..00b8291957c 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java @@ -139,7 +139,7 @@ public class ClusterStateDiffIT extends ESIntegTestCase { for (ObjectCursor node : clusterStateFromDiffs.nodes().nodes().keys()) { DiscoveryNode node1 = clusterState.nodes().get(node.value); DiscoveryNode node2 = clusterStateFromDiffs.nodes().get(node.value); - assertThat(node1.version(), equalTo(node2.version())); + assertThat(node1.getVersion(), equalTo(node2.getVersion())); assertThat(node1.getAddress(), equalTo(node2.getAddress())); assertThat(node1.getAttributes(), equalTo(node2.getAttributes())); } diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java index ab3eb45ef7e..49e38d7adba 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java @@ -415,17 +415,17 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase { String fromId = r.currentNodeId(); assertThat(fromId, notNullValue()); assertThat(toId, notNullValue()); - logger.trace("From: {} with Version: {} to: {} with Version: {}", fromId, routingNodes.node(fromId).node().version(), - toId, routingNodes.node(toId).node().version()); - assertTrue(routingNodes.node(toId).node().version().onOrAfter(routingNodes.node(fromId).node().version())); + logger.trace("From: {} with Version: {} to: {} with Version: {}", fromId, routingNodes.node(fromId).node().getVersion(), + toId, routingNodes.node(toId).node().getVersion()); + assertTrue(routingNodes.node(toId).node().getVersion().onOrAfter(routingNodes.node(fromId).node().getVersion())); } else { ShardRouting primary = routingNodes.activePrimary(r); assertThat(primary, notNullValue()); String fromId = primary.currentNodeId(); String toId = r.relocatingNodeId(); - logger.trace("From: {} with Version: {} to: {} with Version: {}", fromId, routingNodes.node(fromId).node().version(), - toId, routingNodes.node(toId).node().version()); - assertTrue(routingNodes.node(toId).node().version().onOrAfter(routingNodes.node(fromId).node().version())); + logger.trace("From: {} with Version: {} to: {} with Version: {}", fromId, routingNodes.node(fromId).node().getVersion(), + toId, routingNodes.node(toId).node().getVersion()); + assertTrue(routingNodes.node(toId).node().getVersion().onOrAfter(routingNodes.node(fromId).node().getVersion())); } } @@ -436,9 +436,9 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase { assertThat(primary, notNullValue()); String fromId = primary.currentNodeId(); String toId = r.currentNodeId(); - logger.trace("From: {} with Version: {} to: {} with Version: {}", fromId, routingNodes.node(fromId).node().version(), - toId, routingNodes.node(toId).node().version()); - assertTrue(routingNodes.node(toId).node().version().onOrAfter(routingNodes.node(fromId).node().version())); + logger.trace("From: {} with Version: {} to: {} with Version: {}", fromId, routingNodes.node(fromId).node().getVersion(), + toId, routingNodes.node(toId).node().getVersion()); + assertTrue(routingNodes.node(toId).node().getVersion().onOrAfter(routingNodes.node(fromId).node().getVersion())); } } diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java b/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java index 9cd7cc9c99d..2dc53127684 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java @@ -197,7 +197,7 @@ public class ZenDiscoveryIT extends ESIntegTestCase { emptySet(), Version.CURRENT)).masterNodeId("abc"); ClusterState.Builder builder = ClusterState.builder(state); builder.nodes(nodes); - BytesReference bytes = PublishClusterStateAction.serializeFullClusterState(builder.build(), node.version()); + BytesReference bytes = PublishClusterStateAction.serializeFullClusterState(builder.build(), node.getVersion()); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference reference = new AtomicReference<>();