Search in sources :

Example 61 with ClusterSettings

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

the class AutoCreateIndexTests method testUpdate.

public void testUpdate() {
    boolean value = randomBoolean();
    Settings settings;
    if (value && randomBoolean()) {
        settings = Settings.EMPTY;
    } else {
        settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), value).build();
    }
    ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    AutoCreateIndex autoCreateIndex = new AutoCreateIndex(settings, clusterSettings, new IndexNameExpressionResolver(settings));
    assertThat(autoCreateIndex.getAutoCreate().isAutoCreateIndex(), equalTo(value));
    Settings newSettings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), !value).build();
    clusterSettings.applySettings(newSettings);
    assertThat(autoCreateIndex.getAutoCreate().isAutoCreateIndex(), equalTo(!value));
    newSettings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), "logs-*").build();
    clusterSettings.applySettings(newSettings);
    assertThat(autoCreateIndex.getAutoCreate().isAutoCreateIndex(), equalTo(true));
    assertThat(autoCreateIndex.getAutoCreate().getExpressions().size(), equalTo(1));
    assertThat(autoCreateIndex.getAutoCreate().getExpressions().get(0).v1(), equalTo("logs-*"));
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 62 with ClusterSettings

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

the class PublishClusterStateActionTests method buildPublishClusterStateAction.

private static MockPublishAction buildPublishClusterStateAction(Settings settings, MockTransportService transportService, Supplier<ClusterState> clusterStateSupplier, PublishClusterStateAction.NewPendingClusterStateListener listener) {
    DiscoverySettings discoverySettings = new DiscoverySettings(settings, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(ClusterModule.getNamedWriteables());
    return new MockPublishAction(settings, transportService, namedWriteableRegistry, clusterStateSupplier, listener, discoverySettings, CLUSTER_NAME);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) DiscoverySettings(org.elasticsearch.discovery.DiscoverySettings)

Example 63 with ClusterSettings

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

the class SameShardRoutingTests method testForceAllocatePrimaryOnSameNodeNotAllowed.

public void testForceAllocatePrimaryOnSameNodeNotAllowed() {
    SameShardAllocationDecider decider = new SameShardAllocationDecider(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
    ClusterState clusterState = ClusterStateCreationUtils.state("idx", randomIntBetween(2, 4), 1);
    Index index = clusterState.getMetaData().index("idx").getIndex();
    ShardRouting primaryShard = clusterState.routingTable().index(index).shard(0).primaryShard();
    RoutingNode routingNode = clusterState.getRoutingNodes().node(primaryShard.currentNodeId());
    RoutingAllocation routingAllocation = new RoutingAllocation(new AllocationDeciders(Settings.EMPTY, Collections.emptyList()), new RoutingNodes(clusterState, false), clusterState, ClusterInfo.EMPTY, System.nanoTime(), false);
    // can't force allocate same shard copy to the same node
    ShardRouting newPrimary = TestShardRouting.newShardRouting(primaryShard.shardId(), null, true, ShardRoutingState.UNASSIGNED);
    Decision decision = decider.canForceAllocatePrimary(newPrimary, routingNode, routingAllocation);
    assertEquals(Decision.Type.NO, decision.type());
    // can force allocate to a different node
    RoutingNode unassignedNode = null;
    for (RoutingNode node : clusterState.getRoutingNodes()) {
        if (node.isEmpty()) {
            unassignedNode = node;
            break;
        }
    }
    decision = decider.canForceAllocatePrimary(newPrimary, unassignedNode, routingAllocation);
    assertEquals(Decision.Type.YES, decision.type());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) SameShardAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) Index(org.elasticsearch.index.Index) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision)

Example 64 with ClusterSettings

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

the class MemoryCircuitBreakerTests method testThreadedUpdatesToChildBreakerWithParentLimit.

public void testThreadedUpdatesToChildBreakerWithParentLimit() throws Exception {
    final int NUM_THREADS = scaledRandomIntBetween(3, 15);
    final int BYTES_PER_THREAD = scaledRandomIntBetween(500, 4500);
    final int parentLimit = (BYTES_PER_THREAD * NUM_THREADS) - 2;
    final int childLimit = parentLimit + 10;
    final Thread[] threads = new Thread[NUM_THREADS];
    final AtomicInteger tripped = new AtomicInteger(0);
    final AtomicReference<Throwable> lastException = new AtomicReference<>(null);
    final AtomicInteger parentTripped = new AtomicInteger(0);
    final AtomicReference<ChildMemoryCircuitBreaker> breakerRef = new AtomicReference<>(null);
    final CircuitBreakerService service = new HierarchyCircuitBreakerService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)) {

        @Override
        public CircuitBreaker getBreaker(String name) {
            return breakerRef.get();
        }

        @Override
        public void checkParentLimit(String label) throws CircuitBreakingException {
            // Parent will trip right before regular breaker would trip
            if (getBreaker(CircuitBreaker.REQUEST).getUsed() > parentLimit) {
                parentTripped.incrementAndGet();
                logger.info("--> parent tripped");
                throw new CircuitBreakingException("parent tripped");
            }
        }
    };
    final BreakerSettings settings = new BreakerSettings(CircuitBreaker.REQUEST, childLimit, 1.0);
    final ChildMemoryCircuitBreaker breaker = new ChildMemoryCircuitBreaker(settings, logger, (HierarchyCircuitBreakerService) service, CircuitBreaker.REQUEST);
    breakerRef.set(breaker);
    for (int i = 0; i < NUM_THREADS; i++) {
        threads[i] = new Thread(new Runnable() {

            @Override
            public void run() {
                for (int j = 0; j < BYTES_PER_THREAD; j++) {
                    try {
                        breaker.addEstimateBytesAndMaybeBreak(1L, "test");
                    } catch (CircuitBreakingException e) {
                        tripped.incrementAndGet();
                    } catch (Exception e) {
                        lastException.set(e);
                    }
                }
            }
        });
    }
    logger.info("--> NUM_THREADS: [{}], BYTES_PER_THREAD: [{}], TOTAL_BYTES: [{}], PARENT_LIMIT: [{}], CHILD_LIMIT: [{}]", NUM_THREADS, BYTES_PER_THREAD, (BYTES_PER_THREAD * NUM_THREADS), parentLimit, childLimit);
    logger.info("--> starting threads...");
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        t.join();
    }
    logger.info("--> child breaker: used: {}, limit: {}", breaker.getUsed(), breaker.getLimit());
    logger.info("--> parent tripped: {}, total trip count: {} (expecting 1-2 for each)", parentTripped.get(), tripped.get());
    assertThat("no other exceptions were thrown", lastException.get(), equalTo(null));
    assertThat("breaker should be reset back to the parent limit after parent breaker trips", breaker.getUsed(), greaterThanOrEqualTo((long) parentLimit - NUM_THREADS));
    assertThat("parent breaker was tripped at least once", parentTripped.get(), greaterThanOrEqualTo(1));
    assertThat("total breaker was tripped at least once", tripped.get(), greaterThanOrEqualTo(1));
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) AtomicReference(java.util.concurrent.atomic.AtomicReference) BreakerSettings(org.elasticsearch.indices.breaker.BreakerSettings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService)

Example 65 with ClusterSettings

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

the class RoutingIteratorTests method testReplicaShardPreferenceIters.

public void testReplicaShardPreferenceIters() throws Exception {
    AllocationService strategy = createAllocationService(Settings.builder().put("cluster.routing.allocation.node_concurrent_recoveries", 10).build());
    OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(2).numberOfReplicas(2)).build();
    RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test")).build();
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).localNodeId("node1")).build();
    clusterState = strategy.reroute(clusterState, "reroute");
    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    // When replicas haven't initialized, it comes back with the primary first, then initializing replicas
    GroupShardsIterator shardIterators = operationRouting.searchShards(clusterState, new String[] { "test" }, null, "_replica_first");
    // two potential shards
    assertThat(shardIterators.size(), equalTo(2));
    ShardIterator iter = shardIterators.iterator().next();
    // three potential candidates for the shard
    assertThat(iter.size(), equalTo(3));
    ShardRouting routing = iter.nextOrNull();
    assertNotNull(routing);
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    // replicas haven't initialized yet, so primary is first
    assertTrue(routing.primary());
    assertTrue(routing.started());
    routing = iter.nextOrNull();
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());
    assertTrue(routing.initializing());
    routing = iter.nextOrNull();
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());
    assertTrue(routing.initializing());
    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    shardIterators = operationRouting.searchShards(clusterState, new String[] { "test" }, null, "_replica");
    // two potential shards
    assertThat(shardIterators.size(), equalTo(2));
    iter = shardIterators.iterator().next();
    // two potential replicas for the shard
    assertThat(iter.size(), equalTo(2));
    routing = iter.nextOrNull();
    assertNotNull(routing);
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());
    routing = iter.nextOrNull();
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());
    shardIterators = operationRouting.searchShards(clusterState, new String[] { "test" }, null, "_replica_first");
    // two potential shards
    assertThat(shardIterators.size(), equalTo(2));
    iter = shardIterators.iterator().next();
    // three potential candidates for the shard
    assertThat(iter.size(), equalTo(3));
    routing = iter.nextOrNull();
    assertNotNull(routing);
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());
    routing = iter.nextOrNull();
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertFalse(routing.primary());
    // finally the primary
    routing = iter.nextOrNull();
    assertThat(routing.shardId().id(), anyOf(equalTo(0), equalTo(1)));
    assertTrue(routing.primary());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) GroupShardsIterator(org.elasticsearch.cluster.routing.GroupShardsIterator) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) OperationRouting(org.elasticsearch.cluster.routing.OperationRouting) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) PlainShardIterator(org.elasticsearch.cluster.routing.PlainShardIterator) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService)

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