|
9 | 9 |
|
10 | 10 | import org.apache.logging.log4j.LogManager;
|
11 | 11 | import org.apache.logging.log4j.Logger;
|
| 12 | +import org.apache.logging.log4j.util.Supplier; |
12 | 13 | import org.elasticsearch.action.ActionListener;
|
13 | 14 | import org.elasticsearch.action.DocWriteRequest;
|
14 | 15 | import org.elasticsearch.action.index.IndexRequest;
|
15 | 16 | import org.elasticsearch.client.internal.Client;
|
| 17 | +import org.elasticsearch.cluster.ClusterState; |
16 | 18 | import org.elasticsearch.cluster.metadata.Metadata;
|
17 | 19 | import org.elasticsearch.cluster.service.ClusterService;
|
| 20 | +import org.elasticsearch.shutdown.PluginShutdownService; |
18 | 21 | import org.elasticsearch.xcontent.ToXContent;
|
19 | 22 | import org.elasticsearch.xcontent.XContentBuilder;
|
20 | 23 | import org.elasticsearch.xcontent.XContentFactory;
|
@@ -83,20 +86,31 @@ public void putAsync(SnapshotHistoryItem item) {
|
83 | 86 | SLM_HISTORY_DATA_STREAM,
|
84 | 87 | item
|
85 | 88 | );
|
86 |
| - }, exception -> { |
87 |
| - logger.error( |
| 89 | + }, |
| 90 | + exception -> logErrorOrWarning( |
| 91 | + clusterService.state(), |
88 | 92 | () -> format("failed to index snapshot history item in data stream [%s]: [%s]", SLM_HISTORY_DATA_STREAM, item),
|
89 | 93 | exception
|
90 |
| - ); |
91 |
| - })); |
| 94 | + ) |
| 95 | + )); |
92 | 96 | } catch (IOException exception) {
|
93 |
| - logger.error( |
| 97 | + logErrorOrWarning( |
| 98 | + clusterService.state(), |
94 | 99 | () -> format("failed to index snapshot history item in data stream [%s]: [%s]", SLM_HISTORY_DATA_STREAM, item),
|
95 | 100 | exception
|
96 | 101 | );
|
97 | 102 | }
|
98 | 103 | }
|
99 | 104 |
|
| 105 | + // On node shutdown, some operations are expected to fail, we log a warning instead of error during node shutdown for those exceptions |
| 106 | + public static void logErrorOrWarning(ClusterState clusterState, Supplier<?> failureMsgSupplier, Exception exception) { |
| 107 | + if (PluginShutdownService.isLocalNodeShutdown(clusterState)) { |
| 108 | + logger.warn(failureMsgSupplier, exception); |
| 109 | + } else { |
| 110 | + logger.error(failureMsgSupplier, exception); |
| 111 | + } |
| 112 | + } |
| 113 | + |
100 | 114 | public void setSlmHistoryEnabled(boolean slmHistoryEnabled) {
|
101 | 115 | this.slmHistoryEnabled = slmHistoryEnabled;
|
102 | 116 | }
|
|
0 commit comments