Skip to content

Commit 91d7b44

Browse files
committed
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 8c16725 commit 91d7b44

19 files changed

+276
-52
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public DetachClusterCommand() {
5151
@Override
5252
protected void processNodePaths(Terminal terminal, Path[] dataPaths, int nodeLockId, OptionSet options, Environment env)
5353
throws IOException {
54-
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(dataPaths);
54+
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
5555

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

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.elasticsearch.cluster.ClusterName;
3333
import org.elasticsearch.cluster.ClusterState;
3434
import org.elasticsearch.common.collect.Tuple;
35+
import org.elasticsearch.common.settings.ClusterSettings;
36+
import org.elasticsearch.common.settings.Settings;
3537
import org.elasticsearch.common.util.BigArrays;
3638
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3739
import org.elasticsearch.env.Environment;
@@ -76,14 +78,15 @@ public ElasticsearchNodeCommand(String description) {
7678
.withRequiredArg().ofType(Integer.class);
7779
}
7880

79-
public static PersistedClusterStateService createPersistedClusterStateService(Path[] dataPaths) throws IOException {
81+
public static PersistedClusterStateService createPersistedClusterStateService(Settings settings, Path[] dataPaths) throws IOException {
8082
final NodeMetaData nodeMetaData = PersistedClusterStateService.nodeMetaData(dataPaths);
8183
if (nodeMetaData == null) {
8284
throw new ElasticsearchException(NO_NODE_METADATA_FOUND_MSG);
8385
}
8486

8587
String nodeId = nodeMetaData.nodeId();
86-
return new PersistedClusterStateService(dataPaths, nodeId, namedXContentRegistry, BigArrays.NON_RECYCLING_INSTANCE, true);
88+
return new PersistedClusterStateService(dataPaths, nodeId, namedXContentRegistry, BigArrays.NON_RECYCLING_INSTANCE,
89+
new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L, true);
8790
}
8891

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected void processNodePaths(Terminal terminal, Path[] dataPaths, int nodeLoc
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected boolean validateBeforeLock(Terminal terminal, Environment env) {
7979

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

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

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
import org.elasticsearch.env.NodeEnvironment;
8080
import org.elasticsearch.gateway.DanglingIndicesState;
8181
import org.elasticsearch.gateway.GatewayService;
82-
import org.elasticsearch.gateway.IncrementalClusterStateWriter;
82+
import org.elasticsearch.gateway.PersistedClusterStateService;
8383
import org.elasticsearch.http.HttpTransportSettings;
8484
import org.elasticsearch.index.IndexModule;
8585
import org.elasticsearch.index.IndexSettings;
@@ -109,9 +109,9 @@
109109
import org.elasticsearch.search.aggregations.MultiBucketConsumerService;
110110
import org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter;
111111
import org.elasticsearch.threadpool.ThreadPool;
112+
import org.elasticsearch.transport.ProxyConnectionStrategy;
112113
import org.elasticsearch.transport.RemoteClusterService;
113114
import org.elasticsearch.transport.RemoteConnectionStrategy;
114-
import org.elasticsearch.transport.ProxyConnectionStrategy;
115115
import org.elasticsearch.transport.SniffConnectionStrategy;
116116
import org.elasticsearch.transport.TransportSettings;
117117
import org.elasticsearch.watcher.ResourceWatcherService;
@@ -252,7 +252,7 @@ public void apply(Settings value, Settings current, Settings previous) {
252252
GatewayService.RECOVER_AFTER_MASTER_NODES_SETTING,
253253
GatewayService.RECOVER_AFTER_NODES_SETTING,
254254
GatewayService.RECOVER_AFTER_TIME_SETTING,
255-
IncrementalClusterStateWriter.SLOW_WRITE_LOGGING_THRESHOLD,
255+
PersistedClusterStateService.SLOW_WRITE_LOGGING_THRESHOLD,
256256
NetworkModule.HTTP_DEFAULT_TYPE_SETTING,
257257
NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING,
258258
NetworkModule.HTTP_TYPE_SETTING,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private void processNoMasterNoDataNode(Terminal terminal, Path[] dataPaths, Envi
9696

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

99-
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(dataPaths);
99+
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
100100

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

137-
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(dataPaths);
137+
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
138138

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

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

+3-6
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)