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");
}
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);
}
}
Aggregations