Search in sources :

Example 56 with IndexShard

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

the class IndexServiceTests method testAsyncTranslogTrimActuallyWorks.

public void testAsyncTranslogTrimActuallyWorks() throws Exception {
    execute("create table test(x int, data string) clustered into 1 shards with (\"translog.sync_interval\" = '100ms')");
    IndexService indexService = getIndexService("test");
    ensureGreen(indexService.index().getName());
    assertTrue(indexService.getTrimTranslogTask().mustReschedule());
    execute("insert into test (x, data) values (1, 'foo')");
    IndexShard shard = indexService.getShard(0);
    flushShard(shard, true);
    assertBusy(() -> assertThat(EngineTestCase.getTranslog(getEngine(shard)).totalOperations(), equalTo(0)));
}
Also used : IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 57 with IndexShard

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

the class IndexServiceTests method testRescheduleAsyncFsync.

public void testRescheduleAsyncFsync() throws Exception {
    execute("create table test(x int, data string) clustered into 1 shards with (\"translog.sync_interval\" = '100ms', \"translog.durability\" = 'REQUEST')");
    IndexService indexService = getIndexService("test");
    var indexName = indexService.index().getName();
    ensureGreen(indexName);
    assertNull(indexService.getFsyncTask());
    execute("alter table test set (\"translog.durability\" = 'ASYNC')");
    assertNotNull(indexService.getFsyncTask());
    assertTrue(indexService.getFsyncTask().mustReschedule());
    execute("insert into test (x, data) values (1, 'foo')");
    assertNotNull(indexService.getFsyncTask());
    final IndexShard shard = indexService.getShard(0);
    assertBusy(() -> assertFalse(shard.isSyncNeeded()));
    execute("alter table test set (\"translog.durability\" = 'REQUEST')");
    assertNull(indexService.getFsyncTask());
    execute("alter table test set (\"translog.durability\" = 'ASYNC')");
    assertNotNull(indexService.getFsyncTask());
}
Also used : IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 58 with IndexShard

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

the class IndexServiceTests method testAsyncFsyncActuallyWorks.

public void testAsyncFsyncActuallyWorks() throws Exception {
    execute("create table test(x int, data string) clustered into 1 shards with (\"translog.sync_interval\" = '100ms', " + "\"translog.durability\" = 'ASYNC')");
    IndexService indexService = getIndexService("test");
    var indexName = indexService.index().getName();
    ensureGreen(indexName);
    assertTrue(indexService.getRefreshTask().mustReschedule());
    execute("insert into test (x, data) values (1, 'foo')");
    IndexShard shard = indexService.getShard(0);
    assertBusy(() -> assertFalse(shard.isSyncNeeded()));
}
Also used : IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 59 with IndexShard

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

the class RetentionLeaseBackgroundSyncIT method testBackgroundRetentionLeaseSync.

@Test
public void testBackgroundRetentionLeaseSync() throws Exception {
    final int numberOfReplicas = 2 - scaledRandomIntBetween(0, 2);
    internalCluster().ensureAtLeastNumDataNodes(1 + numberOfReplicas);
    execute("create table doc.tbl (x int) clustered into 1 shards " + "with (" + "   \"soft_deletes.retention_lease.sync_interval\" = '1s', " + "   \"soft_deletes.enabled\" = true, " + "   number_of_replicas = ?)", new Object[] { numberOfReplicas });
    ensureGreen("tbl");
    final String primaryShardNodeId = clusterService().state().routingTable().index("tbl").shard(0).primaryShard().currentNodeId();
    final String primaryShardNodeName = clusterService().state().nodes().get(primaryShardNodeId).getName();
    final IndexShard primary = internalCluster().getInstance(IndicesService.class, primaryShardNodeName).getShardOrNull(new ShardId(resolveIndex("tbl"), 0));
    // we will add multiple retention leases and expect to see them synced to all replicas
    final int length = randomIntBetween(1, 8);
    final Map<String, RetentionLease> currentRetentionLeases = new HashMap<>(length);
    final List<String> ids = new ArrayList<>(length);
    for (int i = 0; i < length; i++) {
        final String id = randomValueOtherThanMany(currentRetentionLeases.keySet()::contains, () -> randomAlphaOfLength(8));
        ids.add(id);
        final long retainingSequenceNumber = randomLongBetween(0, Long.MAX_VALUE);
        final String source = randomAlphaOfLength(8);
        final CountDownLatch latch = new CountDownLatch(1);
        // put a new lease
        currentRetentionLeases.put(id, primary.addRetentionLease(id, retainingSequenceNumber, source, ActionListener.wrap(latch::countDown)));
        latch.await();
        // now renew all existing leases; we expect to see these synced to the replicas
        for (int j = 0; j <= i; j++) {
            currentRetentionLeases.put(ids.get(j), primary.renewRetentionLease(ids.get(j), randomLongBetween(currentRetentionLeases.get(ids.get(j)).retainingSequenceNumber(), Long.MAX_VALUE), source));
        }
        assertBusy(() -> {
            // check all retention leases have been synced to all replicas
            for (final ShardRouting replicaShard : clusterService().state().routingTable().index("tbl").shard(0).replicaShards()) {
                final String replicaShardNodeId = replicaShard.currentNodeId();
                final String replicaShardNodeName = clusterService().state().nodes().get(replicaShardNodeId).getName();
                final IndexShard replica = internalCluster().getInstance(IndicesService.class, replicaShardNodeName).getShardOrNull(new ShardId(resolveIndex("tbl"), 0));
                assertThat(replica.getRetentionLeases(), equalTo(primary.getRetentionLeases()));
            }
        });
    }
}
Also used : HashMap(java.util.HashMap) IndexShard(org.elasticsearch.index.shard.IndexShard) ArrayList(java.util.ArrayList) IndicesService(org.elasticsearch.indices.IndicesService) CountDownLatch(java.util.concurrent.CountDownLatch) ShardId(org.elasticsearch.index.shard.ShardId) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Test(org.junit.Test)

Example 60 with IndexShard

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

the class TransportUpgradeAction method shardOperation.

@Override
protected ShardUpgradeResult shardOperation(UpgradeRequest request, ShardRouting shardRouting) throws IOException {
    IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).getShard(shardRouting.shardId().id());
    org.apache.lucene.util.Version oldestLuceneSegment = indexShard.upgrade(request);
    // We are using the current version of Elasticsearch as upgrade version since we update mapping to match the current version
    return new ShardUpgradeResult(shardRouting.shardId(), indexShard.routingEntry().primary(), Version.CURRENT, oldestLuceneSegment);
}
Also used : IndexShard(org.elasticsearch.index.shard.IndexShard)

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