|
12 | 12 | import org.elasticsearch.action.admin.indices.shrink.ResizeType; |
13 | 13 | import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; |
14 | 14 | import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; |
| 15 | +import org.elasticsearch.common.ValidationException; |
15 | 16 | import org.elasticsearch.common.settings.Settings; |
16 | 17 | import org.elasticsearch.index.IndexVersion; |
17 | 18 | import org.elasticsearch.index.query.TermsQueryBuilder; |
|
20 | 21 | import org.elasticsearch.test.index.IndexVersionUtils; |
21 | 22 | import org.elasticsearch.xcontent.XContentType; |
22 | 23 |
|
| 24 | +import java.util.List; |
| 25 | + |
23 | 26 | import static org.elasticsearch.action.admin.indices.create.ShrinkIndexIT.assertNoResizeSourceIndexSettings; |
24 | 27 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
25 | 28 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; |
| 29 | +import static org.hamcrest.Matchers.containsString; |
26 | 30 | import static org.hamcrest.Matchers.equalTo; |
27 | 31 |
|
28 | 32 | public class CloneIndexIT extends ESIntegTestCase { |
@@ -109,4 +113,47 @@ public void testCreateCloneIndex() { |
109 | 113 |
|
110 | 114 | } |
111 | 115 |
|
| 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 | + Settings.builder().put("index.mode", "lookup").build() |
| 123 | + ); |
| 124 | + for (Settings settings : indexSettings) { |
| 125 | + IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> { |
| 126 | + indicesAdmin().prepareResizeIndex("source", "target").setResizeType(ResizeType.CLONE).setSettings(settings).get(); |
| 127 | + }); |
| 128 | + assertThat(error.getMessage(), equalTo("can't change setting [index.mode] during resize")); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + public void testResizeChangeSyntheticSource() { |
| 133 | + prepareCreate("source").setSettings(indexSettings(between(1, 5), 0)) |
| 134 | + .setMapping("@timestamp", "type=date", "host.name", "type=keyword") |
| 135 | + .get(); |
| 136 | + updateIndexSettings(Settings.builder().put("index.blocks.write", true), "source"); |
| 137 | + IllegalArgumentException error = expectThrows(IllegalArgumentException.class, () -> { |
| 138 | + indicesAdmin().prepareResizeIndex("source", "target") |
| 139 | + .setResizeType(ResizeType.CLONE) |
| 140 | + .setSettings(Settings.builder().put("index.mapping.source.mode", "synthetic").putNull("index.blocks.write").build()) |
| 141 | + .get(); |
| 142 | + }); |
| 143 | + assertThat(error.getMessage(), containsString("can't change setting [index.mapping.source.mode] during resize")); |
| 144 | + } |
| 145 | + |
| 146 | + public void testResizeChangeIndexSorts() { |
| 147 | + prepareCreate("source").setSettings(indexSettings(between(1, 5), 0)) |
| 148 | + .setMapping("@timestamp", "type=date", "host.name", "type=keyword") |
| 149 | + .get(); |
| 150 | + updateIndexSettings(Settings.builder().put("index.blocks.write", true), "source"); |
| 151 | + ValidationException error = expectThrows(ValidationException.class, () -> { |
| 152 | + indicesAdmin().prepareResizeIndex("source", "target") |
| 153 | + .setResizeType(ResizeType.CLONE) |
| 154 | + .setSettings(Settings.builder().putList("index.sort.field", List.of("@timestamp")).build()) |
| 155 | + .get(); |
| 156 | + }); |
| 157 | + assertThat(error.getMessage(), containsString("can't override index sort when resizing an index")); |
| 158 | + } |
112 | 159 | } |
0 commit comments