Search in sources :

Example 51 with ClusterSettings

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));
}
Also used : ClusterService(org.elasticsearch.cluster.service.ClusterService) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TransportService(org.elasticsearch.transport.TransportService) ThreadPool(org.elasticsearch.threadpool.ThreadPool) IOException(java.io.IOException)

Example 52 with ClusterSettings

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());
        }
    }
}
Also used : MockDirectoryWrapper(org.apache.lucene.store.MockDirectoryWrapper) Path(java.nio.file.Path) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) ArrayList(java.util.ArrayList) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) IOError(java.io.IOError) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Example 53 with ClusterSettings

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());
        }
    }
}
Also used : Path(java.nio.file.Path) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Example 54 with ClusterSettings

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()) {
        }
    }
}
Also used : Path(java.nio.file.Path) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) FilterDirectory(org.apache.lucene.store.FilterDirectory) Collection(java.util.Collection) Writer(org.elasticsearch.gateway.PersistedClusterStateService.Writer) IndexWriter(org.apache.lucene.index.IndexWriter)

Example 55 with ClusterSettings

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());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) AtomicReference(java.util.concurrent.atomic.AtomicReference) MetaData(org.elasticsearch.cluster.metadata.MetaData) ClusterName(org.elasticsearch.cluster.ClusterName)

Aggregations

ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)109 Settings (org.elasticsearch.common.settings.Settings)58 ClusterState (org.elasticsearch.cluster.ClusterState)50 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)30 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)25 Matchers.containsString (org.hamcrest.Matchers.containsString)25 Test (org.junit.Test)25 MetaData (org.elasticsearch.cluster.metadata.MetaData)21 BalancedShardsAllocator (org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)21 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)20 ClusterInfo (org.elasticsearch.cluster.ClusterInfo)18 DiskUsage (org.elasticsearch.cluster.DiskUsage)18 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)18 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)18 TestGatewayAllocator (org.elasticsearch.test.gateway.TestGatewayAllocator)18 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)17 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)15 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)14 HashSet (java.util.HashSet)13 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)13