Skip to content

Commit 5736dfb

Browse files
authored
Warn on slow metadata performance (#50956)
Has the new cluster state storage layer emit warnings in case metadata performance is very slow. Relates #48701
1 parent 4d2be9b commit 5736dfb

19 files changed

+275
-51
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public DetachClusterCommand() {
5050

5151
@Override
5252
protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException {
53-
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(dataPaths);
53+
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
5454

5555
terminal.println(Terminal.Verbosity.VERBOSE, "Loading cluster state");
5656
final ClusterState oldClusterState = loadTermAndClusterState(persistedClusterStateService, env).v2();

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.elasticsearch.cluster.ClusterName;
3232
import org.elasticsearch.cluster.ClusterState;
3333
import org.elasticsearch.common.collect.Tuple;
34+
import org.elasticsearch.common.settings.ClusterSettings;
35+
import org.elasticsearch.common.settings.Settings;
3436
import org.elasticsearch.common.util.BigArrays;
3537
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3638
import org.elasticsearch.env.Environment;
@@ -72,14 +74,15 @@ public ElasticsearchNodeCommand(String description) {
7274
super(description);
7375
}
7476

75-
public static PersistedClusterStateService createPersistedClusterStateService(Path[] dataPaths) throws IOException {
77+
public static PersistedClusterStateService createPersistedClusterStateService(Settings settings, Path[] dataPaths) throws IOException {
7678
final NodeMetaData nodeMetaData = PersistedClusterStateService.nodeMetaData(dataPaths);
7779
if (nodeMetaData == null) {
7880
throw new ElasticsearchException(NO_NODE_METADATA_FOUND_MSG);
7981
}
8082

8183
String nodeId = nodeMetaData.nodeId();
82-
return new PersistedClusterStateService(dataPaths, nodeId, namedXContentRegistry, BigArrays.NON_RECYCLING_INSTANCE, true);
84+
return new PersistedClusterStateService(dataPaths, nodeId, namedXContentRegistry, BigArrays.NON_RECYCLING_INSTANCE,
85+
new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L, true);
8386
}
8487

8588
public static ClusterState clusterState(Environment environment, PersistedClusterStateService.OnDiskState onDiskState) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet o
6262
throw new UserException(ExitCodes.USAGE, "Must supply at least one setting to remove");
6363
}
6464

65-
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(dataPaths);
65+
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
6666

6767
terminal.println(Terminal.Verbosity.VERBOSE, "Loading cluster state");
6868
final Tuple<Long, ClusterState> termAndClusterState = loadTermAndClusterState(persistedClusterStateService, env);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected boolean validateBeforeLock(Terminal terminal, Environment env) {
7878
}
7979

8080
protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException {
81-
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(dataPaths);
81+
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
8282

8383
final Tuple<Long, ClusterState> state = loadTermAndClusterState(persistedClusterStateService, env);
8484
final ClusterState oldClusterState = state.v2();

server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
import org.elasticsearch.env.NodeEnvironment;
7373
import org.elasticsearch.gateway.DanglingIndicesState;
7474
import org.elasticsearch.gateway.GatewayService;
75-
import org.elasticsearch.gateway.IncrementalClusterStateWriter;
75+
import org.elasticsearch.gateway.PersistedClusterStateService;
7676
import org.elasticsearch.http.HttpTransportSettings;
7777
import org.elasticsearch.index.IndexModule;
7878
import org.elasticsearch.index.IndexSettings;
@@ -102,9 +102,9 @@
102102
import org.elasticsearch.search.aggregations.MultiBucketConsumerService;
103103
import org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter;
104104
import org.elasticsearch.threadpool.ThreadPool;
105+
import org.elasticsearch.transport.ProxyConnectionStrategy;
105106
import org.elasticsearch.transport.RemoteClusterService;
106107
import org.elasticsearch.transport.RemoteConnectionStrategy;
107-
import org.elasticsearch.transport.ProxyConnectionStrategy;
108108
import org.elasticsearch.transport.SniffConnectionStrategy;
109109
import org.elasticsearch.transport.TransportSettings;
110110
import org.elasticsearch.watcher.ResourceWatcherService;
@@ -232,7 +232,7 @@ public void apply(Settings value, Settings current, Settings previous) {
232232
GatewayService.RECOVER_AFTER_MASTER_NODES_SETTING,
233233
GatewayService.RECOVER_AFTER_NODES_SETTING,
234234
GatewayService.RECOVER_AFTER_TIME_SETTING,
235-
IncrementalClusterStateWriter.SLOW_WRITE_LOGGING_THRESHOLD,
235+
PersistedClusterStateService.SLOW_WRITE_LOGGING_THRESHOLD,
236236
NetworkModule.HTTP_DEFAULT_TYPE_SETTING,
237237
NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING,
238238
NetworkModule.HTTP_TYPE_SETTING,

server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private void processNoMasterNoDataNode(Terminal terminal, Path[] dataPaths, Envi
9595

9696
Set<Path> indexPaths = uniqueParentPaths(shardDataPaths, indexMetaDataPaths);
9797

98-
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(dataPaths);
98+
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
9999

100100
final MetaData metaData = loadClusterState(terminal, env, persistedClusterStateService).metaData();
101101
if (indexPaths.isEmpty() && metaData.indices().isEmpty()) {
@@ -133,7 +133,7 @@ private void processMasterNoDataNode(Terminal terminal, Path[] dataPaths, Enviro
133133
return;
134134
}
135135

136-
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(dataPaths);
136+
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
137137

138138
final MetaData metaData = loadClusterState(terminal, env, persistedClusterStateService).metaData();
139139

server/src/main/java/org/elasticsearch/gateway/IncrementalClusterStateWriter.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.cluster.routing.RoutingNode;
2828
import org.elasticsearch.cluster.routing.ShardRouting;
2929
import org.elasticsearch.common.settings.ClusterSettings;
30-
import org.elasticsearch.common.settings.Setting;
3130
import org.elasticsearch.common.settings.Settings;
3231
import org.elasticsearch.common.unit.TimeValue;
3332
import org.elasticsearch.index.Index;
@@ -47,9 +46,6 @@ public class IncrementalClusterStateWriter {
4746

4847
private static final Logger logger = LogManager.getLogger(IncrementalClusterStateWriter.class);
4948

50-
public static final Setting<TimeValue> SLOW_WRITE_LOGGING_THRESHOLD = Setting.timeSetting("gateway.slow_write_logging_threshold",
51-
TimeValue.timeValueSeconds(10), TimeValue.ZERO, Setting.Property.NodeScope, Setting.Property.Dynamic);
52-
5349
private final MetaStateService metaStateService;
5450

5551
// We call updateClusterState on the (unique) cluster applier thread so there's no need to synchronize access to these fields.
@@ -67,8 +63,9 @@ public class IncrementalClusterStateWriter {
6763
this.previousClusterState = clusterState;
6864
this.relativeTimeMillisSupplier = relativeTimeMillisSupplier;
6965
this.incrementalWrite = false;
70-
this.slowWriteLoggingThreshold = SLOW_WRITE_LOGGING_THRESHOLD.get(settings);
71-
clusterSettings.addSettingsUpdateConsumer(SLOW_WRITE_LOGGING_THRESHOLD, this::setSlowWriteLoggingThreshold);
66+
this.slowWriteLoggingThreshold = PersistedClusterStateService.SLOW_WRITE_LOGGING_THRESHOLD.get(settings);
67+
clusterSettings.addSettingsUpdateConsumer(PersistedClusterStateService.SLOW_WRITE_LOGGING_THRESHOLD,
68+
this::setSlowWriteLoggingThreshold);
7269
}
7370

7471
private void setSlowWriteLoggingThreshold(TimeValue slowWriteLoggingThreshold) {

0 commit comments

Comments
 (0)