Skip to content

Commit

Permalink
Strip blocks from settings for reindex targets (#80887) (#81122)
Browse files Browse the repository at this point in the history
When migrating system features, we copy settings from old indices into
the new indices we create before reindexing. However, if we happen to
copy a write block, this causes the reindexing to fail. Here, we strip
the index block settings before applying settings to new indices. Fixes

Co-authored-by: William Brafford <[email protected]>
  • Loading branch information
gwbrown and williamrandolph authored Nov 29, 2021
1 parent f41a6ed commit 8ea0930
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,30 @@ public void testMigrateInternalManagedSystemIndex() throws Exception {
);
}

public void testMigrateIndexWithWriteBlock() throws Exception {
createSystemIndexForDescriptor(INTERNAL_UNMANAGED);

String indexName = Optional.ofNullable(INTERNAL_UNMANAGED.getPrimaryIndex())
.orElse(INTERNAL_UNMANAGED.getIndexPattern().replace("*", "old"));
client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder().put("index.blocks.write", true)).get();

TestPlugin.preMigrationHook.set((state) -> Collections.emptyMap());
TestPlugin.postMigrationHook.set((state, metadata) -> {});

ensureGreen();

client().execute(PostFeatureUpgradeAction.INSTANCE, new PostFeatureUpgradeRequest()).get();

assertBusy(() -> {
GetFeatureUpgradeStatusResponse statusResp = client().execute(
GetFeatureUpgradeStatusAction.INSTANCE,
new GetFeatureUpgradeStatusRequest()
).get();
logger.info(Strings.toString(statusResp));
assertThat(statusResp.getUpgradeStatus(), equalTo(GetFeatureUpgradeStatusResponse.UpgradeStatus.NO_MIGRATION_NEEDED));
});
}

public void assertIndexHasCorrectProperties(
Metadata metadata,
String indexName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -459,9 +460,16 @@ private void createIndex(SystemIndexMigrationInfo migrationInfo, ActionListener<
migrationInfo.getNextIndexName()
);

Settings.Builder settingsBuilder = Settings.builder();
if (Objects.nonNull(migrationInfo.getSettings())) {
settingsBuilder.put(migrationInfo.getSettings());
settingsBuilder.remove("index.blocks.write");
settingsBuilder.remove("index.blocks.read");
settingsBuilder.remove("index.blocks.metadata");
}
createRequest.waitForActiveShards(ActiveShardCount.ALL)
.mappings(Collections.singletonMap("_doc", migrationInfo.getMappings()))
.settings(migrationInfo.getSettings() == null ? Settings.EMPTY : migrationInfo.getSettings());
.settings(migrationInfo.getSettings() == null ? Settings.EMPTY : settingsBuilder.build());
metadataCreateIndexService.createIndex(createRequest, listener);
}

Expand Down

0 comments on commit 8ea0930

Please sign in to comment.