Skip to content

Commit 0f88f21

Browse files
authored
Don't set local node on cluster state used for node join validation (#23311)
When a node wants to join a cluster, it sends a join request to the master. The master then sends a join validation request to the node. This checks that the node can deserialize the current cluster state that exists on the master and that it can thus handle all the indices that are currently in the cluster (see #21830). The current code can trip an assertion as it does not take the cluster state as is but sets itself as the local node on the cluster state. This can result in an inconsistent DiscoveryNodes object as the local node is not yet part of the cluster state and a node with same id but different address can still exist in the cluster state. Also another node with the same address but different id can exist in the cluster state if multiple nodes are run on the same machine and ports have been swapped after node crashes/restarts.
1 parent 708d11f commit 0f88f21

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

core/src/main/java/org/elasticsearch/discovery/zen/MembershipAction.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
import java.io.IOException;
4141
import java.util.concurrent.TimeUnit;
42-
import java.util.function.Supplier;
4342

4443
public class MembershipAction extends AbstractComponent {
4544

@@ -63,8 +62,7 @@ public interface MembershipListener {
6362

6463
private final MembershipListener listener;
6564

66-
public MembershipAction(Settings settings, TransportService transportService,
67-
Supplier<DiscoveryNode> localNodeSupplier, MembershipListener listener) {
65+
public MembershipAction(Settings settings, TransportService transportService, MembershipListener listener) {
6866
super(settings);
6967
this.transportService = transportService;
7068
this.listener = listener;
@@ -73,7 +71,7 @@ public MembershipAction(Settings settings, TransportService transportService,
7371
transportService.registerRequestHandler(DISCOVERY_JOIN_ACTION_NAME, JoinRequest::new,
7472
ThreadPool.Names.GENERIC, new JoinRequestRequestHandler());
7573
transportService.registerRequestHandler(DISCOVERY_JOIN_VALIDATE_ACTION_NAME,
76-
() -> new ValidateJoinRequest(localNodeSupplier), ThreadPool.Names.GENERIC,
74+
() -> new ValidateJoinRequest(), ThreadPool.Names.GENERIC,
7775
new ValidateJoinRequestRequestHandler());
7876
transportService.registerRequestHandler(DISCOVERY_LEAVE_ACTION_NAME, LeaveRequest::new,
7977
ThreadPool.Names.GENERIC, new LeaveRequestRequestHandler());
@@ -155,22 +153,18 @@ public void onFailure(Exception e) {
155153
}
156154

157155
static class ValidateJoinRequest extends TransportRequest {
158-
private final Supplier<DiscoveryNode> localNode;
159156
private ClusterState state;
160157

161-
ValidateJoinRequest(Supplier<DiscoveryNode> localNode) {
162-
this.localNode = localNode;
163-
}
158+
ValidateJoinRequest() {}
164159

165160
ValidateJoinRequest(ClusterState state) {
166161
this.state = state;
167-
this.localNode = state.nodes()::getLocalNode;
168162
}
169163

170164
@Override
171165
public void readFrom(StreamInput in) throws IOException {
172166
super.readFrom(in);
173-
this.state = ClusterState.readFrom(in, localNode.get());
167+
this.state = ClusterState.readFrom(in, null);
174168
}
175169

176170
@Override

core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public ZenDiscovery(Settings settings, ThreadPool threadPool, TransportService t
191191
new NewPendingClusterStateListener(),
192192
discoverySettings,
193193
clusterService.getClusterName());
194-
this.membership = new MembershipAction(settings, transportService, this::localNode, new MembershipListener());
194+
this.membership = new MembershipAction(settings, transportService, new MembershipListener());
195195
this.joinThreadControl = new JoinThreadControl();
196196

197197
transportService.registerRequestHandler(

0 commit comments

Comments
 (0)