Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/118562.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 118562
summary: Update data stream deprecations warnings to new format and filter searchable
snapshots from response
area: Data streams
type: enhancement
issues: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.core.deprecation;

import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;

import java.util.function.Predicate;

public class DeprecatedIndexPredicate {

public static final IndexVersion MINIMUM_WRITEABLE_VERSION_AFTER_UPGRADE = IndexVersions.UPGRADE_TO_LUCENE_10_0_0;

/*
* This predicate allows through only indices that were created with a previous lucene version, meaning that they need to be reindexed
* in order to be writable in the _next_ lucene version.
*
* It ignores searchable snapshots as they are not writable.
*/
public static Predicate<Index> getReindexRequiredPredicate(Metadata metadata) {
return index -> {
IndexMetadata indexMetadata = metadata.index(index);
return reindexRequired(indexMetadata);
};
}

public static boolean reindexRequired(IndexMetadata indexMetadata) {
return creationVersionBeforeMinimumWritableVersion(indexMetadata) && isNotSearchableSnapshot(indexMetadata);
}

private static boolean isNotSearchableSnapshot(IndexMetadata indexMetadata) {
return indexMetadata.isSearchableSnapshot() == false;
}

private static boolean creationVersionBeforeMinimumWritableVersion(IndexMetadata metadata) {
return metadata.getCreationVersion().before(MINIMUM_WRITEABLE_VERSION_AFTER_UPGRADE);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this was onOrBefore but I think before is correct here in that you can write to the minimum version so should not result in a warning or migration?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. You're right!

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,41 @@
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.xpack.core.deprecation.DeprecatedIndexPredicate;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static java.util.Map.entry;
import static java.util.Map.ofEntries;

public class DataStreamDeprecationChecks {
static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
List<Index> backingIndices = dataStream.getIndices();
boolean hasOldIndices = backingIndices.stream()
.anyMatch(index -> clusterState.metadata().index(index).getCompatibilityVersion().before(IndexVersions.V_8_0_0));
if (hasOldIndices) {
long totalIndices = backingIndices.size();
List<Index> oldIndices = backingIndices.stream()
.filter(index -> clusterState.metadata().index(index).getCompatibilityVersion().before(IndexVersions.V_8_0_0))
.toList();
long totalOldIndices = oldIndices.size();
long totalOldSearchableSnapshots = oldIndices.stream()
.filter(index -> clusterState.metadata().index(index).isSearchableSnapshot())
.count();
long totalOldPartiallyMountedSearchableSnapshots = oldIndices.stream()
.filter(index -> clusterState.metadata().index(index).isPartialSearchableSnapshot())
.count();
long totalOldFullyMountedSearchableSnapshots = totalOldSearchableSnapshots - totalOldPartiallyMountedSearchableSnapshots;

Set<String> indicesNeedingUpgrade = backingIndices.stream()
.filter(DeprecatedIndexPredicate.getReindexRequiredPredicate(clusterState.metadata()))
.map(Index::getName)
.collect(Collectors.toUnmodifiableSet());

if (indicesNeedingUpgrade.isEmpty() == false) {
return new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
"Old data stream with a compatibility version < 8.0",
"Old data stream with a compatibility version < 9.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the wording here. Is this correct for 9.0 (Main)? I'm guessing it will need changing back for the backport?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah for main it is correct (for now -- who knows what will be correct when we actually get to 10.0), and for 8.x it'll need to read < 8.0.

"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
"This data stream has backing indices that were created before Elasticsearch 8.0.0",
"This data stream has backing indices that were created before Elasticsearch 9.0.0",
false,
ofEntries(
entry(
"backing_indices",
ofEntries(
entry("count", totalIndices),
entry(
"need_upgrading",
ofEntries(
entry("count", totalOldIndices),
entry(
"searchable_snapshots",
ofEntries(
entry("count", totalOldSearchableSnapshots),
entry("fully_mounted", ofEntries(entry("count", totalOldFullyMountedSearchableSnapshots))),
entry(
"partially_mounted",
ofEntries(entry("count", totalOldPartiallyMountedSearchableSnapshots))
)
)
)
)
)
)
)
entry("reindex_required", true),
entry("total_backing_indices", backingIndices.size()),
entry("indices_requiring_upgrade_count", indicesNeedingUpgrade.size()),
entry("indices_requiring_upgrade", indicesNeedingUpgrade)
)
);
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.engine.frozen.FrozenEngine;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.xpack.core.deprecation.DeprecatedIndexPredicate;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -36,14 +37,14 @@ static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterStat
// TODO: this check needs to be revised. It's trivially true right now.
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
if (currentCompatibilityVersion.before(IndexVersions.V_8_0_0) && isNotDataStreamIndex(indexMetadata, clusterState)) {
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata) && isNotDataStreamIndex(indexMetadata, clusterState)) {
return new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
"Old index with a compatibility version < 8.0",
"Old index with a compatibility version < 9.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
"This index has version: " + currentCompatibilityVersion.toReleaseVersion(),
false,
null
Collections.singletonMap("reindex_required", true)
);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,56 @@
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.snapshots.SearchableSnapshotsSettings;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static java.util.Collections.singletonList;
import static java.util.Map.entry;
import static java.util.Map.ofEntries;
import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.DATA_STREAM_CHECKS;
import static org.hamcrest.Matchers.equalTo;

public class DataStreamDeprecationChecksTests extends ESTestCase {

public void testOldIndicesCheck() {
long oldIndexCount = randomIntBetween(1, 100);
long newIndexCount = randomIntBetween(1, 100);
long oldSearchableSnapshotCount = 0;
long oldFullyManagedSearchableSnapshotCount = 0;
long oldPartiallyManagedSearchableSnapshotCount = 0;
int oldIndexCount = randomIntBetween(1, 100);
int newIndexCount = randomIntBetween(1, 100);

List<Index> allIndices = new ArrayList<>();
Map<String, IndexMetadata> nameToIndexMetadata = new HashMap<>();
Set<String> expectedIndices = new HashSet<>();

for (int i = 0; i < oldIndexCount; i++) {
Settings.Builder settingsBuilder = settings(IndexVersion.fromId(7170099));
if (randomBoolean()) {
settingsBuilder.put("index.store.type", "snapshot");
if (randomBoolean()) {
oldFullyManagedSearchableSnapshotCount++;
} else {
settingsBuilder.put("index.store.snapshot.partial", true);
oldPartiallyManagedSearchableSnapshotCount++;
}
oldSearchableSnapshotCount++;
Settings.Builder settings = settings(IndexVersion.fromId(7170099));

String indexName = "old-data-stream-index-" + i;
if (expectedIndices.isEmpty() == false && randomIntBetween(0, 2) == 0) {
settings.put(INDEX_STORE_TYPE_SETTING.getKey(), SearchableSnapshotsSettings.SEARCHABLE_SNAPSHOT_STORE_TYPE);
} else {
expectedIndices.add(indexName);
}
IndexMetadata oldIndexMetadata = IndexMetadata.builder("old-data-stream-index-" + i)

Settings.Builder settingsBuilder = settings;
IndexMetadata oldIndexMetadata = IndexMetadata.builder(indexName)
.settings(settingsBuilder)
.numberOfShards(1)
.numberOfReplicas(0)
.build();
allIndices.add(oldIndexMetadata.getIndex());
nameToIndexMetadata.put(oldIndexMetadata.getIndex().getName(), oldIndexMetadata);
}

for (int i = 0; i < newIndexCount; i++) {
Settings.Builder settingsBuilder = settings(IndexVersion.current());
if (randomBoolean()) {
settingsBuilder.put("index.store.type", "snapshot");
}
IndexMetadata newIndexMetadata = IndexMetadata.builder("new-data-stream-index-" + i)
.settings(settingsBuilder)
.numberOfShards(1)
Expand All @@ -72,6 +75,7 @@ public void testOldIndicesCheck() {
allIndices.add(newIndexMetadata.getIndex());
nameToIndexMetadata.put(newIndexMetadata.getIndex().getName(), newIndexMetadata);
}

DataStream dataStream = new DataStream(
randomAlphaOfLength(10),
allIndices,
Expand All @@ -88,37 +92,27 @@ public void testOldIndicesCheck() {
randomBoolean(),
null
);

Metadata metadata = Metadata.builder().indices(nameToIndexMetadata).build();
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();

DeprecationIssue expected = new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
"Old data stream with a compatibility version < 8.0",
"Old data stream with a compatibility version < 9.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
"This data stream has backing indices that were created before Elasticsearch 8.0.0",
"This data stream has backing indices that were created before Elasticsearch 9.0.0",
false,
Map.of(
"backing_indices",
Map.of(
"count",
oldIndexCount + newIndexCount,
"need_upgrading",
Map.of(
"count",
oldIndexCount,
"searchable_snapshots",
Map.of(
"count",
oldSearchableSnapshotCount,
"fully_mounted",
Map.of("count", oldFullyManagedSearchableSnapshotCount),
"partially_mounted",
Map.of("count", oldPartiallyManagedSearchableSnapshotCount)
)
)
)
ofEntries(
entry("reindex_required", true),
entry("total_backing_indices", oldIndexCount + newIndexCount),
entry("indices_requiring_upgrade_count", expectedIndices.size()),
entry("indices_requiring_upgrade", expectedIndices)
)
);

List<DeprecationIssue> issues = DeprecationChecks.filterChecks(DATA_STREAM_CHECKS, c -> c.apply(dataStream, clusterState));

assertThat(issues, equalTo(singletonList(expected)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.engine.frozen.FrozenEngine;
import org.elasticsearch.snapshots.SearchableSnapshotsSettings;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;

Expand All @@ -29,6 +29,8 @@
import java.util.Map;

import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.INDEX_SETTINGS_CHECKS;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
Expand All @@ -48,11 +50,11 @@ public void testOldIndicesCheck() {
.build();
DeprecationIssue expected = new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
"Old index with a compatibility version < 8.0",
"Old index with a compatibility version < 9.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
"This index has version: " + createdWith.toReleaseVersion(),
false,
null
singletonMap("reindex_required", true)
);
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata, clusterState));
assertEquals(singletonList(expected), issues);
Expand Down Expand Up @@ -100,6 +102,20 @@ public void testOldIndicesCheckDataStreamIndex() {
assertThat(issues.size(), equalTo(0));
}

public void testOldIndicesCheckSnapshotIgnored() {
IndexVersion createdWith = IndexVersion.fromId(7170099);
Settings.Builder settings = settings(createdWith);
settings.put(INDEX_STORE_TYPE_SETTING.getKey(), SearchableSnapshotsSettings.SEARCHABLE_SNAPSHOT_STORE_TYPE);
IndexMetadata indexMetadata = IndexMetadata.builder("test").settings(settings).numberOfShards(1).numberOfReplicas(0).build();
ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
.metadata(Metadata.builder().put(indexMetadata, true))
.build();

List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata, clusterState));

assertThat(issues, empty());
}

public void testTranslogRetentionSettings() {
Settings.Builder settings = settings(IndexVersion.current());
settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.getKey(), randomPositiveTimeValue());
Expand Down Expand Up @@ -229,7 +245,7 @@ public void testCamelCaseDeprecation() throws IOException {
+ "} }";

IndexMetadata simpleIndex = IndexMetadata.builder(randomAlphaOfLengthBetween(5, 10))
.settings(settings(IndexVersions.MINIMUM_COMPATIBLE))
.settings(settings(IndexVersion.current()))
.numberOfShards(1)
.numberOfReplicas(1)
.putMapping(simpleMapping)
Expand Down
Loading