Fix missing index issue by explicitly creating the index if implicit creation fails
This really shouldn't be happening. Original commit: elastic/x-pack-elasticsearch@7d334ec76f
This commit is contained in:
parent
193865925c
commit
87e056d762
|
@ -33,6 +33,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
|
import org.elasticsearch.indices.IndexMissingException;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
|
|
||||||
|
@ -125,6 +126,7 @@ public class AlertActionManager extends AbstractComponent {
|
||||||
logger.error("Unable to check index availability", e);
|
logger.error("Unable to check index availability", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loadQueue();
|
loadQueue();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -261,17 +263,31 @@ public class AlertActionManager extends AbstractComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAlertAction(Alert alert, DateTime scheduledFireTime, DateTime fireTime) throws IOException {
|
public void addAlertAction(Alert alert, DateTime scheduledFireTime, DateTime fireTime) throws IOException {
|
||||||
|
addAlertAction(alert, scheduledFireTime, fireTime, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAlertAction(Alert alert, DateTime scheduledFireTime, DateTime fireTime, boolean retry) throws IOException {
|
||||||
ensureStarted();
|
ensureStarted();
|
||||||
logger.debug("Adding alert action for alert [{}]", alert.alertName());
|
logger.debug("Adding alert action for alert [{}]", alert.alertName());
|
||||||
|
|
||||||
AlertActionEntry entry = new AlertActionEntry(alert, scheduledFireTime, fireTime, AlertActionState.SEARCH_NEEDED);
|
|
||||||
String alertHistoryIndex = getAlertHistoryIndexNameForTime(scheduledFireTime);
|
String alertHistoryIndex = getAlertHistoryIndexNameForTime(scheduledFireTime);
|
||||||
IndexResponse response = client.prepareIndex(alertHistoryIndex, ALERT_HISTORY_TYPE, entry.getId())
|
AlertActionEntry entry = new AlertActionEntry(alert, scheduledFireTime, fireTime, AlertActionState.SEARCH_NEEDED);
|
||||||
.setSource(XContentFactory.jsonBuilder().value(entry))
|
try {
|
||||||
.setOpType(IndexRequest.OpType.CREATE)
|
IndexResponse response = client.prepareIndex(alertHistoryIndex, ALERT_HISTORY_TYPE, entry.getId())
|
||||||
.get();
|
.setSource(XContentFactory.jsonBuilder().value(entry))
|
||||||
|
.setOpType(IndexRequest.OpType.CREATE)
|
||||||
|
.get();
|
||||||
|
entry.setVersion(response.getVersion());
|
||||||
|
} catch (IndexMissingException ime) {
|
||||||
|
///@TODO This really shouldn't be happening
|
||||||
|
if (retry) {
|
||||||
|
logger.error("Unable to dynamically implicitly create alert history index [" + alertHistoryIndex + "] creating explicitly");
|
||||||
|
client.admin().indices().prepareCreate(alertHistoryIndex).get();
|
||||||
|
addAlertAction(alert, scheduledFireTime, fireTime, false);
|
||||||
|
} else {
|
||||||
|
throw new ElasticsearchException("Unable to create alert history index [" + alertHistoryIndex + "]", ime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entry.setVersion(response.getVersion());
|
|
||||||
long currentSize = actionsToBeProcessed.size() + 1;
|
long currentSize = actionsToBeProcessed.size() + 1;
|
||||||
actionsToBeProcessed.add(entry);
|
actionsToBeProcessed.add(entry);
|
||||||
long currentLargestQueueSize = largestQueueSize.get();
|
long currentLargestQueueSize = largestQueueSize.get();
|
||||||
|
|
Loading…
Reference in New Issue