Also check if the refresh was successful on all the shards it was supposed to execute.

Original commit: elastic/x-pack-elasticsearch@ab867346e4
This commit is contained in:
Martijn van Groningen 2014-11-28 12:49:51 +01:00
parent 737e9567b9
commit b883641b01
2 changed files with 12 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.ElasticsearchIllegalStateException;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexRequest;
@ -196,7 +197,11 @@ public class AlertsStore extends AbstractComponent {
private void loadAlerts() {
assert alertMap.isEmpty() : "No alerts should reside, but there are " + alertMap.size() + " alerts.";
client.admin().indices().refresh(new RefreshRequest(ALERT_INDEX)).actionGet();
RefreshResponse refreshResponse = client.admin().indices().refresh(new RefreshRequest(ALERT_INDEX)).actionGet();
if (refreshResponse.getSuccessfulShards() != refreshResponse.getSuccessfulShards()) {
throw new ElasticsearchException("Not all shards have been refreshed");
}
SearchResponse response = client.prepareSearch(ALERT_INDEX)
.setTypes(ALERT_TYPE)
.setSearchType(SearchType.SCAN)

View File

@ -9,6 +9,7 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.ElasticsearchIllegalStateException;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
@ -162,7 +163,11 @@ public class AlertActionManager extends AbstractComponent {
public void loadQueue() {
assert actionsToBeProcessed.isEmpty() : "Queue should be empty, but contains " + actionsToBeProcessed.size() + " elements.";
client.admin().indices().refresh(new RefreshRequest(ALERT_HISTORY_INDEX_PREFIX + "*")).actionGet();
RefreshResponse refreshResponse = client.admin().indices().refresh(new RefreshRequest(ALERT_HISTORY_INDEX_PREFIX + "*")).actionGet();
if (refreshResponse.getSuccessfulShards() != refreshResponse.getSuccessfulShards()) {
throw new ElasticsearchException("Not all shards have been refreshed");
}
SearchResponse response = client.prepareSearch(ALERT_HISTORY_INDEX_PREFIX + "*")
.setQuery(QueryBuilders.termQuery(STATE, AlertActionState.SEARCH_NEEDED.toString()))
.setSearchType(SearchType.SCAN)