Skip to content

Commit 68f6c78

Browse files
authored
[ML] Ignore failures from renormalizing buckets in read-only index (#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.
1 parent 9b03073 commit 68f6c78

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

docs/changelog/118674.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 118674
2+
summary: Ignore failures from renormalizing buckets in read-only index
3+
area: Machine Learning
4+
type: enhancement
5+
issues: []

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobRenormalizedResultsPersister.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
import org.apache.logging.log4j.LogManager;
1010
import org.apache.logging.log4j.Logger;
11+
import org.elasticsearch.action.bulk.BulkItemResponse;
1112
import org.elasticsearch.action.bulk.BulkRequest;
1213
import org.elasticsearch.action.bulk.BulkResponse;
1314
import org.elasticsearch.action.index.IndexRequest;
1415
import org.elasticsearch.client.internal.Client;
16+
import org.elasticsearch.cluster.metadata.IndexMetadata;
1517
import org.elasticsearch.common.util.concurrent.ThreadContext;
1618
import org.elasticsearch.xcontent.ToXContent;
1719
import org.elasticsearch.xcontent.XContentBuilder;
@@ -102,7 +104,29 @@ public void executeRequest() {
102104
try (ThreadContext.StoredContext ignore = client.threadPool().getThreadContext().stashWithOrigin(ML_ORIGIN)) {
103105
BulkResponse addRecordsResponse = client.bulk(bulkRequest).actionGet();
104106
if (addRecordsResponse.hasFailures()) {
105-
logger.error("[{}] Bulk index of results has errors: {}", jobId, addRecordsResponse.buildFailureMessage());
107+
// Implementation note: Ignore the failures from writing to the read-only index, as it comes
108+
// from changing the index format version.
109+
boolean hasNonReadOnlyFailures = false;
110+
for (BulkItemResponse response : addRecordsResponse.getItems()) {
111+
if (response.isFailed() == false) {
112+
continue;
113+
}
114+
if (response.getFailureMessage().contains(IndexMetadata.INDEX_READ_ONLY_BLOCK.description())) {
115+
// We expect this to happen when the old index is made read-only and being reindexed
116+
logger.debug(
117+
"[{}] Ignoring failure to write renormalized results to a read-only index [{}]: {}",
118+
jobId,
119+
response.getFailure().getIndex(),
120+
response.getFailureMessage()
121+
);
122+
} else {
123+
hasNonReadOnlyFailures = true;
124+
break;
125+
}
126+
}
127+
if (hasNonReadOnlyFailures) {
128+
logger.error("[{}] Bulk index of results has errors: {}", jobId, addRecordsResponse.buildFailureMessage());
129+
}
106130
}
107131
}
108132

0 commit comments

Comments
 (0)