23
23
import com .carrotsearch .hppc .cursors .ObjectCursor ;
24
24
import com .carrotsearch .hppc .cursors .ObjectObjectCursor ;
25
25
26
+ import org .elasticsearch .Version ;
26
27
import org .elasticsearch .client .transport .TransportClient ;
27
28
import org .elasticsearch .cluster .block .ClusterBlock ;
28
29
import org .elasticsearch .cluster .block .ClusterBlocks ;
@@ -178,17 +179,19 @@ default boolean isPrivate() {
178
179
179
180
private final boolean wasReadFromDiff ;
180
181
182
+ private final int minimumMasterNodesOnPublishingMaster ;
183
+
181
184
// built on demand
182
185
private volatile RoutingNodes routingNodes ;
183
186
184
187
public ClusterState (long version , String stateUUID , ClusterState state ) {
185
188
this (state .clusterName , version , stateUUID , state .metaData (), state .routingTable (), state .nodes (), state .blocks (),
186
- state .customs (), false );
189
+ state .customs (), - 1 , false );
187
190
}
188
191
189
192
public ClusterState (ClusterName clusterName , long version , String stateUUID , MetaData metaData , RoutingTable routingTable ,
190
193
DiscoveryNodes nodes , ClusterBlocks blocks , ImmutableOpenMap <String , Custom > customs ,
191
- boolean wasReadFromDiff ) {
194
+ int minimumMasterNodesOnPublishingMaster , boolean wasReadFromDiff ) {
192
195
this .version = version ;
193
196
this .stateUUID = stateUUID ;
194
197
this .clusterName = clusterName ;
@@ -197,6 +200,7 @@ public ClusterState(ClusterName clusterName, long version, String stateUUID, Met
197
200
this .nodes = nodes ;
198
201
this .blocks = blocks ;
199
202
this .customs = customs ;
203
+ this .minimumMasterNodesOnPublishingMaster = minimumMasterNodesOnPublishingMaster ;
200
204
this .wasReadFromDiff = wasReadFromDiff ;
201
205
}
202
206
@@ -290,6 +294,17 @@ public Set<VotingConfigExclusion> getVotingConfigExclusions() {
290
294
return coordinationMetaData ().getVotingConfigExclusions ();
291
295
}
292
296
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
+
293
308
// Used for testing and logging to determine how this cluster state was send over the wire
294
309
public boolean wasReadFromDiff () {
295
310
return wasReadFromDiff ;
@@ -644,7 +659,7 @@ public static class Builder {
644
659
private ClusterBlocks blocks = ClusterBlocks .EMPTY_CLUSTER_BLOCK ;
645
660
private final ImmutableOpenMap .Builder <String , Custom > customs ;
646
661
private boolean fromDiff ;
647
-
662
+ private int minimumMasterNodesOnPublishingMaster = - 1 ;
648
663
649
664
public Builder (ClusterState state ) {
650
665
this .clusterName = state .clusterName ;
@@ -655,6 +670,7 @@ public Builder(ClusterState state) {
655
670
this .metaData = state .metaData ();
656
671
this .blocks = state .blocks ();
657
672
this .customs = ImmutableOpenMap .builder (state .customs ());
673
+ this .minimumMasterNodesOnPublishingMaster = state .minimumMasterNodesOnPublishingMaster ;
658
674
this .fromDiff = false ;
659
675
}
660
676
@@ -715,6 +731,11 @@ public Builder stateUUID(String uuid) {
715
731
return this ;
716
732
}
717
733
734
+ public Builder minimumMasterNodesOnPublishingMaster (int minimumMasterNodesOnPublishingMaster ) {
735
+ this .minimumMasterNodesOnPublishingMaster = minimumMasterNodesOnPublishingMaster ;
736
+ return this ;
737
+ }
738
+
718
739
public Builder putCustom (String type , Custom custom ) {
719
740
customs .put (type , custom );
720
741
return this ;
@@ -739,7 +760,8 @@ public ClusterState build() {
739
760
if (UNKNOWN_UUID .equals (uuid )) {
740
761
uuid = UUIDs .randomBase64UUID ();
741
762
}
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 );
743
765
}
744
766
745
767
public static byte [] toBytes (ClusterState state ) throws IOException {
@@ -782,6 +804,7 @@ public static ClusterState readFrom(StreamInput in, DiscoveryNode localNode) thr
782
804
Custom customIndexMetaData = in .readNamedWriteable (Custom .class );
783
805
builder .putCustom (customIndexMetaData .getWriteableName (), customIndexMetaData );
784
806
}
807
+ builder .minimumMasterNodesOnPublishingMaster = in .getVersion ().onOrAfter (Version .V_7_0_0 ) ? in .readVInt () : -1 ;
785
808
return builder .build ();
786
809
}
787
810
@@ -807,6 +830,9 @@ public void writeTo(StreamOutput out) throws IOException {
807
830
out .writeNamedWriteable (cursor .value );
808
831
}
809
832
}
833
+ if (out .getVersion ().onOrAfter (Version .V_7_0_0 )) {
834
+ out .writeVInt (minimumMasterNodesOnPublishingMaster );
835
+ }
810
836
}
811
837
812
838
private static class ClusterStateDiff implements Diff <ClusterState > {
@@ -829,6 +855,8 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
829
855
830
856
private final Diff <ImmutableOpenMap <String , Custom >> customs ;
831
857
858
+ private final int minimumMasterNodesOnPublishingMaster ;
859
+
832
860
ClusterStateDiff (ClusterState before , ClusterState after ) {
833
861
fromUuid = before .stateUUID ;
834
862
toUuid = after .stateUUID ;
@@ -839,6 +867,7 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
839
867
metaData = after .metaData .diff (before .metaData );
840
868
blocks = after .blocks .diff (before .blocks );
841
869
customs = DiffableUtils .diff (before .customs , after .customs , DiffableUtils .getStringKeySerializer (), CUSTOM_VALUE_SERIALIZER );
870
+ minimumMasterNodesOnPublishingMaster = after .minimumMasterNodesOnPublishingMaster ;
842
871
}
843
872
844
873
ClusterStateDiff (StreamInput in , DiscoveryNode localNode ) throws IOException {
@@ -851,6 +880,7 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
851
880
metaData = MetaData .readDiffFrom (in );
852
881
blocks = ClusterBlocks .readDiffFrom (in );
853
882
customs = DiffableUtils .readImmutableOpenMapDiff (in , DiffableUtils .getStringKeySerializer (), CUSTOM_VALUE_SERIALIZER );
883
+ minimumMasterNodesOnPublishingMaster = in .getVersion ().onOrAfter (Version .V_7_0_0 ) ? in .readVInt () : -1 ;
854
884
}
855
885
856
886
@ Override
@@ -864,6 +894,9 @@ public void writeTo(StreamOutput out) throws IOException {
864
894
metaData .writeTo (out );
865
895
blocks .writeTo (out );
866
896
customs .writeTo (out );
897
+ if (out .getVersion ().onOrAfter (Version .V_7_0_0 )) {
898
+ out .writeVInt (minimumMasterNodesOnPublishingMaster );
899
+ }
867
900
}
868
901
869
902
@ Override
@@ -883,9 +916,9 @@ public ClusterState apply(ClusterState state) {
883
916
builder .metaData (metaData .apply (state .metaData ));
884
917
builder .blocks (blocks .apply (state .blocks ));
885
918
builder .customs (customs .apply (state .customs ));
919
+ builder .minimumMasterNodesOnPublishingMaster (minimumMasterNodesOnPublishingMaster );
886
920
builder .fromDiff (true );
887
921
return builder .build ();
888
922
}
889
-
890
923
}
891
924
}
0 commit comments