33
33
*/
34
34
public class ClusterMetadataManifest implements Writeable , ToXContentFragment {
35
35
36
+ public static final int CODEC_V0 = 0 ; // Older codec version, where we haven't introduced codec versions for manifest.
37
+ public static final int CODEC_V1 = 1 ; // In Codec V1 we have introduced global-metadata and codec version in Manifest file.
38
+
36
39
private static final ParseField CLUSTER_TERM_FIELD = new ParseField ("cluster_term" );
37
40
private static final ParseField STATE_VERSION_FIELD = new ParseField ("state_version" );
38
41
private static final ParseField CLUSTER_UUID_FIELD = new ParseField ("cluster_uuid" );
39
42
private static final ParseField STATE_UUID_FIELD = new ParseField ("state_uuid" );
40
43
private static final ParseField OPENSEARCH_VERSION_FIELD = new ParseField ("opensearch_version" );
41
44
private static final ParseField NODE_ID_FIELD = new ParseField ("node_id" );
42
45
private static final ParseField COMMITTED_FIELD = new ParseField ("committed" );
46
+ private static final ParseField CODEC_VERSION_FIELD = new ParseField ("codec_version" );
47
+ private static final ParseField GLOBAL_METADATA_FIELD = new ParseField ("global_metadata" );
43
48
private static final ParseField INDICES_FIELD = new ParseField ("indices" );
44
49
private static final ParseField PREVIOUS_CLUSTER_UUID = new ParseField ("previous_cluster_uuid" );
45
50
private static final ParseField CLUSTER_UUID_COMMITTED = new ParseField ("cluster_uuid_committed" );
@@ -84,7 +89,33 @@ private static boolean clusterUUIDCommitted(Object[] fields) {
84
89
return (boolean ) fields [9 ];
85
90
}
86
91
87
- private static final ConstructingObjectParser <ClusterMetadataManifest , Void > PARSER = new ConstructingObjectParser <>(
92
+ private static int codecVersion (Object [] fields ) {
93
+ return (int ) fields [10 ];
94
+ }
95
+
96
+ private static String globalMetadataFileName (Object [] fields ) {
97
+ return (String ) fields [11 ];
98
+ }
99
+
100
+ private static final ConstructingObjectParser <ClusterMetadataManifest , Void > PARSER_V0 = new ConstructingObjectParser <>(
101
+ "cluster_metadata_manifest" ,
102
+ fields -> new ClusterMetadataManifest (
103
+ term (fields ),
104
+ version (fields ),
105
+ clusterUUID (fields ),
106
+ stateUUID (fields ),
107
+ opensearchVersion (fields ),
108
+ nodeId (fields ),
109
+ committed (fields ),
110
+ CODEC_V0 ,
111
+ null ,
112
+ indices (fields ),
113
+ previousClusterUUID (fields ),
114
+ clusterUUIDCommitted (fields )
115
+ )
116
+ );
117
+
118
+ private static final ConstructingObjectParser <ClusterMetadataManifest , Void > PARSER_V1 = new ConstructingObjectParser <>(
88
119
"cluster_metadata_manifest" ,
89
120
fields -> new ClusterMetadataManifest (
90
121
term (fields ),
@@ -94,29 +125,45 @@ private static boolean clusterUUIDCommitted(Object[] fields) {
94
125
opensearchVersion (fields ),
95
126
nodeId (fields ),
96
127
committed (fields ),
128
+ codecVersion (fields ),
129
+ globalMetadataFileName (fields ),
97
130
indices (fields ),
98
131
previousClusterUUID (fields ),
99
132
clusterUUIDCommitted (fields )
100
133
)
101
134
);
102
135
136
+ private static final ConstructingObjectParser <ClusterMetadataManifest , Void > CURRENT_PARSER = PARSER_V1 ;
137
+
103
138
static {
104
- PARSER .declareLong (ConstructingObjectParser .constructorArg (), CLUSTER_TERM_FIELD );
105
- PARSER .declareLong (ConstructingObjectParser .constructorArg (), STATE_VERSION_FIELD );
106
- PARSER .declareString (ConstructingObjectParser .constructorArg (), CLUSTER_UUID_FIELD );
107
- PARSER .declareString (ConstructingObjectParser .constructorArg (), STATE_UUID_FIELD );
108
- PARSER .declareInt (ConstructingObjectParser .constructorArg (), OPENSEARCH_VERSION_FIELD );
109
- PARSER .declareString (ConstructingObjectParser .constructorArg (), NODE_ID_FIELD );
110
- PARSER .declareBoolean (ConstructingObjectParser .constructorArg (), COMMITTED_FIELD );
111
- PARSER .declareObjectArray (
139
+ declareParser (PARSER_V0 , CODEC_V0 );
140
+ declareParser (PARSER_V1 , CODEC_V1 );
141
+ }
142
+
143
+ private static void declareParser (ConstructingObjectParser <ClusterMetadataManifest , Void > parser , long codec_version ) {
144
+ parser .declareLong (ConstructingObjectParser .constructorArg (), CLUSTER_TERM_FIELD );
145
+ parser .declareLong (ConstructingObjectParser .constructorArg (), STATE_VERSION_FIELD );
146
+ parser .declareString (ConstructingObjectParser .constructorArg (), CLUSTER_UUID_FIELD );
147
+ parser .declareString (ConstructingObjectParser .constructorArg (), STATE_UUID_FIELD );
148
+ parser .declareInt (ConstructingObjectParser .constructorArg (), OPENSEARCH_VERSION_FIELD );
149
+ parser .declareString (ConstructingObjectParser .constructorArg (), NODE_ID_FIELD );
150
+ parser .declareBoolean (ConstructingObjectParser .constructorArg (), COMMITTED_FIELD );
151
+ parser .declareObjectArray (
112
152
ConstructingObjectParser .constructorArg (),
113
153
(p , c ) -> UploadedIndexMetadata .fromXContent (p ),
114
154
INDICES_FIELD
115
155
);
116
- PARSER .declareString (ConstructingObjectParser .constructorArg (), PREVIOUS_CLUSTER_UUID );
117
- PARSER .declareBoolean (ConstructingObjectParser .constructorArg (), CLUSTER_UUID_COMMITTED );
156
+ parser .declareString (ConstructingObjectParser .constructorArg (), PREVIOUS_CLUSTER_UUID );
157
+ parser .declareBoolean (ConstructingObjectParser .constructorArg (), CLUSTER_UUID_COMMITTED );
158
+
159
+ if (codec_version >= CODEC_V1 ) {
160
+ parser .declareInt (ConstructingObjectParser .constructorArg (), CODEC_VERSION_FIELD );
161
+ parser .declareString (ConstructingObjectParser .constructorArg (), GLOBAL_METADATA_FIELD );
162
+ }
118
163
}
119
164
165
+ private final int codecVersion ;
166
+ private final String globalMetadataFileName ;
120
167
private final List <UploadedIndexMetadata > indices ;
121
168
private final long clusterTerm ;
122
169
private final long stateVersion ;
@@ -168,6 +215,14 @@ public boolean isClusterUUIDCommitted() {
168
215
return clusterUUIDCommitted ;
169
216
}
170
217
218
+ public int getCodecVersion () {
219
+ return codecVersion ;
220
+ }
221
+
222
+ public String getGlobalMetadataFileName () {
223
+ return globalMetadataFileName ;
224
+ }
225
+
171
226
public ClusterMetadataManifest (
172
227
long clusterTerm ,
173
228
long version ,
@@ -176,6 +231,8 @@ public ClusterMetadataManifest(
176
231
Version opensearchVersion ,
177
232
String nodeId ,
178
233
boolean committed ,
234
+ int codecVersion ,
235
+ String globalMetadataFileName ,
179
236
List <UploadedIndexMetadata > indices ,
180
237
String previousClusterUUID ,
181
238
boolean clusterUUIDCommitted
@@ -187,6 +244,8 @@ public ClusterMetadataManifest(
187
244
this .opensearchVersion = opensearchVersion ;
188
245
this .nodeId = nodeId ;
189
246
this .committed = committed ;
247
+ this .codecVersion = codecVersion ;
248
+ this .globalMetadataFileName = globalMetadataFileName ;
190
249
this .indices = Collections .unmodifiableList (indices );
191
250
this .previousClusterUUID = previousClusterUUID ;
192
251
this .clusterUUIDCommitted = clusterUUIDCommitted ;
@@ -203,6 +262,13 @@ public ClusterMetadataManifest(StreamInput in) throws IOException {
203
262
this .indices = Collections .unmodifiableList (in .readList (UploadedIndexMetadata ::new ));
204
263
this .previousClusterUUID = in .readString ();
205
264
this .clusterUUIDCommitted = in .readBoolean ();
265
+ if (in .getVersion ().onOrAfter (Version .V_3_0_0 )) {
266
+ this .codecVersion = in .readInt ();
267
+ this .globalMetadataFileName = in .readString ();
268
+ } else {
269
+ this .codecVersion = CODEC_V0 ; // Default codec
270
+ this .globalMetadataFileName = null ;
271
+ }
206
272
}
207
273
208
274
public static Builder builder () {
@@ -231,6 +297,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
231
297
builder .endArray ();
232
298
builder .field (PREVIOUS_CLUSTER_UUID .getPreferredName (), getPreviousClusterUUID ());
233
299
builder .field (CLUSTER_UUID_COMMITTED .getPreferredName (), isClusterUUIDCommitted ());
300
+ if (onOrAfterCodecVersion (CODEC_V1 )) {
301
+ builder .field (CODEC_VERSION_FIELD .getPreferredName (), getCodecVersion ());
302
+ builder .field (GLOBAL_METADATA_FIELD .getPreferredName (), getGlobalMetadataFileName ());
303
+ }
234
304
return builder ;
235
305
}
236
306
@@ -246,6 +316,10 @@ public void writeTo(StreamOutput out) throws IOException {
246
316
out .writeCollection (indices );
247
317
out .writeString (previousClusterUUID );
248
318
out .writeBoolean (clusterUUIDCommitted );
319
+ if (out .getVersion ().onOrAfter (Version .V_3_0_0 )) {
320
+ out .writeInt (codecVersion );
321
+ out .writeString (globalMetadataFileName );
322
+ }
249
323
}
250
324
251
325
@ Override
@@ -266,12 +340,16 @@ public boolean equals(Object o) {
266
340
&& Objects .equals (nodeId , that .nodeId )
267
341
&& Objects .equals (committed , that .committed )
268
342
&& Objects .equals (previousClusterUUID , that .previousClusterUUID )
269
- && Objects .equals (clusterUUIDCommitted , that .clusterUUIDCommitted );
343
+ && Objects .equals (clusterUUIDCommitted , that .clusterUUIDCommitted )
344
+ && Objects .equals (globalMetadataFileName , that .globalMetadataFileName )
345
+ && Objects .equals (codecVersion , that .codecVersion );
270
346
}
271
347
272
348
@ Override
273
349
public int hashCode () {
274
350
return Objects .hash (
351
+ codecVersion ,
352
+ globalMetadataFileName ,
275
353
indices ,
276
354
clusterTerm ,
277
355
stateVersion ,
@@ -290,8 +368,16 @@ public String toString() {
290
368
return Strings .toString (MediaTypeRegistry .JSON , this );
291
369
}
292
370
371
+ public boolean onOrAfterCodecVersion (int codecVersion ) {
372
+ return this .codecVersion >= codecVersion ;
373
+ }
374
+
375
+ public static ClusterMetadataManifest fromXContentV0 (XContentParser parser ) throws IOException {
376
+ return PARSER_V0 .parse (parser , null );
377
+ }
378
+
293
379
public static ClusterMetadataManifest fromXContent (XContentParser parser ) throws IOException {
294
- return PARSER .parse (parser , null );
380
+ return CURRENT_PARSER .parse (parser , null );
295
381
}
296
382
297
383
/**
@@ -301,6 +387,8 @@ public static ClusterMetadataManifest fromXContent(XContentParser parser) throws
301
387
*/
302
388
public static class Builder {
303
389
390
+ private String globalMetadataFileName ;
391
+ private int codecVersion ;
304
392
private List <UploadedIndexMetadata > indices ;
305
393
private long clusterTerm ;
306
394
private long stateVersion ;
@@ -317,6 +405,16 @@ public Builder indices(List<UploadedIndexMetadata> indices) {
317
405
return this ;
318
406
}
319
407
408
+ public Builder codecVersion (int codecVersion ) {
409
+ this .codecVersion = codecVersion ;
410
+ return this ;
411
+ }
412
+
413
+ public Builder globalMetadataFileName (String globalMetadataFileName ) {
414
+ this .globalMetadataFileName = globalMetadataFileName ;
415
+ return this ;
416
+ }
417
+
320
418
public Builder clusterTerm (long clusterTerm ) {
321
419
this .clusterTerm = clusterTerm ;
322
420
return this ;
@@ -378,6 +476,8 @@ public Builder(ClusterMetadataManifest manifest) {
378
476
this .opensearchVersion = manifest .opensearchVersion ;
379
477
this .nodeId = manifest .nodeId ;
380
478
this .committed = manifest .committed ;
479
+ this .globalMetadataFileName = manifest .globalMetadataFileName ;
480
+ this .codecVersion = manifest .codecVersion ;
381
481
this .indices = new ArrayList <>(manifest .indices );
382
482
this .previousClusterUUID = manifest .previousClusterUUID ;
383
483
this .clusterUUIDCommitted = manifest .clusterUUIDCommitted ;
@@ -392,6 +492,8 @@ public ClusterMetadataManifest build() {
392
492
opensearchVersion ,
393
493
nodeId ,
394
494
committed ,
495
+ codecVersion ,
496
+ globalMetadataFileName ,
395
497
indices ,
396
498
previousClusterUUID ,
397
499
clusterUUIDCommitted
0 commit comments