Shrunk indices should ignore templates
A shrunk index should ignore anything from templates and instead take its mappings, aliases, and settings from the original index, plus any new settings and aliases passed in with the shrink request. This commit causes this to be the case. Relates #25380
This commit is contained in:
parent
b7bc790428
commit
e2bfb35f4a
|
@ -264,6 +264,9 @@ public class MetaDataCreateIndexService extends AbstractComponent {
|
|||
customs.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
final Index shrinkFromIndex = request.shrinkFrom();
|
||||
|
||||
if (shrinkFromIndex == null) {
|
||||
// apply templates, merging the mappings into the request mapping if exists
|
||||
for (IndexTemplateMetaData template : templates) {
|
||||
templateNames.add(template.getName());
|
||||
|
@ -312,11 +315,14 @@ public class MetaDataCreateIndexService extends AbstractComponent {
|
|||
templatesAliases.put(aliasMetaData.alias(), aliasMetaData);
|
||||
}
|
||||
}
|
||||
}
|
||||
Settings.Builder indexSettingsBuilder = Settings.builder();
|
||||
if (shrinkFromIndex == null) {
|
||||
// apply templates, here, in reverse order, since first ones are better matching
|
||||
for (int i = templates.size() - 1; i >= 0; i--) {
|
||||
indexSettingsBuilder.put(templates.get(i).settings());
|
||||
}
|
||||
}
|
||||
// now, put the request settings, so they override templates
|
||||
indexSettingsBuilder.put(request.settings());
|
||||
if (indexSettingsBuilder.get(SETTING_NUMBER_OF_SHARDS) == null) {
|
||||
|
@ -340,7 +346,6 @@ public class MetaDataCreateIndexService extends AbstractComponent {
|
|||
}
|
||||
indexSettingsBuilder.put(IndexMetaData.SETTING_INDEX_PROVIDED_NAME, request.getProvidedName());
|
||||
indexSettingsBuilder.put(SETTING_INDEX_UUID, UUIDs.randomBase64UUID());
|
||||
final Index shrinkFromIndex = request.shrinkFrom();
|
||||
final IndexMetaData.Builder tmpImdBuilder = IndexMetaData.builder(request.index());
|
||||
|
||||
final int routingNumShards;
|
||||
|
|
|
@ -67,6 +67,7 @@ public class PartitionedRoutingIT extends ESIntegTestCase {
|
|||
client().admin().indices().prepareCreate(index)
|
||||
.setSettings(Settings.builder()
|
||||
.put("index.number_of_shards", currentShards)
|
||||
.put("index.number_of_replicas", numberOfReplicas())
|
||||
.put("index.routing_partition_size", partitionSize))
|
||||
.addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}", XContentType.JSON)
|
||||
.execute().actionGet();
|
||||
|
@ -107,6 +108,7 @@ public class PartitionedRoutingIT extends ESIntegTestCase {
|
|||
client().admin().indices().prepareShrinkIndex(previousIndex, index)
|
||||
.setSettings(Settings.builder()
|
||||
.put("index.number_of_shards", currentShards)
|
||||
.put("index.number_of_replicas", numberOfReplicas())
|
||||
.build()).get();
|
||||
ensureGreen();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
---
|
||||
"Shrink index ignores target template mapping":
|
||||
- skip:
|
||||
version: " - 5.99.99"
|
||||
reason: bug fixed in 6.0
|
||||
|
||||
- do:
|
||||
cluster.state: {}
|
||||
# Get master node id
|
||||
|
||||
- set: { master_node: master }
|
||||
|
||||
# create index
|
||||
- do:
|
||||
indices.create:
|
||||
index: source
|
||||
wait_for_active_shards: 1
|
||||
body:
|
||||
settings:
|
||||
# ensure everything is allocated on a single node
|
||||
index.routing.allocation.include._id: $master
|
||||
number_of_replicas: 0
|
||||
mappings:
|
||||
test:
|
||||
properties:
|
||||
count:
|
||||
type: text
|
||||
|
||||
# index document
|
||||
- do:
|
||||
index:
|
||||
index: source
|
||||
type: test
|
||||
id: "1"
|
||||
body: { "count": "1" }
|
||||
|
||||
# create template matching shrink tagret
|
||||
- do:
|
||||
indices.put_template:
|
||||
name: tpl1
|
||||
body:
|
||||
index_patterns: targ*
|
||||
mappings:
|
||||
test:
|
||||
properties:
|
||||
count:
|
||||
type: integer
|
||||
|
||||
# make it read-only
|
||||
- do:
|
||||
indices.put_settings:
|
||||
index: source
|
||||
body:
|
||||
index.blocks.write: true
|
||||
index.number_of_replicas: 0
|
||||
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: green
|
||||
index: source
|
||||
|
||||
# now we do the actual shrink
|
||||
- do:
|
||||
indices.shrink:
|
||||
index: "source"
|
||||
target: "target"
|
||||
wait_for_active_shards: 1
|
||||
master_timeout: 10s
|
||||
body:
|
||||
settings:
|
||||
index.number_of_replicas: 0
|
||||
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: green
|
||||
|
||||
|
Loading…
Reference in New Issue