Skip to content

Commit 3edfe2d

Browse files
committed
Add code to skip ignored indices in the index deprecation checks
1 parent 4baa6a1 commit 3edfe2d

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,23 @@
2020
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
2121

2222
import java.util.ArrayList;
23-
import java.util.Collections;
2423
import java.util.List;
2524
import java.util.Locale;
2625
import java.util.Map;
2726
import java.util.function.BiConsumer;
2827
import java.util.function.BiFunction;
2928
import java.util.function.Function;
3029

30+
import static java.util.Map.entry;
31+
import static java.util.Map.ofEntries;
3132
import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_IGNORE_DEPRECATION_WARNING_FOR_VERSION_KEY;
3233

3334
/**
3435
* Index-specific deprecation checks
3536
*/
3637
public class IndexDeprecationChecks {
3738

38-
private static final IndexVersion MINIMUM_VERSION = IndexVersions.V_8_0_0;
39+
static final IndexVersion MINIMUM_VERSION = IndexVersions.V_8_0_0;
3940

4041
static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
4142
// TODO: this check needs to be revised. It's trivially true right now.
@@ -50,7 +51,7 @@ && notIgnored(indexMetadata)) {
5051
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
5152
"This index has version: " + currentCompatibilityVersion.toReleaseVersion(),
5253
false,
53-
Collections.singletonMap("reindex_required", true)
54+
ofEntries(entry("reindex_required", true), entry("minimum_version_id_required", MINIMUM_VERSION.id()))
5455
);
5556
}
5657
return null;

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
import java.util.Map;
3030

3131
import static java.util.Collections.singletonList;
32-
import static java.util.Collections.singletonMap;
32+
import static java.util.Map.entry;
33+
import static java.util.Map.ofEntries;
3334
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.INDEX_SETTINGS_CHECKS;
35+
import static org.elasticsearch.xpack.deprecation.IndexDeprecationChecks.MINIMUM_VERSION;
3436
import static org.hamcrest.Matchers.empty;
3537
import static org.hamcrest.Matchers.equalTo;
3638
import static org.hamcrest.Matchers.hasItem;
@@ -53,7 +55,7 @@ public void testOldIndicesCheck() {
5355
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
5456
"This index has version: " + createdWith.toReleaseVersion(),
5557
false,
56-
singletonMap("reindex_required", true)
58+
ofEntries(entry("reindex_required", true), entry("minimum_version_id_required", MINIMUM_VERSION.id()))
5759
);
5860
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata, clusterState));
5961
assertEquals(singletonList(expected), issues);
@@ -101,6 +103,21 @@ public void testOldIndicesCheckDataStreamIndex() {
101103
assertThat(issues.size(), equalTo(0));
102104
}
103105

106+
public void testOldIndicesIgnoredCheck() {
107+
IndexVersion createdWith = IndexVersion.fromId(7170099);
108+
109+
Settings.Builder settings = settings(createdWith);
110+
settings.put(IndexMetadata.INDEX_IGNORE_DEPRECATION_WARNING_FOR_VERSION_KEY, MINIMUM_VERSION.id());
111+
112+
IndexMetadata indexMetadata = IndexMetadata.builder("test").settings(settings).numberOfShards(1).numberOfReplicas(0).build();
113+
ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
114+
.metadata(Metadata.builder().put(indexMetadata, true))
115+
.build();
116+
117+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata, clusterState));
118+
assertThat(issues, empty());
119+
}
120+
104121
public void testTranslogRetentionSettings() {
105122
Settings.Builder settings = settings(IndexVersion.current());
106123
settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.getKey(), randomPositiveTimeValue());

0 commit comments

Comments
 (0)