Skip to content

Commit

Permalink
[ML] fixing MlMetadata backwards compatibility with 7.x (elastic#80041)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
benwtrent authored Oct 28, 2021
1 parent f8aec2e commit 0eb7d3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 0eb7d3e

Please sign in to comment.