Skip to content

Commit fa136c9

Browse files
committed
Include resharding metadata in IndexMetadata.equals
Also add a basic BWC serialization test for resharding metadata.
1 parent 10221d1 commit fa136c9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,12 @@ public boolean equals(Object o) {
14831483
if (isSystem != that.isSystem) {
14841484
return false;
14851485
}
1486+
if (reshardingMetadata == null && that.reshardingMetadata != null) {
1487+
return false;
1488+
}
1489+
if (reshardingMetadata != null && reshardingMetadata.equals(that.reshardingMetadata) == false) {
1490+
return false;
1491+
}
14861492
return true;
14871493
}
14881494

@@ -1502,6 +1508,9 @@ public int hashCode() {
15021508
result = 31 * result + rolloverInfos.hashCode();
15031509
result = 31 * result + inferenceFields.hashCode();
15041510
result = 31 * result + Boolean.hashCode(isSystem);
1511+
if (reshardingMetadata != null) {
1512+
result = 31 * result + reshardingMetadata.hashCode();
1513+
}
15051514
return result;
15061515
}
15071516

server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataTests.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
package org.elasticsearch.cluster.metadata;
1111

12+
import org.elasticsearch.TransportVersion;
13+
import org.elasticsearch.TransportVersions;
1214
import org.elasticsearch.action.admin.indices.rollover.MaxAgeCondition;
1315
import org.elasticsearch.action.admin.indices.rollover.MaxDocsCondition;
1416
import org.elasticsearch.action.admin.indices.rollover.MaxPrimaryShardDocsCondition;
@@ -678,6 +680,34 @@ public void testInferenceFieldMetadata() {
678680
assertThat(idxMeta2.getInferenceFields(), equalTo(dynamicFields));
679681
}
680682

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+
681711
private static Settings indexSettingsWithDataTier(String dataTier) {
682712
return indexSettings(IndexVersion.current(), 1, 0).put(DataTier.TIER_PREFERENCE, dataTier).build();
683713
}

0 commit comments

Comments
 (0)