|
14 | 14 | import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; |
15 | 15 |
|
16 | 16 | import java.util.List; |
| 17 | +import java.util.Set; |
| 18 | +import java.util.stream.Collectors; |
17 | 19 |
|
18 | 20 | import static java.util.Map.entry; |
19 | 21 | import static java.util.Map.ofEntries; |
20 | 22 |
|
21 | 23 | public class DataStreamDeprecationChecks { |
22 | 24 | static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clusterState) { |
23 | 25 | List<Index> backingIndices = dataStream.getIndices(); |
24 | | - boolean hasOldIndices = backingIndices.stream() |
25 | | - .anyMatch(index -> clusterState.metadata().index(index).getCompatibilityVersion().before(IndexVersions.V_8_0_0)); |
26 | | - if (hasOldIndices) { |
27 | | - long totalIndices = backingIndices.size(); |
28 | | - List<Index> oldIndices = backingIndices.stream() |
29 | | - .filter(index -> clusterState.metadata().index(index).getCompatibilityVersion().before(IndexVersions.V_8_0_0)) |
30 | | - .toList(); |
31 | | - long totalOldIndices = oldIndices.size(); |
32 | | - long totalOldSearchableSnapshots = oldIndices.stream() |
33 | | - .filter(index -> clusterState.metadata().index(index).isSearchableSnapshot()) |
34 | | - .count(); |
35 | | - long totalOldPartiallyMountedSearchableSnapshots = oldIndices.stream() |
36 | | - .filter(index -> clusterState.metadata().index(index).isPartialSearchableSnapshot()) |
37 | | - .count(); |
38 | | - long totalOldFullyMountedSearchableSnapshots = totalOldSearchableSnapshots - totalOldPartiallyMountedSearchableSnapshots; |
39 | | - return new DeprecationIssue( |
| 26 | + |
| 27 | + Set<String> indiciesNeedingUpgrade = backingIndices.stream() |
| 28 | + .filter(index -> clusterState.metadata().index(index).getCompatibilityVersion().before(IndexVersions.V_8_0_0)) |
| 29 | + .map(Index::getName) |
| 30 | + .collect(Collectors.toUnmodifiableSet()); |
| 31 | + |
| 32 | + if (indiciesNeedingUpgrade.isEmpty() == false) { |
| 33 | + return new DeprecationIssue( |
40 | 34 | DeprecationIssue.Level.CRITICAL, |
41 | 35 | "Old data stream with a compatibility version < 8.0", |
42 | 36 | "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html", |
43 | 37 | "This data stream has backing indices that were created before Elasticsearch 8.0.0", |
44 | 38 | false, |
45 | 39 | ofEntries( |
46 | | - entry( |
47 | | - "backing_indices", |
48 | | - ofEntries( |
49 | | - entry("count", totalIndices), |
50 | | - entry( |
51 | | - "need_upgrading", |
52 | | - ofEntries( |
53 | | - entry("count", totalOldIndices), |
54 | | - entry( |
55 | | - "searchable_snapshots", |
56 | | - ofEntries( |
57 | | - entry("count", totalOldSearchableSnapshots), |
58 | | - entry("fully_mounted", ofEntries(entry("count", totalOldFullyMountedSearchableSnapshots))), |
59 | | - entry( |
60 | | - "partially_mounted", |
61 | | - ofEntries(entry("count", totalOldPartiallyMountedSearchableSnapshots)) |
62 | | - ) |
63 | | - ) |
64 | | - ) |
65 | | - ) |
66 | | - ) |
67 | | - ) |
68 | | - ) |
| 40 | + entry("reindex_required",true), |
| 41 | + entry("total_backing_indicies", backingIndices.size()), |
| 42 | + entry("indicies_requiring_upgrade_count", indiciesNeedingUpgrade.size()), |
| 43 | + entry("indicies_requiring_upgrade", indiciesNeedingUpgrade) |
69 | 44 | ) |
70 | 45 | ); |
71 | 46 | } |
| 47 | + |
72 | 48 | return null; |
73 | 49 | } |
74 | 50 | } |
0 commit comments