From 43d4e38aecfb7a19d8455ccac8e8e092f2526b0b Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Wed, 3 Nov 2021 19:16:26 -0600 Subject: [PATCH] Don't include associated indices when checking Feature migration status (#80051) Prior to this PR, the Get Feature Migration Status API included the status of associated indices, but the migration framework doesn't handle associated indices - those can go though the standard reindex flow like any other index. Also modifies the test case to have an associated index, which causes the test to fail without the fix. --- .../migration/FeatureMigrationIT.java | 42 +++++++++++++++---- ...ransportGetFeatureUpgradeStatusAction.java | 6 +-- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/modules/reindex/src/internalClusterTest/java/org/elasticsearch/migration/FeatureMigrationIT.java b/modules/reindex/src/internalClusterTest/java/org/elasticsearch/migration/FeatureMigrationIT.java index 007359da2fcf0..17847e90cdb05 100644 --- a/modules/reindex/src/internalClusterTest/java/org/elasticsearch/migration/FeatureMigrationIT.java +++ b/modules/reindex/src/internalClusterTest/java/org/elasticsearch/migration/FeatureMigrationIT.java @@ -29,6 +29,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.indices.AssociatedIndexDescriptor; import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.SystemIndexPlugin; @@ -90,6 +91,18 @@ public void testMigrateInternalManagedSystemIndex() throws Exception { createSystemIndexForDescriptor(EXTERNAL_MANAGED); createSystemIndexForDescriptor(EXTERNAL_UNMANAGED); + CreateIndexRequestBuilder createRequest = prepareCreate(ASSOCIATED_INDEX_NAME); + createRequest.setWaitForActiveShards(ActiveShardCount.ALL); + createRequest.setSettings( + Settings.builder() + .put("index.version.created", NEEDS_UPGRADE_VERSION) + .put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0) + .put("index.hidden", true) // So we don't get a warning + .build() + ); + CreateIndexResponse response = createRequest.get(); + assertTrue(response.isShardsAcknowledged()); + ensureGreen(); SetOnce preUpgradeHookCalled = new SetOnce<>(); @@ -226,11 +239,16 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr CreateIndexRequestBuilder createRequest = prepareCreate(indexName); createRequest.setWaitForActiveShards(ActiveShardCount.ALL); if (descriptor.getSettings() != null) { - createRequest.setSettings(Settings.builder().put("index.version.created", Version.CURRENT).build()); + createRequest.setSettings( + Settings.builder() + .put("index.version.created", Version.CURRENT) + .put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0) + .build() + ); } else { createRequest.setSettings( createSimpleSettings( - Version.V_7_0_0, + NEEDS_UPGRADE_VERSION, descriptor.isInternal() ? INTERNAL_UNMANAGED_FLAG_VALUE : EXTERNAL_UNMANAGED_FLAG_VALUE ) ); @@ -258,6 +276,7 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr static final String ORIGIN = FeatureMigrationIT.class.getSimpleName(); static final String FlAG_SETTING_KEY = IndexMetadata.INDEX_PRIORITY_SETTING.getKey(); static final int INDEX_DOC_COUNT = 100; // arbitrarily chosen + public static final Version NEEDS_UPGRADE_VERSION = Version.V_7_0_0; static final int INTERNAL_MANAGED_FLAG_VALUE = 1; static final int INTERNAL_UNMANAGED_FLAG_VALUE = 2; @@ -268,12 +287,12 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr .setAliasName(".internal-managed-alias") .setPrimaryIndex(".int-man-old") .setType(SystemIndexDescriptor.Type.INTERNAL_MANAGED) - .setSettings(createSimpleSettings(Version.V_7_0_0, INTERNAL_MANAGED_FLAG_VALUE)) + .setSettings(createSimpleSettings(NEEDS_UPGRADE_VERSION, INTERNAL_MANAGED_FLAG_VALUE)) .setMappings(createSimpleMapping(true, true)) .setOrigin(ORIGIN) .setVersionMetaKey(VERSION_META_KEY) .setAllowedElasticProductOrigins(Collections.emptyList()) - .setMinimumNodeVersion(Version.V_7_0_0) + .setMinimumNodeVersion(NEEDS_UPGRADE_VERSION) .setPriorSystemIndexDescriptors(Collections.emptyList()) .build(); static final SystemIndexDescriptor INTERNAL_UNMANAGED = SystemIndexDescriptor.builder() @@ -282,7 +301,7 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr .setOrigin(ORIGIN) .setVersionMetaKey(VERSION_META_KEY) .setAllowedElasticProductOrigins(Collections.emptyList()) - .setMinimumNodeVersion(Version.V_7_0_0) + .setMinimumNodeVersion(NEEDS_UPGRADE_VERSION) .setPriorSystemIndexDescriptors(Collections.emptyList()) .build(); static final SystemIndexDescriptor EXTERNAL_MANAGED = SystemIndexDescriptor.builder() @@ -290,12 +309,12 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr .setAliasName(".external-managed-alias") .setPrimaryIndex(".ext-man-old") .setType(SystemIndexDescriptor.Type.EXTERNAL_MANAGED) - .setSettings(createSimpleSettings(Version.V_7_0_0, EXTERNAL_MANAGED_FLAG_VALUE)) + .setSettings(createSimpleSettings(NEEDS_UPGRADE_VERSION, EXTERNAL_MANAGED_FLAG_VALUE)) .setMappings(createSimpleMapping(true, false)) .setOrigin(ORIGIN) .setVersionMetaKey(VERSION_META_KEY) .setAllowedElasticProductOrigins(Collections.singletonList(ORIGIN)) - .setMinimumNodeVersion(Version.V_7_0_0) + .setMinimumNodeVersion(NEEDS_UPGRADE_VERSION) .setPriorSystemIndexDescriptors(Collections.emptyList()) .build(); static final SystemIndexDescriptor EXTERNAL_UNMANAGED = SystemIndexDescriptor.builder() @@ -304,9 +323,10 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr .setOrigin(ORIGIN) .setVersionMetaKey(VERSION_META_KEY) .setAllowedElasticProductOrigins(Collections.singletonList(ORIGIN)) - .setMinimumNodeVersion(Version.V_7_0_0) + .setMinimumNodeVersion(NEEDS_UPGRADE_VERSION) .setPriorSystemIndexDescriptors(Collections.emptyList()) .build(); + static final String ASSOCIATED_INDEX_NAME = ".my-associated-idx"; static Settings createSimpleSettings(Version creationVersion, int flagSettingValue) { return Settings.builder() @@ -367,6 +387,12 @@ public Collection getSystemIndexDescriptors(Settings sett return Arrays.asList(INTERNAL_MANAGED, INTERNAL_UNMANAGED, EXTERNAL_MANAGED, EXTERNAL_UNMANAGED); } + @Override + public Collection getAssociatedIndexDescriptors() { + + return Collections.singletonList(new AssociatedIndexDescriptor(ASSOCIATED_INDEX_NAME, TestPlugin.class.getCanonicalName())); + } + @Override public void prepareForIndicesMigration(ClusterService clusterService, Client client, ActionListener> listener) { listener.onResponse(preMigrationHook.get().apply(clusterService.state())); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/migration/TransportGetFeatureUpgradeStatusAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/migration/TransportGetFeatureUpgradeStatusAction.java index 993a617455dd3..46cf7800445de 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/migration/TransportGetFeatureUpgradeStatusAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/migration/TransportGetFeatureUpgradeStatusAction.java @@ -27,12 +27,10 @@ import org.elasticsearch.upgrades.SingleFeatureMigrationResult; import org.elasticsearch.upgrades.SystemIndexMigrationTaskState; -import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import java.util.stream.Stream; import static org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStatusResponse.UpgradeStatus.ERROR; import static org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStatusResponse.UpgradeStatus.IN_PROGRESS; @@ -148,8 +146,8 @@ static List getIndexInfos(ClusterStat final String failedFeatureName = featureStatus == null ? null : featureStatus.getFailedIndexName(); final Exception exception = featureStatus == null ? null : featureStatus.getException(); - return Stream.of(feature.getIndexDescriptors(), feature.getAssociatedIndexDescriptors()) - .flatMap(Collection::stream) + return feature.getIndexDescriptors() + .stream() .flatMap(descriptor -> descriptor.getMatchingIndices(state.metadata()).stream()) .sorted(String::compareTo) .map(index -> state.metadata().index(index))