Skip to content

Commit 49b707b

Browse files
authored
Remove some old metadata serialization conditions (#117825)
1 parent 285a71b commit 49b707b

File tree

2 files changed

+22
-71
lines changed

2 files changed

+22
-71
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ public static IndexMetadata readFrom(StreamInput in, @Nullable Function<String,
17851785
builder.primaryTerms(in.readVLongArray());
17861786
int mappingsSize = in.readVInt();
17871787
if (mappingsSize == 1) {
1788-
if (mappingLookup != null && in.getTransportVersion().onOrAfter(Metadata.MAPPINGS_AS_HASH_VERSION)) {
1788+
if (mappingLookup != null) {
17891789
final String mappingHash = in.readString();
17901790
final MappingMetadata metadata = mappingLookup.apply(mappingHash);
17911791
assert metadata != null : "failed to find mapping [" + mappingHash + "] for [" + builder.index + "]";
@@ -1860,7 +1860,7 @@ public void writeTo(StreamOutput out, boolean mappingsAsHash) throws IOException
18601860
out.writeVInt(0);
18611861
} else {
18621862
out.writeVInt(1);
1863-
if (mappingsAsHash && out.getTransportVersion().onOrAfter(Metadata.MAPPINGS_AS_HASH_VERSION)) {
1863+
if (mappingsAsHash) {
18641864
out.writeString(mapping.getSha256());
18651865
} else {
18661866
mapping.writeTo(out);

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

Lines changed: 20 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.apache.logging.log4j.Logger;
1414
import org.apache.lucene.util.CollectionUtil;
1515
import org.elasticsearch.TransportVersion;
16-
import org.elasticsearch.TransportVersions;
1716
import org.elasticsearch.cluster.ClusterState;
1817
import org.elasticsearch.cluster.Diff;
1918
import org.elasticsearch.cluster.Diffable;
@@ -24,7 +23,6 @@
2423
import org.elasticsearch.cluster.block.ClusterBlock;
2524
import org.elasticsearch.cluster.block.ClusterBlockLevel;
2625
import org.elasticsearch.cluster.coordination.CoordinationMetadata;
27-
import org.elasticsearch.cluster.coordination.PublicationTransportHandler;
2826
import org.elasticsearch.cluster.metadata.IndexAbstraction.ConcreteIndex;
2927
import org.elasticsearch.cluster.routing.RoutingTable;
3028
import org.elasticsearch.common.Strings;
@@ -1495,10 +1493,7 @@ public Diff<Metadata> diff(Metadata previousState) {
14951493
}
14961494

14971495
public static Diff<Metadata> readDiffFrom(StreamInput in) throws IOException {
1498-
if (in.getTransportVersion().onOrAfter(MetadataDiff.NOOP_METADATA_DIFF_VERSION) && in.readBoolean()) {
1499-
return SimpleDiffable.empty();
1500-
}
1501-
return new MetadataDiff(in);
1496+
return in.readBoolean() ? SimpleDiffable.empty() : new MetadataDiff(in);
15021497
}
15031498

15041499
public static Metadata fromXContent(XContentParser parser) throws IOException {
@@ -1552,10 +1547,6 @@ public Map<String, MappingMetadata> getMappingsByHash() {
15521547

15531548
private static class MetadataDiff implements Diff<Metadata> {
15541549

1555-
private static final TransportVersion NOOP_METADATA_DIFF_VERSION = TransportVersions.V_8_5_0;
1556-
private static final TransportVersion NOOP_METADATA_DIFF_SAFE_VERSION =
1557-
PublicationTransportHandler.INCLUDES_LAST_COMMITTED_DATA_VERSION;
1558-
15591550
private final long version;
15601551
private final String clusterUUID;
15611552
private final boolean clusterUUIDCommitted;
@@ -1620,52 +1611,31 @@ private MetadataDiff(StreamInput in) throws IOException {
16201611
coordinationMetadata = new CoordinationMetadata(in);
16211612
transientSettings = Settings.readSettingsFromStream(in);
16221613
persistentSettings = Settings.readSettingsFromStream(in);
1623-
if (in.getTransportVersion().onOrAfter(TransportVersions.V_7_3_0)) {
1624-
hashesOfConsistentSettings = DiffableStringMap.readDiffFrom(in);
1625-
} else {
1626-
hashesOfConsistentSettings = DiffableStringMap.DiffableStringMapDiff.EMPTY;
1627-
}
1614+
hashesOfConsistentSettings = DiffableStringMap.readDiffFrom(in);
16281615
indices = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), INDEX_METADATA_DIFF_VALUE_READER);
16291616
templates = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), TEMPLATES_DIFF_VALUE_READER);
16301617
customs = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), CUSTOM_VALUE_SERIALIZER);
1631-
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_4_0)) {
1632-
reservedStateMetadata = DiffableUtils.readJdkMapDiff(
1633-
in,
1634-
DiffableUtils.getStringKeySerializer(),
1635-
RESERVED_DIFF_VALUE_READER
1636-
);
1637-
} else {
1638-
reservedStateMetadata = DiffableUtils.emptyDiff();
1639-
}
1618+
reservedStateMetadata = DiffableUtils.readJdkMapDiff(in, DiffableUtils.getStringKeySerializer(), RESERVED_DIFF_VALUE_READER);
16401619
}
16411620

16421621
@Override
16431622
public void writeTo(StreamOutput out) throws IOException {
1644-
if (out.getTransportVersion().onOrAfter(NOOP_METADATA_DIFF_SAFE_VERSION)) {
1645-
out.writeBoolean(empty);
1646-
if (empty) {
1647-
// noop diff
1648-
return;
1649-
}
1650-
} else if (out.getTransportVersion().onOrAfter(NOOP_METADATA_DIFF_VERSION)) {
1651-
// noops are not safe with these versions, see #92259
1652-
out.writeBoolean(false);
1623+
out.writeBoolean(empty);
1624+
if (empty) {
1625+
// noop diff
1626+
return;
16531627
}
16541628
out.writeString(clusterUUID);
16551629
out.writeBoolean(clusterUUIDCommitted);
16561630
out.writeLong(version);
16571631
coordinationMetadata.writeTo(out);
16581632
transientSettings.writeTo(out);
16591633
persistentSettings.writeTo(out);
1660-
if (out.getTransportVersion().onOrAfter(TransportVersions.V_7_3_0)) {
1661-
hashesOfConsistentSettings.writeTo(out);
1662-
}
1634+
hashesOfConsistentSettings.writeTo(out);
16631635
indices.writeTo(out);
16641636
templates.writeTo(out);
16651637
customs.writeTo(out);
1666-
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_4_0)) {
1667-
reservedStateMetadata.writeTo(out);
1668-
}
1638+
reservedStateMetadata.writeTo(out);
16691639
}
16701640

16711641
@Override
@@ -1696,8 +1666,6 @@ public Metadata apply(Metadata part) {
16961666
}
16971667
}
16981668

1699-
public static final TransportVersion MAPPINGS_AS_HASH_VERSION = TransportVersions.V_8_1_0;
1700-
17011669
public static Metadata readFrom(StreamInput in) throws IOException {
17021670
Builder builder = new Builder();
17031671
builder.version = in.readLong();
@@ -1706,17 +1674,11 @@ public static Metadata readFrom(StreamInput in) throws IOException {
17061674
builder.coordinationMetadata(new CoordinationMetadata(in));
17071675
builder.transientSettings(readSettingsFromStream(in));
17081676
builder.persistentSettings(readSettingsFromStream(in));
1709-
if (in.getTransportVersion().onOrAfter(TransportVersions.V_7_3_0)) {
1710-
builder.hashesOfConsistentSettings(DiffableStringMap.readFrom(in));
1711-
}
1677+
builder.hashesOfConsistentSettings(DiffableStringMap.readFrom(in));
17121678
final Function<String, MappingMetadata> mappingLookup;
1713-
if (in.getTransportVersion().onOrAfter(MAPPINGS_AS_HASH_VERSION)) {
1714-
final Map<String, MappingMetadata> mappingMetadataMap = in.readMapValues(MappingMetadata::new, MappingMetadata::getSha256);
1715-
if (mappingMetadataMap.size() > 0) {
1716-
mappingLookup = mappingMetadataMap::get;
1717-
} else {
1718-
mappingLookup = null;
1719-
}
1679+
final Map<String, MappingMetadata> mappingMetadataMap = in.readMapValues(MappingMetadata::new, MappingMetadata::getSha256);
1680+
if (mappingMetadataMap.isEmpty() == false) {
1681+
mappingLookup = mappingMetadataMap::get;
17201682
} else {
17211683
mappingLookup = null;
17221684
}
@@ -1733,11 +1695,9 @@ public static Metadata readFrom(StreamInput in) throws IOException {
17331695
Custom customIndexMetadata = in.readNamedWriteable(Custom.class);
17341696
builder.putCustom(customIndexMetadata.getWriteableName(), customIndexMetadata);
17351697
}
1736-
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_4_0)) {
1737-
int reservedStateSize = in.readVInt();
1738-
for (int i = 0; i < reservedStateSize; i++) {
1739-
builder.put(ReservedStateMetadata.readFrom(in));
1740-
}
1698+
int reservedStateSize = in.readVInt();
1699+
for (int i = 0; i < reservedStateSize; i++) {
1700+
builder.put(ReservedStateMetadata.readFrom(in));
17411701
}
17421702
return builder.build();
17431703
}
@@ -1750,24 +1710,15 @@ public void writeTo(StreamOutput out) throws IOException {
17501710
coordinationMetadata.writeTo(out);
17511711
transientSettings.writeTo(out);
17521712
persistentSettings.writeTo(out);
1753-
if (out.getTransportVersion().onOrAfter(TransportVersions.V_7_3_0)) {
1754-
hashesOfConsistentSettings.writeTo(out);
1755-
}
1756-
// Starting in #MAPPINGS_AS_HASH_VERSION we write the mapping metadata first and then write the indices without metadata so that
1757-
// we avoid writing duplicate mappings twice
1758-
if (out.getTransportVersion().onOrAfter(MAPPINGS_AS_HASH_VERSION)) {
1759-
out.writeMapValues(mappingsByHash);
1760-
}
1713+
hashesOfConsistentSettings.writeTo(out);
1714+
out.writeMapValues(mappingsByHash);
17611715
out.writeVInt(indices.size());
1762-
final boolean writeMappingsHash = out.getTransportVersion().onOrAfter(MAPPINGS_AS_HASH_VERSION);
17631716
for (IndexMetadata indexMetadata : this) {
1764-
indexMetadata.writeTo(out, writeMappingsHash);
1717+
indexMetadata.writeTo(out, true);
17651718
}
17661719
out.writeCollection(templates.values());
17671720
VersionedNamedWriteable.writeVersionedWritables(out, customs);
1768-
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_4_0)) {
1769-
out.writeCollection(reservedStateMetadata.values());
1770-
}
1721+
out.writeCollection(reservedStateMetadata.values());
17711722
}
17721723

17731724
public static Builder builder() {

0 commit comments

Comments
 (0)