Skip to content

Commit f0469a4

Browse files
authored
Prohibit changes to index mode, source, and sort settings during resize (#115812) (#115971) (#117445)
Relates to #115811, but applies to resize requests. The index.mode, source.mode, and index.sort.* settings cannot be modified during resize, as this may lead to data corruption or issues retrieving _source. This change enforces a restriction on modifying these settings during resize. While a fine-grained check could allow equivalent settings, it seems simpler and safer to reject resize requests if any of these settings are specified.
1 parent 7fab756 commit f0469a4

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

docs/changelog/115812.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 115812
2+
summary: "Prohibit changes to index mode, source, and sort settings during resize"
3+
area: Logs
4+
type: bug
5+
issues: []

server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/CloneIndexIT.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
1313
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
1414
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
15+
import org.elasticsearch.common.ValidationException;
1516
import org.elasticsearch.common.settings.Settings;
1617
import org.elasticsearch.index.IndexVersion;
1718
import org.elasticsearch.index.query.TermsQueryBuilder;
@@ -20,9 +21,12 @@
2021
import org.elasticsearch.test.index.IndexVersionUtils;
2122
import org.elasticsearch.xcontent.XContentType;
2223

24+
import java.util.List;
25+
2326
import static org.elasticsearch.action.admin.indices.create.ShrinkIndexIT.assertNoResizeSourceIndexSettings;
2427
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
2528
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
29+
import static org.hamcrest.Matchers.containsString;
2630
import static org.hamcrest.Matchers.equalTo;
2731

2832
public class CloneIndexIT extends ESIntegTestCase {
@@ -109,4 +113,46 @@ public void testCreateCloneIndex() {
109113

110114
}
111115

116+
public void testResizeChangeIndexMode() {
117+
prepareCreate("source").setSettings(indexSettings(1, 0)).setMapping("@timestamp", "type=date", "host.name", "type=keyword").get();
118+
updateIndexSettings(Settings.builder().put("index.blocks.write", true), "source");
119+
List<Settings> indexSettings = List.of(
120+
Settings.builder().put("index.mode", "logsdb").build(),
121+
Settings.builder().put("index.mode", "time_series").put("index.routing_path", "host.name").build()
122+
);
123+
for (Settings settings : indexSettings) {
124+
IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> {
125+
indicesAdmin().prepareResizeIndex("source", "target").setResizeType(ResizeType.CLONE).setSettings(settings).get();
126+
});
127+
assertThat(error.getMessage(), equalTo("can't change setting [index.mode] during resize"));
128+
}
129+
}
130+
131+
public void testResizeChangeSyntheticSource() {
132+
prepareCreate("source").setSettings(indexSettings(between(1, 5), 0))
133+
.setMapping("@timestamp", "type=date", "host.name", "type=keyword")
134+
.get();
135+
updateIndexSettings(Settings.builder().put("index.blocks.write", true), "source");
136+
IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> {
137+
indicesAdmin().prepareResizeIndex("source", "target")
138+
.setResizeType(ResizeType.CLONE)
139+
.setSettings(Settings.builder().put("index.mapping.source.mode", "synthetic").putNull("index.blocks.write").build())
140+
.get();
141+
});
142+
assertThat(error.getMessage(), containsString("can't change setting [index.mapping.source.mode] during resize"));
143+
}
144+
145+
public void testResizeChangeIndexSorts() {
146+
prepareCreate("source").setSettings(indexSettings(between(1, 5), 0))
147+
.setMapping("@timestamp", "type=date", "host.name", "type=keyword")
148+
.get();
149+
updateIndexSettings(Settings.builder().put("index.blocks.write", true), "source");
150+
ValidationException error = expectThrows(ValidationException.class, () -> {
151+
indicesAdmin().prepareResizeIndex("source", "target")
152+
.setResizeType(ResizeType.CLONE)
153+
.setSettings(Settings.builder().putList("index.sort.field", List.of("@timestamp")).build())
154+
.get();
155+
});
156+
assertThat(error.getMessage(), containsString("can't override index sort when resizing an index"));
157+
}
112158
}

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@
6262
import org.elasticsearch.index.IndexSettingProvider;
6363
import org.elasticsearch.index.IndexSettingProviders;
6464
import org.elasticsearch.index.IndexSettings;
65+
import org.elasticsearch.index.IndexSortConfig;
6566
import org.elasticsearch.index.IndexVersion;
6667
import org.elasticsearch.index.IndexVersions;
6768
import org.elasticsearch.index.mapper.DocumentMapper;
6869
import org.elasticsearch.index.mapper.MapperService;
6970
import org.elasticsearch.index.mapper.MapperService.MergeReason;
71+
import org.elasticsearch.index.mapper.SourceFieldMapper;
7072
import org.elasticsearch.index.query.SearchExecutionContext;
7173
import org.elasticsearch.index.shard.IndexLongFieldRange;
7274
import org.elasticsearch.indices.IndexCreationException;
@@ -1549,6 +1551,15 @@ static void validateCloneIndex(
15491551
IndexMetadata.selectCloneShard(0, sourceMetadata, INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings));
15501552
}
15511553

1554+
private static final Set<String> UNMODIFIABLE_SETTINGS_DURING_RESIZE = Set.of(
1555+
IndexSettings.MODE.getKey(),
1556+
SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(),
1557+
IndexSortConfig.INDEX_SORT_FIELD_SETTING.getKey(),
1558+
IndexSortConfig.INDEX_SORT_ORDER_SETTING.getKey(),
1559+
IndexSortConfig.INDEX_SORT_MODE_SETTING.getKey(),
1560+
IndexSortConfig.INDEX_SORT_MISSING_SETTING.getKey()
1561+
);
1562+
15521563
static IndexMetadata validateResize(
15531564
Metadata metadata,
15541565
ClusterBlocks clusterBlocks,
@@ -1586,6 +1597,11 @@ static IndexMetadata validateResize(
15861597
// of if the source shards are divisible by the number of target shards
15871598
IndexMetadata.getRoutingFactor(sourceMetadata.getNumberOfShards(), INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings));
15881599
}
1600+
for (String setting : UNMODIFIABLE_SETTINGS_DURING_RESIZE) {
1601+
if (targetIndexSettings.hasValue(setting)) {
1602+
throw new IllegalArgumentException("can't change setting [" + setting + "] during resize");
1603+
}
1604+
}
15891605
return sourceMetadata;
15901606
}
15911607

0 commit comments

Comments
 (0)