|
@@ -69,6 +69,8 @@ import org.elasticsearch.transport.TransportService;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Set;
|
|
@@ -78,6 +80,7 @@ import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.function.BiConsumer;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -146,15 +149,17 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
|
|
|
|
|
|
private final NodeJoinController nodeJoinController;
|
|
|
private final NodeRemovalClusterStateTaskExecutor nodeRemovalExecutor;
|
|
|
-
|
|
|
private final ClusterApplier clusterApplier;
|
|
|
private final AtomicReference<ClusterState> committedState; // last committed cluster state
|
|
|
private final Object stateMutex = new Object();
|
|
|
+ private final Collection<BiConsumer<DiscoveryNode, ClusterState>> onJoinValidators;
|
|
|
|
|
|
public ZenDiscovery(Settings settings, ThreadPool threadPool, TransportService transportService,
|
|
|
NamedWriteableRegistry namedWriteableRegistry, MasterService masterService, ClusterApplier clusterApplier,
|
|
|
- ClusterSettings clusterSettings, UnicastHostsProvider hostsProvider, AllocationService allocationService) {
|
|
|
+ ClusterSettings clusterSettings, UnicastHostsProvider hostsProvider, AllocationService allocationService,
|
|
|
+ Collection<BiConsumer<DiscoveryNode, ClusterState>> onJoinValidators) {
|
|
|
super(settings);
|
|
|
+ this.onJoinValidators = addBuiltInJoinValidators(onJoinValidators);
|
|
|
this.masterService = masterService;
|
|
|
this.clusterApplier = clusterApplier;
|
|
|
this.transportService = transportService;
|
|
@@ -211,7 +216,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
|
|
|
namedWriteableRegistry,
|
|
|
this,
|
|
|
discoverySettings);
|
|
|
- this.membership = new MembershipAction(settings, transportService, new MembershipListener());
|
|
|
+ this.membership = new MembershipAction(settings, transportService, new MembershipListener(), onJoinValidators);
|
|
|
this.joinThreadControl = new JoinThreadControl();
|
|
|
|
|
|
this.nodeJoinController = new NodeJoinController(masterService, allocationService, electMaster, settings);
|
|
@@ -223,6 +228,17 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
|
|
|
DISCOVERY_REJOIN_ACTION_NAME, RejoinClusterRequest::new, ThreadPool.Names.SAME, new RejoinClusterRequestHandler());
|
|
|
}
|
|
|
|
|
|
+ static Collection<BiConsumer<DiscoveryNode,ClusterState>> addBuiltInJoinValidators(
|
|
|
+ Collection<BiConsumer<DiscoveryNode,ClusterState>> onJoinValidators) {
|
|
|
+ Collection<BiConsumer<DiscoveryNode, ClusterState>> validators = new ArrayList<>();
|
|
|
+ validators.add((node, state) -> {
|
|
|
+ MembershipAction.ensureNodesCompatibility(node.getVersion(), state.getNodes());
|
|
|
+ MembershipAction.ensureIndexCompatibility(node.getVersion(), state.getMetaData());
|
|
|
+ });
|
|
|
+ validators.addAll(onJoinValidators);
|
|
|
+ return Collections.unmodifiableCollection(validators);
|
|
|
+ }
|
|
|
+
|
|
|
// protected to allow overriding in tests
|
|
|
protected ZenPing newZenPing(Settings settings, ThreadPool threadPool, TransportService transportService,
|
|
|
UnicastHostsProvider hostsProvider) {
|
|
@@ -885,8 +901,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
|
|
|
} else {
|
|
|
// we do this in a couple of places including the cluster update thread. This one here is really just best effort
|
|
|
// to ensure we fail as fast as possible.
|
|
|
- MembershipAction.ensureNodesCompatibility(node.getVersion(), state.getNodes());
|
|
|
- MembershipAction.ensureIndexCompatibility(node.getVersion(), state.getMetaData());
|
|
|
+ onJoinValidators.stream().forEach(a -> a.accept(node, state));
|
|
|
if (state.getBlocks().hasGlobalBlock(STATE_NOT_RECOVERED_BLOCK) == false) {
|
|
|
MembershipAction.ensureMajorVersionBarrier(node.getVersion(), state.getNodes().getMinNodeVersion());
|
|
|
}
|
|
@@ -898,7 +913,8 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
|
|
|
try {
|
|
|
membership.sendValidateJoinRequestBlocking(node, state, joinTimeout);
|
|
|
} catch (Exception e) {
|
|
|
- logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed to validate incoming join request from node [{}]", node), e);
|
|
|
+ logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed to validate incoming join request from node [{}]", node),
|
|
|
+ e);
|
|
|
callback.onFailure(new IllegalStateException("failure when sending a validation request to node", e));
|
|
|
return;
|
|
|
}
|
|
@@ -1313,4 +1329,9 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ public final Collection<BiConsumer<DiscoveryNode, ClusterState>> getOnJoinValidators() {
|
|
|
+ return onJoinValidators;
|
|
|
+ }
|
|
|
+
|
|
|
}
|