Search in sources :

Example 56 with ClusterHealthResponse

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

the class ESIntegTestCase method waitNoPendingTasksOnAll.

/**
 * Waits until all nodes have no pending tasks.
 */
public void waitNoPendingTasksOnAll() throws Exception {
    assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).get());
    assertBusy(() -> {
        for (Client client : clients()) {
            ClusterHealthResponse clusterHealth = client.admin().cluster().prepareHealth().setLocal(true).get();
            assertThat("client " + client + " still has in flight fetch", clusterHealth.getNumberOfInFlightFetch(), equalTo(0));
            PendingClusterTasksResponse pendingTasks = client.admin().cluster().preparePendingClusterTasks().setLocal(true).get();
            assertThat("client " + client + " still has pending tasks " + pendingTasks, pendingTasks, Matchers.emptyIterable());
            clusterHealth = client.admin().cluster().prepareHealth().setLocal(true).get();
            assertThat("client " + client + " still has in flight fetch", clusterHealth.getNumberOfInFlightFetch(), equalTo(0));
        }
    });
    assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).get());
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) PendingClusterTasksResponse(org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse) AdminClient(org.elasticsearch.client.AdminClient) Client(org.elasticsearch.client.Client)

Example 57 with ClusterHealthResponse

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

the class ESIntegTestCase method ensureStableCluster.

protected void ensureStableCluster(int nodeCount, TimeValue timeValue, boolean local, @Nullable String viaNode) {
    if (viaNode == null) {
        viaNode = randomFrom(internalCluster().getNodeNames());
    }
    logger.debug("ensuring cluster is stable with [{}] nodes. access node: [{}]. timeout: [{}]", nodeCount, viaNode, timeValue);
    ClusterHealthResponse clusterHealthResponse = client(viaNode).admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes(Integer.toString(nodeCount)).setTimeout(timeValue).setLocal(local).setWaitForNoRelocatingShards(true).get();
    if (clusterHealthResponse.isTimedOut()) {
        ClusterStateResponse stateResponse = client(viaNode).admin().cluster().prepareState().get();
        fail("failed to reach a stable cluster of [" + nodeCount + "] nodes. Tried via [" + viaNode + "]. last cluster state:\n" + stateResponse.getState());
    }
    assertThat(clusterHealthResponse.isTimedOut(), is(false));
    ensureFullyConnectedCluster();
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)

Example 58 with ClusterHealthResponse

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

the class IndexRecoveryIT method testTransientErrorsDuringRecoveryAreRetried.

@Test
public void testTransientErrorsDuringRecoveryAreRetried() throws Exception {
    final String indexName = "test";
    final Settings nodeSettings = Settings.builder().put(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK_SETTING.getKey(), "100ms").put(NodeConnectionsService.CLUSTER_NODE_RECONNECT_INTERVAL_SETTING.getKey(), "500ms").put(RecoverySettings.INDICES_RECOVERY_INTERNAL_ACTION_TIMEOUT_SETTING.getKey(), "10s").build();
    // start a master node
    internalCluster().startNode(nodeSettings);
    final String blueNodeName = internalCluster().startNode(Settings.builder().put("node.attr.color", "blue").put(nodeSettings).build());
    final String redNodeName = internalCluster().startNode(Settings.builder().put("node.attr.color", "red").put(nodeSettings).build());
    ClusterHealthResponse response = client().admin().cluster().prepareHealth().setWaitForNodes(">=3").get();
    assertThat(response.isTimedOut(), is(false));
    execute("CREATE TABLE doc." + indexName + " (id int) CLUSTERED INTO 1 SHARDS " + "WITH (" + " number_of_replicas=0," + " \"routing.allocation.include.color\" = 'blue'" + ")");
    int numDocs = scaledRandomIntBetween(100, 8000);
    // Index 3/4 of the documents and flush. And then index the rest. This attempts to ensure that there
    // is a mix of file chunks and translog ops
    int threeFourths = (int) (numDocs * 0.75);
    var args = new Object[threeFourths][];
    for (int i = 0; i < threeFourths; i++) {
        args[i] = new Object[] { i };
    }
    execute("INSERT INTO doc." + indexName + " (id) VALUES (?)", args);
    execute("OPTIMIZE TABLE doc." + indexName);
    args = new Object[numDocs - threeFourths][];
    for (int i = 0; i < numDocs - threeFourths; i++) {
        args[i] = new Object[] { i };
    }
    execute("INSERT INTO doc." + indexName + " (id) VALUES (?)", args);
    ensureGreen();
    ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
    final String blueNodeId = internalCluster().getInstance(ClusterService.class, blueNodeName).localNode().getId();
    assertFalse(stateResponse.getState().getRoutingNodes().node(blueNodeId).isEmpty());
    refresh();
    var searchResponse = execute("SELECT COUNT(*) FROM doc." + indexName);
    assertThat((long) searchResponse.rows()[0][0], is((long) numDocs));
    String[] recoveryActions = new String[] { PeerRecoveryTargetService.Actions.PREPARE_TRANSLOG, PeerRecoveryTargetService.Actions.TRANSLOG_OPS, PeerRecoveryTargetService.Actions.FILES_INFO, PeerRecoveryTargetService.Actions.FILE_CHUNK, PeerRecoveryTargetService.Actions.CLEAN_FILES, PeerRecoveryTargetService.Actions.FINALIZE };
    final String recoveryActionToBlock = randomFrom(recoveryActions);
    logger.info("--> will temporarily interrupt recovery action between blue & red on [{}]", recoveryActionToBlock);
    MockTransportService blueTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, blueNodeName);
    MockTransportService redTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, redNodeName);
    final AtomicBoolean recoveryStarted = new AtomicBoolean(false);
    final AtomicBoolean finalizeReceived = new AtomicBoolean(false);
    final SingleStartEnforcer validator = new SingleStartEnforcer(indexName, recoveryStarted, finalizeReceived);
    redTransportService.addSendBehavior(blueTransportService, (connection, requestId, action, request, options) -> {
        validator.accept(action, request);
        connection.sendRequest(requestId, action, request, options);
    });
    Runnable connectionBreaker = () -> {
        // Always break connection from source to remote to ensure that actions are retried
        logger.info("--> closing connections from source node to target node");
        blueTransportService.disconnectFromNode(redTransportService.getLocalNode());
        if (randomBoolean()) {
            // Sometimes break connection from remote to source to ensure that recovery is re-established
            logger.info("--> closing connections from target node to source node");
            redTransportService.disconnectFromNode(blueTransportService.getLocalNode());
        }
    };
    TransientReceiveRejected handlingBehavior = new TransientReceiveRejected(recoveryActionToBlock, finalizeReceived, recoveryStarted, connectionBreaker);
    redTransportService.addRequestHandlingBehavior(recoveryActionToBlock, handlingBehavior);
    try {
        logger.info("--> starting recovery from blue to red");
        execute("ALTER TABLE doc." + indexName + " SET (" + " number_of_replicas=1," + " \"routing.allocation.include.color\" = 'red,blue'" + ")");
        ensureGreen();
        // TODO: ES will use the shard routing preference here to prefer `_local` shards on that node
        var nodeRedExecutor = executor(redNodeName);
        searchResponse = nodeRedExecutor.exec("SELECT COUNT(*) FROM doc." + indexName);
        assertThat((long) searchResponse.rows()[0][0], is((long) numDocs));
    } finally {
        blueTransportService.clearAllRules();
        redTransportService.clearAllRules();
    }
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) MockTransportService(org.elasticsearch.test.transport.MockTransportService) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransportService(org.elasticsearch.transport.TransportService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) Test(org.junit.Test)

Example 59 with ClusterHealthResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project graylog2-server by Graylog2.

the class IndicesAdapterES7 method waitForRecovery.

@Override
public HealthStatus waitForRecovery(String index, int timeout) {
    final ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest(index).timeout(TimeValue.timeValueSeconds(timeout));
    clusterHealthRequest.waitForGreenStatus();
    final ClusterHealthResponse result = client.execute((c, requestOptions) -> c.cluster().health(clusterHealthRequest, requestOptions));
    return HealthStatus.fromString(result.getStatus().toString());
}
Also used : ClusterHealthResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)

Example 60 with ClusterHealthResponse

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

the class ElasticsearchClient method clusterReady.

public boolean clusterReady() {
    if (clusterReadyCache)
        return true;
    ClusterHealthResponse chr = elasticsearchClient.admin().cluster().prepareHealth().get();
    clusterReadyCache = chr.getStatus() != ClusterHealthStatus.RED;
    return clusterReadyCache;
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)

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