Search in sources :

Example 1 with BlobIndicesService

use of io.crate.blob.v2.BlobIndicesService in project crate by crate.

the class RecoveryTests method testPrimaryRelocationWhileIndexing.

@Test
public void testPrimaryRelocationWhileIndexing() throws Exception {
    final int numberOfRelocations = 1;
    final int numberOfWriters = 2;
    final String node1 = internalCluster().startNode();
    BlobAdminClient blobAdminClient = internalCluster().getInstance(BlobAdminClient.class, node1);
    logger.trace("--> creating test index ...");
    Settings indexSettings = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "false").build();
    blobAdminClient.createBlobTable("test", indexSettings).get();
    logger.trace("--> starting [node2] ...");
    final String node2 = internalCluster().startNode();
    ensureGreen();
    final AtomicLong idGenerator = new AtomicLong();
    final AtomicLong indexCounter = new AtomicLong();
    final AtomicBoolean stop = new AtomicBoolean(false);
    Thread[] writers = new Thread[numberOfWriters];
    final CountDownLatch stopLatch = new CountDownLatch(writers.length);
    logger.trace("--> starting {} blob upload threads", writers.length);
    final List<String> uploadedDigests = Collections.synchronizedList(new ArrayList<String>(writers.length));
    for (int i = 0; i < writers.length; i++) {
        final int indexerId = i;
        writers[i] = new Thread() {

            @Override
            public void run() {
                try {
                    logger.trace("**** starting blob upload thread {}", indexerId);
                    while (!stop.get()) {
                        long id = idGenerator.incrementAndGet();
                        String digest = uploadFile(internalCluster().client(node1), genFile(id));
                        uploadedDigests.add(digest);
                        indexCounter.incrementAndGet();
                    }
                    logger.trace("**** done indexing thread {}", indexerId);
                } catch (Exception e) {
                    logger.warn("**** failed indexing thread {}", e, indexerId);
                } finally {
                    stopLatch.countDown();
                }
            }
        };
        writers[i].setName("blob-uploader-thread");
        // dispatch threads from parent, ignoring possible leaking threads
        writers[i].setDaemon(true);
        writers[i].start();
    }
    logger.trace("--> waiting for 2 blobs to be uploaded ...");
    while (uploadedDigests.size() < 2) {
        Thread.sleep(10);
    }
    logger.trace("--> 2 blobs uploaded");
    // increase time between chunks in order to make sure that the upload is taking place while relocating
    timeBetweenChunks.set(10);
    logger.trace("--> starting relocations...");
    for (int i = 0; i < numberOfRelocations; i++) {
        String fromNode = (i % 2 == 0) ? node1 : node2;
        String toNode = node1.equals(fromNode) ? node2 : node1;
        logger.trace("--> START relocate the shard from {} to {}", fromNode, toNode);
        internalCluster().client(node1).admin().cluster().prepareReroute().add(new MoveAllocationCommand(BlobIndex.fullIndexName("test"), 0, fromNode, toNode)).execute().actionGet();
        ClusterHealthResponse clusterHealthResponse = internalCluster().client(node1).admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNoRelocatingShards(true).setTimeout(ACCEPTABLE_RELOCATION_TIME).execute().actionGet();
        assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
        clusterHealthResponse = internalCluster().client(node2).admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNoRelocatingShards(true).setTimeout(ACCEPTABLE_RELOCATION_TIME).execute().actionGet();
        assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
        logger.trace("--> DONE relocate the shard from {} to {}", fromNode, toNode);
    }
    logger.trace("--> done relocations");
    logger.trace("--> marking and waiting for upload threads to stop ...");
    timeBetweenChunks.set(0);
    stop.set(true);
    assertThat(stopLatch.await(60, TimeUnit.SECONDS), is(true));
    logger.trace("--> uploading threads stopped");
    logger.trace("--> expected {} got {}", indexCounter.get(), uploadedDigests.size());
    assertEquals(indexCounter.get(), uploadedDigests.size());
    BlobIndicesService blobIndicesService = internalCluster().getInstance(BlobIndicesService.class, node2);
    for (String digest : uploadedDigests) {
        BlobShard blobShard = blobIndicesService.localBlobShard(BlobIndex.fullIndexName("test"), digest);
        long length = blobShard.blobContainer().getFile(digest).length();
        assertThat(length, greaterThanOrEqualTo(1L));
    }
    for (Thread writer : writers) {
        writer.join(6000);
    }
}
Also used : BlobIndicesService(io.crate.blob.v2.BlobIndicesService) BlobAdminClient(io.crate.blob.v2.BlobAdminClient) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) BlobShard(io.crate.blob.v2.BlobShard) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 2 with BlobIndicesService

use of io.crate.blob.v2.BlobIndicesService in project crate by crate.

the class BlobIntegrationTestBase method forEachIndicesMap.

private void forEachIndicesMap(Consumer<Map<String, BlobIndex>> consumer) {
    Iterable<BlobIndicesService> blobIndicesServices = internalCluster().getInstances(BlobIndicesService.class);
    for (BlobIndicesService blobIndicesService : blobIndicesServices) {
        try {
            Map<String, BlobIndex> indices = (Map<String, BlobIndex>) indicesField.get(blobIndicesService);
            consumer.accept(indices);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : BlobIndicesService(io.crate.blob.v2.BlobIndicesService) Map(java.util.Map) BlobIndex(io.crate.blob.v2.BlobIndex)

Example 3 with BlobIndicesService

use of io.crate.blob.v2.BlobIndicesService in project crate by crate.

the class BlobIntegrationTest method getBlobShard.

@Nullable
private BlobShard getBlobShard(String digest) {
    Iterable<BlobIndicesService> services = internalCluster().getInstances(BlobIndicesService.class);
    Iterator<BlobIndicesService> it = services.iterator();
    BlobShard blobShard = null;
    while (it.hasNext()) {
        BlobIndicesService nextService = it.next();
        try {
            blobShard = nextService.localBlobShard(".blob_test", digest);
        } catch (ShardNotFoundException | IndexNotFoundException e) {
            continue;
        }
        if (blobShard != null) {
            break;
        }
    }
    return blobShard;
}
Also used : BlobIndicesService(io.crate.blob.v2.BlobIndicesService) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) BlobShard(io.crate.blob.v2.BlobShard) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Nullable(javax.annotation.Nullable)

Aggregations

BlobIndicesService (io.crate.blob.v2.BlobIndicesService)3 BlobShard (io.crate.blob.v2.BlobShard)2 BlobAdminClient (io.crate.blob.v2.BlobAdminClient)1 BlobIndex (io.crate.blob.v2.BlobIndex)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Nullable (javax.annotation.Nullable)1 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)1 MoveAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand)1 Settings (org.elasticsearch.common.settings.Settings)1 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)1 ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)1 Test (org.junit.Test)1