Search in sources :

Example 46 with ClusterSettings

use of org.elasticsearch.common.settings.ClusterSettings in project crate by crate.

the class ElasticsearchNodeCommand method createPersistedClusterStateService.

public static PersistedClusterStateService createPersistedClusterStateService(Settings settings, Path[] dataPaths) throws IOException {
    final NodeMetadata nodeMetadata = PersistedClusterStateService.nodeMetadata(dataPaths);
    if (nodeMetadata == null) {
        throw new ElasticsearchException(NO_NODE_METADATA_FOUND_MSG);
    }
    String nodeId = nodeMetadata.nodeId();
    return new PersistedClusterStateService(dataPaths, nodeId, NAMED_X_CONTENT_REGISTRY, BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L, true);
}
Also used : NodeMetadata(org.elasticsearch.env.NodeMetadata) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) ElasticsearchException(org.elasticsearch.ElasticsearchException) PersistedClusterStateService(org.elasticsearch.gateway.PersistedClusterStateService)

Example 47 with ClusterSettings

use of org.elasticsearch.common.settings.ClusterSettings in project crate by crate.

the class PersistedClusterStateServiceTests method testFailsGracefullyOnExceptionDuringFlush.

public void testFailsGracefullyOnExceptionDuringFlush() 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 IndexOutput createOutput(String name, IOContext context) throws IOException {
                        if (throwException.get()) {
                            throw new IOException("simulated");
                        }
                        return super.createOutput(name, context);
                    }
                };
            }
        };
        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(IOException.class, () -> writeState(writer, newTerm, newState, clusterState)).getMessage(), containsString("simulated"));
        }
    }
}
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) IOContext(org.apache.lucene.store.IOContext) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) Writer(org.elasticsearch.gateway.PersistedClusterStateService.Writer) IndexWriter(org.apache.lucene.index.IndexWriter)

Example 48 with ClusterSettings

use of org.elasticsearch.common.settings.ClusterSettings in project crate by crate.

the class PersistedClusterStateServiceTests method testSlowLogging.

@TestLogging(value = "org.elasticsearch.gateway:WARN")
public void testSlowLogging() throws IOException, IllegalAccessException {
    final long slowWriteLoggingThresholdMillis;
    final Settings settings;
    if (randomBoolean()) {
        slowWriteLoggingThresholdMillis = PersistedClusterStateService.SLOW_WRITE_LOGGING_THRESHOLD.get(Settings.EMPTY).millis();
        settings = Settings.EMPTY;
    } else {
        slowWriteLoggingThresholdMillis = randomLongBetween(2, 100000);
        settings = Settings.builder().put(PersistedClusterStateService.SLOW_WRITE_LOGGING_THRESHOLD.getKey(), slowWriteLoggingThresholdMillis + "ms").build();
    }
    final DiscoveryNode localNode = new DiscoveryNode("node", buildNewFakeTransportAddress(), Version.CURRENT);
    final ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId())).build();
    final long startTimeMillis = randomLongBetween(0L, Long.MAX_VALUE - slowWriteLoggingThresholdMillis * 10);
    final AtomicLong currentTime = new AtomicLong(startTimeMillis);
    final AtomicLong writeDurationMillis = new AtomicLong(slowWriteLoggingThresholdMillis);
    final ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) {
        PersistedClusterStateService persistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), usually() ? BigArrays.NON_RECYCLING_INSTANCE : new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService()), clusterSettings, () -> currentTime.getAndAdd(writeDurationMillis.get()));
        try (Writer writer = persistedClusterStateService.createWriter()) {
            assertExpectedLogs(1L, null, clusterState, writer, new MockLogAppender.SeenEventExpectation("should see warning at threshold", PersistedClusterStateService.class.getCanonicalName(), Level.WARN, "writing cluster state took [*] which is above the warn threshold of [*]; " + "wrote full state with [0] indices"));
            writeDurationMillis.set(randomLongBetween(slowWriteLoggingThresholdMillis, slowWriteLoggingThresholdMillis * 2));
            assertExpectedLogs(1L, null, clusterState, writer, new MockLogAppender.SeenEventExpectation("should see warning above threshold", PersistedClusterStateService.class.getCanonicalName(), Level.WARN, "writing cluster state took [*] which is above the warn threshold of [*]; " + "wrote full state with [0] indices"));
            writeDurationMillis.set(randomLongBetween(1, slowWriteLoggingThresholdMillis - 1));
            assertExpectedLogs(1L, null, clusterState, writer, new MockLogAppender.UnseenEventExpectation("should not see warning below threshold", PersistedClusterStateService.class.getCanonicalName(), Level.WARN, "*"));
            clusterSettings.applySettings(Settings.builder().put(PersistedClusterStateService.SLOW_WRITE_LOGGING_THRESHOLD.getKey(), writeDurationMillis.get() + "ms").build());
            assertExpectedLogs(1L, null, clusterState, writer, new MockLogAppender.SeenEventExpectation("should see warning at reduced threshold", PersistedClusterStateService.class.getCanonicalName(), Level.WARN, "writing cluster state took [*] which is above the warn threshold of [*]; " + "wrote full state with [0] indices"));
            final ClusterState newClusterState = ClusterState.builder(clusterState).metadata(Metadata.builder(clusterState.metadata()).version(clusterState.version()).put(IndexMetadata.builder("test").settings(Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1).put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0).put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), Version.CURRENT).put(IndexMetadata.SETTING_INDEX_UUID, "test-uuid")))).incrementVersion().build();
            assertExpectedLogs(1L, clusterState, newClusterState, writer, new MockLogAppender.SeenEventExpectation("should see warning at threshold", PersistedClusterStateService.class.getCanonicalName(), Level.WARN, "writing cluster state took [*] which is above the warn threshold of [*]; " + "wrote global metadata [false] and metadata for [1] indices and skipped [0] unchanged indices"));
            writeDurationMillis.set(randomLongBetween(1, writeDurationMillis.get() - 1));
            assertExpectedLogs(1L, clusterState, newClusterState, writer, new MockLogAppender.UnseenEventExpectation("should not see warning below threshold", PersistedClusterStateService.class.getCanonicalName(), Level.WARN, "*"));
            // ensure no overflow
            assertThat(currentTime.get(), lessThan(startTimeMillis + 14 * slowWriteLoggingThresholdMillis));
        }
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) MockLogAppender(org.elasticsearch.test.MockLogAppender) MockPageCacheRecycler(org.elasticsearch.common.util.MockPageCacheRecycler) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) AtomicLong(java.util.concurrent.atomic.AtomicLong) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Writer(org.elasticsearch.gateway.PersistedClusterStateService.Writer) IndexWriter(org.apache.lucene.index.IndexWriter) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging)

Example 49 with ClusterSettings

use of org.elasticsearch.common.settings.ClusterSettings in project crate by crate.

the class PeerRecoverySourceServiceTests method testDuplicateRecoveries.

@Test
public void testDuplicateRecoveries() throws IOException {
    IndexShard primary = newStartedShard(true);
    PeerRecoverySourceService peerRecoverySourceService = new PeerRecoverySourceService(mock(TransportService.class), mock(IndicesService.class), new RecoverySettings(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)));
    StartRecoveryRequest startRecoveryRequest = new StartRecoveryRequest(primary.shardId(), randomAlphaOfLength(10), getFakeDiscoNode("source"), getFakeDiscoNode("target"), Store.MetadataSnapshot.EMPTY, randomBoolean(), randomLong(), SequenceNumbers.UNASSIGNED_SEQ_NO);
    peerRecoverySourceService.start();
    RecoverySourceHandler handler = peerRecoverySourceService.ongoingRecoveries.addNewRecovery(startRecoveryRequest, primary);
    DelayRecoveryException delayRecoveryException = expectThrows(DelayRecoveryException.class, () -> peerRecoverySourceService.ongoingRecoveries.addNewRecovery(startRecoveryRequest, primary));
    assertThat(delayRecoveryException.getMessage(), containsString("recovery with same target already registered"));
    peerRecoverySourceService.ongoingRecoveries.remove(primary, handler);
    // re-adding after removing previous attempt works
    handler = peerRecoverySourceService.ongoingRecoveries.addNewRecovery(startRecoveryRequest, primary);
    peerRecoverySourceService.ongoingRecoveries.remove(primary, handler);
    closeShards(primary);
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TransportService(org.elasticsearch.transport.TransportService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) Test(org.junit.Test)

Example 50 with ClusterSettings

use of org.elasticsearch.common.settings.ClusterSettings in project crate by crate.

the class IncrementalClusterStateWriterTests method testSlowLogging.

@TestLogging(value = "org.elasticsearch.gateway:WARN")
public void testSlowLogging() throws WriteStateException, IllegalAccessException {
    final long slowWriteLoggingThresholdMillis;
    final Settings settings;
    if (randomBoolean()) {
        slowWriteLoggingThresholdMillis = PersistedClusterStateService.SLOW_WRITE_LOGGING_THRESHOLD.get(Settings.EMPTY).millis();
        settings = Settings.EMPTY;
    } else {
        slowWriteLoggingThresholdMillis = randomLongBetween(2, 100000);
        settings = Settings.builder().put(PersistedClusterStateService.SLOW_WRITE_LOGGING_THRESHOLD.getKey(), slowWriteLoggingThresholdMillis + "ms").build();
    }
    final DiscoveryNode localNode = newNode("node");
    final ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId())).build();
    final long startTimeMillis = randomLongBetween(0L, Long.MAX_VALUE - slowWriteLoggingThresholdMillis * 10);
    final AtomicLong currentTime = new AtomicLong(startTimeMillis);
    final AtomicLong writeDurationMillis = new AtomicLong(slowWriteLoggingThresholdMillis);
    final ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    final IncrementalClusterStateWriter incrementalClusterStateWriter = new IncrementalClusterStateWriter(settings, clusterSettings, mock(MetaStateService.class), new Manifest(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), Collections.emptyMap()), clusterState, () -> currentTime.getAndAdd(writeDurationMillis.get()));
    assertExpectedLogs(clusterState, incrementalClusterStateWriter, new MockLogAppender.SeenEventExpectation("should see warning at threshold", IncrementalClusterStateWriter.class.getCanonicalName(), Level.WARN, "writing cluster state took [*] which is above the warn threshold of [*]; " + "wrote metadata for [0] indices and skipped [0] unchanged indices"));
    writeDurationMillis.set(randomLongBetween(slowWriteLoggingThresholdMillis, slowWriteLoggingThresholdMillis * 2));
    assertExpectedLogs(clusterState, incrementalClusterStateWriter, new MockLogAppender.SeenEventExpectation("should see warning above threshold", IncrementalClusterStateWriter.class.getCanonicalName(), Level.WARN, "writing cluster state took [*] which is above the warn threshold of [*]; " + "wrote metadata for [0] indices and skipped [0] unchanged indices"));
    writeDurationMillis.set(randomLongBetween(1, slowWriteLoggingThresholdMillis - 1));
    assertExpectedLogs(clusterState, incrementalClusterStateWriter, new MockLogAppender.UnseenEventExpectation("should not see warning below threshold", IncrementalClusterStateWriter.class.getCanonicalName(), Level.WARN, "*"));
    clusterSettings.applySettings(Settings.builder().put(PersistedClusterStateService.SLOW_WRITE_LOGGING_THRESHOLD.getKey(), writeDurationMillis.get() + "ms").build());
    assertExpectedLogs(clusterState, incrementalClusterStateWriter, new MockLogAppender.SeenEventExpectation("should see warning at reduced threshold", IncrementalClusterStateWriter.class.getCanonicalName(), Level.WARN, "writing cluster state took [*] which is above the warn threshold of [*]; " + "wrote metadata for [0] indices and skipped [0] unchanged indices"));
    // ensure no overflow
    assertThat(currentTime.get(), lessThan(startTimeMillis + 10 * slowWriteLoggingThresholdMillis));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) AtomicLong(java.util.concurrent.atomic.AtomicLong) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) MockLogAppender(org.elasticsearch.test.MockLogAppender) Manifest(org.elasticsearch.cluster.metadata.Manifest) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging)

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