@@ -88,6 +88,7 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, To
88
88
private static final Logger logger = LogManager .getLogger (MetaData .class );
89
89
90
90
public static final String ALL = "_all" ;
91
+ public static final String UNKNOWN_CLUSTER_UUID = "_na_" ;
91
92
92
93
public enum XContentContext {
93
94
/* Custom metadata should be returns as part of API call */
@@ -159,6 +160,7 @@ public interface Custom extends NamedDiffable<Custom>, ToXContentFragment, Clust
159
160
private static final NamedDiffableValueSerializer <Custom > CUSTOM_VALUE_SERIALIZER = new NamedDiffableValueSerializer <>(Custom .class );
160
161
161
162
private final String clusterUUID ;
163
+ private final boolean clusterUUIDCommitted ;
162
164
private final long version ;
163
165
164
166
private final CoordinationMetaData coordinationMetaData ;
@@ -179,12 +181,13 @@ public interface Custom extends NamedDiffable<Custom>, ToXContentFragment, Clust
179
181
180
182
private final SortedMap <String , AliasOrIndex > aliasAndIndexLookup ;
181
183
182
- MetaData (String clusterUUID , long version , CoordinationMetaData coordinationMetaData ,
184
+ MetaData (String clusterUUID , boolean clusterUUIDCommitted , long version , CoordinationMetaData coordinationMetaData ,
183
185
Settings transientSettings , Settings persistentSettings ,
184
186
ImmutableOpenMap <String , IndexMetaData > indices , ImmutableOpenMap <String , IndexTemplateMetaData > templates ,
185
187
ImmutableOpenMap <String , Custom > customs , String [] allIndices , String [] allOpenIndices , String [] allClosedIndices ,
186
188
SortedMap <String , AliasOrIndex > aliasAndIndexLookup ) {
187
189
this .clusterUUID = clusterUUID ;
190
+ this .clusterUUIDCommitted = clusterUUIDCommitted ;
188
191
this .version = version ;
189
192
this .coordinationMetaData = coordinationMetaData ;
190
193
this .transientSettings = transientSettings ;
@@ -218,6 +221,14 @@ public String clusterUUID() {
218
221
return this .clusterUUID ;
219
222
}
220
223
224
+ /**
225
+ * Whether the current node with the given cluster state is locked into the cluster with the UUID returned by {@link #clusterUUID()},
226
+ * meaning that it will not accept any cluster state with a different clusterUUID.
227
+ */
228
+ public boolean clusterUUIDCommitted () {
229
+ return this .clusterUUIDCommitted ;
230
+ }
231
+
221
232
/**
222
233
* Returns the merged transient and persistent settings.
223
234
*/
@@ -757,6 +768,12 @@ public static boolean isGlobalStateEquals(MetaData metaData1, MetaData metaData2
757
768
if (!metaData1 .templates .equals (metaData2 .templates ())) {
758
769
return false ;
759
770
}
771
+ if (!metaData1 .clusterUUID .equals (metaData2 .clusterUUID )) {
772
+ return false ;
773
+ }
774
+ if (metaData1 .clusterUUIDCommitted != metaData2 .clusterUUIDCommitted ) {
775
+ return false ;
776
+ }
760
777
// Check if any persistent metadata needs to be saved
761
778
int customCount1 = 0 ;
762
779
for (ObjectObjectCursor <String , Custom > cursor : metaData1 .customs ) {
@@ -798,6 +815,7 @@ private static class MetaDataDiff implements Diff<MetaData> {
798
815
799
816
private long version ;
800
817
private String clusterUUID ;
818
+ private boolean clusterUUIDCommitted ;
801
819
private CoordinationMetaData coordinationMetaData ;
802
820
private Settings transientSettings ;
803
821
private Settings persistentSettings ;
@@ -807,6 +825,7 @@ private static class MetaDataDiff implements Diff<MetaData> {
807
825
808
826
MetaDataDiff (MetaData before , MetaData after ) {
809
827
clusterUUID = after .clusterUUID ;
828
+ clusterUUIDCommitted = after .clusterUUIDCommitted ;
810
829
version = after .version ;
811
830
coordinationMetaData = after .coordinationMetaData ;
812
831
transientSettings = after .transientSettings ;
@@ -818,8 +837,11 @@ private static class MetaDataDiff implements Diff<MetaData> {
818
837
819
838
MetaDataDiff (StreamInput in ) throws IOException {
820
839
clusterUUID = in .readString ();
840
+ if (in .getVersion ().onOrAfter (Version .V_7_0_0 )) {
841
+ clusterUUIDCommitted = in .readBoolean ();
842
+ }
821
843
version = in .readLong ();
822
- if (in .getVersion ().onOrAfter (Version .V_7_0_0 )) { //TODO revisit after Zen2 BWC is implemented
844
+ if (in .getVersion ().onOrAfter (Version .V_7_0_0 )) {
823
845
coordinationMetaData = new CoordinationMetaData (in );
824
846
} else {
825
847
coordinationMetaData = CoordinationMetaData .EMPTY_META_DATA ;
@@ -836,6 +858,9 @@ private static class MetaDataDiff implements Diff<MetaData> {
836
858
@ Override
837
859
public void writeTo (StreamOutput out ) throws IOException {
838
860
out .writeString (clusterUUID );
861
+ if (out .getVersion ().onOrAfter (Version .V_7_0_0 )) {
862
+ out .writeBoolean (clusterUUIDCommitted );
863
+ }
839
864
out .writeLong (version );
840
865
if (out .getVersion ().onOrAfter (Version .V_7_0_0 )) {
841
866
coordinationMetaData .writeTo (out );
@@ -851,6 +876,7 @@ public void writeTo(StreamOutput out) throws IOException {
851
876
public MetaData apply (MetaData part ) {
852
877
Builder builder = builder ();
853
878
builder .clusterUUID (clusterUUID );
879
+ builder .clusterUUIDCommitted (clusterUUIDCommitted );
854
880
builder .version (version );
855
881
builder .coordinationMetaData (coordinationMetaData );
856
882
builder .transientSettings (transientSettings );
@@ -866,6 +892,9 @@ public static MetaData readFrom(StreamInput in) throws IOException {
866
892
Builder builder = new Builder ();
867
893
builder .version = in .readLong ();
868
894
builder .clusterUUID = in .readString ();
895
+ if (in .getVersion ().onOrAfter (Version .V_7_0_0 )) {
896
+ builder .clusterUUIDCommitted = in .readBoolean ();
897
+ }
869
898
if (in .getVersion ().onOrAfter (Version .V_7_0_0 )) {
870
899
builder .coordinationMetaData (new CoordinationMetaData (in ));
871
900
}
@@ -891,6 +920,9 @@ public static MetaData readFrom(StreamInput in) throws IOException {
891
920
public void writeTo (StreamOutput out ) throws IOException {
892
921
out .writeLong (version );
893
922
out .writeString (clusterUUID );
923
+ if (out .getVersion ().onOrAfter (Version .V_7_0_0 )) {
924
+ out .writeBoolean (clusterUUIDCommitted );
925
+ }
894
926
if (out .getVersion ().onOrAfter (Version .V_7_0_0 )) {
895
927
coordinationMetaData .writeTo (out );
896
928
}
@@ -930,6 +962,7 @@ public static Builder builder(MetaData metaData) {
930
962
public static class Builder {
931
963
932
964
private String clusterUUID ;
965
+ private boolean clusterUUIDCommitted ;
933
966
private long version ;
934
967
935
968
private CoordinationMetaData coordinationMetaData = CoordinationMetaData .EMPTY_META_DATA ;
@@ -941,7 +974,7 @@ public static class Builder {
941
974
private final ImmutableOpenMap .Builder <String , Custom > customs ;
942
975
943
976
public Builder () {
944
- clusterUUID = "_na_" ;
977
+ clusterUUID = UNKNOWN_CLUSTER_UUID ;
945
978
indices = ImmutableOpenMap .builder ();
946
979
templates = ImmutableOpenMap .builder ();
947
980
customs = ImmutableOpenMap .builder ();
@@ -950,6 +983,7 @@ public Builder() {
950
983
951
984
public Builder (MetaData metaData ) {
952
985
this .clusterUUID = metaData .clusterUUID ;
986
+ this .clusterUUIDCommitted = metaData .clusterUUIDCommitted ;
953
987
this .coordinationMetaData = metaData .coordinationMetaData ;
954
988
this .transientSettings = metaData .transientSettings ;
955
989
this .persistentSettings = metaData .persistentSettings ;
@@ -1125,8 +1159,13 @@ public Builder clusterUUID(String clusterUUID) {
1125
1159
return this ;
1126
1160
}
1127
1161
1162
+ public Builder clusterUUIDCommitted (boolean clusterUUIDCommitted ) {
1163
+ this .clusterUUIDCommitted = clusterUUIDCommitted ;
1164
+ return this ;
1165
+ }
1166
+
1128
1167
public Builder generateClusterUuidIfNeeded () {
1129
- if (clusterUUID .equals ("_na_" )) {
1168
+ if (clusterUUID .equals (UNKNOWN_CLUSTER_UUID )) {
1130
1169
clusterUUID = UUIDs .randomBase64UUID ();
1131
1170
}
1132
1171
return this ;
@@ -1182,8 +1221,9 @@ public MetaData build() {
1182
1221
String [] allOpenIndicesArray = allOpenIndices .toArray (new String [allOpenIndices .size ()]);
1183
1222
String [] allClosedIndicesArray = allClosedIndices .toArray (new String [allClosedIndices .size ()]);
1184
1223
1185
- return new MetaData (clusterUUID , version , coordinationMetaData , transientSettings , persistentSettings , indices .build (),
1186
- templates .build (), customs .build (), allIndicesArray , allOpenIndicesArray , allClosedIndicesArray , aliasAndIndexLookup );
1224
+ return new MetaData (clusterUUID , clusterUUIDCommitted , version , coordinationMetaData , transientSettings , persistentSettings ,
1225
+ indices .build (), templates .build (), customs .build (), allIndicesArray , allOpenIndicesArray , allClosedIndicesArray ,
1226
+ aliasAndIndexLookup );
1187
1227
}
1188
1228
1189
1229
private SortedMap <String , AliasOrIndex > buildAliasAndIndexLookup () {
@@ -1226,6 +1266,7 @@ public static void toXContent(MetaData metaData, XContentBuilder builder, ToXCon
1226
1266
1227
1267
builder .field ("version" , metaData .version ());
1228
1268
builder .field ("cluster_uuid" , metaData .clusterUUID );
1269
+ builder .field ("cluster_uuid_committed" , metaData .clusterUUIDCommitted );
1229
1270
1230
1271
builder .startObject ("cluster_coordination" );
1231
1272
metaData .coordinationMetaData ().toXContent (builder , params );
@@ -1324,6 +1365,8 @@ public static MetaData fromXContent(XContentParser parser) throws IOException {
1324
1365
builder .version = parser .longValue ();
1325
1366
} else if ("cluster_uuid" .equals (currentFieldName ) || "uuid" .equals (currentFieldName )) {
1326
1367
builder .clusterUUID = parser .text ();
1368
+ } else if ("cluster_uuid_committed" .equals (currentFieldName )) {
1369
+ builder .clusterUUIDCommitted = parser .booleanValue ();
1327
1370
} else {
1328
1371
throw new IllegalArgumentException ("Unexpected field [" + currentFieldName + "]" );
1329
1372
}
0 commit comments