|
9 | 9 |
|
10 | 10 | package org.elasticsearch.cluster.metadata; |
11 | 11 |
|
| 12 | +import org.elasticsearch.TransportVersion; |
| 13 | +import org.elasticsearch.TransportVersions; |
12 | 14 | import org.elasticsearch.action.admin.indices.rollover.MaxAgeCondition; |
13 | 15 | import org.elasticsearch.action.admin.indices.rollover.MaxDocsCondition; |
14 | 16 | import org.elasticsearch.action.admin.indices.rollover.MaxPrimaryShardDocsCondition; |
@@ -678,6 +680,34 @@ public void testInferenceFieldMetadata() { |
678 | 680 | assertThat(idxMeta2.getInferenceFields(), equalTo(dynamicFields)); |
679 | 681 | } |
680 | 682 |
|
| 683 | + public void testReshardingBWCSerialization() throws IOException { |
| 684 | + final int numShards = randomIntBetween(1, 8); |
| 685 | + final var settings = indexSettings(IndexVersion.current(), numShards, 0); |
| 686 | + final var reshardingMetadata = IndexReshardingMetadata.newSplitByMultiple(numShards, randomIntBetween(2, 5)); |
| 687 | + IndexMetadata idx = IndexMetadata.builder("test").settings(settings).reshardingMetadata(reshardingMetadata).build(); |
| 688 | + |
| 689 | + // the version prior to TransportVersions.INDEX_RESHARDING_METADATA |
| 690 | + final var version = TransportVersions.ML_INFERENCE_DEEPSEEK; |
| 691 | + // should round trip |
| 692 | + final var deserialized = roundTripWithVersion(idx, version); |
| 693 | + |
| 694 | + // but be missing resharding metadata |
| 695 | + assertNull(deserialized.getReshardingMetadata()); |
| 696 | + // but otherwise be equal |
| 697 | + assertEquals(idx, IndexMetadata.builder(deserialized).reshardingMetadata(reshardingMetadata).build()); |
| 698 | + } |
| 699 | + |
| 700 | + private IndexMetadata roundTripWithVersion(IndexMetadata indexMetadata, TransportVersion version) throws IOException { |
| 701 | + try (BytesStreamOutput out = new BytesStreamOutput()) { |
| 702 | + out.setTransportVersion(version); |
| 703 | + indexMetadata.writeTo(out); |
| 704 | + try (StreamInput in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), writableRegistry())) { |
| 705 | + in.setTransportVersion(version); |
| 706 | + return IndexMetadata.readFrom(in); |
| 707 | + } |
| 708 | + } |
| 709 | + } |
| 710 | + |
681 | 711 | private static Settings indexSettingsWithDataTier(String dataTier) { |
682 | 712 | return indexSettings(IndexVersion.current(), 1, 0).put(DataTier.TIER_PREFERENCE, dataTier).build(); |
683 | 713 | } |
|
0 commit comments