Skip to content

Commit 6a04403

Browse files
authored
Repeat cluster.initial_master_nodes log warning (#92744)
Today we log a warning about removing `cluster.initial_master_nodes` at startup, but this is easy to miss in amongst all the other messages. With this commit we repeat the warning message every 12 hours. Relates #92741
1 parent 8871dfa commit 6a04403

File tree

3 files changed

+43
-22
lines changed

3 files changed

+43
-22
lines changed

docs/changelog/92744.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 92744
2+
summary: Repeat `cluster.initial_master_nodes` log warning
3+
area: Cluster Coordination
4+
type: enhancement
5+
issues: []

server/src/main/java/org/elasticsearch/cluster/coordination/ClusterBootstrapService.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,9 @@ void logBootstrapState(Metadata metadata) {
129129
if (bootstrapRequirements.isEmpty()) {
130130
logger.info("this node is locked into cluster UUID [{}] and will not attempt further cluster bootstrapping", clusterUUID);
131131
} else {
132-
logger.warn(
133-
"""
134-
this node is locked into cluster UUID [{}] but [{}] is set to {}; \
135-
remove this setting to avoid possible data loss caused by subsequent cluster bootstrap attempts""",
136-
clusterUUID,
137-
INITIAL_MASTER_NODES_SETTING.getKey(),
138-
bootstrapRequirements
139-
);
132+
transportService.getThreadPool()
133+
.scheduleWithFixedDelay(() -> logRemovalWarning(clusterUUID), TimeValue.timeValueHours(12), Names.SAME);
134+
logRemovalWarning(clusterUUID);
140135
}
141136
} else {
142137
logger.info(
@@ -147,6 +142,17 @@ void logBootstrapState(Metadata metadata) {
147142
}
148143
}
149144

145+
private void logRemovalWarning(String clusterUUID) {
146+
logger.warn(
147+
"""
148+
this node is locked into cluster UUID [{}] but [{}] is set to {}; \
149+
remove this setting to avoid possible data loss caused by subsequent cluster bootstrap attempts""",
150+
clusterUUID,
151+
INITIAL_MASTER_NODES_SETTING.getKey(),
152+
bootstrapRequirements
153+
);
154+
}
155+
150156
@Override
151157
public void onFoundPeersUpdated() {
152158
final Set<DiscoveryNode> nodes = getDiscoveredNodes();

server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
package org.elasticsearch.cluster.coordination;
99

1010
import org.apache.logging.log4j.Level;
11-
import org.apache.logging.log4j.LogManager;
1211
import org.elasticsearch.ElasticsearchException;
1312
import org.elasticsearch.Version;
1413
import org.elasticsearch.cluster.metadata.Metadata;
1514
import org.elasticsearch.cluster.node.DiscoveryNode;
1615
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
1716
import org.elasticsearch.common.UUIDs;
18-
import org.elasticsearch.common.logging.Loggers;
1917
import org.elasticsearch.common.settings.Settings;
2018
import org.elasticsearch.common.util.concurrent.DeterministicTaskQueue;
19+
import org.elasticsearch.core.TimeValue;
2120
import org.elasticsearch.discovery.DiscoveryModule;
2221
import org.elasticsearch.test.ESTestCase;
2322
import org.elasticsearch.test.MockLogAppender;
@@ -661,13 +660,9 @@ public void testFailBootstrapNonMasterEligibleNodeWithSingleNodeDiscovery() {
661660
);
662661
}
663662

664-
public void testBootstrapStateLogging() throws IllegalAccessException {
663+
public void testBootstrapStateLogging() {
665664
final var mockAppender = new MockLogAppender();
666-
mockAppender.start();
667-
final var serviceLogger = LogManager.getLogger(ClusterBootstrapService.class);
668-
Loggers.addAppender(serviceLogger, mockAppender);
669-
670-
try {
665+
try (var ignored = mockAppender.capturing(ClusterBootstrapService.class)) {
671666
mockAppender.addExpectation(
672667
new MockLogAppender.SeenEventExpectation(
673668
"fresh node message",
@@ -710,14 +705,16 @@ public void testBootstrapStateLogging() throws IllegalAccessException {
710705

711706
mockAppender.assertAllExpectationsMatched();
712707

708+
final var warningMessagePattern = """
709+
this node is locked into cluster UUID [test-uuid] but [cluster.initial_master_nodes] is set to [node1, node2]; \
710+
remove this setting to avoid possible data loss caused by subsequent cluster bootstrap attempts""";
711+
713712
mockAppender.addExpectation(
714713
new MockLogAppender.SeenEventExpectation(
715714
"bootstrapped node message if bootstrapping still configured",
716715
ClusterBootstrapService.class.getCanonicalName(),
717716
Level.WARN,
718-
"""
719-
this node is locked into cluster UUID [test-uuid] but [cluster.initial_master_nodes] is set to [node1, node2]; \
720-
remove this setting to avoid possible data loss caused by subsequent cluster bootstrap attempts"""
717+
warningMessagePattern
721718
)
722719
);
723720

@@ -731,9 +728,22 @@ public void testBootstrapStateLogging() throws IllegalAccessException {
731728

732729
mockAppender.assertAllExpectationsMatched();
733730

734-
} finally {
735-
Loggers.removeAppender(serviceLogger, mockAppender);
736-
mockAppender.stop();
731+
mockAppender.addExpectation(
732+
new MockLogAppender.SeenEventExpectation(
733+
"bootstrapped node message if bootstrapping still configured",
734+
ClusterBootstrapService.class.getCanonicalName(),
735+
Level.WARN,
736+
warningMessagePattern
737+
)
738+
);
739+
740+
var startTime = deterministicTaskQueue.getCurrentTimeMillis();
741+
while (deterministicTaskQueue.getCurrentTimeMillis() <= startTime + TimeValue.timeValueHours(12).millis()) {
742+
deterministicTaskQueue.runAllRunnableTasks();
743+
deterministicTaskQueue.advanceTime();
744+
}
745+
746+
mockAppender.assertAllExpectationsMatched();
737747
}
738748
}
739749
}

0 commit comments

Comments
 (0)