4747import org .elasticsearch .common .xcontent .ChunkedToXContentHelper ;
4848import org .elasticsearch .core .Nullable ;
4949import org .elasticsearch .core .SuppressForbidden ;
50+ import org .elasticsearch .core .UpdateForV9 ;
5051import org .elasticsearch .index .shard .IndexLongFieldRange ;
5152import org .elasticsearch .indices .SystemIndexDescriptor ;
5253import org .elasticsearch .xcontent .ToXContent ;
@@ -1025,52 +1026,25 @@ public static ClusterState readFrom(StreamInput in, DiscoveryNode localNode) thr
10251026 builder .metadata = Metadata .readFrom (in );
10261027 builder .routingTable = RoutingTable .readFrom (in );
10271028 builder .nodes = DiscoveryNodes .readFrom (in , localNode );
1028- if (in .getTransportVersion ().onOrAfter (TransportVersions .V_8_8_0 )) {
1029- builder .nodeIdsToCompatibilityVersions (in .readMap (CompatibilityVersions ::readVersion ));
1030- } else {
1031- // this clusterstate is from a pre-8.8.0 node
1032- // infer the versions from discoverynodes for now
1033- // leave mappings versions empty
1034- builder .nodes ()
1035- .getNodes ()
1036- .values ()
1037- .forEach (n -> builder .putCompatibilityVersions (n .getId (), inferTransportVersion (n ), Map .of ()));
1038- }
1039- if (in .getTransportVersion ().onOrAfter (TransportVersions .V_8_12_0 )) {
1040- builder .nodeFeatures (ClusterFeatures .readFrom (in ));
1041- }
1029+ builder .nodeIdsToCompatibilityVersions (in .readMap (CompatibilityVersions ::readVersion ));
1030+ builder .nodeFeatures (ClusterFeatures .readFrom (in ));
10421031 builder .blocks = ClusterBlocks .readFrom (in );
10431032 int customSize = in .readVInt ();
10441033 for (int i = 0 ; i < customSize ; i ++) {
10451034 Custom customIndexMetadata = in .readNamedWriteable (Custom .class );
10461035 builder .putCustom (customIndexMetadata .getWriteableName (), customIndexMetadata );
10471036 }
1048- if (in .getTransportVersion ().before (TransportVersions .V_8_0_0 )) {
1049- in .readVInt (); // used to be minimumMasterNodesOnPublishingMaster, which was used in 7.x for BWC with 6.x
1050- }
10511037 return builder .build ();
10521038 }
10531039
10541040 /**
10551041 * If the cluster state does not contain transport version information, this is the version
10561042 * that is inferred for all nodes on version 8.8.0 or above.
10571043 */
1044+ @ UpdateForV9 (owner = UpdateForV9 .Owner .CORE_INFRA )
10581045 public static final TransportVersion INFERRED_TRANSPORT_VERSION = TransportVersions .V_8_8_0 ;
1059-
10601046 public static final Version VERSION_INTRODUCING_TRANSPORT_VERSIONS = Version .V_8_8_0 ;
10611047
1062- private static TransportVersion inferTransportVersion (DiscoveryNode node ) {
1063- TransportVersion tv ;
1064- if (node .getVersion ().before (VERSION_INTRODUCING_TRANSPORT_VERSIONS )) {
1065- // 1-to-1 mapping between Version and TransportVersion
1066- tv = TransportVersion .fromId (node .getPre811VersionId ().getAsInt ());
1067- } else {
1068- // use the lowest value it could be for now
1069- tv = INFERRED_TRANSPORT_VERSION ;
1070- }
1071- return tv ;
1072- }
1073-
10741048 @ Override
10751049 public void writeTo (StreamOutput out ) throws IOException {
10761050 clusterName .writeTo (out );
@@ -1079,17 +1053,10 @@ public void writeTo(StreamOutput out) throws IOException {
10791053 metadata .writeTo (out );
10801054 routingTable .writeTo (out );
10811055 nodes .writeTo (out );
1082- if (out .getTransportVersion ().onOrAfter (TransportVersions .V_8_8_0 )) {
1083- out .writeMap (compatibilityVersions , StreamOutput ::writeWriteable );
1084- }
1085- if (out .getTransportVersion ().onOrAfter (TransportVersions .V_8_12_0 )) {
1086- clusterFeatures .writeTo (out );
1087- }
1056+ out .writeMap (compatibilityVersions , StreamOutput ::writeWriteable );
1057+ clusterFeatures .writeTo (out );
10881058 blocks .writeTo (out );
10891059 VersionedNamedWriteable .writeVersionedWritables (out , customs );
1090- if (out .getTransportVersion ().before (TransportVersions .V_8_0_0 )) {
1091- out .writeVInt (-1 ); // used to be minimumMasterNodesOnPublishingMaster, which was used in 7.x for BWC with 6.x
1092- }
10931060 }
10941061
10951062 private static class ClusterStateDiff implements Diff <ClusterState > {
@@ -1106,7 +1073,6 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
11061073
11071074 private final Diff <DiscoveryNodes > nodes ;
11081075
1109- @ Nullable
11101076 private final Diff <Map <String , CompatibilityVersions >> versions ;
11111077 private final Diff <ClusterFeatures > features ;
11121078
@@ -1142,26 +1108,13 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
11421108 toVersion = in .readLong ();
11431109 routingTable = RoutingTable .readDiffFrom (in );
11441110 nodes = DiscoveryNodes .readDiffFrom (in , localNode );
1145- if (in .getTransportVersion ().onOrAfter (TransportVersions .V_8_8_0 ) && in .readBoolean ()) {
1146- versions = DiffableUtils .readJdkMapDiff (
1147- in ,
1148- DiffableUtils .getStringKeySerializer (),
1149- COMPATIBILITY_VERSIONS_VALUE_SERIALIZER
1150- );
1151- } else {
1152- versions = null ; // infer at application time
1153- }
1154- if (in .getTransportVersion ().onOrAfter (TransportVersions .V_8_12_0 )) {
1155- features = ClusterFeatures .readDiffFrom (in );
1156- } else {
1157- features = null ; // fill in when nodes re-register with a master that understands features
1158- }
1111+ boolean versionPresent = in .readBoolean ();
1112+ if (versionPresent == false ) throw new IOException ("ClusterStateDiff stream must have versions" );
1113+ versions = DiffableUtils .readJdkMapDiff (in , DiffableUtils .getStringKeySerializer (), COMPATIBILITY_VERSIONS_VALUE_SERIALIZER );
1114+ features = ClusterFeatures .readDiffFrom (in );
11591115 metadata = Metadata .readDiffFrom (in );
11601116 blocks = ClusterBlocks .readDiffFrom (in );
11611117 customs = DiffableUtils .readJdkMapDiff (in , DiffableUtils .getStringKeySerializer (), CUSTOM_VALUE_SERIALIZER );
1162- if (in .getTransportVersion ().before (TransportVersions .V_8_0_0 )) {
1163- in .readVInt (); // used to be minimumMasterNodesOnPublishingMaster, which was used in 7.x for BWC with 6.x
1164- }
11651118 }
11661119
11671120 @ Override
@@ -1172,18 +1125,12 @@ public void writeTo(StreamOutput out) throws IOException {
11721125 out .writeLong (toVersion );
11731126 routingTable .writeTo (out );
11741127 nodes .writeTo (out );
1175- if (out .getTransportVersion ().onOrAfter (TransportVersions .V_8_8_0 )) {
1176- out .writeOptionalWriteable (versions );
1177- }
1178- if (out .getTransportVersion ().onOrAfter (TransportVersions .V_8_12_0 )) {
1179- features .writeTo (out );
1180- }
1128+ out .writeBoolean (true );
1129+ versions .writeTo (out );
1130+ features .writeTo (out );
11811131 metadata .writeTo (out );
11821132 blocks .writeTo (out );
11831133 customs .writeTo (out );
1184- if (out .getTransportVersion ().before (TransportVersions .V_8_0_0 )) {
1185- out .writeVInt (-1 ); // used to be minimumMasterNodesOnPublishingMaster, which was used in 7.x for BWC with 6.x
1186- }
11871134 }
11881135
11891136 @ Override
@@ -1200,19 +1147,8 @@ public ClusterState apply(ClusterState state) {
12001147 builder .version (toVersion );
12011148 builder .routingTable (routingTable .apply (state .routingTable ));
12021149 builder .nodes (nodes .apply (state .nodes ));
1203- if (versions != null ) {
1204- builder .nodeIdsToCompatibilityVersions (this .versions .apply (state .compatibilityVersions ));
1205- } else {
1206- // infer the versions from discoverynodes for now
1207- // leave mappings versions empty
1208- builder .nodes ()
1209- .getNodes ()
1210- .values ()
1211- .forEach (n -> builder .putCompatibilityVersions (n .getId (), inferTransportVersion (n ), Map .of ()));
1212- }
1213- if (features != null ) {
1214- builder .nodeFeatures (this .features .apply (state .clusterFeatures ));
1215- }
1150+ builder .nodeIdsToCompatibilityVersions (this .versions .apply (state .compatibilityVersions ));
1151+ builder .nodeFeatures (this .features .apply (state .clusterFeatures ));
12161152 builder .metadata (metadata .apply (state .metadata ));
12171153 builder .blocks (blocks .apply (state .blocks ));
12181154 builder .customs (customs .apply (state .customs ));
0 commit comments