use of org.elasticsearch.cluster.coordination.CoordinationMetadata in project crate by crate.
the class TransportAddVotingConfigExclusionsActionTests method testSucceedsEvenIfAllExclusionsAlreadyAdded.
public void testSucceedsEvenIfAllExclusionsAlreadyAdded() throws InterruptedException {
final ClusterState state = clusterService.state();
final ClusterState.Builder builder = builder(state);
builder.metadata(Metadata.builder(state.metadata()).coordinationMetadata(CoordinationMetadata.builder(state.coordinationMetadata()).addVotingConfigExclusion(otherNode1Exclusion).build()));
setState(clusterService, builder);
final CountDownLatch countDownLatch = new CountDownLatch(1);
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest(new String[] { "other1" }), expectSuccess(r -> {
assertNotNull(r);
countDownLatch.countDown();
}));
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), contains(otherNode1Exclusion));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata in project crate by crate.
the class TransportClearVotingConfigExclusionsActionTests method setupForTest.
@Before
public void setupForTest() {
final MockTransport transport = new MockTransport();
transportService = transport.createTransportService(Settings.EMPTY, threadPool, boundTransportAddress -> localNode, null);
new TransportClearVotingConfigExclusionsAction(transportService, clusterService, threadPool, // registers action
new IndexNameExpressionResolver());
transportService.start();
transportService.acceptIncomingRequests();
final ClusterState.Builder builder = builder(new ClusterName("cluster")).nodes(new Builder().add(localNode).add(otherNode1).add(otherNode2).localNodeId(localNode.getId()).masterNodeId(localNode.getId()));
builder.metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().addVotingConfigExclusion(otherNode1Exclusion).addVotingConfigExclusion(otherNode2Exclusion).build()));
setState(clusterService, builder);
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata in project crate by crate.
the class GatewayMetaStatePersistedStateTests method testSetLastAcceptedState.
public void testSetLastAcceptedState() throws IOException {
CoordinationState.PersistedState gateway = null;
try {
gateway = newGatewayPersistedState();
final long term = randomNonNegativeLong();
for (int i = 0; i < randomIntBetween(1, 5); i++) {
final long version = randomNonNegativeLong();
final String indexName = randomAlphaOfLength(10);
final IndexMetadata indexMetadata = createIndexMetadata(indexName, randomIntBetween(1, 5), randomNonNegativeLong());
final Metadata metadata = Metadata.builder().persistentSettings(Settings.builder().put(randomAlphaOfLength(10), randomAlphaOfLength(10)).build()).coordinationMetadata(createCoordinationMetadata(term)).put(indexMetadata, false).build();
ClusterState state = createClusterState(version, metadata);
gateway.setLastAcceptedState(state);
gateway = maybeNew(gateway);
ClusterState lastAcceptedState = gateway.getLastAcceptedState();
assertClusterStateEqual(state, lastAcceptedState);
}
} finally {
IOUtils.close(gateway);
}
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata in project crate by crate.
the class GatewayMetaStatePersistedStateTests method testMarkAcceptedConfigAsCommitted.
public void testMarkAcceptedConfigAsCommitted() throws IOException {
CoordinationState.PersistedState gateway = null;
try {
gateway = newGatewayPersistedState();
// generate random coordinationMetadata with different lastAcceptedConfiguration and lastCommittedConfiguration
CoordinationMetadata coordinationMetadata;
do {
coordinationMetadata = createCoordinationMetadata(randomNonNegativeLong());
} while (coordinationMetadata.getLastAcceptedConfiguration().equals(coordinationMetadata.getLastCommittedConfiguration()));
ClusterState state = createClusterState(randomNonNegativeLong(), Metadata.builder().coordinationMetadata(coordinationMetadata).clusterUUID(randomAlphaOfLength(10)).build());
gateway.setLastAcceptedState(state);
gateway = maybeNew(gateway);
assertThat(gateway.getLastAcceptedState().getLastAcceptedConfiguration(), not(equalTo(gateway.getLastAcceptedState().getLastCommittedConfiguration())));
gateway.markLastAcceptedStateAsCommitted();
CoordinationMetadata expectedCoordinationMetadata = CoordinationMetadata.builder(coordinationMetadata).lastCommittedConfiguration(coordinationMetadata.getLastAcceptedConfiguration()).build();
ClusterState expectedClusterState = ClusterState.builder(state).metadata(Metadata.builder().coordinationMetadata(expectedCoordinationMetadata).clusterUUID(state.metadata().clusterUUID()).clusterUUIDCommitted(true).build()).build();
gateway = maybeNew(gateway);
assertClusterStateEqual(expectedClusterState, gateway.getLastAcceptedState());
gateway.markLastAcceptedStateAsCommitted();
gateway = maybeNew(gateway);
assertClusterStateEqual(expectedClusterState, gateway.getLastAcceptedState());
} finally {
IOUtils.close(gateway);
}
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata in project crate by crate.
the class GatewayMetaStatePersistedStateTests method testStatePersistenceWithIOIssues.
public void testStatePersistenceWithIOIssues() throws IOException {
final AtomicReference<Double> ioExceptionRate = new AtomicReference<>(0.01d);
final List<MockDirectoryWrapper> list = new ArrayList<>();
final PersistedClusterStateService persistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L) {
@Override
Directory createDirectory(Path path) {
final MockDirectoryWrapper wrapper = newMockFSDirectory(path);
wrapper.setAllowRandomFileNotFoundException(randomBoolean());
wrapper.setRandomIOExceptionRate(ioExceptionRate.get());
wrapper.setRandomIOExceptionRateOnOpen(ioExceptionRate.get());
list.add(wrapper);
return wrapper;
}
};
ClusterState state = createClusterState(randomNonNegativeLong(), Metadata.builder().clusterUUID(randomAlphaOfLength(10)).build());
long currentTerm = 42L;
try (GatewayMetaState.LucenePersistedState persistedState = new GatewayMetaState.LucenePersistedState(persistedClusterStateService, currentTerm, state)) {
try {
if (randomBoolean()) {
final ClusterState newState = createClusterState(randomNonNegativeLong(), Metadata.builder().clusterUUID(randomAlphaOfLength(10)).build());
persistedState.setLastAcceptedState(newState);
state = newState;
} else {
final long newTerm = currentTerm + 1;
persistedState.setCurrentTerm(newTerm);
currentTerm = newTerm;
}
} catch (IOError | Exception e) {
assertNotNull(ExceptionsHelper.unwrap(e, IOException.class));
}
ioExceptionRate.set(0.0d);
for (MockDirectoryWrapper wrapper : list) {
wrapper.setRandomIOExceptionRate(ioExceptionRate.get());
wrapper.setRandomIOExceptionRateOnOpen(ioExceptionRate.get());
}
for (int i = 0; i < randomIntBetween(1, 5); i++) {
if (randomBoolean()) {
final long version = randomNonNegativeLong();
final String indexName = randomAlphaOfLength(10);
final IndexMetadata indexMetadata = createIndexMetadata(indexName, randomIntBetween(1, 5), randomNonNegativeLong());
final Metadata metadata = Metadata.builder().persistentSettings(Settings.builder().put(randomAlphaOfLength(10), randomAlphaOfLength(10)).build()).coordinationMetadata(createCoordinationMetadata(1L)).put(indexMetadata, false).build();
state = createClusterState(version, metadata);
persistedState.setLastAcceptedState(state);
} else {
currentTerm += 1;
persistedState.setCurrentTerm(currentTerm);
}
}
assertEquals(state, persistedState.getLastAcceptedState());
assertEquals(currentTerm, persistedState.getCurrentTerm());
} catch (IOError | Exception e) {
if (ioExceptionRate.get() == 0.0d) {
throw e;
}
assertNotNull(ExceptionsHelper.unwrap(e, IOException.class));
return;
}
nodeEnvironment.close();
// verify that the freshest state was rewritten to each data path
for (Path path : nodeEnvironment.nodeDataPaths()) {
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath()).put(Environment.PATH_DATA_SETTING.getKey(), path.toString()).build();
try (NodeEnvironment nodeEnvironment = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings))) {
final PersistedClusterStateService newPersistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L);
final PersistedClusterStateService.OnDiskState onDiskState = newPersistedClusterStateService.loadBestOnDiskState();
assertFalse(onDiskState.empty());
assertThat(onDiskState.currentTerm, equalTo(currentTerm));
assertClusterStateEqual(state, ClusterState.builder(ClusterName.DEFAULT).version(onDiskState.lastAcceptedVersion).metadata(onDiskState.metadata).build());
}
}
}
Aggregations