From 0eb7d3e90a440b5b631e61387d5690f947d83034 Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Thu, 28 Oct 2021 15:55:50 -0400 Subject: [PATCH] [ML] fixing MlMetadata backwards compatibility with 7.x (#80041) Since 7.13, MlMetadata with reset mode has been serializable. But, this was never adjusted in the 8.0.0 branch. This commit fixes a serialization bug currently present in alpha + beta1 releases of Elasticsearch 8.0.0. When MlMetadata exists in a cluster, a rolling upgrade, or mixed-version environment may fail to serialize cluster state between 8.0.0 nodes and nodes 7.13-7.16 --- .../java/org/elasticsearch/xpack/core/ml/MlMetadata.java | 8 ++++---- .../xpack/core/ml/inference/TrainedModelConfig.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java index ed605f4fea43c..1c79ec8bd9819 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java @@ -162,7 +162,7 @@ public MlMetadata(StreamInput in) throws IOException { this.datafeeds = datafeeds; this.groupOrJobLookup = new GroupOrJobLookup(jobs.values()); this.upgradeMode = in.readBoolean(); - if (in.getVersion().onOrAfter(Version.V_8_0_0)) { + if (in.getVersion().onOrAfter(Version.V_7_13_0)) { this.resetMode = in.readBoolean(); } else { this.resetMode = false; @@ -174,7 +174,7 @@ public void writeTo(StreamOutput out) throws IOException { writeMap(jobs, out); writeMap(datafeeds, out); out.writeBoolean(upgradeMode); - if (out.getVersion().onOrAfter(Version.V_8_0_0)) { + if (out.getVersion().onOrAfter(Version.V_7_13_0)) { out.writeBoolean(resetMode); } } @@ -240,7 +240,7 @@ public MlMetadataDiff(StreamInput in) throws IOException { MlMetadataDiff::readDatafeedDiffFrom ); upgradeMode = in.readBoolean(); - if (in.getVersion().onOrAfter(Version.V_8_0_0)) { + if (in.getVersion().onOrAfter(Version.V_7_13_0)) { resetMode = in.readBoolean(); } else { resetMode = false; @@ -264,7 +264,7 @@ public void writeTo(StreamOutput out) throws IOException { jobs.writeTo(out); datafeeds.writeTo(out); out.writeBoolean(upgradeMode); - if (out.getVersion().onOrAfter(Version.V_8_0_0)) { + if (out.getVersion().onOrAfter(Version.V_7_13_0)) { out.writeBoolean(resetMode); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/TrainedModelConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/TrainedModelConfig.java index cad6a3668c223..5e9efc658ab7c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/TrainedModelConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/TrainedModelConfig.java @@ -885,7 +885,7 @@ public static LazyModelDefinition fromBase64String(String base64String) { } public static LazyModelDefinition fromStreamInput(StreamInput input) throws IOException { - if (input.getVersion().onOrAfter(Version.V_8_0_0)) { // TODO adjust on backport + if (input.getVersion().onOrAfter(Version.V_8_0_0)) { return new LazyModelDefinition(input.readBytesReference(), null); } else { return fromBase64String(input.readString()); @@ -949,7 +949,7 @@ private void ensureParsedDefinitionUnsafe(NamedXContentRegistry xContentRegistry @Override public void writeTo(StreamOutput out) throws IOException { - if (out.getVersion().onOrAfter(Version.V_8_0_0)) { // TODO adjust on backport + if (out.getVersion().onOrAfter(Version.V_8_0_0)) { out.writeBytesReference(getCompressedDefinition()); } else { out.writeString(getBase64CompressedDefinition());