Skip to content

Commit 8496dde

Browse files
authored
[Deprecation] Add transform_ids to outdated index (elastic#120821) (elastic#121169)
When a transform is writing to an outdated destination index, the transform's id will show up in the index's deprecation warning under `index_settings._meta.transform_ids`.
1 parent f820c92 commit 8496dde

File tree

5 files changed

+221
-104
lines changed

5 files changed

+221
-104
lines changed

docs/changelog/120821.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 120821
2+
summary: "[Deprecation] Add `transform_ids` to outdated index"
3+
area: Transform
4+
type: enhancement
5+
issues: []

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecker.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
2121

2222
import java.util.ArrayList;
23-
import java.util.Collections;
2423
import java.util.HashMap;
2524
import java.util.List;
2625
import java.util.Locale;
@@ -39,21 +38,13 @@
3938
public 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,

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransformDeprecationChecker.java

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@
88
package org.elasticsearch.xpack.deprecation;
99

1010
import org.elasticsearch.action.ActionListener;
11-
import org.elasticsearch.cluster.metadata.Metadata;
1211
import org.elasticsearch.common.settings.Settings;
13-
import org.elasticsearch.xpack.core.action.util.PageParams;
1412
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
15-
import org.elasticsearch.xpack.core.transform.action.GetTransformAction;
1613
import org.elasticsearch.xpack.core.transform.transforms.TransformConfig;
1714

1815
import java.util.ArrayList;
1916
import java.util.List;
2017

21-
public class TransformDeprecationChecker implements DeprecationChecker {
18+
class TransformDeprecationChecker implements DeprecationChecker {
2219

2320
public static final String TRANSFORM_DEPRECATION_KEY = "transform_settings";
21+
private final List<TransformConfig> transformConfigs;
22+
23+
TransformDeprecationChecker(List<TransformConfig> transformConfigs) {
24+
this.transformConfigs = transformConfigs;
25+
}
2426

2527
@Override
2628
public boolean enabled(Settings settings) {
@@ -30,43 +32,17 @@ public boolean enabled(Settings settings) {
3032

3133
@Override
3234
public void check(Components components, ActionListener<CheckResult> deprecationIssueListener) {
33-
34-
PageParams startPage = new PageParams(0, PageParams.DEFAULT_SIZE);
35-
List<DeprecationIssue> issues = new ArrayList<>();
36-
recursiveGetTransformsAndCollectDeprecations(
37-
components,
38-
issues,
39-
startPage,
40-
deprecationIssueListener.delegateFailureAndWrap((l, allIssues) -> l.onResponse(new CheckResult(getName(), allIssues)))
41-
);
35+
ActionListener.completeWith(deprecationIssueListener, () -> {
36+
List<DeprecationIssue> allIssues = new ArrayList<>();
37+
for (var config : transformConfigs) {
38+
allIssues.addAll(config.checkForDeprecations(components.xContentRegistry()));
39+
}
40+
return new CheckResult(getName(), allIssues);
41+
});
4242
}
4343

4444
@Override
4545
public String getName() {
4646
return TRANSFORM_DEPRECATION_KEY;
4747
}
48-
49-
private static void recursiveGetTransformsAndCollectDeprecations(
50-
Components components,
51-
List<DeprecationIssue> issues,
52-
PageParams page,
53-
ActionListener<List<DeprecationIssue>> listener
54-
) {
55-
final GetTransformAction.Request request = new GetTransformAction.Request(Metadata.ALL);
56-
request.setPageParams(page);
57-
request.setAllowNoResources(true);
58-
59-
components.client()
60-
.execute(GetTransformAction.INSTANCE, request, listener.delegateFailureAndWrap((delegate, getTransformResponse) -> {
61-
for (TransformConfig config : getTransformResponse.getTransformConfigurations()) {
62-
issues.addAll(config.checkForDeprecations(components.xContentRegistry()));
63-
}
64-
if (getTransformResponse.getTransformConfigurationCount() >= (page.getFrom() + page.getSize())) {
65-
PageParams nextPage = new PageParams(page.getFrom() + page.getSize(), PageParams.DEFAULT_SIZE);
66-
recursiveGetTransformsAndCollectDeprecations(components, issues, nextPage, delegate);
67-
} else {
68-
delegate.onResponse(issues);
69-
}
70-
}));
71-
}
7248
}

0 commit comments

Comments
 (0)