use of org.elasticsearch.common.settings.ClusterSettings in project crate by crate.
the class MockGatewayMetaState method start.
public void start(Settings settings, NodeEnvironment nodeEnvironment, NamedXContentRegistry xContentRegistry) {
final TransportService transportService = mock(TransportService.class);
when(transportService.getThreadPool()).thenReturn(mock(ThreadPool.class));
final ClusterService clusterService = mock(ClusterService.class);
when(clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
final MetaStateService metaStateService = mock(MetaStateService.class);
try {
when(metaStateService.loadFullState()).thenReturn(new Tuple<>(Manifest.empty(), Metadata.builder().build()));
} catch (IOException e) {
throw new AssertionError(e);
}
start(settings, transportService, clusterService, metaStateService, null, null, new PersistedClusterStateService(nodeEnvironment, xContentRegistry, BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L));
}
use of org.elasticsearch.common.settings.ClusterSettings 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());
}
}
}
use of org.elasticsearch.common.settings.ClusterSettings in project crate by crate.
the class GatewayMetaStatePersistedStateTests method testStatePersistedOnLoad.
public void testStatePersistedOnLoad() throws IOException {
// open LucenePersistedState to make sure that cluster state is written out to each data path
final PersistedClusterStateService persistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L);
final ClusterState state = createClusterState(randomNonNegativeLong(), Metadata.builder().clusterUUID(randomAlphaOfLength(10)).build());
try (GatewayMetaState.LucenePersistedState ignored = new GatewayMetaState.LucenePersistedState(persistedClusterStateService, 42L, state)) {
}
nodeEnvironment.close();
// verify that the freshest state was rewritten to each data path
Path[] paths = nodeEnvironment.nodeDataPaths();
for (Path path : paths) {
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("Path should not be empty: " + path.toAbsolutePath(), onDiskState.empty());
assertThat(onDiskState.currentTerm, equalTo(42L));
assertClusterStateEqual(state, ClusterState.builder(ClusterName.DEFAULT).version(onDiskState.lastAcceptedVersion).metadata(onDiskState.metadata).build());
}
}
}
use of org.elasticsearch.common.settings.ClusterSettings in project crate by crate.
the class PersistedClusterStateServiceTests method testClosesWriterOnFatalError.
public void testClosesWriterOnFatalError() throws IOException {
final AtomicBoolean throwException = new AtomicBoolean();
try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) {
final PersistedClusterStateService persistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L) {
@Override
Directory createDirectory(Path path) throws IOException {
return new FilterDirectory(super.createDirectory(path)) {
@Override
public void sync(Collection<String> names) {
throw new OutOfMemoryError("simulated");
}
};
}
};
try (Writer writer = persistedClusterStateService.createWriter()) {
final ClusterState clusterState = loadPersistedClusterState(persistedClusterStateService);
final long newTerm = randomNonNegativeLong();
final ClusterState newState = ClusterState.builder(clusterState).metadata(Metadata.builder(clusterState.metadata()).clusterUUID(UUIDs.randomBase64UUID(random())).clusterUUIDCommitted(true).version(randomLongBetween(1L, Long.MAX_VALUE))).incrementVersion().build();
throwException.set(true);
assertThat(expectThrows(OutOfMemoryError.class, () -> {
if (randomBoolean()) {
writeState(writer, newTerm, newState, clusterState);
} else {
writer.commit(newTerm, newState.version());
}
}).getMessage(), containsString("simulated"));
assertFalse(writer.isOpen());
}
// check if we can open writer again
try (Writer ignored = persistedClusterStateService.createWriter()) {
}
}
}
use of org.elasticsearch.common.settings.ClusterSettings in project elasticsearch by elastic.
the class SettingsUpdaterTests method testAllOrNothing.
public void testAllOrNothing() {
ClusterState.Builder builder = ClusterState.builder(new ClusterName("foo"));
ClusterSettings settingsService = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
AtomicReference<Float> index = new AtomicReference<>();
AtomicReference<Float> shard = new AtomicReference<>();
settingsService.addSettingsUpdateConsumer(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING, index::set);
settingsService.addSettingsUpdateConsumer(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING, shard::set);
SettingsUpdater updater = new SettingsUpdater(settingsService);
MetaData.Builder metaData = MetaData.builder().persistentSettings(Settings.builder().put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 1.5).put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 2.5).build()).transientSettings(Settings.builder().put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 3.5).put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 4.5).build());
ClusterState build = builder.metaData(metaData).build();
try {
updater.updateSettings(build, Settings.builder().put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), "not a float").build(), Settings.builder().put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), "not a float").put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 1.0f).build());
fail("all or nothing");
} catch (IllegalArgumentException ex) {
logger.info("", ex);
assertEquals("Failed to parse value [not a float] for setting [cluster.routing.allocation.balance.index]", ex.getMessage());
}
assertNull("updater only does a dryRun", index.get());
assertNull("updater only does a dryRun", shard.get());
}
Aggregations