@@ -41,6 +41,7 @@ public class ClusterMetadataManifest implements Writeable, ToXContentFragment {
41
41
public static final int CODEC_V0 = 0 ; // Older codec version, where we haven't introduced codec versions for manifest.
42
42
public static final int CODEC_V1 = 1 ; // In Codec V1 we have introduced global-metadata and codec version in Manifest file.
43
43
public static final int CODEC_V2 = 2 ; // In Codec V2, there are seperate metadata files rather than a single global metadata file.
44
+ public static final int CODEC_V3 = 3 ; // In Codec V3, we introduce index routing-metadata in manifest file.
44
45
45
46
private static final ParseField CLUSTER_TERM_FIELD = new ParseField ("cluster_term" );
46
47
private static final ParseField STATE_VERSION_FIELD = new ParseField ("state_version" );
@@ -58,6 +59,8 @@ public class ClusterMetadataManifest implements Writeable, ToXContentFragment {
58
59
private static final ParseField UPLOADED_SETTINGS_METADATA = new ParseField ("uploaded_settings_metadata" );
59
60
private static final ParseField UPLOADED_TEMPLATES_METADATA = new ParseField ("uploaded_templates_metadata" );
60
61
private static final ParseField UPLOADED_CUSTOM_METADATA = new ParseField ("uploaded_custom_metadata" );
62
+ private static final ParseField ROUTING_TABLE_VERSION_FIELD = new ParseField ("routing_table_version" );
63
+ private static final ParseField INDICES_ROUTING_FIELD = new ParseField ("indices_routing" );
61
64
62
65
private static ClusterMetadataManifest .Builder manifestV0Builder (Object [] fields ) {
63
66
return ClusterMetadataManifest .builder ()
@@ -86,6 +89,12 @@ private static ClusterMetadataManifest.Builder manifestV2Builder(Object[] fields
86
89
.customMetadataMap (customMetadata (fields ));
87
90
}
88
91
92
+ private static ClusterMetadataManifest .Builder manifestV3Builder (Object [] fields ) {
93
+ return manifestV2Builder (fields ).codecVersion (codecVersion (fields ))
94
+ .routingTableVersion (routingTableVersion (fields ))
95
+ .indicesRouting (indicesRouting (fields ));
96
+ }
97
+
89
98
private static long term (Object [] fields ) {
90
99
return (long ) fields [0 ];
91
100
}
@@ -151,6 +160,14 @@ private static Map<String, UploadedMetadataAttribute> customMetadata(Object[] fi
151
160
return customs .stream ().collect (Collectors .toMap (UploadedMetadataAttribute ::getAttributeName , Function .identity ()));
152
161
}
153
162
163
+ private static long routingTableVersion (Object [] fields ) {
164
+ return (long ) fields [15 ];
165
+ }
166
+
167
+ private static List <UploadedIndexMetadata > indicesRouting (Object [] fields ) {
168
+ return (List <UploadedIndexMetadata >) fields [16 ];
169
+ }
170
+
154
171
private static final ConstructingObjectParser <ClusterMetadataManifest , Void > PARSER_V0 = new ConstructingObjectParser <>(
155
172
"cluster_metadata_manifest" ,
156
173
fields -> manifestV0Builder (fields ).build ()
@@ -166,12 +183,18 @@ private static Map<String, UploadedMetadataAttribute> customMetadata(Object[] fi
166
183
fields -> manifestV2Builder (fields ).build ()
167
184
);
168
185
169
- private static final ConstructingObjectParser <ClusterMetadataManifest , Void > CURRENT_PARSER = PARSER_V2 ;
186
+ private static final ConstructingObjectParser <ClusterMetadataManifest , Void > PARSER_V3 = new ConstructingObjectParser <>(
187
+ "cluster_metadata_manifest" ,
188
+ fields -> manifestV3Builder (fields ).build ()
189
+ );
190
+
191
+ private static final ConstructingObjectParser <ClusterMetadataManifest , Void > CURRENT_PARSER = PARSER_V3 ;
170
192
171
193
static {
172
194
declareParser (PARSER_V0 , CODEC_V0 );
173
195
declareParser (PARSER_V1 , CODEC_V1 );
174
196
declareParser (PARSER_V2 , CODEC_V2 );
197
+ declareParser (PARSER_V3 , CODEC_V3 );
175
198
}
176
199
177
200
private static void declareParser (ConstructingObjectParser <ClusterMetadataManifest , Void > parser , long codec_version ) {
@@ -216,6 +239,14 @@ private static void declareParser(ConstructingObjectParser<ClusterMetadataManife
216
239
UPLOADED_CUSTOM_METADATA
217
240
);
218
241
}
242
+ if (codec_version >= CODEC_V3 ) {
243
+ parser .declareLong (ConstructingObjectParser .constructorArg (), ROUTING_TABLE_VERSION_FIELD );
244
+ parser .declareObjectArray (
245
+ ConstructingObjectParser .constructorArg (),
246
+ (p , c ) -> UploadedIndexMetadata .fromXContent (p ),
247
+ INDICES_ROUTING_FIELD
248
+ );
249
+ }
219
250
}
220
251
221
252
private final int codecVersion ;
@@ -234,6 +265,8 @@ private static void declareParser(ConstructingObjectParser<ClusterMetadataManife
234
265
private final boolean committed ;
235
266
private final String previousClusterUUID ;
236
267
private final boolean clusterUUIDCommitted ;
268
+ private final long routingTableVersion ;
269
+ private final List <UploadedIndexMetadata > indicesRouting ;
237
270
238
271
public List <UploadedIndexMetadata > getIndices () {
239
272
return indices ;
@@ -306,6 +339,14 @@ public boolean hasMetadataAttributesFiles() {
306
339
|| !uploadedCustomMetadataMap .isEmpty ();
307
340
}
308
341
342
+ public long getRoutingTableVersion () {
343
+ return routingTableVersion ;
344
+ }
345
+
346
+ public List <UploadedIndexMetadata > getIndicesRouting () {
347
+ return indicesRouting ;
348
+ }
349
+
309
350
public ClusterMetadataManifest (
310
351
long clusterTerm ,
311
352
long version ,
@@ -322,7 +363,9 @@ public ClusterMetadataManifest(
322
363
UploadedMetadataAttribute uploadedCoordinationMetadata ,
323
364
UploadedMetadataAttribute uploadedSettingsMetadata ,
324
365
UploadedMetadataAttribute uploadedTemplatesMetadata ,
325
- Map <String , UploadedMetadataAttribute > uploadedCustomMetadataMap
366
+ Map <String , UploadedMetadataAttribute > uploadedCustomMetadataMap ,
367
+ long routingTableVersion ,
368
+ List <UploadedIndexMetadata > indicesRouting
326
369
) {
327
370
this .clusterTerm = clusterTerm ;
328
371
this .stateVersion = version ;
@@ -336,6 +379,8 @@ public ClusterMetadataManifest(
336
379
this .indices = Collections .unmodifiableList (indices );
337
380
this .previousClusterUUID = previousClusterUUID ;
338
381
this .clusterUUIDCommitted = clusterUUIDCommitted ;
382
+ this .routingTableVersion = routingTableVersion ;
383
+ this .indicesRouting = Collections .unmodifiableList (indicesRouting );
339
384
this .uploadedCoordinationMetadata = uploadedCoordinationMetadata ;
340
385
this .uploadedSettingsMetadata = uploadedSettingsMetadata ;
341
386
this .uploadedTemplatesMetadata = uploadedTemplatesMetadata ;
@@ -364,20 +409,26 @@ public ClusterMetadataManifest(StreamInput in) throws IOException {
364
409
in .readMap (StreamInput ::readString , UploadedMetadataAttribute ::new )
365
410
);
366
411
this .globalMetadataFileName = null ;
412
+ this .routingTableVersion = in .readLong ();
413
+ this .indicesRouting = Collections .unmodifiableList (in .readList (UploadedIndexMetadata ::new ));
367
414
} else if (in .getVersion ().onOrAfter (Version .V_2_12_0 )) {
368
415
this .codecVersion = in .readInt ();
369
416
this .globalMetadataFileName = in .readString ();
370
417
this .uploadedCoordinationMetadata = null ;
371
418
this .uploadedSettingsMetadata = null ;
372
419
this .uploadedTemplatesMetadata = null ;
373
420
this .uploadedCustomMetadataMap = null ;
421
+ this .routingTableVersion = -1 ;
422
+ this .indicesRouting = null ;
374
423
} else {
375
424
this .codecVersion = CODEC_V0 ; // Default codec
376
425
this .globalMetadataFileName = null ;
377
426
this .uploadedCoordinationMetadata = null ;
378
427
this .uploadedSettingsMetadata = null ;
379
428
this .uploadedTemplatesMetadata = null ;
380
429
this .uploadedCustomMetadataMap = null ;
430
+ this .routingTableVersion = -1 ;
431
+ this .indicesRouting = null ;
381
432
}
382
433
}
383
434
@@ -401,7 +452,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
401
452
builder .startArray (INDICES_FIELD .getPreferredName ());
402
453
{
403
454
for (UploadedIndexMetadata uploadedIndexMetadata : indices ) {
455
+ builder .startObject ();
404
456
uploadedIndexMetadata .toXContent (builder , params );
457
+ builder .endObject ();
405
458
}
406
459
}
407
460
builder .endArray ();
@@ -433,6 +486,18 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
433
486
builder .field (CODEC_VERSION_FIELD .getPreferredName (), getCodecVersion ());
434
487
builder .field (GLOBAL_METADATA_FIELD .getPreferredName (), getGlobalMetadataFileName ());
435
488
}
489
+ if (onOrAfterCodecVersion (CODEC_V3 )) {
490
+ builder .field (ROUTING_TABLE_VERSION_FIELD .getPreferredName (), getRoutingTableVersion ());
491
+ builder .startArray (INDICES_ROUTING_FIELD .getPreferredName ());
492
+ {
493
+ for (UploadedIndexMetadata uploadedIndexMetadata : indicesRouting ) {
494
+ builder .startObject ();
495
+ uploadedIndexMetadata .toXContent (builder , params );
496
+ builder .endObject ();
497
+ }
498
+ }
499
+ builder .endArray ();
500
+ }
436
501
return builder ;
437
502
}
438
503
@@ -454,6 +519,8 @@ public void writeTo(StreamOutput out) throws IOException {
454
519
uploadedSettingsMetadata .writeTo (out );
455
520
uploadedTemplatesMetadata .writeTo (out );
456
521
out .writeMap (uploadedCustomMetadataMap , StreamOutput ::writeString , (o , v ) -> v .writeTo (o ));
522
+ out .writeLong (routingTableVersion );
523
+ out .writeCollection (indicesRouting );
457
524
} else if (out .getVersion ().onOrAfter (Version .V_2_12_0 )) {
458
525
out .writeInt (codecVersion );
459
526
out .writeString (globalMetadataFileName );
@@ -480,7 +547,9 @@ public boolean equals(Object o) {
480
547
&& Objects .equals (previousClusterUUID , that .previousClusterUUID )
481
548
&& Objects .equals (clusterUUIDCommitted , that .clusterUUIDCommitted )
482
549
&& Objects .equals (globalMetadataFileName , that .globalMetadataFileName )
483
- && Objects .equals (codecVersion , that .codecVersion );
550
+ && Objects .equals (codecVersion , that .codecVersion )
551
+ && Objects .equals (routingTableVersion , that .routingTableVersion )
552
+ && Objects .equals (indicesRouting , that .indicesRouting );
484
553
}
485
554
486
555
@ Override
@@ -497,7 +566,9 @@ public int hashCode() {
497
566
nodeId ,
498
567
committed ,
499
568
previousClusterUUID ,
500
- clusterUUIDCommitted
569
+ clusterUUIDCommitted ,
570
+ routingTableVersion ,
571
+ indicesRouting
501
572
);
502
573
}
503
574
@@ -518,6 +589,10 @@ public static ClusterMetadataManifest fromXContentV1(XContentParser parser) thro
518
589
return PARSER_V1 .parse (parser , null );
519
590
}
520
591
592
+ public static ClusterMetadataManifest fromXContentV2 (XContentParser parser ) throws IOException {
593
+ return PARSER_V2 .parse (parser , null );
594
+ }
595
+
521
596
public static ClusterMetadataManifest fromXContent (XContentParser parser ) throws IOException {
522
597
return CURRENT_PARSER .parse (parser , null );
523
598
}
@@ -545,12 +620,24 @@ public static class Builder {
545
620
private String previousClusterUUID ;
546
621
private boolean committed ;
547
622
private boolean clusterUUIDCommitted ;
623
+ private long routingTableVersion ;
624
+ private List <UploadedIndexMetadata > indicesRouting ;
548
625
549
626
public Builder indices (List <UploadedIndexMetadata > indices ) {
550
627
this .indices = indices ;
551
628
return this ;
552
629
}
553
630
631
+ public Builder routingTableVersion (long routingTableVersion ) {
632
+ this .routingTableVersion = routingTableVersion ;
633
+ return this ;
634
+ }
635
+
636
+ public Builder indicesRouting (List <UploadedIndexMetadata > indicesRouting ) {
637
+ this .indicesRouting = indicesRouting ;
638
+ return this ;
639
+ }
640
+
554
641
public Builder codecVersion (int codecVersion ) {
555
642
this .codecVersion = codecVersion ;
556
643
return this ;
@@ -625,6 +712,10 @@ public List<UploadedIndexMetadata> getIndices() {
625
712
return indices ;
626
713
}
627
714
715
+ public List <UploadedIndexMetadata > getIndicesRouting () {
716
+ return indicesRouting ;
717
+ }
718
+
628
719
public Builder previousClusterUUID (String previousClusterUUID ) {
629
720
this .previousClusterUUID = previousClusterUUID ;
630
721
return this ;
@@ -638,6 +729,7 @@ public Builder clusterUUIDCommitted(boolean clusterUUIDCommitted) {
638
729
public Builder () {
639
730
indices = new ArrayList <>();
640
731
customMetadataMap = new HashMap <>();
732
+ indicesRouting = new ArrayList <>();
641
733
}
642
734
643
735
public Builder (ClusterMetadataManifest manifest ) {
@@ -657,6 +749,8 @@ public Builder(ClusterMetadataManifest manifest) {
657
749
this .indices = new ArrayList <>(manifest .indices );
658
750
this .previousClusterUUID = manifest .previousClusterUUID ;
659
751
this .clusterUUIDCommitted = manifest .clusterUUIDCommitted ;
752
+ this .routingTableVersion = manifest .routingTableVersion ;
753
+ this .indicesRouting = new ArrayList <>(manifest .indicesRouting );
660
754
}
661
755
662
756
public ClusterMetadataManifest build () {
@@ -676,7 +770,9 @@ public ClusterMetadataManifest build() {
676
770
coordinationMetadata ,
677
771
settingsMetadata ,
678
772
templatesMetadata ,
679
- customMetadataMap
773
+ customMetadataMap ,
774
+ routingTableVersion ,
775
+ indicesRouting
680
776
);
681
777
}
682
778
@@ -776,11 +872,9 @@ public String getIndexUUID() {
776
872
777
873
@ Override
778
874
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
779
- return builder .startObject ()
780
- .field (INDEX_NAME_FIELD .getPreferredName (), getIndexName ())
875
+ return builder .field (INDEX_NAME_FIELD .getPreferredName (), getIndexName ())
781
876
.field (INDEX_UUID_FIELD .getPreferredName (), getIndexUUID ())
782
- .field (UPLOADED_FILENAME_FIELD .getPreferredName (), getUploadedFilePath ())
783
- .endObject ();
877
+ .field (UPLOADED_FILENAME_FIELD .getPreferredName (), getUploadedFilePath ());
784
878
}
785
879
786
880
@ Override
0 commit comments