Skip to content

Commit

Permalink
[ML] Ignore failures from renormalizing buckets in read-only index (#…
Browse files Browse the repository at this point in the history
…118674) (#118886)

In anomaly detection, score renormalization will update the anomaly score in the result indices. However, if the index in the old format was marked as read-only, the score update will fail. Since this failure is expected, this PR suppresses the error logging in this specific case.
  • Loading branch information
valeriy42 authored Dec 17, 2024
1 parent 9b03073 commit 68f6c78
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/118674.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 118674
summary: Ignore failures from renormalizing buckets in read-only index
area: Machine Learning
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
Expand Down Expand Up @@ -102,7 +104,29 @@ public void executeRequest() {
try (ThreadContext.StoredContext ignore = client.threadPool().getThreadContext().stashWithOrigin(ML_ORIGIN)) {
BulkResponse addRecordsResponse = client.bulk(bulkRequest).actionGet();
if (addRecordsResponse.hasFailures()) {
logger.error("[{}] Bulk index of results has errors: {}", jobId, addRecordsResponse.buildFailureMessage());
// Implementation note: Ignore the failures from writing to the read-only index, as it comes
// from changing the index format version.
boolean hasNonReadOnlyFailures = false;
for (BulkItemResponse response : addRecordsResponse.getItems()) {
if (response.isFailed() == false) {
continue;
}
if (response.getFailureMessage().contains(IndexMetadata.INDEX_READ_ONLY_BLOCK.description())) {
// We expect this to happen when the old index is made read-only and being reindexed
logger.debug(
"[{}] Ignoring failure to write renormalized results to a read-only index [{}]: {}",
jobId,
response.getFailure().getIndex(),
response.getFailureMessage()
);
} else {
hasNonReadOnlyFailures = true;
break;
}
}
if (hasNonReadOnlyFailures) {
logger.error("[{}] Bulk index of results has errors: {}", jobId, addRecordsResponse.buildFailureMessage());
}
}
}

Expand Down

0 comments on commit 68f6c78

Please sign in to comment.