Skip to content

Commit

Permalink
Correctly migrate system indices that are still using named types (#8…
Browse files Browse the repository at this point in the history
…3817)

Prior to this PR, the system index migration facility did not use the
index type configured in the descriptor, instead always using `_doc`.

This PR adjusts the migration facility to use the index type specified
in the descriptor instead.

Note that this PR is only targeted at 7.17, as it is the only version impacted.
  • Loading branch information
gwbrown committed Feb 17, 2022
1 parent f8e5598 commit c3f34f6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/83817.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 83817
summary: Correctly migrate system indices that are still using named types
area: Infra/Core
type: bug
issues:
- 83779
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,13 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
.setPrimaryIndex(".int-man-old")
.setType(SystemIndexDescriptor.Type.INTERNAL_MANAGED)
.setSettings(createSimpleSettings(NEEDS_UPGRADE_VERSION, INTERNAL_MANAGED_FLAG_VALUE))
.setMappings(createSimpleMapping(true, true, true))
.setMappings(createSimpleMapping(true, true, false)) // See note below
.setOrigin(ORIGIN)
.setVersionMetaKey(VERSION_META_KEY)
.setAllowedElasticProductOrigins(Collections.emptyList())
.setMinimumNodeVersion(NEEDS_UPGRADE_VERSION)
.setPriorSystemIndexDescriptors(Collections.emptyList())
.setIndexType("doc") // This simulates `.tasks`, which uses a nonstandard type name. EXTERNAL_MANAGED tests the default type.
.build();
static final SystemIndexDescriptor INTERNAL_UNMANAGED = SystemIndexDescriptor.builder()
.setIndexPattern(".int-unman-*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class SystemIndexMigrationInfo implements Comparable<SystemIndexMigrationInfo> {
private final Settings settings;
private final String mapping;
private final String origin;
private final String indexType;
private final SystemIndices.Feature owningFeature;

private static final Comparator<SystemIndexMigrationInfo> SAME_CLASS_COMPARATOR = Comparator.comparing(
Expand All @@ -59,13 +60,15 @@ private SystemIndexMigrationInfo(
Settings settings,
String mapping,
String origin,
String indexType,
SystemIndices.Feature owningFeature
) {
this.currentIndex = currentIndex;
this.featureName = featureName;
this.settings = settings;
this.mapping = mapping;
this.origin = origin;
this.indexType = indexType;
this.owningFeature = owningFeature;
}

Expand Down Expand Up @@ -118,6 +121,13 @@ String getOrigin() {
return origin;
}

/**
* Gets the type that should be used for the mapping of this index
*/
String getIndexType() {
return indexType;
}

/**
* Invokes the pre-migration hook for the feature that owns this index.
* See {@link SystemIndexPlugin#prepareForIndicesMigration(ClusterService, Client, ActionListener)}.
Expand Down Expand Up @@ -220,7 +230,15 @@ static SystemIndexMigrationInfo build(
}
}

return new SystemIndexMigrationInfo(currentIndex, feature.getName(), settings, mapping, descriptor.getOrigin(), feature);
return new SystemIndexMigrationInfo(
currentIndex,
feature.getName(),
settings,
mapping,
descriptor.getOrigin(),
descriptor.getIndexType(),
feature
);
}

private static Settings copySettingsForNewIndex(Settings currentIndexSettings, IndexScopedSettings indexScopedSettings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ private void createIndex(SystemIndexMigrationInfo migrationInfo, ActionListener<
settingsBuilder.remove("index.blocks.metadata");
}
createRequest.waitForActiveShards(ActiveShardCount.ALL)
.mappings(Collections.singletonMap("_doc", migrationInfo.getMappings()))
.mappings(Collections.singletonMap(migrationInfo.getIndexType(), migrationInfo.getMappings()))
.settings(migrationInfo.getSettings() == null ? Settings.EMPTY : settingsBuilder.build());
metadataCreateIndexService.createIndex(createRequest, listener);
}
Expand Down

0 comments on commit c3f34f6

Please sign in to comment.