Search in sources :

Example 6 with ClusterHealthStatus

use of org.elasticsearch.cluster.health.ClusterHealthStatus in project elasticsearch by elastic.

the class SearchWhileCreatingIndexIT method searchWhileCreatingIndex.

private void searchWhileCreatingIndex(boolean createIndex, int numberOfReplicas) throws Exception {
    // TODO: randomize the wait for active shards value on index creation and ensure the appropriate
    // number of data nodes are started for the randomized active shard count value
    String id = randomAsciiOfLength(5);
    // we will go the primary or the replica, but in a
    // randomized re-creatable manner
    int counter = 0;
    String preference = randomAsciiOfLength(5);
    logger.info("running iteration for id {}, preference {}", id, preference);
    if (createIndex) {
        createIndex("test");
    }
    client().prepareIndex("test", "type1", id).setSource("field", "test").execute().actionGet();
    RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").execute().actionGet();
    // at least one shard should be successful when refreshing
    assertThat(refreshResponse.getSuccessfulShards(), greaterThanOrEqualTo(1));
    logger.info("using preference {}", preference);
    // we want to make sure that while recovery happens, and a replica gets recovered, its properly refreshed
    ClusterHealthStatus status = ClusterHealthStatus.RED;
    while (status != ClusterHealthStatus.GREEN) {
        // first, verify that search on the primary search works
        SearchResponse searchResponse = client().prepareSearch("test").setPreference("_primary").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
        assertHitCount(searchResponse, 1);
        Client client = client();
        searchResponse = client.prepareSearch("test").setPreference(preference + Integer.toString(counter++)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
        if (searchResponse.getHits().getTotalHits() != 1) {
            refresh();
            SearchResponse searchResponseAfterRefresh = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
            logger.info("hits count mismatch on any shard search failed, post explicit refresh hits are {}", searchResponseAfterRefresh.getHits().getTotalHits());
            ensureGreen();
            SearchResponse searchResponseAfterGreen = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
            logger.info("hits count mismatch on any shard search failed, post explicit wait for green hits are {}", searchResponseAfterGreen.getHits().getTotalHits());
            assertHitCount(searchResponse, 1);
        }
        assertHitCount(searchResponse, 1);
        status = client().admin().cluster().prepareHealth("test").get().getStatus();
        internalCluster().ensureAtLeastNumDataNodes(numberOfReplicas + 1);
    }
    cluster().wipeIndices("test");
}
Also used : ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) Client(org.elasticsearch.client.Client) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 7 with ClusterHealthStatus

use of org.elasticsearch.cluster.health.ClusterHealthStatus in project elasticsearch by elastic.

the class AllocationService method logClusterHealthStateChange.

private void logClusterHealthStateChange(ClusterStateHealth previousStateHealth, ClusterStateHealth newStateHealth, String reason) {
    ClusterHealthStatus previousHealth = previousStateHealth.getStatus();
    ClusterHealthStatus currentHealth = newStateHealth.getStatus();
    if (!previousHealth.equals(currentHealth)) {
        logger.info("Cluster health status changed from [{}] to [{}] (reason: [{}]).", previousHealth, currentHealth, reason);
    }
}
Also used : ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus)

Aggregations

ClusterHealthStatus (org.elasticsearch.cluster.health.ClusterHealthStatus)7 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)1 NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)1 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)1 RefreshResponse (org.elasticsearch.action.admin.indices.refresh.RefreshResponse)1 CommonStats (org.elasticsearch.action.admin.indices.stats.CommonStats)1 IndexStats (org.elasticsearch.action.admin.indices.stats.IndexStats)1 ShardStats (org.elasticsearch.action.admin.indices.stats.ShardStats)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 Client (org.elasticsearch.client.Client)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 ClusterIndexHealth (org.elasticsearch.cluster.health.ClusterIndexHealth)1 ClusterStateHealth (org.elasticsearch.cluster.health.ClusterStateHealth)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 GroupShardsIterator (org.elasticsearch.cluster.routing.GroupShardsIterator)1 ShardIterator (org.elasticsearch.cluster.routing.ShardIterator)1 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)1