Skip to content

Commit c4693bb

Browse files
authored
Don't include associated indices when checking Feature migration status (#80051) (#80324)
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.
1 parent 7e23c54 commit c4693bb

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

modules/reindex/src/internalClusterTest/java/org/elasticsearch/migration/FeatureMigrationIT.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.cluster.service.ClusterService;
3030
import org.elasticsearch.common.Strings;
3131
import org.elasticsearch.common.settings.Settings;
32+
import org.elasticsearch.indices.AssociatedIndexDescriptor;
3233
import org.elasticsearch.indices.SystemIndexDescriptor;
3334
import org.elasticsearch.plugins.Plugin;
3435
import org.elasticsearch.plugins.SystemIndexPlugin;
@@ -90,6 +91,18 @@ public void testMigrateInternalManagedSystemIndex() throws Exception {
9091
createSystemIndexForDescriptor(EXTERNAL_MANAGED);
9192
createSystemIndexForDescriptor(EXTERNAL_UNMANAGED);
9293

94+
CreateIndexRequestBuilder createRequest = prepareCreate(ASSOCIATED_INDEX_NAME);
95+
createRequest.setWaitForActiveShards(ActiveShardCount.ALL);
96+
createRequest.setSettings(
97+
Settings.builder()
98+
.put("index.version.created", NEEDS_UPGRADE_VERSION)
99+
.put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
100+
.put("index.hidden", true) // So we don't get a warning
101+
.build()
102+
);
103+
CreateIndexResponse response = createRequest.get();
104+
assertTrue(response.isShardsAcknowledged());
105+
93106
ensureGreen();
94107

95108
SetOnce<Boolean> preUpgradeHookCalled = new SetOnce<>();
@@ -226,11 +239,16 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
226239
CreateIndexRequestBuilder createRequest = prepareCreate(indexName);
227240
createRequest.setWaitForActiveShards(ActiveShardCount.ALL);
228241
if (descriptor.getSettings() != null) {
229-
createRequest.setSettings(Settings.builder().put("index.version.created", Version.CURRENT).build());
242+
createRequest.setSettings(
243+
Settings.builder()
244+
.put("index.version.created", Version.CURRENT)
245+
.put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
246+
.build()
247+
);
230248
} else {
231249
createRequest.setSettings(
232250
createSimpleSettings(
233-
Version.V_7_0_0,
251+
NEEDS_UPGRADE_VERSION,
234252
descriptor.isInternal() ? INTERNAL_UNMANAGED_FLAG_VALUE : EXTERNAL_UNMANAGED_FLAG_VALUE
235253
)
236254
);
@@ -258,6 +276,7 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
258276
static final String ORIGIN = FeatureMigrationIT.class.getSimpleName();
259277
static final String FlAG_SETTING_KEY = IndexMetadata.INDEX_PRIORITY_SETTING.getKey();
260278
static final int INDEX_DOC_COUNT = 100; // arbitrarily chosen
279+
public static final Version NEEDS_UPGRADE_VERSION = Version.V_7_0_0;
261280

262281
static final int INTERNAL_MANAGED_FLAG_VALUE = 1;
263282
static final int INTERNAL_UNMANAGED_FLAG_VALUE = 2;
@@ -268,12 +287,12 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
268287
.setAliasName(".internal-managed-alias")
269288
.setPrimaryIndex(".int-man-old")
270289
.setType(SystemIndexDescriptor.Type.INTERNAL_MANAGED)
271-
.setSettings(createSimpleSettings(Version.V_7_0_0, INTERNAL_MANAGED_FLAG_VALUE))
290+
.setSettings(createSimpleSettings(NEEDS_UPGRADE_VERSION, INTERNAL_MANAGED_FLAG_VALUE))
272291
.setMappings(createSimpleMapping(true, true))
273292
.setOrigin(ORIGIN)
274293
.setVersionMetaKey(VERSION_META_KEY)
275294
.setAllowedElasticProductOrigins(Collections.emptyList())
276-
.setMinimumNodeVersion(Version.V_7_0_0)
295+
.setMinimumNodeVersion(NEEDS_UPGRADE_VERSION)
277296
.setPriorSystemIndexDescriptors(Collections.emptyList())
278297
.build();
279298
static final SystemIndexDescriptor INTERNAL_UNMANAGED = SystemIndexDescriptor.builder()
@@ -282,20 +301,20 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
282301
.setOrigin(ORIGIN)
283302
.setVersionMetaKey(VERSION_META_KEY)
284303
.setAllowedElasticProductOrigins(Collections.emptyList())
285-
.setMinimumNodeVersion(Version.V_7_0_0)
304+
.setMinimumNodeVersion(NEEDS_UPGRADE_VERSION)
286305
.setPriorSystemIndexDescriptors(Collections.emptyList())
287306
.build();
288307
static final SystemIndexDescriptor EXTERNAL_MANAGED = SystemIndexDescriptor.builder()
289308
.setIndexPattern(".ext-man-*")
290309
.setAliasName(".external-managed-alias")
291310
.setPrimaryIndex(".ext-man-old")
292311
.setType(SystemIndexDescriptor.Type.EXTERNAL_MANAGED)
293-
.setSettings(createSimpleSettings(Version.V_7_0_0, EXTERNAL_MANAGED_FLAG_VALUE))
312+
.setSettings(createSimpleSettings(NEEDS_UPGRADE_VERSION, EXTERNAL_MANAGED_FLAG_VALUE))
294313
.setMappings(createSimpleMapping(true, false))
295314
.setOrigin(ORIGIN)
296315
.setVersionMetaKey(VERSION_META_KEY)
297316
.setAllowedElasticProductOrigins(Collections.singletonList(ORIGIN))
298-
.setMinimumNodeVersion(Version.V_7_0_0)
317+
.setMinimumNodeVersion(NEEDS_UPGRADE_VERSION)
299318
.setPriorSystemIndexDescriptors(Collections.emptyList())
300319
.build();
301320
static final SystemIndexDescriptor EXTERNAL_UNMANAGED = SystemIndexDescriptor.builder()
@@ -304,9 +323,10 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
304323
.setOrigin(ORIGIN)
305324
.setVersionMetaKey(VERSION_META_KEY)
306325
.setAllowedElasticProductOrigins(Collections.singletonList(ORIGIN))
307-
.setMinimumNodeVersion(Version.V_7_0_0)
326+
.setMinimumNodeVersion(NEEDS_UPGRADE_VERSION)
308327
.setPriorSystemIndexDescriptors(Collections.emptyList())
309328
.build();
329+
static final String ASSOCIATED_INDEX_NAME = ".my-associated-idx";
310330

311331
static Settings createSimpleSettings(Version creationVersion, int flagSettingValue) {
312332
return Settings.builder()
@@ -367,6 +387,12 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
367387
return Arrays.asList(INTERNAL_MANAGED, INTERNAL_UNMANAGED, EXTERNAL_MANAGED, EXTERNAL_UNMANAGED);
368388
}
369389

390+
@Override
391+
public Collection<AssociatedIndexDescriptor> getAssociatedIndexDescriptors() {
392+
393+
return Collections.singletonList(new AssociatedIndexDescriptor(ASSOCIATED_INDEX_NAME, TestPlugin.class.getCanonicalName()));
394+
}
395+
370396
@Override
371397
public void prepareForIndicesMigration(ClusterService clusterService, Client client, ActionListener<Map<String, Object>> listener) {
372398
listener.onResponse(preMigrationHook.get().apply(clusterService.state()));

server/src/main/java/org/elasticsearch/action/admin/cluster/migration/TransportGetFeatureUpgradeStatusAction.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@
2727
import org.elasticsearch.upgrades.SingleFeatureMigrationResult;
2828
import org.elasticsearch.upgrades.SystemIndexMigrationTaskState;
2929

30-
import java.util.Collection;
3130
import java.util.Comparator;
3231
import java.util.List;
3332
import java.util.Optional;
3433
import java.util.stream.Collectors;
35-
import java.util.stream.Stream;
3634

3735
import static org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStatusResponse.UpgradeStatus.ERROR;
3836
import static org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStatusResponse.UpgradeStatus.IN_PROGRESS;
@@ -148,8 +146,8 @@ static List<GetFeatureUpgradeStatusResponse.IndexInfo> getIndexInfos(ClusterStat
148146
final String failedFeatureName = featureStatus == null ? null : featureStatus.getFailedIndexName();
149147
final Exception exception = featureStatus == null ? null : featureStatus.getException();
150148

151-
return Stream.of(feature.getIndexDescriptors(), feature.getAssociatedIndexDescriptors())
152-
.flatMap(Collection::stream)
149+
return feature.getIndexDescriptors()
150+
.stream()
153151
.flatMap(descriptor -> descriptor.getMatchingIndices(state.metadata()).stream())
154152
.sorted(String::compareTo)
155153
.map(index -> state.metadata().index(index))

0 commit comments

Comments
 (0)