Search in sources :

Example 51 with ClusterHealthResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse 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 52 with ClusterHealthResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project crate by crate.

the class ClusterHealthIT method testHealth.

@Test
public void testHealth() {
    logger.info("--> running cluster health on an index that does not exists");
    ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth("test1").setWaitForYellowStatus().setTimeout("1s").execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(true));
    assertThat(healthResponse.getStatus(), equalTo(ClusterHealthStatus.RED));
    assertThat(healthResponse.getIndices().isEmpty(), equalTo(true));
    logger.info("--> running cluster wide health");
    healthResponse = client().admin().cluster().prepareHealth().setWaitForGreenStatus().setTimeout("10s").execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    assertThat(healthResponse.getStatus(), equalTo(ClusterHealthStatus.GREEN));
    assertThat(healthResponse.getIndices().isEmpty(), equalTo(true));
    logger.info("--> Creating index test1 with zero replicas");
    createIndex("test1");
    logger.info("--> running cluster health on an index that does exists");
    healthResponse = client().admin().cluster().prepareHealth("test1").setWaitForGreenStatus().setTimeout("10s").execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    assertThat(healthResponse.getStatus(), equalTo(ClusterHealthStatus.GREEN));
    assertThat(healthResponse.getIndices().get("test1").getStatus(), equalTo(ClusterHealthStatus.GREEN));
    logger.info("--> running cluster health on an index that does exists and an index that doesn't exists");
    healthResponse = client().admin().cluster().prepareHealth("test1", "test2").setWaitForYellowStatus().setTimeout("1s").execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(true));
    assertThat(healthResponse.getStatus(), equalTo(ClusterHealthStatus.RED));
    assertThat(healthResponse.getIndices().get("test1").getStatus(), equalTo(ClusterHealthStatus.GREEN));
    assertThat(healthResponse.getIndices().size(), equalTo(1));
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) Test(org.junit.Test)

Example 53 with ClusterHealthResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project crate by crate.

the class ClusterHealthIT method testWaitForEventsRetriesIfOtherConditionsNotMet.

@Test
public void testWaitForEventsRetriesIfOtherConditionsNotMet() throws Exception {
    final ActionFuture<ClusterHealthResponse> healthResponseFuture = client().admin().cluster().prepareHealth("index").setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute();
    final AtomicBoolean keepSubmittingTasks = new AtomicBoolean(true);
    final ClusterService clusterService = internalCluster().getInstance(ClusterService.class, internalCluster().getMasterName());
    clusterService.submitStateUpdateTask("looping task", new ClusterStateUpdateTask(Priority.LOW) {

        @Override
        public ClusterState execute(ClusterState currentState) {
            return currentState;
        }

        @Override
        public void onFailure(String source, Exception e) {
            throw new AssertionError(source, e);
        }

        @Override
        public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
            if (keepSubmittingTasks.get()) {
                clusterService.submitStateUpdateTask("looping task", this);
            }
        }
    });
    createIndex("index");
    assertFalse(client().admin().cluster().prepareHealth("index").setWaitForGreenStatus().get().isTimedOut());
    // at this point the original health response should not have returned: there was never a point where the index was green AND
    // the master had processed all pending tasks above LANGUID priority.
    assertFalse(healthResponseFuture.isDone());
    keepSubmittingTasks.set(false);
    assertFalse(healthResponseFuture.get().isTimedOut());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterService(org.elasticsearch.cluster.service.ClusterService) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) Test(org.junit.Test)

Example 54 with ClusterHealthResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project crate by crate.

the class ClusterHealthIT method testSimpleLocalHealth.

@Test
public void testSimpleLocalHealth() {
    execute("create table test (id int) with (number_of_replicas = 0)");
    // master should think it's green now.
    ensureGreen();
    for (final String node : internalCluster().getNodeNames()) {
        // a very high time out, which should never fire due to the local flag
        logger.info("--> getting cluster health on [{}]", node);
        final ClusterHealthResponse health = client(node).admin().cluster().prepareHealth().setLocal(true).setWaitForEvents(Priority.LANGUID).setTimeout("30s").execute().actionGet(REQUEST_TIMEOUT);
        logger.info("--> got cluster health on [{}]", node);
        assertFalse("timed out on " + node, health.isTimedOut());
        assertThat("health status on " + node, health.getStatus(), equalTo(ClusterHealthStatus.GREEN));
    }
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) Test(org.junit.Test)

Example 55 with ClusterHealthResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project crate by crate.

the class ClusterHealthIT method testHealthOnIndexCreation.

@Test
public void testHealthOnIndexCreation() throws Exception {
    final AtomicBoolean finished = new AtomicBoolean(false);
    Thread clusterHealthThread = new Thread() {

        @Override
        public void run() {
            while (finished.get() == false) {
                ClusterHealthResponse health = client().admin().cluster().prepareHealth().get();
                assertThat(health.getStatus(), not(equalTo(ClusterHealthStatus.RED)));
            }
        }
    };
    clusterHealthThread.start();
    for (int i = 0; i < 10; i++) {
        createIndex("test" + i);
    }
    finished.set(true);
    clusterHealthThread.join();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) Test(org.junit.Test)

Aggregations

ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)123 Settings (org.elasticsearch.common.settings.Settings)29 Client (org.elasticsearch.client.Client)24 ClusterState (org.elasticsearch.cluster.ClusterState)16 ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)15 Test (org.junit.Test)15 IOException (java.io.IOException)13 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)12 SearchResponse (org.elasticsearch.action.search.SearchResponse)11 MoveAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand)10 CloseIndexResponse (org.elasticsearch.action.admin.indices.close.CloseIndexResponse)9 OpenIndexResponse (org.elasticsearch.action.admin.indices.open.OpenIndexResponse)9 CountDownLatch (java.util.concurrent.CountDownLatch)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)7 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)7 Index (org.elasticsearch.index.Index)7 MockTransportService (org.elasticsearch.test.transport.MockTransportService)6 TransportService (org.elasticsearch.transport.TransportService)6 Path (java.nio.file.Path)5