diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java index cc05bb4c82ceb..57a666763a92e 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java @@ -54,6 +54,7 @@ public class TestSystemIndexDescriptor extends SystemIndexDescriptor { "version", "stack", null, + null, Type.INTERNAL_MANAGED, List.of(), List.of(), @@ -75,6 +76,7 @@ public class TestSystemIndexDescriptor extends SystemIndexDescriptor { "version", "stack", Version.fromString(Build.current().minWireCompatVersion()), + null, Type.INTERNAL_MANAGED, List.of(), List.of(), diff --git a/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java b/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java index cf8ecccaf67e8..5fa8221d263b6 100644 --- a/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java +++ b/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java @@ -14,6 +14,7 @@ import org.apache.lucene.util.automaton.Operations; import org.apache.lucene.util.automaton.RegExp; import org.elasticsearch.Version; +import org.elasticsearch.action.admin.cluster.migration.TransportGetFeatureUpgradeStatusAction; import org.elasticsearch.action.admin.indices.create.AutoCreateAction; import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction; import org.elasticsearch.cluster.metadata.IndexMetadata; @@ -149,6 +150,24 @@ public class SystemIndexDescriptor implements IndexPatternMatcher, Comparable + * Note: the script usually should only exist in the versions supporting migration to the next major release - + * specifically, the last (two) minors of the current major. + * It should be created once the last minor branch has diverged from the next major branch (main). + * This ensures the script is available only in the versions where it is needed + * and avoids removing and maintaining it in the next major branch. + * For example: In order to migrate an index created in v7 when upgrading to v9, + * the script should be in the v8 minors supporting upgrade to v9 - 8.18 and 8.19. + *
+ * See: Reindex scripts + */ + private final String migrationScript; + /** The minimum cluster node version required for this descriptor */ private final Version minimumNodeVersion; @@ -210,6 +229,7 @@ public class SystemIndexDescriptor implements IndexPatternMatcher, Comparable allowedElasticProductOrigins, List priorSystemIndexDescriptors, @@ -365,6 +386,7 @@ protected SystemIndexDescriptor( this.description = description; this.mappings = mappings; + this.migrationScript = migrationScript; settings = Objects.isNull(settings) ? Settings.EMPTY : settings; @@ -644,6 +666,10 @@ public ExecutorNames getThreadPoolNames() { return this.executorNames; } + public String getMigrationScript() { + return migrationScript; + } + public static Builder builder() { return new Builder(); } @@ -748,6 +774,7 @@ public static class Builder { private String versionMetaKey = null; private String origin = null; private Version minimumNodeVersion = Version.CURRENT.minimumCompatibilityVersion(); + private String migrationScript; private Type type = Type.INTERNAL_MANAGED; private List allowedElasticProductOrigins = List.of(); private List priorSystemIndexDescriptors = List.of(); @@ -820,6 +847,11 @@ public Builder setMinimumNodeVersion(Version version) { return this; } + public Builder setMigrationScript(String migrationScript) { + this.migrationScript = migrationScript; + return this; + } + public Builder setType(Type type) { this.type = type; return this; @@ -866,6 +898,7 @@ public SystemIndexDescriptor build() { versionMetaKey, origin, minimumNodeVersion, + migrationScript, type, allowedElasticProductOrigins, priorSystemIndexDescriptors, diff --git a/server/src/main/java/org/elasticsearch/upgrades/SystemIndexMigrationInfo.java b/server/src/main/java/org/elasticsearch/upgrades/SystemIndexMigrationInfo.java index a0e9461558b6b..4768a5cae7dad 100644 --- a/server/src/main/java/org/elasticsearch/upgrades/SystemIndexMigrationInfo.java +++ b/server/src/main/java/org/elasticsearch/upgrades/SystemIndexMigrationInfo.java @@ -44,6 +44,7 @@ class SystemIndexMigrationInfo implements Comparable { private final Settings settings; private final String mapping; private final String origin; + private final String migrationScript; private final SystemIndices.Feature owningFeature; private final boolean allowsTemplates; @@ -57,6 +58,7 @@ private SystemIndexMigrationInfo( Settings settings, String mapping, String origin, + String migrationScript, SystemIndices.Feature owningFeature, boolean allowsTemplates ) { @@ -65,6 +67,7 @@ private SystemIndexMigrationInfo( this.settings = settings; this.mapping = mapping; this.origin = origin; + this.migrationScript = migrationScript; this.owningFeature = owningFeature; this.allowsTemplates = allowsTemplates; } @@ -118,6 +121,10 @@ String getOrigin() { return origin; } + String getMigrationScript() { + return migrationScript; + } + /** * By default, system indices should not be affected by user defined templates, so this * method should return false in almost all cases. At the moment certain Kibana indices use @@ -217,6 +224,7 @@ static SystemIndexMigrationInfo build( settings, mapping, descriptor.getOrigin(), + descriptor.getMigrationScript(), feature, descriptor.allowsTemplates() ); diff --git a/server/src/main/java/org/elasticsearch/upgrades/SystemIndexMigrator.java b/server/src/main/java/org/elasticsearch/upgrades/SystemIndexMigrator.java index 3e1d901a1f237..2215fd33730eb 100644 --- a/server/src/main/java/org/elasticsearch/upgrades/SystemIndexMigrator.java +++ b/server/src/main/java/org/elasticsearch/upgrades/SystemIndexMigrator.java @@ -44,6 +44,7 @@ import org.elasticsearch.index.reindex.ReindexRequest; import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.persistent.AllocatedPersistentTask; +import org.elasticsearch.script.Script; import org.elasticsearch.tasks.TaskId; import java.util.LinkedList; @@ -556,6 +557,10 @@ private void reindex(SystemIndexMigrationInfo migrationInfo, ActionListener