Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Boolean> preUpgradeHookCalled = new SetOnce<>();
Expand Down Expand Up @@ -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
)
);
Expand Down Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -282,20 +301,20 @@ 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()
.setIndexPattern(".ext-man-*")
.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()
Expand All @@ -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()
Expand Down Expand Up @@ -367,6 +387,12 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
return Arrays.asList(INTERNAL_MANAGED, INTERNAL_UNMANAGED, EXTERNAL_MANAGED, EXTERNAL_UNMANAGED);
}

@Override
public Collection<AssociatedIndexDescriptor> getAssociatedIndexDescriptors() {

return Collections.singletonList(new AssociatedIndexDescriptor(ASSOCIATED_INDEX_NAME, TestPlugin.class.getCanonicalName()));
}

@Override
public void prepareForIndicesMigration(ClusterService clusterService, Client client, ActionListener<Map<String, Object>> listener) {
listener.onResponse(preMigrationHook.get().apply(clusterService.state()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,8 +146,8 @@ static List<GetFeatureUpgradeStatusResponse.IndexInfo> 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))
Expand Down