use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion in project crate by crate.
the class AddVotingConfigExclusionsRequest method resolveVotingConfigExclusions.
Set<VotingConfigExclusion> resolveVotingConfigExclusions(ClusterState currentState) {
final DiscoveryNodes allNodes = currentState.nodes();
final Set<VotingConfigExclusion> resolvedNodes = Arrays.stream(allNodes.resolveNodes(nodeDescriptions)).map(allNodes::get).filter(DiscoveryNode::isMasterEligibleNode).map(VotingConfigExclusion::new).collect(Collectors.toSet());
if (resolvedNodes.isEmpty()) {
throw new IllegalArgumentException("add voting config exclusions request for " + Arrays.asList(nodeDescriptions) + " matched no master-eligible nodes");
}
resolvedNodes.removeIf(n -> currentState.getVotingConfigExclusions().contains(n));
return resolvedNodes;
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion in project crate by crate.
the class TransportClearVotingConfigExclusionsAction method masterOperation.
@Override
protected void masterOperation(ClearVotingConfigExclusionsRequest request, ClusterState initialState, ActionListener<ClearVotingConfigExclusionsResponse> listener) throws Exception {
final long startTimeMillis = threadPool.relativeTimeInMillis();
final Predicate<ClusterState> allExclusionsRemoved = newState -> {
for (VotingConfigExclusion tombstone : initialState.getVotingConfigExclusions()) {
// NB checking for the existence of any node with this persistent ID, because persistent IDs are how votes are counted.
if (newState.nodes().nodeExists(tombstone.getNodeId())) {
return false;
}
}
return true;
};
if (request.getWaitForRemoval() && allExclusionsRemoved.test(initialState) == false) {
final ClusterStateObserver clusterStateObserver = new ClusterStateObserver(initialState, clusterService, request.getTimeout(), logger);
clusterStateObserver.waitForNextChange(new Listener() {
@Override
public void onNewClusterState(ClusterState state) {
submitClearVotingConfigExclusionsTask(request, startTimeMillis, listener);
}
@Override
public void onClusterServiceClose() {
listener.onFailure(new ElasticsearchException("cluster service closed while waiting for removal of nodes " + initialState.getVotingConfigExclusions()));
}
@Override
public void onTimeout(TimeValue timeout) {
listener.onFailure(new ElasticsearchTimeoutException("timed out waiting for removal of nodes; if nodes should not be removed, set waitForRemoval to false. " + initialState.getVotingConfigExclusions()));
}
}, allExclusionsRemoved);
} else {
submitClearVotingConfigExclusionsTask(request, startTimeMillis, listener);
}
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion in project crate by crate.
the class CoordinationMetadataTests method testVotingTombstoneXContent.
public void testVotingTombstoneXContent() throws IOException {
VotingConfigExclusion originalTombstone = new VotingConfigExclusion(randomAlphaOfLength(10), randomAlphaOfLength(10));
final XContentBuilder builder = JsonXContent.contentBuilder();
originalTombstone.toXContent(builder, ToXContent.EMPTY_PARAMS);
try (XContentParser parser = createParser(JsonXContent.JSON_XCONTENT, BytesReference.bytes(builder))) {
final VotingConfigExclusion fromXContentTombstone = VotingConfigExclusion.fromXContent(parser);
assertThat(originalTombstone, equalTo(fromXContentTombstone));
}
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion in project crate by crate.
the class Coordinator method improveConfiguration.
// Package-private for testing
ClusterState improveConfiguration(ClusterState clusterState) {
assert Thread.holdsLock(mutex) : "Coordinator mutex not held";
// exclude any nodes whose ID is in the voting config exclusions list ...
final Stream<String> excludedNodeIds = clusterState.getVotingConfigExclusions().stream().map(VotingConfigExclusion::getNodeId);
// ... and also automatically exclude the node IDs of master-ineligible nodes that were previously master-eligible and are still in
// the voting config. We could exclude all the master-ineligible nodes here, but there could be quite a few of them and that makes
// the logging much harder to follow.
final Stream<String> masterIneligibleNodeIdsInVotingConfig = StreamSupport.stream(clusterState.nodes().spliterator(), false).filter(n -> n.isMasterEligibleNode() == false && (clusterState.getLastAcceptedConfiguration().getNodeIds().contains(n.getId()) || clusterState.getLastCommittedConfiguration().getNodeIds().contains(n.getId()))).map(DiscoveryNode::getId);
final Set<DiscoveryNode> liveNodes = StreamSupport.stream(clusterState.nodes().spliterator(), false).filter(DiscoveryNode::isMasterEligibleNode).filter(coordinationState.get()::containsJoinVoteFor).collect(Collectors.toSet());
final VotingConfiguration newConfig = reconfigurator.reconfigure(liveNodes, Stream.concat(masterIneligibleNodeIdsInVotingConfig, excludedNodeIds).collect(Collectors.toSet()), getLocalNode(), clusterState.getLastAcceptedConfiguration());
if (newConfig.equals(clusterState.getLastAcceptedConfiguration()) == false) {
assert coordinationState.get().joinVotesHaveQuorumFor(newConfig);
return ClusterState.builder(clusterState).metadata(Metadata.builder(clusterState.metadata()).coordinationMetadata(CoordinationMetadata.builder(clusterState.coordinationMetadata()).lastAcceptedConfiguration(newConfig).build())).build();
}
return clusterState;
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion in project crate by crate.
the class TransportAddVotingConfigExclusionsActionTests method createThreadPoolAndClusterService.
@BeforeClass
public static void createThreadPoolAndClusterService() {
threadPool = new TestThreadPool("test", Settings.EMPTY);
localNode = makeDiscoveryNode("local");
localNodeExclusion = new VotingConfigExclusion(localNode);
otherNode1 = makeDiscoveryNode("other1");
otherNode1Exclusion = new VotingConfigExclusion(otherNode1);
otherNode2 = makeDiscoveryNode("other2");
otherNode2Exclusion = new VotingConfigExclusion(otherNode2);
otherDataNode = new DiscoveryNode("data", "data", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
clusterService = createClusterService(threadPool, localNode);
}
Aggregations