From f26d05eac894bc00559aad1a59897f8c451dc7f7 Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 30 Mar 2016 15:17:09 +0200 Subject: [PATCH] Remove DiscoveryNodes#localNodeId in favour of existing DiscoveryNodes#getLocalNodeId --- .../replication/TransportReplicationAction.java | 6 +++--- .../cluster/node/DiscoveryNodes.java | 15 +++------------ .../cluster/routing/OperationRouting.java | 6 +++--- .../cluster/service/ClusterService.java | 2 +- .../elasticsearch/discovery/zen/ZenDiscovery.java | 2 +- .../discovery/zen/fd/MasterFaultDetection.java | 2 +- .../zen/ping/unicast/UnicastZenPing.java | 2 +- .../elasticsearch/gateway/GatewayMetaState.java | 2 +- .../cluster/IndicesClusterStateService.java | 14 +++++++------- .../elasticsearch/snapshots/RestoreService.java | 8 ++++---- .../snapshots/SnapshotShardsService.java | 8 ++++---- .../TransportReplicationActionTests.java | 4 ++-- .../elasticsearch/cluster/ClusterStateDiffIT.java | 2 +- .../cluster/node/DiscoveryNodesTests.java | 2 +- .../cluster/service/ClusterServiceTests.java | 2 +- .../nodesinfo/SimpleNodesInfoIT.java | 8 ++++---- 16 files changed, 38 insertions(+), 47 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java index d27a8547fa6..d3a4698c53a 100644 --- a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java @@ -449,7 +449,7 @@ public abstract class TransportReplicationAction implements return this.masterNodeId; } - /** - * Get the id of the local node - * - * @return id of the local node - */ - public String localNodeId() { - return this.localNodeId; - } - /** * Get the id of the local node * * @return id of the local node */ public String getLocalNodeId() { - return localNodeId(); + return this.localNodeId; } /** @@ -302,7 +293,7 @@ public class DiscoveryNodes extends AbstractDiffable implements ObjectHashSet resolvedNodesIds = new ObjectHashSet<>(nodesIds.length); for (String nodeId : nodesIds) { if (nodeId.equals("_local")) { - String localNodeId = localNodeId(); + String localNodeId = getLocalNodeId(); if (localNodeId != null) { resolvedNodesIds.add(localNodeId); } @@ -595,7 +586,7 @@ public class DiscoveryNodes extends AbstractDiffable implements public Builder(DiscoveryNodes nodes) { this.masterNodeId = nodes.getMasterNodeId(); - this.localNodeId = nodes.localNodeId(); + this.localNodeId = nodes.getLocalNodeId(); this.nodes = ImmutableOpenMap.builder(nodes.getNodes()); } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java index 3db26b45254..aabb1a8de6e 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java @@ -58,12 +58,12 @@ public class OperationRouting extends AbstractComponent { } public ShardIterator getShards(ClusterState clusterState, String index, String type, String id, @Nullable String routing, @Nullable String preference) { - return preferenceActiveShardIterator(shards(clusterState, index, id, routing), clusterState.nodes().localNodeId(), clusterState.nodes(), preference); + return preferenceActiveShardIterator(shards(clusterState, index, id, routing), clusterState.nodes().getLocalNodeId(), clusterState.nodes(), preference); } public ShardIterator getShards(ClusterState clusterState, String index, int shardId, @Nullable String preference) { final IndexShardRoutingTable indexShard = clusterState.getRoutingTable().shardRoutingTable(index, shardId); - return preferenceActiveShardIterator(indexShard, clusterState.nodes().localNodeId(), clusterState.nodes(), preference); + return preferenceActiveShardIterator(indexShard, clusterState.nodes().getLocalNodeId(), clusterState.nodes(), preference); } public int searchShardsCount(ClusterState clusterState, String[] concreteIndices, @Nullable Map> routing) { @@ -75,7 +75,7 @@ public class OperationRouting extends AbstractComponent { final Set shards = computeTargetedShards(clusterState, concreteIndices, routing); final Set set = new HashSet<>(shards.size()); for (IndexShardRoutingTable shard : shards) { - ShardIterator iterator = preferenceActiveShardIterator(shard, clusterState.nodes().localNodeId(), clusterState.nodes(), preference); + ShardIterator iterator = preferenceActiveShardIterator(shard, clusterState.nodes().getLocalNodeId(), clusterState.nodes(), preference); if (iterator != null) { set.add(iterator); } diff --git a/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java b/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java index 559c5d6300e..924a20c2c3a 100644 --- a/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java +++ b/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java @@ -158,7 +158,7 @@ public class ClusterService extends AbstractLifecycleComponent { } synchronized public void setLocalNode(DiscoveryNode localNode) { - assert clusterState.nodes().localNodeId() == null : "local node is already set"; + assert clusterState.nodes().getLocalNodeId() == null : "local node is already set"; DiscoveryNodes.Builder nodeBuilder = DiscoveryNodes.builder(clusterState.nodes()).put(localNode).localNodeId(localNode.getId()); this.clusterState = ClusterState.builder(clusterState).nodes(nodeBuilder).build(); } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index d7aaac5612b..22c5221c0e8 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -967,7 +967,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen // since the network connections are asymmetric, it may be that we received a state but have disconnected from the node // in the past (after a master failure, for example) transportService.connectToNode(otherMaster); - transportService.sendRequest(otherMaster, DISCOVERY_REJOIN_ACTION_NAME, new RejoinClusterRequest(localClusterState.nodes().localNodeId()), new EmptyTransportResponseHandler(ThreadPool.Names.SAME) { + transportService.sendRequest(otherMaster, DISCOVERY_REJOIN_ACTION_NAME, new RejoinClusterRequest(localClusterState.nodes().getLocalNodeId()), new EmptyTransportResponseHandler(ThreadPool.Names.SAME) { @Override public void handleException(TransportException exp) { diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java b/core/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java index a3974fd48e1..116e622088e 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java @@ -328,7 +328,7 @@ public class MasterFaultDetection extends FaultDetection { final DiscoveryNodes nodes = clusterService.state().nodes(); // check if we are really the same master as the one we seemed to be think we are // this can happen if the master got "kill -9" and then another node started using the same port - if (!request.masterNodeId.equals(nodes.localNodeId())) { + if (!request.masterNodeId.equals(nodes.getLocalNodeId())) { throw new ThisIsNotTheMasterYouAreLookingForException(); } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java b/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java index 0135b53a844..69f107d0ab1 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java @@ -469,7 +469,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen try { DiscoveryNodes discoveryNodes = contextProvider.nodes(); for (PingResponse pingResponse : response.pingResponses) { - if (pingResponse.node().getId().equals(discoveryNodes.localNodeId())) { + if (pingResponse.node().getId().equals(discoveryNodes.getLocalNodeId())) { // that's us, ignore continue; } diff --git a/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java b/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java index a229b8ed5a1..905e572160c 100644 --- a/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java +++ b/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java @@ -285,7 +285,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL } public static Set getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, Set previouslyWrittenIndices) { - RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().localNodeId()); + RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId()); if (newRoutingNode == null) { throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state"); } diff --git a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java index 82f1466bf13..0a9a73cf0f1 100644 --- a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -193,7 +193,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent hasAllocations = new HashSet<>(); - final RoutingNode node = event.state().getRoutingNodes().node(event.state().nodes().localNodeId()); + final RoutingNode node = event.state().getRoutingNodes().node(event.state().nodes().getLocalNodeId()); // if no shards are allocated ie. if this node is a master-only node it can return nul if (node != null) { for (ShardRouting routing : node) { @@ -362,7 +362,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear().get(primaryNodeId); assertThat(capturedRequests, notNullValue()); assertThat(capturedRequests.size(), equalTo(1)); - if (clusterService.state().nodes().localNodeId().equals(primaryNodeId)) { + if (clusterService.state().nodes().getLocalNodeId().equals(primaryNodeId)) { assertThat(capturedRequests.get(0).action, equalTo("testAction[p]")); assertPhase(task, "waiting_on_primary"); } else { @@ -722,7 +722,7 @@ public class TransportReplicationActionTests extends ESTestCase { assertEquals(request.shardId, replicationRequest.shardId); } - String localNodeId = clusterService.state().getNodes().localNodeId(); + String localNodeId = clusterService.state().getNodes().getLocalNodeId(); // no request was sent to the local node assertThat(nodesSentTo.keySet(), not(hasItem(localNodeId))); diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java b/core/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java index 0490864dbc2..88eb7c37097 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterStateDiffIT.java @@ -134,7 +134,7 @@ public class ClusterStateDiffIT extends ESIntegTestCase { // Check nodes assertThat(clusterStateFromDiffs.nodes().getNodes(), equalTo(clusterState.nodes().getNodes())); - assertThat(clusterStateFromDiffs.nodes().localNodeId(), equalTo(previousClusterStateFromDiffs.nodes().localNodeId())); + assertThat(clusterStateFromDiffs.nodes().getLocalNodeId(), equalTo(previousClusterStateFromDiffs.nodes().getLocalNodeId())); assertThat(clusterStateFromDiffs.nodes().getNodes(), equalTo(clusterState.nodes().getNodes())); for (ObjectCursor node : clusterStateFromDiffs.nodes().getNodes().keys()) { DiscoveryNode node1 = clusterState.nodes().get(node.value); diff --git a/core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java b/core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java index 74b81736971..b0942ab401c 100644 --- a/core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java @@ -124,7 +124,7 @@ public class DiscoveryNodesTests extends ESTestCase { LOCAL("_local") { @Override Set matchingNodeIds(DiscoveryNodes nodes) { - return Collections.singleton(nodes.localNodeId()); + return Collections.singleton(nodes.getLocalNodeId()); } }, ELECTED_MASTER("_master") { @Override diff --git a/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java index 66b5fd0671b..94b54b771e6 100644 --- a/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceTests.java @@ -123,7 +123,7 @@ public class ClusterServiceTests extends ESTestCase { ClusterState state = timedClusterService.state(); final DiscoveryNodes nodes = state.nodes(); final DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(nodes) - .masterNodeId(makeMaster ? nodes.localNodeId() : null); + .masterNodeId(makeMaster ? nodes.getLocalNodeId() : null); state = ClusterState.builder(state).blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK) .nodes(nodesBuilder).build(); setState(timedClusterService, state); diff --git a/core/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java b/core/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java index 03b7a258f4f..c38aeb967ef 100644 --- a/core/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java +++ b/core/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java @@ -49,8 +49,8 @@ public class SimpleNodesInfoIT extends ESIntegTestCase { ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").get(); logger.info("--> done cluster_health, status {}", clusterHealth.getStatus()); - String server1NodeId = internalCluster().getInstance(ClusterService.class, node_1).state().nodes().localNodeId(); - String server2NodeId = internalCluster().getInstance(ClusterService.class, node_2).state().nodes().localNodeId(); + String server1NodeId = internalCluster().getInstance(ClusterService.class, node_1).state().nodes().getLocalNodeId(); + String server2NodeId = internalCluster().getInstance(ClusterService.class, node_2).state().nodes().getLocalNodeId(); logger.info("--> started nodes: {} and {}", server1NodeId, server2NodeId); NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().execute().actionGet(); @@ -93,8 +93,8 @@ public class SimpleNodesInfoIT extends ESIntegTestCase { ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").get(); logger.info("--> done cluster_health, status {}", clusterHealth.getStatus()); - String server1NodeId = internalCluster().getInstance(ClusterService.class, node_1).state().nodes().localNodeId(); - String server2NodeId = internalCluster().getInstance(ClusterService.class, node_2).state().nodes().localNodeId(); + String server1NodeId = internalCluster().getInstance(ClusterService.class, node_1).state().nodes().getLocalNodeId(); + String server2NodeId = internalCluster().getInstance(ClusterService.class, node_2).state().nodes().getLocalNodeId(); logger.info("--> started nodes: {} and {}", server1NodeId, server2NodeId); NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().execute().actionGet();