|
8 | 8 |
|
9 | 9 | import org.apache.logging.log4j.LogManager; |
10 | 10 | import org.apache.logging.log4j.Logger; |
| 11 | +import org.elasticsearch.action.bulk.BulkItemResponse; |
11 | 12 | import org.elasticsearch.action.bulk.BulkRequest; |
12 | 13 | import org.elasticsearch.action.bulk.BulkResponse; |
13 | 14 | import org.elasticsearch.action.index.IndexRequest; |
14 | 15 | import org.elasticsearch.client.internal.Client; |
| 16 | +import org.elasticsearch.cluster.metadata.IndexMetadata; |
15 | 17 | import org.elasticsearch.common.util.concurrent.ThreadContext; |
16 | 18 | import org.elasticsearch.xcontent.ToXContent; |
17 | 19 | import org.elasticsearch.xcontent.XContentBuilder; |
@@ -102,7 +104,29 @@ public void executeRequest() { |
102 | 104 | try (ThreadContext.StoredContext ignore = client.threadPool().getThreadContext().stashWithOrigin(ML_ORIGIN)) { |
103 | 105 | BulkResponse addRecordsResponse = client.bulk(bulkRequest).actionGet(); |
104 | 106 | 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 | + } |
106 | 130 | } |
107 | 131 | } |
108 | 132 |
|
|
0 commit comments