From ca3da7af8531d35b4212a76378be412575f24b7f Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Fri, 3 Jul 2020 15:24:31 +0200 Subject: [PATCH] [ML] handle broken setup with state alias being an index (#58999) .ml-state-write is supposed to be an index alias, however by accident it can become an index. If .ml-state-write is a concrete index instead of an alias ML stops working. This change improves error handling by setting the job to failed and properly log and audit the problem. The user still has to manually fix the problem. This change should lead to a quicker resolution of the problem. fixes #58482 --- .../autodetect/AutodetectProcessManager.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java index ae5cbb9d799b..a0e57cee60b9 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java @@ -28,6 +28,7 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.index.analysis.AnalysisRegistry; +import org.elasticsearch.indices.InvalidAliasNameException; import org.elasticsearch.persistent.PersistentTasksCustomMetadata.PersistentTask; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.threadpool.ThreadPool; @@ -426,7 +427,19 @@ protected void doRun() { e -> closeHandler.accept(e, true) )); }, - e -> closeHandler.accept(e, true)); + e -> { + if (ExceptionsHelper.unwrapCause(e) instanceof InvalidAliasNameException) { + String msg = "Detected a problem with your setup of machine learning, the state index alias [" + + AnomalyDetectorsIndex.jobStateIndexWriteAlias() + + "] exists as index but must be an alias."; + logger.error(new ParameterizedMessage("[{}] {}", jobId, msg), e); + auditor.error(jobId, msg); + setJobState(jobTask, JobState.FAILED, msg, e2 -> closeHandler.accept(e, true)); + } else { + closeHandler.accept(e, true); + } + } + ); // Make sure the state index and alias exist ActionListener resultsMappingUpdateHandler = ActionListener.wrap(