Skip to content

Commit 2dfaf7a

Browse files
authored
Remove MDP from PersistedClusterStateService (#72278)
This commit removes multiple data path support from the PersistedClusterStateService. Most notably, many error cases are no longer possible where duplicate/conflicting data could previously exist across multiple paths, there is now only one path. relates #71205
1 parent a4ae1a5 commit 2dfaf7a

12 files changed

Lines changed: 172 additions & 150 deletions

File tree

server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void testBootstrapNoClusterState() throws IOException {
156156
internalCluster().stopRandomDataNode();
157157
Environment environment = TestEnvironment.newEnvironment(
158158
Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
159-
PersistedClusterStateService.deleteAll(nodeEnvironment.nodeDataPath());
159+
PersistedClusterStateService.delete(nodeEnvironment.nodeDataPath());
160160

161161
expectThrows(() -> unsafeBootstrap(environment), ElasticsearchNodeCommand.NO_NODE_METADATA_FOUND_MSG);
162162
}
@@ -170,7 +170,7 @@ public void testDetachNoClusterState() throws IOException {
170170
internalCluster().stopRandomDataNode();
171171
Environment environment = TestEnvironment.newEnvironment(
172172
Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
173-
PersistedClusterStateService.deleteAll(nodeEnvironment.nodeDataPath());
173+
PersistedClusterStateService.delete(nodeEnvironment.nodeDataPath());
174174

175175
expectThrows(() -> detachCluster(environment), ElasticsearchNodeCommand.NO_NODE_METADATA_FOUND_MSG);
176176
}
@@ -253,7 +253,7 @@ public void test3MasterNodes2Failed() throws Exception {
253253
logger.info("--> unsafely-bootstrap 1st master-eligible node");
254254
MockTerminal terminal = unsafeBootstrap(environmentMaster1);
255255
Metadata metadata = ElasticsearchNodeCommand.createPersistedClusterStateService(Settings.EMPTY, nodeEnvironment.nodeDataPath())
256-
.loadBestOnDiskState().metadata;
256+
.loadOnDiskState().metadata;
257257
assertThat(terminal.getOutput(), containsString(
258258
String.format(Locale.ROOT, UnsafeBootstrapMasterCommand.CLUSTER_STATE_TERM_VERSION_MSG_FORMAT,
259259
metadata.coordinationMetadata().term(), metadata.version())));

server/src/internalClusterTest/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,7 @@ public void testResolvePath() throws Exception {
566566
for (String nodeName : nodeNames) {
567567
final Path indexPath = indexPathByNodeName.get(nodeName);
568568
final OptionSet options = parser.parse("--dir", indexPath.toAbsolutePath().toString());
569-
command.findAndProcessShardPath(options, environmentByNodeName.get(nodeName),
570-
environmentByNodeName.get(nodeName).dataFile(),
569+
command.findAndProcessShardPath(options, environmentByNodeName.get(nodeName), environmentByNodeName.get(nodeName).dataFile(),
571570
state, shardPath -> assertThat(shardPath.resolveIndex(), equalTo(indexPath)));
572571
}
573572
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static PersistedClusterStateService createPersistedClusterStateService(Se
106106
}
107107

108108
String nodeId = nodeMetadata.nodeId();
109-
return new PersistedClusterStateService(new Path[] { dataPath }, nodeId, namedXContentRegistry, BigArrays.NON_RECYCLING_INSTANCE,
109+
return new PersistedClusterStateService(dataPath, nodeId, namedXContentRegistry, BigArrays.NON_RECYCLING_INSTANCE,
110110
new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L);
111111
}
112112

@@ -119,7 +119,7 @@ public static ClusterState clusterState(Environment environment, PersistedCluste
119119

120120
public static Tuple<Long, ClusterState> loadTermAndClusterState(PersistedClusterStateService psf,
121121
Environment env) throws IOException {
122-
final PersistedClusterStateService.OnDiskState bestOnDiskState = psf.loadBestOnDiskState();
122+
final PersistedClusterStateService.OnDiskState bestOnDiskState = psf.loadOnDiskState();
123123
if (bestOnDiskState.empty()) {
124124
throw new ElasticsearchException(CS_MISSING_MSG);
125125
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ protected void processNodePaths(Terminal terminal, Path dataPath, OptionSet opti
5252
}
5353

5454
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPath);
55-
5655
terminal.println(Terminal.Verbosity.VERBOSE, "Loading cluster state");
5756
final Tuple<Long, ClusterState> termAndClusterState = loadTermAndClusterState(persistedClusterStateService, env);
5857
final ClusterState oldClusterState = termAndClusterState.v2();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private void processMasterNoDataNode(Terminal terminal, Path dataPath, Environme
143143

144144
private ClusterState loadClusterState(Terminal terminal, Environment env, PersistedClusterStateService psf) throws IOException {
145145
terminal.println(Terminal.Verbosity.VERBOSE, "Loading cluster state");
146-
return clusterState(env, psf.loadBestOnDiskState());
146+
return clusterState(env, psf.loadOnDiskState());
147147
}
148148

149149
private void outputVerboseInformation(Terminal terminal, Collection<Path> pathsToCleanup, Set<String> indexUUIDs, Metadata metadata) {

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import org.elasticsearch.cluster.coordination.CoordinationState.PersistedState;
2323
import org.elasticsearch.cluster.coordination.InMemoryPersistedState;
2424
import org.elasticsearch.cluster.metadata.IndexMetadata;
25+
import org.elasticsearch.cluster.metadata.IndexMetadataVerifier;
2526
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
2627
import org.elasticsearch.cluster.metadata.Manifest;
2728
import org.elasticsearch.cluster.metadata.Metadata;
28-
import org.elasticsearch.cluster.metadata.IndexMetadataVerifier;
2929
import org.elasticsearch.cluster.node.DiscoveryNode;
3030
import org.elasticsearch.cluster.service.ClusterService;
3131
import org.elasticsearch.common.collect.ImmutableOpenMap;
@@ -94,7 +94,7 @@ public void start(Settings settings, TransportService transportService, ClusterS
9494

9595
if (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.canContainData(settings)) {
9696
try {
97-
final PersistedClusterStateService.OnDiskState onDiskState = persistedClusterStateService.loadBestOnDiskState();
97+
final PersistedClusterStateService.OnDiskState onDiskState = persistedClusterStateService.loadOnDiskState();
9898

9999
Metadata metadata = onDiskState.metadata;
100100
long lastAcceptedVersion = onDiskState.lastAcceptedVersion;
@@ -132,7 +132,7 @@ public void start(Settings settings, TransportService transportService, ClusterS
132132
}
133133
// write legacy node metadata to prevent accidental downgrades from spawning empty cluster state
134134
NodeMetadata.FORMAT.writeAndCleanup(new NodeMetadata(persistedClusterStateService.getNodeId(), Version.CURRENT),
135-
persistedClusterStateService.getDataPaths());
135+
persistedClusterStateService.getDataPath());
136136
success = true;
137137
} finally {
138138
if (success == false) {
@@ -148,23 +148,21 @@ public void start(Settings settings, TransportService transportService, ClusterS
148148
final long currentTerm = 0L;
149149
final ClusterState clusterState = prepareInitialClusterState(transportService, clusterService,
150150
ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings)).build());
151-
if (persistedClusterStateService.getDataPaths().length > 0) {
152-
// write empty cluster state just so that we have a persistent node id. There is no need to write out global metadata with
153-
// cluster uuid as coordinating-only nodes do not snap into a cluster as they carry no state
154-
try (PersistedClusterStateService.Writer persistenceWriter = persistedClusterStateService.createWriter()) {
155-
persistenceWriter.writeFullStateAndCommit(currentTerm, clusterState);
156-
} catch (IOException e) {
157-
throw new ElasticsearchException("failed to load metadata", e);
158-
}
159-
try {
160-
// delete legacy cluster state files
161-
metaStateService.deleteAll();
162-
// write legacy node metadata to prevent downgrades from spawning empty cluster state
163-
NodeMetadata.FORMAT.writeAndCleanup(new NodeMetadata(persistedClusterStateService.getNodeId(), Version.CURRENT),
164-
persistedClusterStateService.getDataPaths());
165-
} catch (IOException e) {
166-
throw new UncheckedIOException(e);
167-
}
151+
// write empty cluster state just so that we have a persistent node id. There is no need to write out global metadata with
152+
// cluster uuid as coordinating-only nodes do not snap into a cluster as they carry no state
153+
try (PersistedClusterStateService.Writer persistenceWriter = persistedClusterStateService.createWriter()) {
154+
persistenceWriter.writeFullStateAndCommit(currentTerm, clusterState);
155+
} catch (IOException e) {
156+
throw new ElasticsearchException("failed to load metadata", e);
157+
}
158+
try {
159+
// delete legacy cluster state files
160+
metaStateService.deleteAll();
161+
// write legacy node metadata to prevent downgrades from spawning empty cluster state
162+
NodeMetadata.FORMAT.writeAndCleanup(new NodeMetadata(persistedClusterStateService.getNodeId(), Version.CURRENT),
163+
persistedClusterStateService.getDataPath());
164+
} catch (IOException e) {
165+
throw new UncheckedIOException(e);
168166
}
169167
persistedState.set(new InMemoryPersistedState(currentTerm, clusterState));
170168
}

0 commit comments

Comments
 (0)