Search in sources :

Example 26 with IndicesService

use of org.elasticsearch.indices.IndicesService in project crate by crate.

the class RetentionLeaseBackgroundSyncActionTests method testRetentionLeaseBackgroundSyncActionOnReplica.

@Test
public void testRetentionLeaseBackgroundSyncActionOnReplica() throws WriteStateException {
    final IndicesService indicesService = mock(IndicesService.class);
    final Index index = new Index("index", "uuid");
    final IndexService indexService = mock(IndexService.class);
    when(indicesService.indexServiceSafe(index)).thenReturn(indexService);
    final int id = randomIntBetween(0, 4);
    final IndexShard indexShard = mock(IndexShard.class);
    when(indexService.getShard(id)).thenReturn(indexShard);
    final ShardId shardId = new ShardId(index, id);
    when(indexShard.shardId()).thenReturn(shardId);
    final RetentionLeaseBackgroundSyncAction action = new RetentionLeaseBackgroundSyncAction(transportService, clusterService, indicesService, threadPool, shardStateAction);
    final RetentionLeases retentionLeases = mock(RetentionLeases.class);
    final RetentionLeaseBackgroundSyncAction.Request request = new RetentionLeaseBackgroundSyncAction.Request(indexShard.shardId(), retentionLeases);
    final TransportReplicationAction.ReplicaResult result = action.shardOperationOnReplica(request, indexShard);
    // the retention leases on the shard should be updated
    verify(indexShard).updateRetentionLeasesOnReplica(retentionLeases);
    // the retention leases on the shard should be persisted
    verify(indexShard).persistRetentionLeases();
    // the result should indicate success
    final AtomicBoolean success = new AtomicBoolean();
    result.runPostReplicaActions(ActionListener.wrap(r -> success.set(true), e -> fail(e.toString())));
    assertTrue(success.get());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) ClusterService(org.elasticsearch.cluster.service.ClusterService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Index(org.elasticsearch.index.Index) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) WriteStateException(org.elasticsearch.gateway.WriteStateException) ThreadPool(org.elasticsearch.threadpool.ThreadPool) LatchedActionListener(org.elasticsearch.action.LatchedActionListener) IndicesService(org.elasticsearch.indices.IndicesService) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IOUtils(io.crate.common.io.IOUtils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) TransportReplicationAction(org.elasticsearch.action.support.replication.TransportReplicationAction) Mockito.verify(org.mockito.Mockito.verify) CountDownLatch(java.util.concurrent.CountDownLatch) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ActionTestUtils(org.elasticsearch.action.support.ActionTestUtils) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) ActionListener(org.elasticsearch.action.ActionListener) Mockito.mock(org.mockito.Mockito.mock) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index) TransportReplicationAction(org.elasticsearch.action.support.replication.TransportReplicationAction) ShardId(org.elasticsearch.index.shard.ShardId) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 27 with IndicesService

use of org.elasticsearch.indices.IndicesService in project crate by crate.

the class RetentionLeaseBackgroundSyncActionTests method testBlocks.

@Test
public void testBlocks() {
    final IndicesService indicesService = mock(IndicesService.class);
    final Index index = new Index("index", "uuid");
    final IndexService indexService = mock(IndexService.class);
    when(indicesService.indexServiceSafe(index)).thenReturn(indexService);
    final int id = randomIntBetween(0, 4);
    final IndexShard indexShard = mock(IndexShard.class);
    when(indexService.getShard(id)).thenReturn(indexShard);
    final ShardId shardId = new ShardId(index, id);
    when(indexShard.shardId()).thenReturn(shardId);
    final RetentionLeaseBackgroundSyncAction action = new RetentionLeaseBackgroundSyncAction(transportService, clusterService, indicesService, threadPool, shardStateAction);
    assertNull(action.indexBlockLevel());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index) Test(org.junit.Test)

Example 28 with IndicesService

use of org.elasticsearch.indices.IndicesService in project crate by crate.

the class IndexRecoveryIT method testRerouteRecovery.

@Test
public void testRerouteRecovery() throws Exception {
    logger.info("--> start node A");
    final String nodeA = internalCluster().startNode();
    logger.info("--> create index on node: {}", nodeA);
    createAndPopulateIndex(INDEX_NAME, 1, SHARD_COUNT, REPLICA_COUNT);
    execute("SELECT size FROM sys.shards WHERE table_name = '" + INDEX_NAME + "' AND primary=true");
    long shardSize = (long) response.rows()[0][0];
    logger.info("--> start node B");
    final String nodeB = internalCluster().startNode();
    ensureGreen();
    logger.info("--> slowing down recoveries");
    slowDownRecovery(shardSize);
    logger.info("--> move shard from: {} to: {}", nodeA, nodeB);
    execute("ALTER TABLE " + INDEX_NAME + " REROUTE MOVE SHARD 0 FROM '" + nodeA + "' TO '" + nodeB + "'");
    logger.info("--> waiting for recovery to start both on source and target");
    final Index index = resolveIndex(IndexParts.toIndexName(sqlExecutor.getCurrentSchema(), INDEX_NAME, null));
    assertBusy(() -> {
        IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeA);
        assertThat(indicesService.indexServiceSafe(index).getShard(0).recoveryStats().currentAsSource(), equalTo(1));
        indicesService = internalCluster().getInstance(IndicesService.class, nodeB);
        assertThat(indicesService.indexServiceSafe(index).getShard(0).recoveryStats().currentAsTarget(), equalTo(1));
    });
    logger.info("--> request recoveries");
    RecoveryResponse response = client().execute(RecoveryAction.INSTANCE, new RecoveryRequest(index.getName())).actionGet();
    List<RecoveryState> recoveryStates = response.shardRecoveryStates().get(index.getName());
    List<RecoveryState> nodeARecoveryStates = findRecoveriesForTargetNode(nodeA, recoveryStates);
    assertThat(nodeARecoveryStates.size(), equalTo(1));
    List<RecoveryState> nodeBRecoveryStates = findRecoveriesForTargetNode(nodeB, recoveryStates);
    assertThat(nodeBRecoveryStates.size(), equalTo(1));
    assertRecoveryState(nodeARecoveryStates.get(0), 0, RecoverySource.EmptyStoreRecoverySource.INSTANCE, true, RecoveryState.Stage.DONE, null, nodeA);
    validateIndexRecoveryState(nodeARecoveryStates.get(0).getIndex());
    assertOnGoingRecoveryState(nodeBRecoveryStates.get(0), 0, RecoverySource.PeerRecoverySource.INSTANCE, true, nodeA, nodeB);
    validateIndexRecoveryState(nodeBRecoveryStates.get(0).getIndex());
    logger.info("--> request node recovery stats");
    IndicesService indicesServiceNodeA = internalCluster().getInstance(IndicesService.class, nodeA);
    var recoveryStatsNodeA = indicesServiceNodeA.indexServiceSafe(index).getShard(0).recoveryStats();
    assertThat("node A should have ongoing recovery as source", recoveryStatsNodeA.currentAsSource(), equalTo(1));
    assertThat("node A should not have ongoing recovery as target", recoveryStatsNodeA.currentAsTarget(), equalTo(0));
    long nodeAThrottling = recoveryStatsNodeA.throttleTime().millis();
    IndicesService indicesServiceNodeB = internalCluster().getInstance(IndicesService.class, nodeB);
    var recoveryStatsNodeB = indicesServiceNodeB.indexServiceSafe(index).getShard(0).recoveryStats();
    assertThat("node B should not have ongoing recovery as source", recoveryStatsNodeB.currentAsSource(), equalTo(0));
    assertThat("node B should have ongoing recovery as target", recoveryStatsNodeB.currentAsTarget(), equalTo(1));
    long nodeBThrottling = recoveryStatsNodeB.throttleTime().millis();
    logger.info("--> checking throttling increases");
    final long finalNodeAThrottling = nodeAThrottling;
    final long finalNodeBThrottling = nodeBThrottling;
    assertBusy(() -> {
        var recoveryStats = indicesServiceNodeA.indexServiceSafe(index).getShard(0).recoveryStats();
        assertThat("node A throttling should increase", recoveryStats.throttleTime().millis(), greaterThan(finalNodeAThrottling));
        recoveryStats = indicesServiceNodeB.indexServiceSafe(index).getShard(0).recoveryStats();
        assertThat("node B throttling should increase", recoveryStats.throttleTime().millis(), greaterThan(finalNodeBThrottling));
    });
    logger.info("--> speeding up recoveries");
    restoreRecoverySpeed();
    // wait for it to be finished
    ensureGreen(index.getName());
    response = client().execute(RecoveryAction.INSTANCE, new RecoveryRequest(index.getName())).actionGet();
    recoveryStates = response.shardRecoveryStates().get(index.getName());
    assertThat(recoveryStates.size(), equalTo(1));
    assertRecoveryState(recoveryStates.get(0), 0, RecoverySource.PeerRecoverySource.INSTANCE, true, RecoveryState.Stage.DONE, nodeA, nodeB);
    validateIndexRecoveryState(recoveryStates.get(0).getIndex());
    Consumer<String> assertNodeHasThrottleTimeAndNoRecoveries = nodeName -> {
        IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeName);
        var recoveryStats = indicesService.indexServiceSafe(index).getShard(0).recoveryStats();
        assertThat(recoveryStats.currentAsSource(), equalTo(0));
        assertThat(recoveryStats.currentAsTarget(), equalTo(0));
        assertThat(nodeName + " throttling should be >0", recoveryStats.throttleTime().millis(), greaterThan(0L));
    };
    // we have to use assertBusy as recovery counters are decremented only when the last reference to the RecoveryTarget
    // is decremented, which may happen after the recovery was done.
    // CrateDB does not expose the RecoveryStats via an API, it can only be retrieved by by the IndicesService.
    // NodeA does not hold the index anymore, such resolving RecoveryStats via NodeA is not possible.
    // assertBusy(() -> assertNodeHasThrottleTimeAndNoRecoveries.accept(nodeA));
    assertBusy(() -> assertNodeHasThrottleTimeAndNoRecoveries.accept(nodeB));
    logger.info("--> bump replica count");
    execute("ALTER TABLE " + INDEX_NAME + " SET (number_of_replicas=1)");
    ensureGreen();
    // TODO: NodeA should now contain the replica shards, thus resolving RecoveryStats via the IndicesService
    // is possible again. BUT checked throttle time never increased on target NodeA, too fast?
    // assertBusy(() -> assertNodeHasThrottleTimeAndNoRecoveries.accept(nodeA));
    assertBusy(() -> assertNodeHasThrottleTimeAndNoRecoveries.accept(nodeB));
    logger.info("--> start node C");
    String nodeC = internalCluster().startNode();
    assertFalse(client().admin().cluster().prepareHealth().setWaitForNodes("3").get().isTimedOut());
    logger.info("--> slowing down recoveries");
    slowDownRecovery(shardSize);
    logger.info("--> move replica shard from: {} to: {}", nodeA, nodeC);
    execute("ALTER TABLE " + INDEX_NAME + " REROUTE MOVE SHARD 0 FROM '" + nodeA + "' TO '" + nodeC + "'");
    response = client().execute(RecoveryAction.INSTANCE, new RecoveryRequest(index.getName())).actionGet();
    recoveryStates = response.shardRecoveryStates().get(index.getName());
    nodeARecoveryStates = findRecoveriesForTargetNode(nodeA, recoveryStates);
    assertThat(nodeARecoveryStates.size(), equalTo(1));
    nodeBRecoveryStates = findRecoveriesForTargetNode(nodeB, recoveryStates);
    assertThat(nodeBRecoveryStates.size(), equalTo(1));
    List<RecoveryState> nodeCRecoveryStates = findRecoveriesForTargetNode(nodeC, recoveryStates);
    assertThat(nodeCRecoveryStates.size(), equalTo(1));
    assertRecoveryState(nodeARecoveryStates.get(0), 0, RecoverySource.PeerRecoverySource.INSTANCE, false, RecoveryState.Stage.DONE, nodeB, nodeA);
    validateIndexRecoveryState(nodeARecoveryStates.get(0).getIndex());
    assertRecoveryState(nodeBRecoveryStates.get(0), 0, RecoverySource.PeerRecoverySource.INSTANCE, true, RecoveryState.Stage.DONE, nodeA, nodeB);
    validateIndexRecoveryState(nodeBRecoveryStates.get(0).getIndex());
    // relocations of replicas are marked as REPLICA and the source node is the node holding the primary (B)
    assertOnGoingRecoveryState(nodeCRecoveryStates.get(0), 0, RecoverySource.PeerRecoverySource.INSTANCE, false, nodeB, nodeC);
    validateIndexRecoveryState(nodeCRecoveryStates.get(0).getIndex());
    if (randomBoolean()) {
        // shutdown node with relocation source of replica shard and check if recovery continues
        internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeA));
        ensureStableCluster(2);
        response = client().execute(RecoveryAction.INSTANCE, new RecoveryRequest(index.getName())).actionGet();
        recoveryStates = response.shardRecoveryStates().get(index.getName());
        nodeARecoveryStates = findRecoveriesForTargetNode(nodeA, recoveryStates);
        assertThat(nodeARecoveryStates.size(), equalTo(0));
        nodeBRecoveryStates = findRecoveriesForTargetNode(nodeB, recoveryStates);
        assertThat(nodeBRecoveryStates.size(), equalTo(1));
        nodeCRecoveryStates = findRecoveriesForTargetNode(nodeC, recoveryStates);
        assertThat(nodeCRecoveryStates.size(), equalTo(1));
        assertRecoveryState(nodeBRecoveryStates.get(0), 0, RecoverySource.PeerRecoverySource.INSTANCE, true, RecoveryState.Stage.DONE, nodeA, nodeB);
        validateIndexRecoveryState(nodeBRecoveryStates.get(0).getIndex());
        assertOnGoingRecoveryState(nodeCRecoveryStates.get(0), 0, RecoverySource.PeerRecoverySource.INSTANCE, false, nodeB, nodeC);
        validateIndexRecoveryState(nodeCRecoveryStates.get(0).getIndex());
    }
    logger.info("--> speeding up recoveries");
    restoreRecoverySpeed();
    ensureGreen();
    response = client().execute(RecoveryAction.INSTANCE, new RecoveryRequest(index.getName())).actionGet();
    recoveryStates = response.shardRecoveryStates().get(index.getName());
    nodeARecoveryStates = findRecoveriesForTargetNode(nodeA, recoveryStates);
    assertThat(nodeARecoveryStates.size(), equalTo(0));
    nodeBRecoveryStates = findRecoveriesForTargetNode(nodeB, recoveryStates);
    assertThat(nodeBRecoveryStates.size(), equalTo(1));
    nodeCRecoveryStates = findRecoveriesForTargetNode(nodeC, recoveryStates);
    assertThat(nodeCRecoveryStates.size(), equalTo(1));
    assertRecoveryState(nodeBRecoveryStates.get(0), 0, RecoverySource.PeerRecoverySource.INSTANCE, true, RecoveryState.Stage.DONE, nodeA, nodeB);
    validateIndexRecoveryState(nodeBRecoveryStates.get(0).getIndex());
    // relocations of replicas are marked as REPLICA and the source node is the node holding the primary (B)
    assertRecoveryState(nodeCRecoveryStates.get(0), 0, RecoverySource.PeerRecoverySource.INSTANCE, false, RecoveryState.Stage.DONE, nodeB, nodeC);
    validateIndexRecoveryState(nodeCRecoveryStates.get(0).getIndex());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Arrays(java.util.Arrays) ByteSizeUnit(org.elasticsearch.common.unit.ByteSizeUnit) SyncedFlushUtil(org.elasticsearch.indices.flush.SyncedFlushUtil) Matchers.not(org.hamcrest.Matchers.not) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) RecoverySettingsChunkSizePlugin(org.elasticsearch.node.RecoverySettingsChunkSizePlugin) ClusterState(org.elasticsearch.cluster.ClusterState) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Scope(org.elasticsearch.test.ESIntegTestCase.Scope) Map(java.util.Map) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule) Priority(org.elasticsearch.common.Priority) Transport(org.elasticsearch.transport.Transport) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) Set(java.util.Set) TransportRequestHandler(org.elasticsearch.transport.TransportRequestHandler) CountDownLatch(java.util.concurrent.CountDownLatch) RecoverySource(org.elasticsearch.cluster.routing.RecoverySource) Stream(java.util.stream.Stream) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) ReplicationTracker(org.elasticsearch.index.seqno.ReplicationTracker) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) TransportChannel(org.elasticsearch.transport.TransportChannel) ClusterService(org.elasticsearch.cluster.service.ClusterService) SQLIntegrationTestCase(io.crate.integrationtests.SQLIntegrationTestCase) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) RandomizedTest.biasedDoubleBetween(com.carrotsearch.randomizedtesting.RandomizedTest.biasedDoubleBetween) ArrayList(java.util.ArrayList) RetentionLeases(org.elasticsearch.index.seqno.RetentionLeases) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) BiConsumer(java.util.function.BiConsumer) Matchers.hasSize(org.hamcrest.Matchers.hasSize) StreamSupport(java.util.stream.StreamSupport) IndicesService(org.elasticsearch.indices.IndicesService) TransportService(org.elasticsearch.transport.TransportService) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) ClusterScope(org.elasticsearch.test.ESIntegTestCase.ClusterScope) SequenceNumbers(org.elasticsearch.index.seqno.SequenceNumbers) MockFSIndexStore(org.elasticsearch.test.store.MockFSIndexStore) TokenStream(org.apache.lucene.analysis.TokenStream) SetOnce(org.apache.lucene.util.SetOnce) IndexShard(org.elasticsearch.index.shard.IndexShard) BackgroundIndexer(org.elasticsearch.test.BackgroundIndexer) IOException(java.io.IOException) Test(org.junit.Test) ReplicationResponse(org.elasticsearch.action.support.replication.ReplicationResponse) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) AnalysisPlugin(org.elasticsearch.plugins.AnalysisPlugin) IndexParts(io.crate.metadata.IndexParts) TransportRequest(org.elasticsearch.transport.TransportRequest) CHUNK_SIZE_SETTING(org.elasticsearch.node.RecoverySettingsChunkSizePlugin.CHUNK_SIZE_SETTING) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) Settings(org.elasticsearch.common.settings.Settings) SyncedFlushAction(org.elasticsearch.action.admin.indices.flush.SyncedFlushAction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GetSnapshotsAction(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsAction) RecoveryAction(org.elasticsearch.action.admin.indices.recovery.RecoveryAction) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) RecoveryResponse(org.elasticsearch.action.admin.indices.recovery.RecoveryResponse) PluginsService(org.elasticsearch.plugins.PluginsService) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Collection(java.util.Collection) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) Collectors(java.util.stream.Collectors) Engine(org.elasticsearch.index.engine.Engine) InternalSettingsPlugin(org.elasticsearch.test.InternalSettingsPlugin) List(java.util.List) Version(org.elasticsearch.Version) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TimeValue(io.crate.common.unit.TimeValue) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Index(org.elasticsearch.index.Index) Strings(org.elasticsearch.common.Strings) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) IndexSettings(org.elasticsearch.index.IndexSettings) Collections.singletonMap(java.util.Collections.singletonMap) MockTransportService(org.elasticsearch.test.transport.MockTransportService) SyncedFlushRequest(org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest) MockEngineFactoryPlugin(org.elasticsearch.index.MockEngineFactoryPlugin) MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) Matchers.empty(org.hamcrest.Matchers.empty) Semaphore(java.util.concurrent.Semaphore) StubbableTransport(org.elasticsearch.test.transport.StubbableTransport) RecoveryRequest(org.elasticsearch.action.admin.indices.recovery.RecoveryRequest) Plugin(org.elasticsearch.plugins.Plugin) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) Consumer(java.util.function.Consumer) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) NodeConnectionsService(org.elasticsearch.cluster.NodeConnectionsService) AbstractTokenFilterFactory(org.elasticsearch.index.analysis.AbstractTokenFilterFactory) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) Ignore(org.junit.Ignore) TokenFilterFactory(org.elasticsearch.index.analysis.TokenFilterFactory) Snapshot(org.elasticsearch.snapshots.Snapshot) RecoveryRequest(org.elasticsearch.action.admin.indices.recovery.RecoveryRequest) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index) RecoveryResponse(org.elasticsearch.action.admin.indices.recovery.RecoveryResponse) Test(org.junit.Test)

Example 29 with IndicesService

use of org.elasticsearch.indices.IndicesService in project crate by crate.

the class RetentionLeaseSyncActionTests method testBlocks.

@Test
public void testBlocks() {
    final IndicesService indicesService = mock(IndicesService.class);
    final Index index = new Index("index", "uuid");
    final IndexService indexService = mock(IndexService.class);
    when(indicesService.indexServiceSafe(index)).thenReturn(indexService);
    final int id = randomIntBetween(0, 4);
    final IndexShard indexShard = mock(IndexShard.class);
    when(indexService.getShard(id)).thenReturn(indexShard);
    final ShardId shardId = new ShardId(index, id);
    when(indexShard.shardId()).thenReturn(shardId);
    final RetentionLeaseSyncAction action = new RetentionLeaseSyncAction(Settings.EMPTY, transportService, clusterService, indicesService, threadPool, shardStateAction);
    assertNull(action.indexBlockLevel());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index) Test(org.junit.Test)

Example 30 with IndicesService

use of org.elasticsearch.indices.IndicesService in project crate by crate.

the class RetentionLeaseSyncActionTests method testRetentionLeaseSyncActionOnPrimary.

@Test
public void testRetentionLeaseSyncActionOnPrimary() throws WriteStateException {
    final IndicesService indicesService = mock(IndicesService.class);
    final Index index = new Index("index", "uuid");
    final IndexService indexService = mock(IndexService.class);
    when(indicesService.indexServiceSafe(index)).thenReturn(indexService);
    final int id = randomIntBetween(0, 4);
    final IndexShard indexShard = mock(IndexShard.class);
    when(indexService.getShard(id)).thenReturn(indexShard);
    final ShardId shardId = new ShardId(index, id);
    when(indexShard.shardId()).thenReturn(shardId);
    final RetentionLeaseSyncAction action = new RetentionLeaseSyncAction(Settings.EMPTY, transportService, clusterService, indicesService, threadPool, shardStateAction);
    final RetentionLeases retentionLeases = mock(RetentionLeases.class);
    final RetentionLeaseSyncAction.Request request = new RetentionLeaseSyncAction.Request(indexShard.shardId(), retentionLeases);
    action.shardOperationOnPrimary(request, indexShard, ActionTestUtils.assertNoFailureListener(result -> {
        // the retention leases on the shard should be persisted
        verify(indexShard).persistRetentionLeases();
        // we should forward the request containing the current retention leases to the replica
        assertThat(result.replicaRequest(), sameInstance(request));
        // we should start with an empty replication response
        assertNull(result.finalResponseIfSuccessful.getShardInfo());
    }));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ShardId(org.elasticsearch.index.shard.ShardId) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) ClusterService(org.elasticsearch.cluster.service.ClusterService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Index(org.elasticsearch.index.Index) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) Settings(org.elasticsearch.common.settings.Settings) WriteStateException(org.elasticsearch.gateway.WriteStateException) ThreadPool(org.elasticsearch.threadpool.ThreadPool) IndicesService(org.elasticsearch.indices.IndicesService) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IOUtils(io.crate.common.io.IOUtils) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ActionTestUtils(org.elasticsearch.action.support.ActionTestUtils) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) ActionListener(org.elasticsearch.action.ActionListener) TransportWriteAction(org.elasticsearch.action.support.replication.TransportWriteAction) Mockito.mock(org.mockito.Mockito.mock) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index) Test(org.junit.Test)

Aggregations

IndicesService (org.elasticsearch.indices.IndicesService)57 IndexService (org.elasticsearch.index.IndexService)41 IndexShard (org.elasticsearch.index.shard.IndexShard)29 Index (org.elasticsearch.index.Index)21 ClusterState (org.elasticsearch.cluster.ClusterState)12 Settings (org.elasticsearch.common.settings.Settings)12 ClusterService (org.elasticsearch.cluster.service.ClusterService)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)9 ShardId (org.elasticsearch.index.shard.ShardId)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)7 Test (org.junit.Test)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 ActionListener (org.elasticsearch.action.ActionListener)5