Search in sources :

Example 86 with IndexShard

use of org.elasticsearch.index.shard.IndexShard in project crate by crate.

the class IndexingMemoryControllerTests method testThrottling.

public void testThrottling() throws Exception {
    MockController controller = new MockController(Settings.builder().put("indices.memory.index_buffer_size", "4mb").build());
    IndexShard shard0 = newStartedShard();
    IndexShard shard1 = newStartedShard();
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard0);
    controller.assertBuffer(shard0, 3);
    controller.simulateIndexing(shard1);
    controller.simulateIndexing(shard1);
    // We are now using 5 MB, so we should be writing shard0 since it's using the most heap:
    controller.assertWriting(shard0, 3);
    controller.assertWriting(shard1, 0);
    controller.assertBuffer(shard0, 0);
    controller.assertBuffer(shard1, 2);
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard1);
    controller.simulateIndexing(shard1);
    // Now we are still writing 3 MB (shard0), and using 5 MB index buffers, so we should now 1) be writing shard1,
    // and 2) be throttling shard1:
    controller.assertWriting(shard0, 3);
    controller.assertWriting(shard1, 4);
    controller.assertBuffer(shard0, 1);
    controller.assertBuffer(shard1, 0);
    controller.assertNotThrottled(shard0);
    controller.assertThrottled(shard1);
    logger.info("--> Indexing more data");
    // More indexing to shard0
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard0);
    // Now we are using 5 MB again, so shard0 should also be writing and now also be throttled:
    controller.assertWriting(shard0, 8);
    controller.assertWriting(shard1, 4);
    controller.assertBuffer(shard0, 0);
    controller.assertBuffer(shard1, 0);
    controller.assertThrottled(shard0);
    controller.assertThrottled(shard1);
    // Both shards finally finish writing, and throttling should stop:
    controller.doneWriting(shard0);
    controller.doneWriting(shard1);
    controller.forceCheck();
    controller.assertNotThrottled(shard0);
    controller.assertNotThrottled(shard1);
    closeShards(shard0, shard1);
}
Also used : IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 87 with IndexShard

use of org.elasticsearch.index.shard.IndexShard in project crate by crate.

the class IndexingMemoryControllerTests method testActiveInactive.

public void testActiveInactive() throws IOException {
    MockController controller = new MockController(Settings.builder().put("indices.memory.index_buffer_size", "5mb").build());
    IndexShard shard0 = newStartedShard();
    controller.simulateIndexing(shard0);
    IndexShard shard1 = newStartedShard();
    controller.simulateIndexing(shard1);
    controller.assertBuffer(shard0, 1);
    controller.assertBuffer(shard1, 1);
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard1);
    controller.assertBuffer(shard0, 2);
    controller.assertBuffer(shard1, 2);
    // index into one shard only, crosses the 5mb limit, so shard1 is refreshed
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard0);
    controller.assertBuffer(shard0, 0);
    controller.assertBuffer(shard1, 2);
    controller.simulateIndexing(shard1);
    controller.simulateIndexing(shard1);
    controller.assertBuffer(shard1, 4);
    controller.simulateIndexing(shard1);
    controller.simulateIndexing(shard1);
    // shard1 crossed 5 mb and is now cleared:
    controller.assertBuffer(shard1, 0);
    closeShards(shard0, shard1);
}
Also used : IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 88 with IndexShard

use of org.elasticsearch.index.shard.IndexShard 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 89 with IndexShard

use of org.elasticsearch.index.shard.IndexShard 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)

Example 90 with IndexShard

use of org.elasticsearch.index.shard.IndexShard in project crate by crate.

the class RetentionLeaseSyncActionTests method testRetentionLeaseSyncActionOnReplica.

@Test
public void testRetentionLeaseSyncActionOnReplica() 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);
    final TransportWriteAction.WriteReplicaResult<RetentionLeaseSyncAction.Request> 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) 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) ShardId(org.elasticsearch.index.shard.ShardId) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransportWriteAction(org.elasticsearch.action.support.replication.TransportWriteAction) Test(org.junit.Test)

Aggregations

IndexShard (org.elasticsearch.index.shard.IndexShard)173 IndexService (org.elasticsearch.index.IndexService)74 ShardId (org.elasticsearch.index.shard.ShardId)49 IndicesService (org.elasticsearch.indices.IndicesService)47 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)36 Test (org.junit.Test)35 IOException (java.io.IOException)29 Engine (org.elasticsearch.index.engine.Engine)26 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)21 ElasticsearchException (org.elasticsearch.ElasticsearchException)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)18 Settings (org.elasticsearch.common.settings.Settings)18 ArrayList (java.util.ArrayList)16 Translog (org.elasticsearch.index.translog.Translog)16 HashMap (java.util.HashMap)15 Index (org.elasticsearch.index.Index)15 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)13 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)12 List (java.util.List)11