Skip to content

Commit a425c05

Browse files
[8.18] Move system indices migration to migrate plugin (elastic#123551) (elastic#123934)
* Move system indices migration to migrate plugin (elastic#123551) It seems the best way to fix elastic#122949 is to use existing data stream reindex API. However, this API is located in the migrate x-pack plugin. This commit moves the system indices migration logic (REST handlers, transport actions, and task) to the migrate plugin. (cherry picked from commit 0a769c8) * Restore tests
1 parent ca7981c commit a425c05

File tree

51 files changed

+370
-410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+370
-410
lines changed

modules/reindex/build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ dependencies {
4545
clusterModules project(':modules:lang-painless')
4646
clusterModules project(':modules:parent-join')
4747
clusterModules project(":modules:rest-root")
48-
49-
internalClusterTestImplementation project(':modules:lang-painless')
50-
internalClusterTestImplementation project(':modules:lang-painless:spi')
5148
}
5249

5350
restResources {

modules/reindex/src/main/plugin-metadata/plugin-security.policy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
grant {
1111
// reindex opens socket connections using the rest client
1212
permission java.net.SocketPermission "*", "connect";
13-
14-
// needed for Painless to generate runtime classes
15-
permission java.lang.RuntimePermission "createClassLoader";
1613
};
1714

1815
grant codeBase "${codebase.elasticsearch-rest-client}" {

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/FeatureUpgradeIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
import com.carrotsearch.randomizedtesting.annotations.Name;
1313

14-
import org.elasticsearch.action.admin.cluster.migration.TransportGetFeatureUpgradeStatusAction;
1514
import org.elasticsearch.client.Request;
1615
import org.elasticsearch.client.ResponseException;
16+
import org.elasticsearch.indices.SystemIndices;
1717
import org.elasticsearch.test.XContentTestUtils;
1818
import org.junit.BeforeClass;
1919

@@ -112,7 +112,7 @@ public void testGetFeatureUpgradeStatus() throws Exception {
112112
// for the next major version upgrade (see e.g. #93666). Trying to express this with features may be problematic, so we
113113
// want to keep using versions here. We also assume that for non-semantic version migrations are not required.
114114
boolean migrationNeeded = parseLegacyVersion(getOldClusterVersion()).map(
115-
v -> v.before(TransportGetFeatureUpgradeStatusAction.NO_UPGRADE_REQUIRED_VERSION)
115+
v -> v.before(SystemIndices.NO_UPGRADE_REQUIRED_VERSION)
116116
).orElse(false);
117117
if (migrationNeeded) {
118118
assertThat(feature.get("migration_status"), equalTo("MIGRATION_NEEDED"));

rest-api-spec/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,6 @@ tasks.named("yamlRestTestV7CompatTransform").configure({ task ->
276276
task.skipTest("search.vectors/130_knn_query_nested_search/nested kNN search inner_hits size > 1", "waiting for #118774 backport")
277277
task.skipTest("search.vectors/110_knn_query_with_filter/PRE_FILTER: pre-filter across multiple aliases", "waiting for #118774 backport")
278278
task.skipTest("search.vectors/160_knn_query_missing_params/kNN search in a dis_max query - missing num_candidates", "waiting for #118774 backport")
279+
task.skipTest("migration/10_get_feature_upgrade_status/Get feature upgrade status", "Moved to plugin")
280+
task.skipTest("migration/20_post_feature_upgrade/Get feature upgrade status", "Moved to plugin")
279281
})

server/src/main/java/module-info.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
exports org.elasticsearch.action.admin.cluster.coordination;
6363
exports org.elasticsearch.action.admin.cluster.desirednodes;
6464
exports org.elasticsearch.action.admin.cluster.health;
65-
exports org.elasticsearch.action.admin.cluster.migration;
6665
exports org.elasticsearch.action.admin.cluster.node.capabilities;
6766
exports org.elasticsearch.action.admin.cluster.node.hotthreads;
6867
exports org.elasticsearch.action.admin.cluster.node.info;
@@ -380,7 +379,6 @@
380379
exports org.elasticsearch.tasks;
381380
exports org.elasticsearch.threadpool;
382381
exports org.elasticsearch.transport;
383-
exports org.elasticsearch.upgrades;
384382
exports org.elasticsearch.usage;
385383
exports org.elasticsearch.watcher;
386384

server/src/main/java/org/elasticsearch/action/ActionModule.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
import org.elasticsearch.action.admin.cluster.desirednodes.TransportUpdateDesiredNodesAction;
2727
import org.elasticsearch.action.admin.cluster.desirednodes.UpdateDesiredNodesAction;
2828
import org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction;
29-
import org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStatusAction;
30-
import org.elasticsearch.action.admin.cluster.migration.PostFeatureUpgradeAction;
31-
import org.elasticsearch.action.admin.cluster.migration.TransportGetFeatureUpgradeStatusAction;
32-
import org.elasticsearch.action.admin.cluster.migration.TransportPostFeatureUpgradeAction;
3329
import org.elasticsearch.action.admin.cluster.node.capabilities.TransportNodesCapabilitiesAction;
3430
import org.elasticsearch.action.admin.cluster.node.features.TransportNodesFeaturesAction;
3531
import org.elasticsearch.action.admin.cluster.node.hotthreads.TransportNodesHotThreadsAction;
@@ -283,7 +279,6 @@
283279
import org.elasticsearch.rest.action.admin.cluster.RestDeleteStoredScriptAction;
284280
import org.elasticsearch.rest.action.admin.cluster.RestGetDesiredBalanceAction;
285281
import org.elasticsearch.rest.action.admin.cluster.RestGetDesiredNodesAction;
286-
import org.elasticsearch.rest.action.admin.cluster.RestGetFeatureUpgradeStatusAction;
287282
import org.elasticsearch.rest.action.admin.cluster.RestGetRepositoriesAction;
288283
import org.elasticsearch.rest.action.admin.cluster.RestGetScriptContextAction;
289284
import org.elasticsearch.rest.action.admin.cluster.RestGetScriptLanguageAction;
@@ -297,7 +292,6 @@
297292
import org.elasticsearch.rest.action.admin.cluster.RestNodesStatsAction;
298293
import org.elasticsearch.rest.action.admin.cluster.RestNodesUsageAction;
299294
import org.elasticsearch.rest.action.admin.cluster.RestPendingClusterTasksAction;
300-
import org.elasticsearch.rest.action.admin.cluster.RestPostFeatureUpgradeAction;
301295
import org.elasticsearch.rest.action.admin.cluster.RestPrevalidateNodeRemovalAction;
302296
import org.elasticsearch.rest.action.admin.cluster.RestPutRepositoryAction;
303297
import org.elasticsearch.rest.action.admin.cluster.RestPutStoredScriptAction;
@@ -671,10 +665,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
671665
actions.register(TransportSnapshotsStatusAction.TYPE, TransportSnapshotsStatusAction.class);
672666
actions.register(SnapshottableFeaturesAction.INSTANCE, TransportSnapshottableFeaturesAction.class);
673667
actions.register(ResetFeatureStateAction.INSTANCE, TransportResetFeatureStateAction.class);
674-
actions.register(GetFeatureUpgradeStatusAction.INSTANCE, TransportGetFeatureUpgradeStatusAction.class);
675-
actions.register(PostFeatureUpgradeAction.INSTANCE, TransportPostFeatureUpgradeAction.class);
676668
actions.register(TransportGetShardSnapshotAction.TYPE, TransportGetShardSnapshotAction.class);
677-
678669
actions.register(IndicesStatsAction.INSTANCE, TransportIndicesStatsAction.class);
679670
actions.register(IndicesSegmentsAction.INSTANCE, TransportIndicesSegmentsAction.class);
680671
actions.register(TransportIndicesShardStoresAction.TYPE, TransportIndicesShardStoresAction.class);
@@ -872,8 +863,6 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster, Predicate<
872863
registerHandler.accept(new RestSnapshotsStatusAction());
873864
registerHandler.accept(new RestSnapshottableFeaturesAction());
874865
registerHandler.accept(new RestResetFeatureStateAction());
875-
registerHandler.accept(new RestGetFeatureUpgradeStatusAction());
876-
registerHandler.accept(new RestPostFeatureUpgradeAction());
877866
registerHandler.accept(new RestGetIndicesAction());
878867
registerHandler.accept(new RestIndicesStatsAction());
879868
registerHandler.accept(new RestIndicesSegmentsAction());

server/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected void masterOperation(
142142
listener.onFailure(new IllegalStateException(message));
143143
return;
144144
}
145-
updateRequest = buildSystemIndexUpdateRequest(request, cause, descriptor);
145+
updateRequest = buildManagedSystemIndexUpdateRequest(request, cause, descriptor);
146146
} else {
147147
updateRequest = buildUpdateRequest(request, cause, indexName, resolvedAt);
148148
}
@@ -174,30 +174,54 @@ private CreateIndexClusterStateUpdateRequest buildUpdateRequest(
174174
.waitForActiveShards(request.waitForActiveShards());
175175
}
176176

177-
private static CreateIndexClusterStateUpdateRequest buildSystemIndexUpdateRequest(
177+
private static CreateIndexClusterStateUpdateRequest buildManagedSystemIndexUpdateRequest(
178178
CreateIndexRequest request,
179179
String cause,
180180
SystemIndexDescriptor descriptor
181181
) {
182-
final Settings settings = Objects.requireNonNullElse(descriptor.getSettings(), Settings.EMPTY);
182+
boolean indexMigrationInProgress = cause.equals(SystemIndices.MIGRATE_SYSTEM_INDEX_CAUSE)
183+
&& request.index().endsWith(SystemIndices.UPGRADED_INDEX_SUFFIX);
183184

185+
final Settings settings;
186+
final String mappings;
184187
final Set<Alias> aliases;
185-
if (descriptor.getAliasName() == null) {
188+
final String indexName;
189+
190+
// if we are migrating a system index to a new index, we use settings/mappings/index name from the request,
191+
// since it was created by SystemIndexMigrator
192+
if (indexMigrationInProgress) {
193+
settings = request.settings();
194+
mappings = request.mappings();
195+
indexName = request.index();
196+
// we will update alias later on
186197
aliases = Set.of();
187198
} else {
188-
aliases = Set.of(new Alias(descriptor.getAliasName()).isHidden(true).writeIndex(true));
189-
}
199+
settings = Objects.requireNonNullElse(descriptor.getSettings(), Settings.EMPTY);
200+
mappings = descriptor.getMappings();
201+
202+
if (descriptor.getAliasName() == null) {
203+
aliases = Set.of();
204+
} else {
205+
aliases = Set.of(new Alias(descriptor.getAliasName()).isHidden(true).writeIndex(true));
206+
}
190207

191-
// Throw an error if we are trying to directly create a system index other than the primary system index (or the alias)
192-
if (request.index().equals(descriptor.getPrimaryIndex()) == false && request.index().equals(descriptor.getAliasName()) == false) {
193-
throw new IllegalArgumentException(
194-
"Cannot create system index with name " + request.index() + "; descriptor primary index is " + descriptor.getPrimaryIndex()
195-
);
208+
// Throw an error if we are trying to directly create a system index other
209+
// than the primary system index (or the alias, or we are migrating the index)
210+
if (request.index().equals(descriptor.getPrimaryIndex()) == false
211+
&& request.index().equals(descriptor.getAliasName()) == false) {
212+
throw new IllegalArgumentException(
213+
"Cannot create system index with name "
214+
+ request.index()
215+
+ "; descriptor primary index is "
216+
+ descriptor.getPrimaryIndex()
217+
);
218+
}
219+
indexName = descriptor.getPrimaryIndex();
196220
}
197221

198-
return new CreateIndexClusterStateUpdateRequest(cause, descriptor.getPrimaryIndex(), request.index()).aliases(aliases)
222+
return new CreateIndexClusterStateUpdateRequest(cause, indexName, request.index()).aliases(aliases)
199223
.waitForActiveShards(ActiveShardCount.ALL)
200-
.mappings(descriptor.getMappings())
224+
.mappings(mappings)
201225
.settings(settings);
202226
}
203227
}

server/src/main/java/org/elasticsearch/cluster/ClusterModule.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
import org.elasticsearch.tasks.TaskResultsService;
8585
import org.elasticsearch.telemetry.TelemetryProvider;
8686
import org.elasticsearch.threadpool.ThreadPool;
87-
import org.elasticsearch.upgrades.FeatureMigrationResults;
8887
import org.elasticsearch.xcontent.NamedXContentRegistry;
8988
import org.elasticsearch.xcontent.ParseField;
9089

@@ -235,7 +234,6 @@ public static List<Entry> getNamedWriteables() {
235234
);
236235
registerMetadataCustom(entries, DataStreamMetadata.TYPE, DataStreamMetadata::new, DataStreamMetadata::readDiffFrom);
237236
registerMetadataCustom(entries, NodesShutdownMetadata.TYPE, NodesShutdownMetadata::new, NodesShutdownMetadata::readDiffFrom);
238-
registerMetadataCustom(entries, FeatureMigrationResults.TYPE, FeatureMigrationResults::new, FeatureMigrationResults::readDiffFrom);
239237
registerMetadataCustom(entries, DesiredNodesMetadata.TYPE, DesiredNodesMetadata::new, DesiredNodesMetadata::readDiffFrom);
240238
registerMetadataCustom(
241239
entries,

server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.apache.lucene.util.automaton.Operations;
1515
import org.apache.lucene.util.automaton.RegExp;
1616
import org.elasticsearch.Version;
17-
import org.elasticsearch.action.admin.cluster.migration.TransportGetFeatureUpgradeStatusAction;
1817
import org.elasticsearch.action.admin.indices.create.AutoCreateAction;
1918
import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
2019
import org.elasticsearch.cluster.metadata.IndexMetadata;
@@ -152,7 +151,7 @@ public class SystemIndexDescriptor implements IndexPatternMatcher, Comparable<Sy
152151

153152
/**
154153
* An optional reindexing script to use when migrating an index created
155-
* before {@link TransportGetFeatureUpgradeStatusAction#NO_UPGRADE_REQUIRED_INDEX_VERSION}.
154+
* before {@link SystemIndices#NO_UPGRADE_REQUIRED_INDEX_VERSION}.
156155
* This script can be used to modify documents before they are added to the new index.
157156
* For example, it can be used to remove deprecated fields from the index.
158157
* <br>

server/src/main/java/org/elasticsearch/indices/SystemIndices.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.apache.lucene.util.automaton.CharacterRunAutomaton;
1717
import org.apache.lucene.util.automaton.MinimizationOperations;
1818
import org.apache.lucene.util.automaton.Operations;
19+
import org.elasticsearch.Version;
1920
import org.elasticsearch.action.ActionListener;
2021
import org.elasticsearch.action.admin.cluster.snapshots.features.ResetFeatureStateResponse.ResetFeatureStateStatus;
2122
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
@@ -37,6 +38,8 @@
3738
import org.elasticsearch.core.Predicates;
3839
import org.elasticsearch.core.Tuple;
3940
import org.elasticsearch.index.Index;
41+
import org.elasticsearch.index.IndexVersion;
42+
import org.elasticsearch.index.IndexVersions;
4043
import org.elasticsearch.plugins.SystemIndexPlugin;
4144
import org.elasticsearch.snapshots.SnapshotsService;
4245

@@ -111,7 +114,16 @@
111114
public class SystemIndices {
112115
public static final String SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY = "_system_index_access_allowed";
113116
public static final String EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY = "_external_system_index_access_origin";
114-
public static final String UPGRADED_INDEX_SUFFIX = "-reindexed-for-9";
117+
118+
/**
119+
* These versions should be set to current major and current major's index version
120+
*/
121+
public static final Version NO_UPGRADE_REQUIRED_VERSION = Version.V_8_0_0;
122+
public static final IndexVersion NO_UPGRADE_REQUIRED_INDEX_VERSION = IndexVersions.V_8_0_0;
123+
public static final String MIGRATE_SYSTEM_INDEX_CAUSE = "migrate-system-index";
124+
125+
private static final int UPGRADED_TO_VERSION = NO_UPGRADE_REQUIRED_VERSION.major + 1;
126+
public static final String UPGRADED_INDEX_SUFFIX = "-reindexed-for-" + UPGRADED_TO_VERSION;
115127

116128
private static final Automaton EMPTY = Automata.makeEmpty();
117129

@@ -347,6 +359,7 @@ public ExecutorSelector getExecutorSelector() {
347359

348360
/**
349361
* Finds a single matching {@link SystemIndexDescriptor}, if any, for the given index name.
362+
* Does not take into account system data streams and their backing indices.
350363
* @param name the name of the index
351364
* @return The matching {@link SystemIndexDescriptor} or {@code null} if no descriptor is found
352365
*/
@@ -355,7 +368,7 @@ public ExecutorSelector getExecutorSelector() {
355368
}
356369

357370
@Nullable
358-
static SystemIndexDescriptor findMatchingDescriptor(SystemIndexDescriptor[] indexDescriptors, String name) {
371+
private static SystemIndexDescriptor findMatchingDescriptor(SystemIndexDescriptor[] indexDescriptors, String name) {
359372
SystemIndexDescriptor matchingDescriptor = null;
360373
for (SystemIndexDescriptor systemIndexDescriptor : indexDescriptors) {
361374
if (systemIndexDescriptor.matchesIndexPattern(name)) {

0 commit comments

Comments
 (0)