diff --git a/server/src/main/java/org/elasticsearch/TransportVersions.java b/server/src/main/java/org/elasticsearch/TransportVersions.java index f2b52349fa210..60255891ec98d 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersions.java +++ b/server/src/main/java/org/elasticsearch/TransportVersions.java @@ -150,6 +150,8 @@ static TransportVersion def(int id) { public static final TransportVersion ML_INFERENCE_DEEPSEEK_8_19 = def(8_841_0_09); public static final TransportVersion ESQL_SERIALIZE_BLOCK_TYPE_CODE_8_19 = def(8_841_0_10); public static final TransportVersion ESQL_FAILURE_FROM_REMOTE_8_19 = def(8_841_0_11); + public static final TransportVersion ESQL_AGGREGATE_METRIC_DOUBLE_LITERAL_8_19 = def(8_841_0_12); + public static final TransportVersion INFERENCE_MODEL_REGISTRY_METADATA_8_19 = def(8_841_0_13); public static final TransportVersion INITIAL_ELASTICSEARCH_9_0 = def(9_000_0_00); public static final TransportVersion REMOVE_SNAPSHOT_FAILURES_90 = def(9_000_0_01); public static final TransportVersion TRANSPORT_STATS_HANDLING_TIME_REQUIRED_90 = def(9_000_0_02); diff --git a/server/src/main/java/org/elasticsearch/cluster/NamedDiff.java b/server/src/main/java/org/elasticsearch/cluster/NamedDiff.java index cae73963dde96..ad4837c06f5d4 100644 --- a/server/src/main/java/org/elasticsearch/cluster/NamedDiff.java +++ b/server/src/main/java/org/elasticsearch/cluster/NamedDiff.java @@ -17,8 +17,23 @@ */ public interface NamedDiff> extends Diff, NamedWriteable { /** - * The minimal version of the recipient this custom object can be sent to + * The minimal version of the recipient this object can be sent to. + * See {@link #supportsVersion(TransportVersion)} for the default serialization check. */ TransportVersion getMinimalSupportedVersion(); + /** + * Determines whether this instance should be serialized based on the provided transport version. + * + * The default implementation returns {@code true} if the given transport version is + * equal to or newer than {@link #getMinimalSupportedVersion()}. + * Subclasses may override this method to define custom serialization logic. + * + * @param version the transport version of the receiving node + * @return {@code true} if the instance should be serialized, {@code false} otherwise + */ + default boolean supportsVersion(TransportVersion version) { + return version.onOrAfter(getMinimalSupportedVersion()); + } + } diff --git a/server/src/main/java/org/elasticsearch/cluster/NamedDiffableValueSerializer.java b/server/src/main/java/org/elasticsearch/cluster/NamedDiffableValueSerializer.java index 0600ec9b95d8b..4a2795bb15411 100644 --- a/server/src/main/java/org/elasticsearch/cluster/NamedDiffableValueSerializer.java +++ b/server/src/main/java/org/elasticsearch/cluster/NamedDiffableValueSerializer.java @@ -32,12 +32,12 @@ public T read(StreamInput in, String key) throws IOException { @Override public boolean supportsVersion(Diff value, TransportVersion version) { - return version.onOrAfter(((NamedDiff) value).getMinimalSupportedVersion()); + return ((NamedDiff) value).supportsVersion(version); } @Override public boolean supportsVersion(T value, TransportVersion version) { - return version.onOrAfter(value.getMinimalSupportedVersion()); + return value.supportsVersion(version); } @SuppressWarnings("unchecked") diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java b/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java index a81491c4b3068..11d9730948d25 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java @@ -25,26 +25,28 @@ public interface VersionedNamedWriteable extends NamedWriteable { String getWriteableName(); /** - * The minimal version of the recipient this object can be sent to + * The minimal version of the recipient this object can be sent to. + * See {@link #supportsVersion(TransportVersion)} for the default serialization check. */ TransportVersion getMinimalSupportedVersion(); /** - * Tests whether or not the custom should be serialized. The criteria is the output stream must be at least the minimum supported - * version of the custom. That is, we only serialize customs to clients than can understand the custom based on the version of the - * client. + * Determines whether this instance should be serialized based on the provided transport version. * - * @param out the output stream - * @param custom the custom to serialize - * @param the type of the custom - * @return true if the custom should be serialized and false otherwise + * The default implementation returns {@code true} if the given transport version is + * equal to or newer than {@link #getMinimalSupportedVersion()}. + * Subclasses may override this method to define custom serialization logic. + * + * @param version the transport version of the receiving node + * @return {@code true} if the instance should be serialized, {@code false} otherwise */ - static boolean shouldSerialize(final StreamOutput out, final T custom) { - return out.getTransportVersion().onOrAfter(custom.getMinimalSupportedVersion()); + default boolean supportsVersion(TransportVersion version) { + return version.onOrAfter(getMinimalSupportedVersion()); } /** - * Writes all those values in the given map to {@code out} that pass the version check in {@link #shouldSerialize} as a list. + * Writes all those values in the given map to {@code out} that pass the version check in + * {@link VersionedNamedWriteable#supportsVersion} as a list. * * @param out stream to write to * @param customs map of customs @@ -58,13 +60,13 @@ static void writeVersionedWriteables(StreamOutput out, Iterable> filteredTasks = tasks().stream() - .filter(t -> VersionedNamedWriteable.shouldSerialize(out, t.getParams())) + .filter(t -> t.getParams().supportsVersion(out.getTransportVersion())) .collect(Collectors.toMap(PersistentTask::getId, Function.identity())); out.writeMap(filteredTasks, StreamOutput::writeWriteable); } diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/OperatorStatus.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/OperatorStatus.java index 7576661decf20..6d83338faf7c5 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/OperatorStatus.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/OperatorStatus.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.VersionedNamedWriteable; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.core.Nullable; import org.elasticsearch.xcontent.ToXContentObject; @@ -33,7 +32,7 @@ public static OperatorStatus readFrom(StreamInput in) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(operator); - out.writeOptionalNamedWriteable(status != null && VersionedNamedWriteable.shouldSerialize(out, status) ? status : null); + out.writeOptionalNamedWriteable(status != null && status.supportsVersion(out.getTransportVersion()) ? status : null); } @Override diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/registry/ModelRegistryMetadata.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/registry/ModelRegistryMetadata.java index 4ac7dd09c45ba..57cd7747737c5 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/registry/ModelRegistryMetadata.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/registry/ModelRegistryMetadata.java @@ -38,6 +38,8 @@ import java.util.Objects; import java.util.Set; +import static org.elasticsearch.TransportVersions.INFERENCE_MODEL_REGISTRY_METADATA; +import static org.elasticsearch.TransportVersions.INFERENCE_MODEL_REGISTRY_METADATA_8_19; import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; @@ -234,7 +236,12 @@ public String getWriteableName() { @Override public TransportVersion getMinimalSupportedVersion() { - return TransportVersions.INFERENCE_MODEL_REGISTRY_METADATA; + return INFERENCE_MODEL_REGISTRY_METADATA_8_19; + } + + @Override + public boolean supportsVersion(TransportVersion version) { + return shouldSerialize(version); } @Override @@ -300,7 +307,12 @@ public String getWriteableName() { @Override public TransportVersion getMinimalSupportedVersion() { - return TransportVersions.INFERENCE_MODEL_REGISTRY_METADATA; + return INFERENCE_MODEL_REGISTRY_METADATA_8_19; + } + + @Override + public boolean supportsVersion(TransportVersion version) { + return shouldSerialize(version); } @Override @@ -313,4 +325,8 @@ public Metadata.ProjectCustom apply(Metadata.ProjectCustom part) { } } } + + static boolean shouldSerialize(TransportVersion version) { + return version.isPatchFrom(INFERENCE_MODEL_REGISTRY_METADATA_8_19) || version.onOrAfter(INFERENCE_MODEL_REGISTRY_METADATA); + } }