Skip to content

Commit 4baa6a1

Browse files
committed
Add code to skip ignored indices in the DS deprecation checks
1 parent 1e16962 commit 4baa6a1

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.cluster.ClusterState;
1111
import org.elasticsearch.cluster.metadata.DataStream;
1212
import org.elasticsearch.index.Index;
13+
import org.elasticsearch.index.IndexVersion;
1314
import org.elasticsearch.index.IndexVersions;
1415
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
1516

@@ -19,13 +20,24 @@
1920

2021
import static java.util.Map.entry;
2122
import static java.util.Map.ofEntries;
23+
import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_IGNORE_DEPRECATION_WARNING_FOR_VERSION_KEY;
2224

2325
public class DataStreamDeprecationChecks {
26+
27+
static final IndexVersion MINIMUM_VERSION = IndexVersions.UPGRADE_TO_LUCENE_10_0_0;
28+
2429
static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
2530
List<Index> backingIndices = dataStream.getIndices();
2631

2732
Set<String> indicesNeedingUpgrade = backingIndices.stream()
28-
.filter(index -> clusterState.metadata().index(index).getCreationVersion().onOrBefore(IndexVersions.UPGRADE_TO_LUCENE_10_0_0))
33+
.filter(index -> clusterState.metadata().index(index).getCreationVersion().before(MINIMUM_VERSION))
34+
.filter(index -> {
35+
IndexVersion ignoreVersion = clusterState.metadata()
36+
.index(index)
37+
.getSettings()
38+
.getAsVersionId(INDEX_IGNORE_DEPRECATION_WARNING_FOR_VERSION_KEY, IndexVersion::fromId);
39+
return ignoreVersion == null || MINIMUM_VERSION.after(ignoreVersion);
40+
})
2941
.map(Index::getName)
3042
.collect(Collectors.toUnmodifiableSet());
3143

@@ -38,6 +50,7 @@ static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clus
3850
false,
3951
ofEntries(
4052
entry("reindex_required", true),
53+
entry("minimum_version_id_required", MINIMUM_VERSION.id()),
4154
entry("total_backing_indices", backingIndices.size()),
4255
entry("indices_requiring_upgrade_count", indicesNeedingUpgrade.size()),
4356
entry("indices_requiring_upgrade", indicesNeedingUpgrade)

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,22 @@
2828
import java.util.function.BiFunction;
2929
import java.util.function.Function;
3030

31+
import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_IGNORE_DEPRECATION_WARNING_FOR_VERSION_KEY;
32+
3133
/**
3234
* Index-specific deprecation checks
3335
*/
3436
public class IndexDeprecationChecks {
3537

38+
private static final IndexVersion MINIMUM_VERSION = IndexVersions.V_8_0_0;
39+
3640
static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
3741
// TODO: this check needs to be revised. It's trivially true right now.
3842
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
3943
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
40-
if (currentCompatibilityVersion.before(IndexVersions.V_8_0_0) && isNotDataStreamIndex(indexMetadata, clusterState)) {
44+
if (currentCompatibilityVersion.before(MINIMUM_VERSION)
45+
&& isNotDataStreamIndex(indexMetadata, clusterState)
46+
&& notIgnored(indexMetadata)) {
4147
return new DeprecationIssue(
4248
DeprecationIssue.Level.CRITICAL,
4349
"Old index with a compatibility version < 8.0",
@@ -50,6 +56,12 @@ static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterStat
5056
return null;
5157
}
5258

59+
private static boolean notIgnored(IndexMetadata indexMetadata) {
60+
IndexVersion ignoreVersion = indexMetadata.getSettings()
61+
.getAsVersionId(INDEX_IGNORE_DEPRECATION_WARNING_FOR_VERSION_KEY, IndexVersion::fromId);
62+
return ignoreVersion == null || IndexVersions.V_8_0_0.after(ignoreVersion);
63+
}
64+
5365
private static boolean isNotDataStreamIndex(IndexMetadata indexMetadata, ClusterState clusterState) {
5466
return clusterState.metadata().findDataStreams(indexMetadata.getIndex().getName()).isEmpty();
5567
}

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222

2323
import java.util.ArrayList;
2424
import java.util.HashMap;
25+
import java.util.HashSet;
2526
import java.util.List;
2627
import java.util.Map;
27-
import java.util.stream.Collectors;
28+
import java.util.Set;
2829

2930
import static java.util.Collections.singletonList;
3031
import static java.util.Map.entry;
3132
import static java.util.Map.ofEntries;
33+
import static org.elasticsearch.xpack.deprecation.DataStreamDeprecationChecks.MINIMUM_VERSION;
3234
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.DATA_STREAM_CHECKS;
3335
import static org.hamcrest.Matchers.equalTo;
3436

@@ -41,14 +43,26 @@ public void testOldIndicesCheck() {
4143
List<Index> allIndices = new ArrayList<>();
4244
Map<String, IndexMetadata> nameToIndexMetadata = new HashMap<>();
4345

46+
Set<String> indicesToUpgrade = new HashSet<>();
47+
4448
for (int i = 0; i < oldIndexCount; i++) {
4549
Settings.Builder settingsBuilder = settings(IndexVersion.fromId(7170099));
50+
51+
// Ensure at least 1 index does not have the ignore setting, otherwise 1 in 3 should be ignored
52+
boolean shouldIgnore = indicesToUpgrade.isEmpty() == false || randomIntBetween(0, 2) == 0;
53+
if (shouldIgnore) {
54+
settingsBuilder.put(IndexMetadata.INDEX_IGNORE_DEPRECATION_WARNING_FOR_VERSION_KEY, MINIMUM_VERSION.id());
55+
}
56+
4657
IndexMetadata oldIndexMetadata = IndexMetadata.builder("old-data-stream-index-" + i)
4758
.settings(settingsBuilder)
4859
.numberOfShards(1)
4960
.numberOfReplicas(0)
5061
.build();
5162
allIndices.add(oldIndexMetadata.getIndex());
63+
if (shouldIgnore == false) {
64+
indicesToUpgrade.add(oldIndexMetadata.getIndex().getName());
65+
}
5266
nameToIndexMetadata.put(oldIndexMetadata.getIndex().getName(), oldIndexMetadata);
5367
}
5468

@@ -90,16 +104,11 @@ public void testOldIndicesCheck() {
90104
"This data stream has backing indices that were created before Elasticsearch 8.0.0",
91105
false,
92106
ofEntries(
107+
entry("minimum_version_id_required", MINIMUM_VERSION.id()),
93108
entry("reindex_required", true),
94109
entry("total_backing_indices", oldIndexCount + newIndexCount),
95-
entry("indices_requiring_upgrade_count", oldIndexCount),
96-
entry(
97-
"indices_requiring_upgrade",
98-
nameToIndexMetadata.keySet()
99-
.stream()
100-
.filter(name -> name.startsWith("old-data-stream-index-"))
101-
.collect(Collectors.toUnmodifiableSet())
102-
)
110+
entry("indices_requiring_upgrade_count", indicesToUpgrade.size()),
111+
entry("indices_requiring_upgrade", indicesToUpgrade)
103112
)
104113
);
105114

@@ -108,4 +117,5 @@ public void testOldIndicesCheck() {
108117
assertThat(issues, equalTo(singletonList(expected)));
109118
}
110119

120+
111121
}

0 commit comments

Comments
 (0)