Skip to content

Commit d07afa4

Browse files
authored
Revert "Update upgrade assistant API to account for percolator fields (elastic#137548)" (elastic#137910)
Reverts elastic#137548
1 parent 2b96865 commit d07afa4

File tree

8 files changed

+151
-324
lines changed

8 files changed

+151
-324
lines changed

docs/reference/rest-api/common-options.asciidoc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ Returns:
243243
"index.creation_date": "1474389951325",
244244
"index.uuid": "n6gzFZTgS664GUfx0Xrpjw",
245245
"index.version.created": ...,
246-
"index.transport_version.created": ...,
247246
"index.routing.allocation.include._tier_preference" : "data_content",
248247
"index.provided_name" : "my-index-000001"
249248
}
@@ -253,7 +252,6 @@ Returns:
253252
// TESTRESPONSE[s/1474389951325/$body.my-index-000001.settings.index\\\\.creation_date/]
254253
// TESTRESPONSE[s/n6gzFZTgS664GUfx0Xrpjw/$body.my-index-000001.settings.index\\\\.uuid/]
255254
// TESTRESPONSE[s/"index.version.created": \.\.\./"index.version.created": $body.my-index-000001.settings.index\\\\.version\\\\.created/]
256-
// TESTRESPONSE[s/"index.transport_version.created": \.\.\./"index.transport_version.created": $body.my-index-000001.settings.index\\\\.transport_version\\\\.created/]
257255

258256
When the `flat_settings` flag is `false`, settings are returned in a more
259257
human readable structured format:
@@ -277,10 +275,7 @@ Returns:
277275
"creation_date": "1474389951325",
278276
"uuid": "n6gzFZTgS664GUfx0Xrpjw",
279277
"version": {
280-
"created": .v.
281-
},
282-
"transport_version": {
283-
"created": .tv.
278+
"created": ...
284279
},
285280
"routing": {
286281
"allocation": {
@@ -297,8 +292,7 @@ Returns:
297292
--------------------------------------------------
298293
// TESTRESPONSE[s/1474389951325/$body.my-index-000001.settings.index.creation_date/]
299294
// TESTRESPONSE[s/n6gzFZTgS664GUfx0Xrpjw/$body.my-index-000001.settings.index.uuid/]
300-
// TESTRESPONSE[s/"created": \.v\./"created": $body.my-index-000001.settings.index.version.created/]
301-
// TESTRESPONSE[s/"created": \.tv\./"created": $body.my-index-000001.settings.index.transport_version.created/]
295+
// TESTRESPONSE[s/"created": \.\.\./"created": $body.my-index-000001.settings.index.version.created/]
302296

303297
By default `flat_settings` is set to `false`.
304298

server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,16 +369,6 @@ public static APIBlock readFrom(StreamInput input) throws IOException {
369369
Property.PrivateIndex
370370
);
371371

372-
public static final String SETTING_TRANSPORT_VERSION_CREATED = "index.transport_version.created";
373-
374-
public static final Setting<TransportVersion> SETTING_INDEX_TRANSPORT_VERSION_CREATED = Setting.versionIdSetting(
375-
SETTING_TRANSPORT_VERSION_CREATED,
376-
TransportVersion.fromId(0),
377-
TransportVersion::fromId,
378-
Property.IndexScope,
379-
Property.PrivateIndex
380-
);
381-
382372
public static final String SETTING_VERSION_CREATED_STRING = "index.version.created_string";
383373
public static final String SETTING_CREATION_DATE = "index.creation_date";
384374

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,9 +1127,6 @@ static Settings aggregateIndexSettings(
11271127
IndexVersion createdVersion = IndexVersion.min(IndexVersion.current(), nodes.getMaxDataNodeCompatibleIndexVersion());
11281128
indexSettingsBuilder.put(IndexMetadata.SETTING_VERSION_CREATED, createdVersion);
11291129
}
1130-
if (indexSettingsBuilder.get(IndexMetadata.SETTING_TRANSPORT_VERSION_CREATED) == null) {
1131-
indexSettingsBuilder.put(IndexMetadata.SETTING_TRANSPORT_VERSION_CREATED, TransportVersion.current());
1132-
}
11331130
if (INDEX_NUMBER_OF_SHARDS_SETTING.exists(indexSettingsBuilder) == false) {
11341131
indexSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, INDEX_NUMBER_OF_SHARDS_SETTING.get(settings));
11351132
}

server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
5858
MergeSchedulerConfig.MAX_THREAD_COUNT_SETTING,
5959
IndexMetadata.SETTING_INDEX_VERSION_CREATED,
6060
IndexMetadata.SETTING_INDEX_VERSION_COMPATIBILITY,
61-
IndexMetadata.SETTING_INDEX_TRANSPORT_VERSION_CREATED,
6261
IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_SETTING,
6362
IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_SETTING,
6463
IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING,

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

Lines changed: 1 addition & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,13 @@
77

88
package org.elasticsearch.xpack.core.deprecation;
99

10-
import org.elasticsearch.TransportVersion;
1110
import org.elasticsearch.cluster.metadata.IndexMetadata;
1211
import org.elasticsearch.cluster.metadata.Metadata;
1312
import org.elasticsearch.cluster.metadata.MetadataIndexStateService;
1413
import org.elasticsearch.index.Index;
1514
import org.elasticsearch.index.IndexVersion;
1615
import org.elasticsearch.index.IndexVersions;
1716

18-
import java.util.ArrayList;
19-
import java.util.List;
20-
import java.util.Map;
21-
import java.util.function.BiFunction;
22-
import java.util.function.Function;
2317
import java.util.function.Predicate;
2418

2519
public class DeprecatedIndexPredicate {
@@ -55,7 +49,7 @@ public static Predicate<Index> getReindexRequiredPredicate(Metadata metadata, bo
5549
* if false, only those without a block are returned
5650
* @param includeSystem if true, all indices including system will be returned,
5751
* if false, only non-system indices are returned
58-
* @return returns true for indices that need to be reindexed
52+
* @return a predicate that returns true for indices that need to be reindexed
5953
*/
6054
public static boolean reindexRequired(IndexMetadata indexMetadata, boolean filterToBlockedStatus, boolean includeSystem) {
6155
return creationVersionBeforeMinimumWritableVersion(indexMetadata)
@@ -64,59 +58,6 @@ && isNotSearchableSnapshot(indexMetadata)
6458
&& matchBlockedStatus(indexMetadata, filterToBlockedStatus);
6559
}
6660

67-
/**
68-
* This method checks if this index is on the current transport version for the current minor release version.
69-
*
70-
* @param indexMetadata the index metadata
71-
* @param filterToBlockedStatus if true, only indices that are write blocked will be returned,
72-
* if false, only those without a block are returned
73-
* @param includeSystem if true, all indices including system will be returned,
74-
* if false, only non-system indices are returned
75-
* @return returns true for indices that need to be reindexed
76-
*/
77-
public static boolean reindexRequiredForTransportVersion(
78-
IndexMetadata indexMetadata,
79-
boolean filterToBlockedStatus,
80-
boolean includeSystem
81-
) {
82-
return transportVersionBeforeCurrentMinorRelease(indexMetadata)
83-
&& (includeSystem || isNotSystem(indexMetadata))
84-
&& isNotSearchableSnapshot(indexMetadata)
85-
&& matchBlockedStatus(indexMetadata, filterToBlockedStatus);
86-
}
87-
88-
/**
89-
* This method checks if this index requires reindexing based on if it has percolator fields older than the current transport version
90-
* for the current minor release.
91-
*
92-
* @param indexMetadata the index metadata
93-
* @param filterToBlockedStatus if true, only indices that are write blocked will be returned,
94-
* if false, only those without a block are returned
95-
* @param includeSystem if true, all indices including system will be returned,
96-
* if false, only non-system indices are returned
97-
* @return returns a message as a string for each incompatible percolator field found
98-
*/
99-
public static List<String> reindexRequiredForPecolatorFields(
100-
IndexMetadata indexMetadata,
101-
boolean filterToBlockedStatus,
102-
boolean includeSystem
103-
) {
104-
List<String> percolatorIncompatibleFieldMappings = new ArrayList<>();
105-
if (reindexRequiredForTransportVersion(indexMetadata, filterToBlockedStatus, includeSystem) && indexMetadata.mapping() != null) {
106-
percolatorIncompatibleFieldMappings.addAll(
107-
findInPropertiesRecursively(
108-
indexMetadata.mapping().type(),
109-
indexMetadata.mapping().sourceAsMap(),
110-
property -> "percolator".equals(property.get("type")),
111-
(type, entry) -> "Field [" + entry.getKey() + "] is of type [" + indexMetadata.mapping().type() + "]",
112-
"",
113-
""
114-
)
115-
);
116-
}
117-
return percolatorIncompatibleFieldMappings;
118-
}
119-
12061
private static boolean isNotSystem(IndexMetadata indexMetadata) {
12162
return indexMetadata.isSystem() == false;
12263
}
@@ -132,76 +73,4 @@ private static boolean creationVersionBeforeMinimumWritableVersion(IndexMetadata
13273
private static boolean matchBlockedStatus(IndexMetadata indexMetadata, boolean filterToBlockedStatus) {
13374
return MetadataIndexStateService.VERIFIED_READ_ONLY_SETTING.get(indexMetadata.getSettings()) == filterToBlockedStatus;
13475
}
135-
136-
private static boolean transportVersionBeforeCurrentMinorRelease(IndexMetadata indexMetadata) {
137-
// We divide each transport version by 1000 to get the base id.
138-
return IndexMetadata.SETTING_INDEX_TRANSPORT_VERSION_CREATED.get(indexMetadata.getSettings()).id() / 1000 < TransportVersion
139-
.current()
140-
.id() / 1000;
141-
}
142-
143-
/**
144-
* iterates through the "properties" field of mappings and returns any predicates that match in the
145-
* form of issue-strings.
146-
*
147-
* @param type the document type
148-
* @param parentMap the mapping to read properties from
149-
* @param predicate the predicate to check against for issues, issue is returned if predicate evaluates to true
150-
* @param fieldFormatter a function that takes a type and mapping field entry and returns a formatted field representation
151-
* @return a list of issues found in fields
152-
*/
153-
@SuppressWarnings("unchecked")
154-
public static List<String> findInPropertiesRecursively(
155-
String type,
156-
Map<String, Object> parentMap,
157-
Function<Map<?, ?>, Boolean> predicate,
158-
BiFunction<String, Map.Entry<?, ?>, String> fieldFormatter,
159-
String fieldBeginMarker,
160-
String fieldEndMarker
161-
) {
162-
List<String> issues = new ArrayList<>();
163-
Map<?, ?> properties = (Map<?, ?>) parentMap.get("properties");
164-
if (properties == null) {
165-
return issues;
166-
}
167-
for (Map.Entry<?, ?> entry : properties.entrySet()) {
168-
Map<String, Object> valueMap = (Map<String, Object>) entry.getValue();
169-
if (predicate.apply(valueMap)) {
170-
issues.add(fieldBeginMarker + fieldFormatter.apply(type, entry) + fieldEndMarker);
171-
}
172-
173-
Map<?, ?> values = (Map<?, ?>) valueMap.get("fields");
174-
if (values != null) {
175-
for (Map.Entry<?, ?> multifieldEntry : values.entrySet()) {
176-
Map<String, Object> multifieldValueMap = (Map<String, Object>) multifieldEntry.getValue();
177-
if (predicate.apply(multifieldValueMap)) {
178-
issues.add(
179-
fieldBeginMarker
180-
+ fieldFormatter.apply(type, entry)
181-
+ ", multifield: "
182-
+ multifieldEntry.getKey()
183-
+ fieldEndMarker
184-
);
185-
}
186-
if (multifieldValueMap.containsKey("properties")) {
187-
issues.addAll(
188-
findInPropertiesRecursively(
189-
type,
190-
multifieldValueMap,
191-
predicate,
192-
fieldFormatter,
193-
fieldBeginMarker,
194-
fieldEndMarker
195-
)
196-
);
197-
}
198-
}
199-
}
200-
if (valueMap.containsKey("properties")) {
201-
issues.addAll(findInPropertiesRecursively(type, valueMap, predicate, fieldFormatter, fieldBeginMarker, fieldEndMarker));
202-
}
203-
}
204-
205-
return issues;
206-
}
20776
}

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

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,9 @@ public Map<String, List<DeprecationIssue>> check(ClusterState clusterState) {
8888

8989
static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
9090
List<Index> backingIndices = dataStream.getIndices();
91-
Set<String> percolatorIndicesNeedingUpgrade = getReindexRequiredIndicesWithPercolatorFields(backingIndices, clusterState, false);
92-
if (percolatorIndicesNeedingUpgrade.isEmpty() == false) {
93-
return new DeprecationIssue(
94-
DeprecationIssue.Level.CRITICAL,
95-
"Field mappings with incompatible percolator type",
96-
"https://www.elastic.co/guide/en/elasticsearch/reference/8.19/percolator.html#_reindexing_your_percolator_queries",
97-
"The data stream was created before 8.19 and contains mappings that must be reindexed due to containing percolator fields.",
98-
false,
99-
ofEntries(
100-
entry("reindex_required", true),
101-
entry("excluded_actions", List.of("readOnly")),
102-
entry("total_backing_indices", backingIndices.size()),
103-
entry("indices_requiring_upgrade_count", percolatorIndicesNeedingUpgrade.size()),
104-
entry("indices_requiring_upgrade", percolatorIndicesNeedingUpgrade)
105-
)
106-
);
107-
}
91+
10892
Set<String> indicesNeedingUpgrade = getReindexRequiredIndices(backingIndices, clusterState, false);
93+
10994
if (indicesNeedingUpgrade.isEmpty() == false) {
11095
return new DeprecationIssue(
11196
DeprecationIssue.Level.CRITICAL,
@@ -127,23 +112,6 @@ static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clus
127112

128113
static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
129114
List<Index> backingIndices = dataStream.getIndices();
130-
Set<String> percolatorIgnoredIndices = getReindexRequiredIndicesWithPercolatorFields(backingIndices, clusterState, true);
131-
if (percolatorIgnoredIndices.isEmpty() == false) {
132-
return new DeprecationIssue(
133-
DeprecationIssue.Level.CRITICAL,
134-
"Field mappings with incompatible percolator type",
135-
"https://www.elastic.co/guide/en/elasticsearch/reference/8.19/percolator.html#_reindexing_your_percolator_queries",
136-
"The data stream was created before 8.19 and contains mappings that must be reindexed due to containing percolator fields.",
137-
false,
138-
ofEntries(
139-
entry("reindex_required", true),
140-
entry("excluded_actions", List.of("readOnly")),
141-
entry("total_backing_indices", backingIndices.size()),
142-
entry("ignored_indices_requiring_upgrade_count", percolatorIgnoredIndices.size()),
143-
entry("ignored_indices_requiring_upgrade", percolatorIgnoredIndices)
144-
)
145-
);
146-
}
147115
Set<String> ignoredIndices = getReindexRequiredIndices(backingIndices, clusterState, true);
148116
if (ignoredIndices.isEmpty() == false) {
149117
return new DeprecationIssue(
@@ -176,23 +144,6 @@ private static Set<String> getReindexRequiredIndices(
176144
.collect(Collectors.toUnmodifiableSet());
177145
}
178146

179-
private static Set<String> getReindexRequiredIndicesWithPercolatorFields(
180-
List<Index> backingIndices,
181-
ClusterState clusterState,
182-
boolean filterToBlockedStatus
183-
) {
184-
return backingIndices.stream()
185-
.filter(
186-
index -> DeprecatedIndexPredicate.reindexRequiredForPecolatorFields(
187-
clusterState.metadata().index(index),
188-
filterToBlockedStatus,
189-
false
190-
).isEmpty() == false
191-
)
192-
.map(Index::getName)
193-
.collect(Collectors.toUnmodifiableSet());
194-
}
195-
196147
@Override
197148
public String getName() {
198149
return NAME;

0 commit comments

Comments
 (0)