2323import com .carrotsearch .hppc .cursors .ObjectCursor ;
2424import com .carrotsearch .hppc .cursors .ObjectObjectCursor ;
2525
26+ import org .elasticsearch .Version ;
2627import org .elasticsearch .client .transport .TransportClient ;
2728import org .elasticsearch .cluster .block .ClusterBlock ;
2829import org .elasticsearch .cluster .block .ClusterBlocks ;
@@ -178,17 +179,19 @@ default boolean isPrivate() {
178179
179180 private final boolean wasReadFromDiff ;
180181
182+ private final int minimumMasterNodesOnPublishingMaster ;
183+
181184 // built on demand
182185 private volatile RoutingNodes routingNodes ;
183186
184187 public ClusterState (long version , String stateUUID , ClusterState state ) {
185188 this (state .clusterName , version , stateUUID , state .metaData (), state .routingTable (), state .nodes (), state .blocks (),
186- state .customs (), false );
189+ state .customs (), - 1 , false );
187190 }
188191
189192 public ClusterState (ClusterName clusterName , long version , String stateUUID , MetaData metaData , RoutingTable routingTable ,
190193 DiscoveryNodes nodes , ClusterBlocks blocks , ImmutableOpenMap <String , Custom > customs ,
191- boolean wasReadFromDiff ) {
194+ int minimumMasterNodesOnPublishingMaster , boolean wasReadFromDiff ) {
192195 this .version = version ;
193196 this .stateUUID = stateUUID ;
194197 this .clusterName = clusterName ;
@@ -197,6 +200,7 @@ public ClusterState(ClusterName clusterName, long version, String stateUUID, Met
197200 this .nodes = nodes ;
198201 this .blocks = blocks ;
199202 this .customs = customs ;
203+ this .minimumMasterNodesOnPublishingMaster = minimumMasterNodesOnPublishingMaster ;
200204 this .wasReadFromDiff = wasReadFromDiff ;
201205 }
202206
@@ -290,6 +294,17 @@ public Set<VotingConfigExclusion> getVotingConfigExclusions() {
290294 return coordinationMetaData ().getVotingConfigExclusions ();
291295 }
292296
297+ /**
298+ * The node-level `discovery.zen.minimum_master_nodes` setting on the master node that published this cluster state, for use in rolling
299+ * upgrades from 6.x to 7.x. Once all the 6.x master-eligible nodes have left the cluster, the 7.x nodes use this value to determine how
300+ * many master-eligible nodes must be discovered before the cluster can be bootstrapped. Note that this method returns the node-level
301+ * value of this setting, and ignores any cluster-level override that was set via the API. Callers are expected to combine this value
302+ * with any value set in the cluster-level settings. This should be removed once we no longer need support for {@link Version#V_6_7_0}.
303+ */
304+ public int getMinimumMasterNodesOnPublishingMaster () {
305+ return minimumMasterNodesOnPublishingMaster ;
306+ }
307+
293308 // Used for testing and logging to determine how this cluster state was send over the wire
294309 public boolean wasReadFromDiff () {
295310 return wasReadFromDiff ;
@@ -644,7 +659,7 @@ public static class Builder {
644659 private ClusterBlocks blocks = ClusterBlocks .EMPTY_CLUSTER_BLOCK ;
645660 private final ImmutableOpenMap .Builder <String , Custom > customs ;
646661 private boolean fromDiff ;
647-
662+ private int minimumMasterNodesOnPublishingMaster = - 1 ;
648663
649664 public Builder (ClusterState state ) {
650665 this .clusterName = state .clusterName ;
@@ -655,6 +670,7 @@ public Builder(ClusterState state) {
655670 this .metaData = state .metaData ();
656671 this .blocks = state .blocks ();
657672 this .customs = ImmutableOpenMap .builder (state .customs ());
673+ this .minimumMasterNodesOnPublishingMaster = state .minimumMasterNodesOnPublishingMaster ;
658674 this .fromDiff = false ;
659675 }
660676
@@ -715,6 +731,11 @@ public Builder stateUUID(String uuid) {
715731 return this ;
716732 }
717733
734+ public Builder minimumMasterNodesOnPublishingMaster (int minimumMasterNodesOnPublishingMaster ) {
735+ this .minimumMasterNodesOnPublishingMaster = minimumMasterNodesOnPublishingMaster ;
736+ return this ;
737+ }
738+
718739 public Builder putCustom (String type , Custom custom ) {
719740 customs .put (type , custom );
720741 return this ;
@@ -739,7 +760,8 @@ public ClusterState build() {
739760 if (UNKNOWN_UUID .equals (uuid )) {
740761 uuid = UUIDs .randomBase64UUID ();
741762 }
742- return new ClusterState (clusterName , version , uuid , metaData , routingTable , nodes , blocks , customs .build (), fromDiff );
763+ return new ClusterState (clusterName , version , uuid , metaData , routingTable , nodes , blocks , customs .build (),
764+ minimumMasterNodesOnPublishingMaster , fromDiff );
743765 }
744766
745767 public static byte [] toBytes (ClusterState state ) throws IOException {
@@ -782,6 +804,7 @@ public static ClusterState readFrom(StreamInput in, DiscoveryNode localNode) thr
782804 Custom customIndexMetaData = in .readNamedWriteable (Custom .class );
783805 builder .putCustom (customIndexMetaData .getWriteableName (), customIndexMetaData );
784806 }
807+ builder .minimumMasterNodesOnPublishingMaster = in .getVersion ().onOrAfter (Version .V_7_0_0 ) ? in .readVInt () : -1 ;
785808 return builder .build ();
786809 }
787810
@@ -807,6 +830,9 @@ public void writeTo(StreamOutput out) throws IOException {
807830 out .writeNamedWriteable (cursor .value );
808831 }
809832 }
833+ if (out .getVersion ().onOrAfter (Version .V_7_0_0 )) {
834+ out .writeVInt (minimumMasterNodesOnPublishingMaster );
835+ }
810836 }
811837
812838 private static class ClusterStateDiff implements Diff <ClusterState > {
@@ -829,6 +855,8 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
829855
830856 private final Diff <ImmutableOpenMap <String , Custom >> customs ;
831857
858+ private final int minimumMasterNodesOnPublishingMaster ;
859+
832860 ClusterStateDiff (ClusterState before , ClusterState after ) {
833861 fromUuid = before .stateUUID ;
834862 toUuid = after .stateUUID ;
@@ -839,6 +867,7 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
839867 metaData = after .metaData .diff (before .metaData );
840868 blocks = after .blocks .diff (before .blocks );
841869 customs = DiffableUtils .diff (before .customs , after .customs , DiffableUtils .getStringKeySerializer (), CUSTOM_VALUE_SERIALIZER );
870+ minimumMasterNodesOnPublishingMaster = after .minimumMasterNodesOnPublishingMaster ;
842871 }
843872
844873 ClusterStateDiff (StreamInput in , DiscoveryNode localNode ) throws IOException {
@@ -851,6 +880,7 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
851880 metaData = MetaData .readDiffFrom (in );
852881 blocks = ClusterBlocks .readDiffFrom (in );
853882 customs = DiffableUtils .readImmutableOpenMapDiff (in , DiffableUtils .getStringKeySerializer (), CUSTOM_VALUE_SERIALIZER );
883+ minimumMasterNodesOnPublishingMaster = in .getVersion ().onOrAfter (Version .V_7_0_0 ) ? in .readVInt () : -1 ;
854884 }
855885
856886 @ Override
@@ -864,6 +894,9 @@ public void writeTo(StreamOutput out) throws IOException {
864894 metaData .writeTo (out );
865895 blocks .writeTo (out );
866896 customs .writeTo (out );
897+ if (out .getVersion ().onOrAfter (Version .V_7_0_0 )) {
898+ out .writeVInt (minimumMasterNodesOnPublishingMaster );
899+ }
867900 }
868901
869902 @ Override
@@ -883,9 +916,9 @@ public ClusterState apply(ClusterState state) {
883916 builder .metaData (metaData .apply (state .metaData ));
884917 builder .blocks (blocks .apply (state .blocks ));
885918 builder .customs (customs .apply (state .customs ));
919+ builder .minimumMasterNodesOnPublishingMaster (minimumMasterNodesOnPublishingMaster );
886920 builder .fromDiff (true );
887921 return builder .build ();
888922 }
889-
890923 }
891924}
0 commit comments