-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Update data stream deprecations warnings to new format and filter searchable snapshots from response #118562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update data stream deprecations warnings to new format and filter searchable snapshots from response #118562
Changes from all commits
07265aa
e02283f
2727b1b
3048dae
629122b
9f04049
6c515d3
b56522f
ad352b1
6758723
21de2d2
a767959
4fd61a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this was
onOrBeforebut I thinkbeforeis correct here in that you can write to the minimum version so should not result in a warning or migration?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. You're right!