Skip to content

Commit a056bd8

Browse files
authored
[Zen2] Move ClusterState fields to be persisted to ClusterState.MetaData (#35625)
Today we have a way to atomically persist global MetaData and IndexMetaData to disk when new ClusterState is received. All other ClusterState fields are not persisted. However, there are other parts of ClusterState that should be persisted, namely: version term lastCommittedConfiguration lastAcceptedConfiguration votingTombstones version is changed frequently, other fields are not. We decided to group term, lastCommittedConfiguration, lastAcceptedConfiguration and votingTombstones into CoordinationMetaData class and make CoordinationMetaData a field inside MetaData. MetaData.toXContent and MetaData.fromXContent should take care of CoordinationMetaData. version stays as a top level field in ClusterState and will be persisted as part of Manifest in a follow-up commit. Also MetaData.isGlobalStateEquals should be extended to include coordinationMetaData in comparison. This commit favors exposing getters, such as getTerm directly in ClusterState to avoid massive code changes. An example of CoordinationMetaState.toXContent: { "term": 1, "last_committed_config": [ "TiIuBcbBtpuXyDDVHXeD", "ZIAoVbkjjLPLUuYLaTkw" ], "last_accepted_config": [ "OwkXbXZNOZPJqccdFHdz", "LouzsGYwmQzpeQMrboZe", "fCKGRZdjLTqzXAqPUtGL", "pLoxshjpJXwDhbgjfYJy", "SjINLwFIlIEFZCbjrSFo", "MDkVncJEVyZLJktopWje" ] }
1 parent 6ac0cb1 commit a056bd8

31 files changed

+752
-388
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/bootstrap/BootstrapConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package org.elasticsearch.action.admin.cluster.bootstrap;
2020

2121
import org.elasticsearch.ElasticsearchException;
22-
import org.elasticsearch.cluster.ClusterState.VotingConfiguration;
22+
import org.elasticsearch.cluster.coordination.CoordinationMetaData.VotingConfiguration;
2323
import org.elasticsearch.cluster.node.DiscoveryNode;
2424
import org.elasticsearch.common.Nullable;
2525
import org.elasticsearch.common.io.stream.StreamInput;

server/src/main/java/org/elasticsearch/action/admin/cluster/configuration/TransportAddVotingTombstonesAction.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
import org.elasticsearch.action.support.ActionFilters;
2525
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
2626
import org.elasticsearch.cluster.ClusterState;
27-
import org.elasticsearch.cluster.ClusterState.Builder;
2827
import org.elasticsearch.cluster.ClusterStateObserver;
2928
import org.elasticsearch.cluster.ClusterStateObserver.Listener;
3029
import org.elasticsearch.cluster.ClusterStateUpdateTask;
3130
import org.elasticsearch.cluster.block.ClusterBlockException;
3231
import org.elasticsearch.cluster.block.ClusterBlockLevel;
32+
import org.elasticsearch.cluster.coordination.CoordinationMetaData;
3333
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
34+
import org.elasticsearch.cluster.metadata.MetaData;
3435
import org.elasticsearch.cluster.node.DiscoveryNode;
3536
import org.elasticsearch.cluster.service.ClusterService;
3637
import org.elasticsearch.common.Priority;
@@ -90,9 +91,10 @@ public ClusterState execute(ClusterState currentState) {
9091
assert resolvedNodes == null : resolvedNodes;
9192
resolvedNodes = resolveNodesAndCheckMaximum(request, currentState);
9293

93-
final Builder builder = ClusterState.builder(currentState);
94+
final CoordinationMetaData.Builder builder = CoordinationMetaData.builder(currentState.coordinationMetaData());
9495
resolvedNodes.forEach(builder::addVotingTombstone);
95-
final ClusterState newState = builder.build();
96+
final MetaData newMetaData = MetaData.builder(currentState.metaData()).coordinationMetaData(builder.build()).build();
97+
final ClusterState newState = ClusterState.builder(currentState).metaData(newMetaData).build();
9698
assert newState.getVotingTombstones().size() <= MAXIMUM_VOTING_TOMBSTONES_SETTING.get(currentState.metaData().settings());
9799
return newState;
98100
}

server/src/main/java/org/elasticsearch/action/admin/cluster/configuration/TransportClearVotingTombstonesAction.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
import org.elasticsearch.action.support.ActionFilters;
2525
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
2626
import org.elasticsearch.cluster.ClusterState;
27-
import org.elasticsearch.cluster.ClusterState.Builder;
2827
import org.elasticsearch.cluster.ClusterStateObserver;
2928
import org.elasticsearch.cluster.ClusterStateObserver.Listener;
3029
import org.elasticsearch.cluster.ClusterStateUpdateTask;
3130
import org.elasticsearch.cluster.block.ClusterBlockException;
3231
import org.elasticsearch.cluster.block.ClusterBlockLevel;
32+
import org.elasticsearch.cluster.coordination.CoordinationMetaData;
3333
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
34+
import org.elasticsearch.cluster.metadata.MetaData;
3435
import org.elasticsearch.cluster.node.DiscoveryNode;
3536
import org.elasticsearch.cluster.service.ClusterService;
3637
import org.elasticsearch.common.Priority;
@@ -119,9 +120,11 @@ private void submitClearTombstonesTask(ClearVotingTombstonesRequest request, lon
119120
clusterService.submitStateUpdateTask("clear-voting-tombstones", new ClusterStateUpdateTask(Priority.URGENT) {
120121
@Override
121122
public ClusterState execute(ClusterState currentState) {
122-
final Builder builder = ClusterState.builder(currentState);
123-
builder.clearVotingTombstones();
124-
return builder.build();
123+
final CoordinationMetaData newCoordinationMetaData =
124+
CoordinationMetaData.builder(currentState.coordinationMetaData()).clearVotingTombstones().build();
125+
final MetaData newMetaData = MetaData.builder(currentState.metaData()).
126+
coordinationMetaData(newCoordinationMetaData).build();
127+
return ClusterState.builder(currentState).metaData(newMetaData).build();
125128
}
126129

127130
@Override

server/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,9 @@ protected void masterOperation(final ClusterStateRequest request, final ClusterS
7777
ClusterState currentState = clusterService.state();
7878
logger.trace("Serving cluster state request using version {}", currentState.version());
7979
ClusterState.Builder builder = ClusterState.builder(currentState.getClusterName());
80-
builder.term(currentState.term());
8180
builder.version(currentState.version());
8281
builder.stateUUID(currentState.stateUUID());
83-
builder.lastCommittedConfiguration(currentState.getLastCommittedConfiguration());
84-
builder.lastAcceptedConfiguration(currentState.getLastAcceptedConfiguration());
82+
8583
if (request.nodes()) {
8684
builder.nodes(currentState.nodes());
8785
}
@@ -105,6 +103,7 @@ protected void masterOperation(final ClusterStateRequest request, final ClusterS
105103

106104
MetaData.Builder mdBuilder = MetaData.builder();
107105
mdBuilder.clusterUUID(currentState.metaData().clusterUUID());
106+
mdBuilder.coordinationMetaData(currentState.coordinationMetaData());
108107

109108
if (request.metaData()) {
110109
if (request.indices().length > 0) {

0 commit comments

Comments
 (0)