Search in sources :

Example 86 with ClusterSettings

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

the class ProjectingRowConsumerTest method prepare.

@Before
public void prepare() {
    nodeCtx = createNodeContext();
    memoryManager = new OnHeapMemoryManager(usedBytes -> {
    });
    projectorFactory = new ProjectionToProjectorVisitor(clusterService, new NodeLimits(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), new NoneCircuitBreakerService(), nodeCtx, THREAD_POOL, Settings.EMPTY, mock(TransportActionProvider.class, Answers.RETURNS_DEEP_STUBS), new InputFactory(nodeCtx), new EvaluatingNormalizer(nodeCtx, RowGranularity.SHARD, r -> Literal.ofUnchecked(r.valueType(), r.valueType().implicitCast("1")), null), t -> null, t -> null, Version.CURRENT, new ShardId("dummy", UUID.randomUUID().toString(), 0), Map.of(LocalFsFileOutputFactory.NAME, new LocalFsFileOutputFactory()));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) TransactionContext(io.crate.metadata.TransactionContext) java.util(java.util) InputColumn(io.crate.expression.symbol.InputColumn) SENTINEL(io.crate.data.SentinelRow.SENTINEL) CompletableFuture(java.util.concurrent.CompletableFuture) BatchIterator(io.crate.data.BatchIterator) SearchPath(io.crate.metadata.SearchPath) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) LocalFsFileOutputFactory(io.crate.execution.engine.export.LocalFsFileOutputFactory) NodeLimits(io.crate.execution.jobs.NodeLimits) Settings(org.elasticsearch.common.settings.Settings) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) UnhandledServerException(io.crate.exceptions.UnhandledServerException) TestingHelpers.createNodeContext(io.crate.testing.TestingHelpers.createNodeContext) Nullable(javax.annotation.Nullable) Before(org.junit.Before) NodeContext(io.crate.metadata.NodeContext) Answers(org.mockito.Answers) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) Test(org.junit.Test) EqOperator(io.crate.expression.operator.EqOperator) Function(io.crate.expression.symbol.Function) RamAccounting(io.crate.breaker.RamAccounting) TransportActionProvider(io.crate.execution.TransportActionProvider) RowConsumer(io.crate.data.RowConsumer) WriterProjection(io.crate.execution.dsl.projection.WriterProjection) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Version(org.elasticsearch.Version) RowGranularity(io.crate.metadata.RowGranularity) Row(io.crate.data.Row) Literal(io.crate.expression.symbol.Literal) Symbol(io.crate.expression.symbol.Symbol) AggregateMode(io.crate.expression.symbol.AggregateMode) DataTypes(io.crate.types.DataTypes) Matchers.is(org.hamcrest.Matchers.is) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) InputFactory(io.crate.expression.InputFactory) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Mockito.mock(org.mockito.Mockito.mock) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) ShardId(org.elasticsearch.index.shard.ShardId) InputFactory(io.crate.expression.InputFactory) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) LocalFsFileOutputFactory(io.crate.execution.engine.export.LocalFsFileOutputFactory) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) NodeLimits(io.crate.execution.jobs.NodeLimits) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 87 with ClusterSettings

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

the class SysNodeChecksTest method test_max_shard_per_node_check.

@Test
public void test_max_shard_per_node_check() {
    var nodeId = "node_1";
    var node = new DiscoveryNode(nodeId, nodeId, buildNewFakeTransportAddress(), Map.of(), Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE), Version.CURRENT);
    var discoveryNodes = DiscoveryNodes.builder().add(node).masterNodeId(nodeId).localNodeId(nodeId).build();
    var numberOfShards = 85;
    var indexRoutingTableBuilder = IndexRoutingTable.builder(new Index("test", UUID.randomUUID().toString()));
    // Create a routing table for 85 shards on the same node
    for (int i = 1; i <= numberOfShards; i++) {
        indexRoutingTableBuilder.addShard(TestShardRouting.newShardRouting("test", i, nodeId, true, ShardRoutingState.STARTED));
    }
    var routingTable = RoutingTable.builder().add(indexRoutingTableBuilder).build();
    var meta = IndexMetadata.builder("test").settings(settings(Version.CURRENT)).numberOfShards(numberOfShards).numberOfReplicas(0);
    var clusterState = ClusterState.builder(new ClusterName("crate")).version(1L).metadata(Metadata.builder().put(meta)).routingTable(routingTable).nodes(discoveryNodes).build();
    // Validate that with `cluster.max_shards_per_node = 100` and 85 shards the check passes
    var setting = Settings.builder().put(ShardLimitValidator.SETTING_CLUSTER_MAX_SHARDS_PER_NODE.getKey(), 100).build();
    var clusterSettings = new ClusterSettings(setting, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    var clusterService = mock(ClusterService.class, Answers.RETURNS_DEEP_STUBS);
    when(clusterService.state()).thenReturn(clusterState);
    when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
    var maxShardsPerNodeSysCheck = new MaxShardsPerNodeSysCheck(clusterService);
    assertThat(maxShardsPerNodeSysCheck.id(), is(8));
    assertThat(maxShardsPerNodeSysCheck.severity(), is(SysCheck.Severity.MEDIUM));
    assertThat(maxShardsPerNodeSysCheck.isValid(), is(true));
    // Validate that with `cluster.max_shards_per_node = 90` and 85 shards the check fails
    setting = Settings.builder().put(ShardLimitValidator.SETTING_CLUSTER_MAX_SHARDS_PER_NODE.getKey(), 90).build();
    clusterSettings = new ClusterSettings(setting, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    when(clusterService.state()).thenReturn(clusterState);
    when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
    maxShardsPerNodeSysCheck = new MaxShardsPerNodeSysCheck(clusterService);
    assertThat(maxShardsPerNodeSysCheck.isValid(), is(false));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) ClusterName(org.elasticsearch.cluster.ClusterName) Index(org.elasticsearch.index.Index) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 88 with ClusterSettings

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

the class NodeDisconnectJobMonitorServiceTest method testOnParticipatingNodeDisconnectedKillsJob.

@Test
public void testOnParticipatingNodeDisconnectedKillsJob() throws Exception {
    TasksService tasksService = tasksInstance();
    DiscoveryNode coordinator = newNode("coordinator");
    DiscoveryNode dataNode = newNode("dataNode");
    RootTask.Builder builder = tasksService.newBuilder(UUID.randomUUID(), "dummy-user", coordinator.getId(), Arrays.asList(coordinator.getId(), dataNode.getId()));
    builder.addTask(new DummyTask());
    tasksService.createTask(builder);
    // add a second job that is coordinated by the other node to make sure the the broadcast logic is run
    // even though there are jobs coordinated by the disconnected node
    builder = tasksService.newBuilder(UUID.randomUUID(), "dummy-user", dataNode.getId(), Collections.emptySet());
    builder.addTask(new DummyTask());
    tasksService.createTask(builder);
    AtomicInteger broadcasts = new AtomicInteger(0);
    TransportKillJobsNodeAction killAction = new TransportKillJobsNodeAction(tasksService, clusterService, mock(TransportService.class)) {

        @Override
        public void broadcast(KillJobsRequest request, ActionListener<Long> listener, Collection<String> excludedNodeIds) {
            broadcasts.incrementAndGet();
        }
    };
    NodeDisconnectJobMonitorService monitorService = new NodeDisconnectJobMonitorService(tasksService, new NodeLimits(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), mock(TransportService.class), killAction);
    monitorService.onNodeDisconnected(dataNode, mock(Transport.Connection.class));
    assertThat(broadcasts.get(), is(1));
    monitorService.close();
}
Also used : TransportKillJobsNodeAction(io.crate.execution.jobs.kill.TransportKillJobsNodeAction) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DummyTask(io.crate.execution.jobs.DummyTask) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TasksService(io.crate.execution.jobs.TasksService) RootTask(io.crate.execution.jobs.RootTask) ActionListener(org.elasticsearch.action.ActionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransportService(org.elasticsearch.transport.TransportService) KillJobsRequest(io.crate.execution.jobs.kill.KillJobsRequest) NodeLimits(io.crate.execution.jobs.NodeLimits) Collection(java.util.Collection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 89 with ClusterSettings

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

the class NodeDisconnectJobMonitorServiceTest method testOnNodeDisconnectedKillsJobOriginatingFromThatNode.

@Test
public void testOnNodeDisconnectedKillsJobOriginatingFromThatNode() throws Exception {
    TasksService tasksService = tasksInstance();
    RootTask.Builder builder = tasksService.newBuilder(UUID.randomUUID());
    builder.addTask(new DummyTask());
    RootTask context = tasksService.createTask(builder);
    NodeDisconnectJobMonitorService monitorService = new NodeDisconnectJobMonitorService(tasksService, new NodeLimits(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), mock(TransportService.class), mock(TransportKillJobsNodeAction.class));
    monitorService.onNodeDisconnected(new DiscoveryNode(NODE_ID, buildNewFakeTransportAddress(), Version.CURRENT), mock(Transport.Connection.class));
    expectedException.expect(TaskMissing.class);
    tasksService.getTask(context.jobId());
    monitorService.close();
}
Also used : TransportKillJobsNodeAction(io.crate.execution.jobs.kill.TransportKillJobsNodeAction) DummyTask(io.crate.execution.jobs.DummyTask) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TransportService(org.elasticsearch.transport.TransportService) NodeLimits(io.crate.execution.jobs.NodeLimits) TasksService(io.crate.execution.jobs.TasksService) RootTask(io.crate.execution.jobs.RootTask) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 90 with ClusterSettings

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

the class NodeJoinTests method setupRealMasterServiceAndCoordinator.

private void setupRealMasterServiceAndCoordinator(long term, ClusterState initialState) {
    MasterService masterService = new MasterService(Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "test_node").build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), threadPool);
    AtomicReference<ClusterState> clusterStateRef = new AtomicReference<>(initialState);
    masterService.setClusterStatePublisher((event, publishListener, ackListener) -> {
        clusterStateRef.set(event.state());
        publishListener.onResponse(null);
    });
    setupMasterServiceAndCoordinator(term, initialState, masterService, threadPool, new Random(Randomness.get().nextLong()));
    masterService.setClusterStateSupplier(clusterStateRef::get);
    masterService.start();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Random(java.util.Random) AtomicReference(java.util.concurrent.atomic.AtomicReference) MasterService(org.elasticsearch.cluster.service.MasterService) FakeThreadPoolMasterService(org.elasticsearch.cluster.service.FakeThreadPoolMasterService)

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