Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING;
import static org.elasticsearch.discovery.SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING;

public class ClusterBootstrapService {
public class ClusterBootstrapService implements Coordinator.PeerFinderListener {

public static final Setting<List<String>> INITIAL_MASTER_NODES_SETTING = Setting.listSetting(
"cluster.initial_master_nodes",
Expand Down Expand Up @@ -147,7 +147,7 @@ void logBootstrapState(Metadata metadata) {
}
}

void onFoundPeersUpdated() {
public void onFoundPeersUpdated() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void onFoundPeersUpdated() {
@Override
public void onFoundPeersUpdated() {

final Set<DiscoveryNode> nodes = getDiscoveredNodes();
if (bootstrappingPermitted.get()
&& transportService.getLocalNode().isMasterNode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
Expand Down Expand Up @@ -174,6 +175,7 @@ public class Coordinator extends AbstractLifecycleComponent implements ClusterSt
private JoinHelper.JoinAccumulator joinAccumulator;
private Optional<CoordinatorPublication> currentPublication = Optional.empty();
private final NodeHealthService nodeHealthService;
private final List<PeerFinderListener> peerFinderListeners;

/**
* @param nodeName The name of the node, used to name the {@link java.util.concurrent.ExecutorService} of the {@link SeedHostsResolver}.
Expand Down Expand Up @@ -295,6 +297,8 @@ public Coordinator(
joinHelper::logLastFailedJoinAttempt
);
this.nodeHealthService = nodeHealthService;
this.peerFinderListeners = new CopyOnWriteArrayList<>();
this.peerFinderListeners.add(clusterBootstrapService);
}

/**
Expand Down Expand Up @@ -1515,6 +1519,10 @@ boolean hasIdleJoinValidationService() {
return joinValidationService.isIdle();
}

public void addPeerFinderListener(PeerFinderListener peerFinderListener) {
this.peerFinderListeners.add(peerFinderListener);
}

public enum Mode {
CANDIDATE,
LEADER,
Expand Down Expand Up @@ -1570,8 +1578,7 @@ protected void onFoundPeersUpdated() {
}
}
}

clusterBootstrapService.onFoundPeersUpdated();
peerFinderListeners.forEach(PeerFinderListener::onFoundPeersUpdated);
}
}

Expand Down Expand Up @@ -1937,4 +1944,8 @@ protected void sendApplyCommit(
);
}
}

public interface PeerFinderListener {
void onFoundPeersUpdated();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,23 @@ public void testImproveConfigurationPerformsVotingConfigExclusionStateCheck() {
}
}

public void testPeerFinderListener() throws Exception {
try (Cluster cluster = new Cluster(3, true, Settings.EMPTY)) {
cluster.runRandomly();
cluster.stabilise();
ClusterNode leader = cluster.getAnyLeader();
ClusterNode nodeWithListener = cluster.getAnyNodeExcept(leader);
AtomicBoolean listenerCalled = new AtomicBoolean(false);
nodeWithListener.coordinator.addPeerFinderListener(() -> listenerCalled.set(true));
assertFalse(listenerCalled.get());
leader.disconnect();
cluster.runFor(DEFAULT_STABILISATION_TIME, "Letting disconnect take effect");
cluster.stabilise();
assertTrue(cluster.clusterNodes.contains(nodeWithListener));
assertBusy(() -> assertTrue(listenerCalled.get()));
}
}

private ClusterState buildNewClusterStateWithVotingConfigExclusion(
ClusterState currentState,
Set<CoordinationMetadata.VotingConfigExclusion> newVotingConfigExclusion
Expand Down