20
20
import org .elasticsearch .xpack .core .deprecation .DeprecationIssue ;
21
21
22
22
import java .util .ArrayList ;
23
- import java .util .Collections ;
24
23
import java .util .HashMap ;
25
24
import java .util .List ;
26
25
import java .util .Locale ;
39
38
public class IndexDeprecationChecker implements ResourceDeprecationChecker {
40
39
41
40
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
- );
52
41
53
42
private final IndexNameExpressionResolver indexNameExpressionResolver ;
43
+ private final Map <String , List <String >> indexToTransformIds ;
54
44
55
- public IndexDeprecationChecker (IndexNameExpressionResolver indexNameExpressionResolver ) {
45
+ public IndexDeprecationChecker (IndexNameExpressionResolver indexNameExpressionResolver , Map < String , List < String >> indexToTransformIds ) {
56
46
this .indexNameExpressionResolver = indexNameExpressionResolver ;
47
+ this .indexToTransformIds = indexToTransformIds ;
57
48
}
58
49
59
50
@ Override
@@ -62,7 +53,7 @@ public Map<String, List<DeprecationIssue>> check(ClusterState clusterState, Depr
62
53
String [] concreteIndexNames = indexNameExpressionResolver .concreteIndexNames (clusterState , request );
63
54
for (String concreteIndex : concreteIndexNames ) {
64
55
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 ));
66
57
if (singleIndexIssues .isEmpty () == false ) {
67
58
indexSettingsIssues .put (concreteIndex , singleIndexIssues );
68
59
}
@@ -73,12 +64,25 @@ public Map<String, List<DeprecationIssue>> check(ClusterState clusterState, Depr
73
64
return indexSettingsIssues ;
74
65
}
75
66
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
+
76
80
@ Override
77
81
public String getName () {
78
82
return NAME ;
79
83
}
80
84
81
- static DeprecationIssue oldIndicesCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
85
+ private DeprecationIssue oldIndicesCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
82
86
// TODO: this check needs to be revised. It's trivially true right now.
83
87
IndexVersion currentCompatibilityVersion = indexMetadata .getCompatibilityVersion ();
84
88
// 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
89
93
"https://www.elastic.co/guide/en/elasticsearch/reference/current/migrating-8.0.html#breaking-changes-8.0" ,
90
94
"This index has version: " + currentCompatibilityVersion .toReleaseVersion (),
91
95
false ,
92
- Collections . singletonMap ( "reindex_required" , true )
96
+ meta ( indexMetadata )
93
97
);
94
98
}
95
99
return null ;
96
100
}
97
101
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 ) {
99
112
IndexVersion currentCompatibilityVersion = indexMetadata .getCompatibilityVersion ();
100
113
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
101
114
if (DeprecatedIndexPredicate .reindexRequired (indexMetadata , true ) && isNotDataStreamIndex (indexMetadata , clusterState )) {
@@ -107,7 +120,7 @@ static DeprecationIssue ignoredOldIndicesCheck(IndexMetadata indexMetadata, Clus
107
120
+ currentCompatibilityVersion .toReleaseVersion ()
108
121
+ " and will be supported as read-only in 9.0" ,
109
122
false ,
110
- Collections . singletonMap ( "reindex_required" , true )
123
+ meta ( indexMetadata )
111
124
);
112
125
}
113
126
return null ;
@@ -117,7 +130,7 @@ private static boolean isNotDataStreamIndex(IndexMetadata indexMetadata, Cluster
117
130
return clusterState .metadata ().findDataStreams (indexMetadata .getIndex ().getName ()).isEmpty ();
118
131
}
119
132
120
- static DeprecationIssue translogRetentionSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
133
+ private static DeprecationIssue translogRetentionSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
121
134
final boolean softDeletesEnabled = IndexSettings .INDEX_SOFT_DELETES_SETTING .get (indexMetadata .getSettings ());
122
135
if (softDeletesEnabled ) {
123
136
if (IndexSettings .INDEX_TRANSLOG_RETENTION_SIZE_SETTING .exists (indexMetadata .getSettings ())
@@ -144,7 +157,7 @@ static DeprecationIssue translogRetentionSettingCheck(IndexMetadata indexMetadat
144
157
return null ;
145
158
}
146
159
147
- static DeprecationIssue checkIndexDataPath (IndexMetadata indexMetadata , ClusterState clusterState ) {
160
+ private static DeprecationIssue checkIndexDataPath (IndexMetadata indexMetadata , ClusterState clusterState ) {
148
161
if (IndexMetadata .INDEX_DATA_PATH_SETTING .exists (indexMetadata .getSettings ())) {
149
162
final String message = String .format (
150
163
Locale .ROOT ,
@@ -159,7 +172,7 @@ static DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ClusterS
159
172
return null ;
160
173
}
161
174
162
- static DeprecationIssue storeTypeSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
175
+ private static DeprecationIssue storeTypeSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
163
176
final String storeType = IndexModule .INDEX_STORE_TYPE_SETTING .get (indexMetadata .getSettings ());
164
177
if (IndexModule .Type .SIMPLEFS .match (storeType )) {
165
178
return new DeprecationIssue (
@@ -176,7 +189,7 @@ static DeprecationIssue storeTypeSettingCheck(IndexMetadata indexMetadata, Clust
176
189
return null ;
177
190
}
178
191
179
- static DeprecationIssue frozenIndexSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
192
+ private static DeprecationIssue frozenIndexSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
180
193
Boolean isIndexFrozen = FrozenEngine .INDEX_FROZEN .get (indexMetadata .getSettings ());
181
194
if (Boolean .TRUE .equals (isIndexFrozen )) {
182
195
String indexName = indexMetadata .getIndex ().getName ();
@@ -194,7 +207,7 @@ static DeprecationIssue frozenIndexSettingCheck(IndexMetadata indexMetadata, Clu
194
207
return null ;
195
208
}
196
209
197
- static DeprecationIssue legacyRoutingSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
210
+ private static DeprecationIssue legacyRoutingSettingCheck (IndexMetadata indexMetadata , ClusterState clusterState ) {
198
211
List <String > deprecatedSettings = LegacyTiersDetection .getDeprecatedFilteredAllocationSettings (indexMetadata .getSettings ());
199
212
if (deprecatedSettings .isEmpty ()) {
200
213
return null ;
@@ -228,7 +241,7 @@ private static void fieldLevelMappingIssue(IndexMetadata indexMetadata, BiConsum
228
241
* @return a list of issues found in fields
229
242
*/
230
243
@ SuppressWarnings ("unchecked" )
231
- static List <String > findInPropertiesRecursively (
244
+ private static List <String > findInPropertiesRecursively (
232
245
String type ,
233
246
Map <String , Object > parentMap ,
234
247
Function <Map <?, ?>, Boolean > predicate ,
@@ -282,7 +295,7 @@ static List<String> findInPropertiesRecursively(
282
295
return issues ;
283
296
}
284
297
285
- static DeprecationIssue deprecatedCamelCasePattern (IndexMetadata indexMetadata , ClusterState clusterState ) {
298
+ private static DeprecationIssue deprecatedCamelCasePattern (IndexMetadata indexMetadata , ClusterState clusterState ) {
286
299
List <String > fields = new ArrayList <>();
287
300
fieldLevelMappingIssue (
288
301
indexMetadata ,
0 commit comments