Skip to content

Commit f06e936

Browse files
authored
Ensure removal of index blocks does not leave key with null value (#122246) (#122264)
* ES-10801 Ensure removal of index blocks does not leave key with null value * Update docs/changelog/122246.yaml
1 parent 3c250e8 commit f06e936

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

docs/changelog/122246.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122246
2+
summary: Ensure removal of index blocks does not leave key with null value
3+
area: Data streams
4+
type: bug
5+
issues: []

x-pack/plugin/migrate/src/internalClusterTest/java/org/elasticsearch/xpack/migrate/action/CreateIndexFromSourceActionIT.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.Map;
3333

3434
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
35+
import static org.hamcrest.Matchers.hasItem;
36+
import static org.hamcrest.Matchers.not;
3537

3638
public class CreateIndexFromSourceActionIT extends ESIntegTestCase {
3739

@@ -236,9 +238,9 @@ public void testRemoveIndexBlocksByDefault() throws Exception {
236238
var destSettings = settingsResponse.getIndexToSettings().get(destIndex);
237239

238240
// remove block settings override both source settings and override settings
239-
assertNull(destSettings.get(IndexMetadata.SETTING_BLOCKS_WRITE));
240-
assertNull(destSettings.get(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE));
241-
assertNull(destSettings.get(IndexMetadata.SETTING_BLOCKS_READ));
241+
assertThat(destSettings.keySet(), not(hasItem(IndexMetadata.SETTING_BLOCKS_WRITE)));
242+
assertThat(destSettings.keySet(), not(hasItem(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE)));
243+
assertThat(destSettings.keySet(), not(hasItem(IndexMetadata.SETTING_BLOCKS_READ)));
242244
}
243245

244246
public void testMappingsOverridden() {

x-pack/plugin/migrate/src/main/java/org/elasticsearch/xpack/migrate/action/CreateIndexFromSourceTransportAction.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ public class CreateIndexFromSourceTransportAction extends HandledTransportAction
4646
private final ClusterService clusterService;
4747
private final Client client;
4848
private final IndexScopedSettings indexScopedSettings;
49-
private static final Settings REMOVE_INDEX_BLOCKS_SETTING_OVERRIDE = Settings.builder()
50-
.putNull(IndexMetadata.SETTING_READ_ONLY)
51-
.putNull(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE)
52-
.putNull(IndexMetadata.SETTING_BLOCKS_WRITE)
53-
.putNull(IndexMetadata.SETTING_BLOCKS_METADATA)
54-
.putNull(IndexMetadata.SETTING_BLOCKS_READ)
55-
.build();
49+
private static final Set<String> INDEX_BLOCK_SETTINGS = Set.of(
50+
IndexMetadata.SETTING_READ_ONLY,
51+
IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE,
52+
IndexMetadata.SETTING_BLOCKS_WRITE,
53+
IndexMetadata.SETTING_BLOCKS_METADATA,
54+
IndexMetadata.SETTING_BLOCKS_READ
55+
);
5656

5757
@Inject
5858
public CreateIndexFromSourceTransportAction(
@@ -94,7 +94,7 @@ protected void doExecute(Task task, CreateIndexFromSourceAction.Request request,
9494
.put(request.settingsOverride());
9595
if (request.removeIndexBlocks()) {
9696
// lastly, override with settings to remove index blocks if requested
97-
settings.put(REMOVE_INDEX_BLOCKS_SETTING_OVERRIDE);
97+
INDEX_BLOCK_SETTINGS.forEach(settings::remove);
9898
}
9999

100100
Map<String, Object> mergeMappings;

0 commit comments

Comments
 (0)