From 87f5a7c22aa7da38aa9577d7abcf695f13a6e5a4 Mon Sep 17 00:00:00 2001 From: Andrei Dan Date: Tue, 7 Dec 2021 12:40:49 +0000 Subject: [PATCH] Implement getMinimalSupportedVersion for all NameDiffs (#81374) (#81408) This removes the default implementation of `getMinimalSupportedVersion` and implements it in all `NameDiffs` implementations. The default implementation was rather broad, `minimumIndexCompatibilityVersion` as the index compatibility are wider than our wire compatibility. Having a default implementation also had the implementors forget about adjusting the wire compatibility to the correct version. --- .../src/main/java/org/elasticsearch/cluster/NamedDiff.java | 4 +--- .../cluster/metadata/ComponentTemplateMetadata.java | 5 +++++ .../cluster/metadata/ComposableIndexTemplateMetadata.java | 5 +++++ .../elasticsearch/cluster/metadata/DataStreamMetadata.java | 5 +++++ .../org/elasticsearch/cluster/metadata/IndexGraveyard.java | 5 +++++ .../cluster/metadata/NodesShutdownMetadata.java | 6 ++++++ .../main/java/org/elasticsearch/ingest/IngestMetadata.java | 5 +++++ .../main/java/org/elasticsearch/script/ScriptMetadata.java | 5 +++++ .../elasticsearch/upgrades/FeatureMigrationResults.java | 6 ++++++ .../xpack/autoscaling/AutoscalingMetadata.java | 4 ++++ .../xpack/core/ilm/IndexLifecycleMetadata.java | 5 +++++ .../java/org/elasticsearch/xpack/core/ml/MlMetadata.java | 7 ++++++- .../xpack/core/slm/SnapshotLifecycleMetadata.java | 6 ++++++ .../xpack/core/transform/TransformMetadata.java | 7 ++++++- .../xpack/ml/inference/ModelAliasMetadata.java | 6 ++++++ .../allocation/TrainedModelAllocationMetadata.java | 5 +++++ 16 files changed, 81 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/NamedDiff.java b/server/src/main/java/org/elasticsearch/cluster/NamedDiff.java index 87b5e91157c88..598f43112f23e 100644 --- a/server/src/main/java/org/elasticsearch/cluster/NamedDiff.java +++ b/server/src/main/java/org/elasticsearch/cluster/NamedDiff.java @@ -18,8 +18,6 @@ public interface NamedDiff> extends Diff, NamedWriteabl /** * The minimal version of the recipient this custom object can be sent to */ - default Version getMinimalSupportedVersion() { - return Version.CURRENT.minimumIndexCompatibilityVersion(); - } + Version getMinimalSupportedVersion(); } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/ComponentTemplateMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/ComponentTemplateMetadata.java index 95b6d0bb7942b..92fe6f18f9b50 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/ComponentTemplateMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/ComponentTemplateMetadata.java @@ -164,5 +164,10 @@ public void writeTo(StreamOutput out) throws IOException { public String getWriteableName() { return TYPE; } + + @Override + public Version getMinimalSupportedVersion() { + return Version.V_7_7_0; + } } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplateMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplateMetadata.java index 374d19cb57363..1b5193510aa62 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplateMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplateMetadata.java @@ -165,5 +165,10 @@ public void writeTo(StreamOutput out) throws IOException { public String getWriteableName() { return TYPE; } + + @Override + public Version getMinimalSupportedVersion() { + return Version.V_7_7_0; + } } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamMetadata.java index c8bed2493a17e..e8af3cf14d05c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamMetadata.java @@ -197,5 +197,10 @@ public void writeTo(StreamOutput out) throws IOException { public String getWriteableName() { return TYPE; } + + @Override + public Version getMinimalSupportedVersion() { + return Version.V_7_7_0; + } } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexGraveyard.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexGraveyard.java index 966dc82c9493c..3496adb0df93c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexGraveyard.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexGraveyard.java @@ -332,6 +332,11 @@ public int getRemovedCount() { public String getWriteableName() { return TYPE; } + + @Override + public Version getMinimalSupportedVersion() { + return Version.CURRENT.minimumCompatibilityVersion(); + } } /** diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/NodesShutdownMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/NodesShutdownMetadata.java index 67b3370282b40..bbbbff441331d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/NodesShutdownMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/NodesShutdownMetadata.java @@ -195,6 +195,12 @@ public void writeTo(StreamOutput out) throws IOException { static Diff readNodesDiffFrom(StreamInput in) throws IOException { return AbstractDiffable.readDiffFrom(SingleNodeShutdownMetadata::new, in); } + + @Override + public Version getMinimalSupportedVersion() { + return NODE_SHUTDOWN_VERSION; + } + } } diff --git a/server/src/main/java/org/elasticsearch/ingest/IngestMetadata.java b/server/src/main/java/org/elasticsearch/ingest/IngestMetadata.java index 753c52b1b0ccb..895f6ade21ec9 100644 --- a/server/src/main/java/org/elasticsearch/ingest/IngestMetadata.java +++ b/server/src/main/java/org/elasticsearch/ingest/IngestMetadata.java @@ -152,6 +152,11 @@ public void writeTo(StreamOutput out) throws IOException { public String getWriteableName() { return TYPE; } + + @Override + public Version getMinimalSupportedVersion() { + return Version.CURRENT.minimumCompatibilityVersion(); + } } @Override diff --git a/server/src/main/java/org/elasticsearch/script/ScriptMetadata.java b/server/src/main/java/org/elasticsearch/script/ScriptMetadata.java index 878f12fc80ec8..e2a0782d0cb6c 100644 --- a/server/src/main/java/org/elasticsearch/script/ScriptMetadata.java +++ b/server/src/main/java/org/elasticsearch/script/ScriptMetadata.java @@ -125,6 +125,11 @@ public Metadata.Custom apply(Metadata.Custom part) { public void writeTo(StreamOutput out) throws IOException { pipelines.writeTo(out); } + + @Override + public Version getMinimalSupportedVersion() { + return Version.CURRENT.minimumCompatibilityVersion(); + } } /** diff --git a/server/src/main/java/org/elasticsearch/upgrades/FeatureMigrationResults.java b/server/src/main/java/org/elasticsearch/upgrades/FeatureMigrationResults.java index 96f0884a36052..2e5b2dc9c34a0 100644 --- a/server/src/main/java/org/elasticsearch/upgrades/FeatureMigrationResults.java +++ b/server/src/main/java/org/elasticsearch/upgrades/FeatureMigrationResults.java @@ -189,6 +189,12 @@ public void writeTo(StreamOutput out) throws IOException { static Diff readDiffFrom(StreamInput in) throws IOException { return AbstractDiffable.readDiffFrom(SingleFeatureMigrationResult::new, in); } + + @Override + public Version getMinimalSupportedVersion() { + return MIGRATION_ADDED_VERSION; + } + } } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingMetadata.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingMetadata.java index a5a80d15661ab..bcf8d81a86d47 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingMetadata.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingMetadata.java @@ -165,6 +165,10 @@ static Diff readFrom(final StreamInput in) throws IOE return AbstractDiffable.readDiffFrom(AutoscalingPolicyMetadata::new, in); } + @Override + public Version getMinimalSupportedVersion() { + return Version.V_7_8_0; + } } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleMetadata.java index 97d4249049916..2f89fbae4f4d4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleMetadata.java @@ -182,6 +182,11 @@ public String getWriteableName() { return TYPE; } + @Override + public Version getMinimalSupportedVersion() { + return Version.CURRENT.minimumCompatibilityVersion(); + } + static Diff readLifecyclePolicyDiffFrom(StreamInput in) throws IOException { return AbstractDiffable.readDiffFrom(LifecyclePolicyMetadata::new, in); } 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 7c0bc35ab09cf..59e52f7582278 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 @@ -64,7 +64,7 @@ public boolean isResetMode() { @Override public Version getMinimalSupportedVersion() { - return Version.CURRENT.minimumIndexCompatibilityVersion(); + return Version.CURRENT.minimumCompatibilityVersion(); } @Override @@ -175,6 +175,11 @@ public String getWriteableName() { return TYPE; } + @Override + public Version getMinimalSupportedVersion() { + return Version.CURRENT.minimumCompatibilityVersion(); + } + static Diff readJobDiffFrom(StreamInput in) throws IOException { return AbstractDiffable.readDiffFrom(Job::new, in); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/SnapshotLifecycleMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/SnapshotLifecycleMetadata.java index f0f89523945d2..c3202410e69e8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/SnapshotLifecycleMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/SnapshotLifecycleMetadata.java @@ -213,5 +213,11 @@ public void writeTo(StreamOutput out) throws IOException { static Diff readLifecyclePolicyDiffFrom(StreamInput in) throws IOException { return AbstractDiffable.readDiffFrom(SnapshotLifecyclePolicyMetadata::new, in); } + + @Override + public Version getMinimalSupportedVersion() { + return Version.V_7_4_0; + } + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformMetadata.java index 48fc48ab102b6..5a3df91cd25af 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformMetadata.java @@ -53,7 +53,7 @@ public boolean isResetMode() { @Override public Version getMinimalSupportedVersion() { - return Version.CURRENT.minimumIndexCompatibilityVersion(); + return Version.CURRENT.minimumCompatibilityVersion(); } @Override @@ -117,6 +117,11 @@ public void writeTo(StreamOutput out) throws IOException { public String getWriteableName() { return TYPE; } + + @Override + public Version getMinimalSupportedVersion() { + return Version.CURRENT.minimumCompatibilityVersion(); + } } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ModelAliasMetadata.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ModelAliasMetadata.java index 844f1905736d4..2dcc7d511b8f3 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ModelAliasMetadata.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ModelAliasMetadata.java @@ -161,6 +161,12 @@ public String getWriteableName() { public void writeTo(StreamOutput out) throws IOException { modelAliasesDiff.writeTo(out); } + + @Override + public Version getMinimalSupportedVersion() { + return Version.V_7_13_0; + } + } public static class ModelAliasEntry extends AbstractDiffable implements ToXContentObject { diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/allocation/TrainedModelAllocationMetadata.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/allocation/TrainedModelAllocationMetadata.java index a93d3ae53da59..322c75e15d8c6 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/allocation/TrainedModelAllocationMetadata.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/allocation/TrainedModelAllocationMetadata.java @@ -219,6 +219,11 @@ public String getWriteableName() { return NAME; } + @Override + public Version getMinimalSupportedVersion() { + return Version.V_8_0_0; + } + @Override public void writeTo(StreamOutput out) throws IOException { modelRoutingEntries.writeTo(out);