Skip to content

Commit 5a38160

Browse files
authored
Lower log level for some SLM logs during master shutdown (#131646)
1 parent 819248f commit 5a38160

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

server/src/main/java/org/elasticsearch/shutdown/PluginShutdownService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public static Set<String> shutdownNodes(final ClusterState clusterState) {
4646
return clusterState.metadata().nodeShutdowns().getAllNodeIds();
4747
}
4848

49+
/**
50+
* Return if the current node is requested to shut down
51+
*/
52+
public static boolean isLocalNodeShutdown(final ClusterState clusterState) {
53+
String localNodeId = clusterState.nodes().getLocalNodeId();
54+
return localNodeId != null && shutdownNodes(clusterState).contains(localNodeId);
55+
}
56+
4957
/**
5058
* Return all nodes shutting down with the given shutdown types from the given cluster state
5159
*/

x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ public void onResponse(CreateSnapshotResponse createSnapshotResponse) {
151151

152152
@Override
153153
public void onFailure(Exception e) {
154-
logger.error("failed to create snapshot for snapshot lifecycle policy [{}]: {}", policyMetadata.getPolicy().getId(), e);
154+
SnapshotHistoryStore.logErrorOrWarning(
155+
clusterService.state(),
156+
() -> format("failed to create snapshot for snapshot lifecycle policy [{}]", policyMetadata.getPolicy().getId()),
157+
e
158+
);
155159
final long timestamp = Instant.now().toEpochMilli();
156160
submitUnbatchedTask(
157161
clusterService,

x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStore.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99

1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
12+
import org.apache.logging.log4j.util.Supplier;
1213
import org.elasticsearch.action.ActionListener;
1314
import org.elasticsearch.action.DocWriteRequest;
1415
import org.elasticsearch.action.index.IndexRequest;
1516
import org.elasticsearch.client.internal.Client;
17+
import org.elasticsearch.cluster.ClusterState;
1618
import org.elasticsearch.cluster.metadata.Metadata;
1719
import org.elasticsearch.cluster.service.ClusterService;
20+
import org.elasticsearch.shutdown.PluginShutdownService;
1821
import org.elasticsearch.xcontent.ToXContent;
1922
import org.elasticsearch.xcontent.XContentBuilder;
2023
import org.elasticsearch.xcontent.XContentFactory;
@@ -83,20 +86,31 @@ public void putAsync(SnapshotHistoryItem item) {
8386
SLM_HISTORY_DATA_STREAM,
8487
item
8588
);
86-
}, exception -> {
87-
logger.error(
89+
},
90+
exception -> logErrorOrWarning(
91+
clusterService.state(),
8892
() -> format("failed to index snapshot history item in data stream [%s]: [%s]", SLM_HISTORY_DATA_STREAM, item),
8993
exception
90-
);
91-
}));
94+
)
95+
));
9296
} catch (IOException exception) {
93-
logger.error(
97+
logErrorOrWarning(
98+
clusterService.state(),
9499
() -> format("failed to index snapshot history item in data stream [%s]: [%s]", SLM_HISTORY_DATA_STREAM, item),
95100
exception
96101
);
97102
}
98103
}
99104

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+
100114
public void setSlmHistoryEnabled(boolean slmHistoryEnabled) {
101115
this.slmHistoryEnabled = slmHistoryEnabled;
102116
}

0 commit comments

Comments
 (0)