2020import org .elasticsearch .xpack .core .deprecation .DeprecationIssue ;
2121
2222import java .util .ArrayList ;
23- import java .util .Collections ;
2423import java .util .HashMap ;
2524import java .util .List ;
2625import java .util .Locale ;
3938public class IndexDeprecationChecker implements ResourceDeprecationChecker {
4039
4140 public static final String NAME = "index_settings" ;
42- private static final List <BiFunction <IndexMetadata , ClusterState , DeprecationIssue >> INDEX_SETTINGS_CHECKS = List .of (
43- IndexDeprecationChecker ::oldIndicesCheck ,
44- IndexDeprecationChecker ::ignoredOldIndicesCheck ,
45- IndexDeprecationChecker ::translogRetentionSettingCheck ,
46- IndexDeprecationChecker ::checkIndexDataPath ,
47- IndexDeprecationChecker ::storeTypeSettingCheck ,
48- IndexDeprecationChecker ::frozenIndexSettingCheck ,
49- IndexDeprecationChecker ::deprecatedCamelCasePattern ,
50- IndexDeprecationChecker ::legacyRoutingSettingCheck
51- );
5241
5342 private final IndexNameExpressionResolver indexNameExpressionResolver ;
43+ private final Map <String , List <String >> indexToTransformIds ;
5444
55- public IndexDeprecationChecker (IndexNameExpressionResolver indexNameExpressionResolver ) {
45+ public IndexDeprecationChecker (IndexNameExpressionResolver indexNameExpressionResolver , Map < String , List < String >> indexToTransformIds ) {
5646 this .indexNameExpressionResolver = indexNameExpressionResolver ;
47+ this .indexToTransformIds = indexToTransformIds ;
5748 }
5849
5950 @ Override
@@ -62,7 +53,7 @@ public Map<String, List<DeprecationIssue>> check(ClusterState clusterState, Depr
6253 String [] concreteIndexNames = indexNameExpressionResolver .concreteIndexNames (clusterState , request );
6354 for (String concreteIndex : concreteIndexNames ) {
6455 IndexMetadata indexMetadata = clusterState .getMetadata ().index (concreteIndex );
65- List <DeprecationIssue > singleIndexIssues = filterChecks (INDEX_SETTINGS_CHECKS , c -> c .apply (indexMetadata , clusterState ));
56+ List <DeprecationIssue > singleIndexIssues = filterChecks (indexSettingsChecks () , c -> c .apply (indexMetadata , clusterState ));
6657 if (singleIndexIssues .isEmpty () == false ) {
6758 indexSettingsIssues .put (concreteIndex , singleIndexIssues );
6859 }
@@ -73,12 +64,25 @@ public Map<String, List<DeprecationIssue>> check(ClusterState clusterState, Depr
7364 return indexSettingsIssues ;
7465 }
7566
67+ private List <BiFunction <IndexMetadata , ClusterState , DeprecationIssue >> indexSettingsChecks () {
68+ return List .of (
69+ this ::oldIndicesCheck ,
70+ this ::ignoredOldIndicesCheck ,
71+ IndexDeprecationChecker ::translogRetentionSettingCheck ,
72+ IndexDeprecationChecker ::checkIndexDataPath ,
73+ IndexDeprecationChecker ::storeTypeSettingCheck ,
74+ IndexDeprecationChecker ::frozenIndexSettingCheck ,
75+ IndexDeprecationChecker ::deprecatedCamelCasePattern ,
76+ IndexDeprecationChecker ::legacyRoutingSettingCheck
77+ );
78+ }
79+
7680 @ Override
7781 public String getName () {
7882 return NAME ;
7983 }
8084
81- static DeprecationIssue oldIndicesCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
85+ private DeprecationIssue oldIndicesCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
8286 // TODO: this check needs to be revised. It's trivially true right now.
8387 IndexVersion currentCompatibilityVersion = indexMetadata .getCompatibilityVersion ();
8488 // We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
@@ -89,13 +93,22 @@ static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterStat
8993 "https://www.elastic.co/guide/en/elasticsearch/reference/current/migrating-8.0.html#breaking-changes-8.0" ,
9094 "This index has version: " + currentCompatibilityVersion .toReleaseVersion (),
9195 false ,
92- Collections . singletonMap ( "reindex_required" , true )
96+ meta ( indexMetadata )
9397 );
9498 }
9599 return null ;
96100 }
97101
98- static DeprecationIssue ignoredOldIndicesCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
102+ private Map <String , Object > meta (IndexMetadata indexMetadata ) {
103+ var transforms = indexToTransformIds .getOrDefault (indexMetadata .getIndex ().getName (), List .of ());
104+ if (transforms .isEmpty ()) {
105+ return Map .of ("reindex_required" , true );
106+ } else {
107+ return Map .of ("reindex_required" , true , "transform_ids" , transforms );
108+ }
109+ }
110+
111+ private DeprecationIssue ignoredOldIndicesCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
99112 IndexVersion currentCompatibilityVersion = indexMetadata .getCompatibilityVersion ();
100113 // We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
101114 if (DeprecatedIndexPredicate .reindexRequired (indexMetadata , true ) && isNotDataStreamIndex (indexMetadata , clusterState )) {
@@ -107,7 +120,7 @@ static DeprecationIssue ignoredOldIndicesCheck(IndexMetadata indexMetadata, Clus
107120 + currentCompatibilityVersion .toReleaseVersion ()
108121 + " and will be supported as read-only in 9.0" ,
109122 false ,
110- Collections . singletonMap ( "reindex_required" , true )
123+ meta ( indexMetadata )
111124 );
112125 }
113126 return null ;
@@ -117,7 +130,7 @@ private static boolean isNotDataStreamIndex(IndexMetadata indexMetadata, Cluster
117130 return clusterState .metadata ().findDataStreams (indexMetadata .getIndex ().getName ()).isEmpty ();
118131 }
119132
120- static DeprecationIssue translogRetentionSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
133+ private static DeprecationIssue translogRetentionSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
121134 final boolean softDeletesEnabled = IndexSettings .INDEX_SOFT_DELETES_SETTING .get (indexMetadata .getSettings ());
122135 if (softDeletesEnabled ) {
123136 if (IndexSettings .INDEX_TRANSLOG_RETENTION_SIZE_SETTING .exists (indexMetadata .getSettings ())
@@ -144,7 +157,7 @@ static DeprecationIssue translogRetentionSettingCheck(IndexMetadata indexMetadat
144157 return null ;
145158 }
146159
147- static DeprecationIssue checkIndexDataPath (IndexMetadata indexMetadata , ClusterState clusterState ) {
160+ private static DeprecationIssue checkIndexDataPath (IndexMetadata indexMetadata , ClusterState clusterState ) {
148161 if (IndexMetadata .INDEX_DATA_PATH_SETTING .exists (indexMetadata .getSettings ())) {
149162 final String message = String .format (
150163 Locale .ROOT ,
@@ -159,7 +172,7 @@ static DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ClusterS
159172 return null ;
160173 }
161174
162- static DeprecationIssue storeTypeSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
175+ private static DeprecationIssue storeTypeSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
163176 final String storeType = IndexModule .INDEX_STORE_TYPE_SETTING .get (indexMetadata .getSettings ());
164177 if (IndexModule .Type .SIMPLEFS .match (storeType )) {
165178 return new DeprecationIssue (
@@ -176,7 +189,7 @@ static DeprecationIssue storeTypeSettingCheck(IndexMetadata indexMetadata, Clust
176189 return null ;
177190 }
178191
179- static DeprecationIssue frozenIndexSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
192+ private static DeprecationIssue frozenIndexSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
180193 Boolean isIndexFrozen = FrozenEngine .INDEX_FROZEN .get (indexMetadata .getSettings ());
181194 if (Boolean .TRUE .equals (isIndexFrozen )) {
182195 String indexName = indexMetadata .getIndex ().getName ();
@@ -194,7 +207,7 @@ static DeprecationIssue frozenIndexSettingCheck(IndexMetadata indexMetadata, Clu
194207 return null ;
195208 }
196209
197- static DeprecationIssue legacyRoutingSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
210+ private static DeprecationIssue legacyRoutingSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
198211 List <String > deprecatedSettings = LegacyTiersDetection .getDeprecatedFilteredAllocationSettings (indexMetadata .getSettings ());
199212 if (deprecatedSettings .isEmpty ()) {
200213 return null ;
@@ -228,7 +241,7 @@ private static void fieldLevelMappingIssue(IndexMetadata indexMetadata, BiConsum
228241 * @return a list of issues found in fields
229242 */
230243 @ SuppressWarnings ("unchecked" )
231- static List <String > findInPropertiesRecursively (
244+ private static List <String > findInPropertiesRecursively (
232245 String type ,
233246 Map <String , Object > parentMap ,
234247 Function <Map <?, ?>, Boolean > predicate ,
@@ -282,7 +295,7 @@ static List<String> findInPropertiesRecursively(
282295 return issues ;
283296 }
284297
285- static DeprecationIssue deprecatedCamelCasePattern (IndexMetadata indexMetadata , ClusterState clusterState ) {
298+ private static DeprecationIssue deprecatedCamelCasePattern (IndexMetadata indexMetadata , ClusterState clusterState ) {
286299 List <String > fields = new ArrayList <>();
287300 fieldLevelMappingIssue (
288301 indexMetadata ,
0 commit comments