|
23 | 23 | import org.elasticsearch.common.settings.Settings; |
24 | 24 | import org.elasticsearch.common.unit.ByteSizeUnit; |
25 | 25 | import org.elasticsearch.core.TimeValue; |
| 26 | +import org.elasticsearch.index.IndexMode; |
26 | 27 | import org.elasticsearch.index.IndexVersion; |
27 | 28 | import org.elasticsearch.index.IndexVersions; |
28 | 29 | import org.elasticsearch.indices.InvalidIndexNameException; |
@@ -761,6 +762,68 @@ public void testChangeSettingsOnRestore() throws Exception { |
761 | 762 | assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "bar")), numdocs); |
762 | 763 | } |
763 | 764 |
|
| 765 | + public void testRestoreChangeIndexMode() { |
| 766 | + Client client = client(); |
| 767 | + createRepository("test-repo", "fs"); |
| 768 | + String indexName = "test-idx"; |
| 769 | + assertAcked(client.admin().indices().prepareCreate(indexName).setSettings(Settings.builder().put(indexSettings()))); |
| 770 | + createSnapshot("test-repo", "test-snap", Collections.singletonList(indexName)); |
| 771 | + cluster().wipeIndices(indexName); |
| 772 | + for (IndexMode mode : IndexMode.values()) { |
| 773 | + var error = expectThrows(SnapshotRestoreException.class, () -> { |
| 774 | + client.admin() |
| 775 | + .cluster() |
| 776 | + .prepareRestoreSnapshot(TEST_REQUEST_TIMEOUT, "test-repo", "test-snap") |
| 777 | + .setIndexSettings(Settings.builder().put("index.mode", mode.name())) |
| 778 | + .setWaitForCompletion(true) |
| 779 | + .get(); |
| 780 | + }); |
| 781 | + assertThat(error.getMessage(), containsString("cannot modify setting [index.mode] on restore")); |
| 782 | + } |
| 783 | + } |
| 784 | + |
| 785 | + public void testRestoreChangeSyntheticSource() { |
| 786 | + Client client = client(); |
| 787 | + createRepository("test-repo", "fs"); |
| 788 | + String indexName = "test-idx"; |
| 789 | + assertAcked(client.admin().indices().prepareCreate(indexName).setSettings(Settings.builder().put(indexSettings()))); |
| 790 | + createSnapshot("test-repo", "test-snap", Collections.singletonList(indexName)); |
| 791 | + cluster().wipeIndices(indexName); |
| 792 | + var error = expectThrows(SnapshotRestoreException.class, () -> { |
| 793 | + client.admin() |
| 794 | + .cluster() |
| 795 | + .prepareRestoreSnapshot(TEST_REQUEST_TIMEOUT, "test-repo", "test-snap") |
| 796 | + .setIndexSettings(Settings.builder().put("index.mapping.source.mode", "synthetic")) |
| 797 | + .setWaitForCompletion(true) |
| 798 | + .get(); |
| 799 | + }); |
| 800 | + assertThat(error.getMessage(), containsString("cannot modify setting [index.mapping.source.mode] on restore")); |
| 801 | + } |
| 802 | + |
| 803 | + public void testRestoreChangeIndexSorts() { |
| 804 | + Client client = client(); |
| 805 | + createRepository("test-repo", "fs"); |
| 806 | + String indexName = "test-idx"; |
| 807 | + assertAcked( |
| 808 | + client.admin() |
| 809 | + .indices() |
| 810 | + .prepareCreate(indexName) |
| 811 | + .setMapping("host.name", "type=keyword", "@timestamp", "type=date") |
| 812 | + .setSettings(Settings.builder().put(indexSettings()).putList("index.sort.field", List.of("@timestamp", "host.name"))) |
| 813 | + ); |
| 814 | + createSnapshot("test-repo", "test-snap", Collections.singletonList(indexName)); |
| 815 | + cluster().wipeIndices(indexName); |
| 816 | + var error = expectThrows(SnapshotRestoreException.class, () -> { |
| 817 | + client.admin() |
| 818 | + .cluster() |
| 819 | + .prepareRestoreSnapshot(TEST_REQUEST_TIMEOUT, "test-repo", "test-snap") |
| 820 | + .setIndexSettings(Settings.builder().putList("index.sort.field", List.of("host.name"))) |
| 821 | + .setWaitForCompletion(true) |
| 822 | + .get(); |
| 823 | + }); |
| 824 | + assertThat(error.getMessage(), containsString("cannot modify setting [index.sort.field] on restore")); |
| 825 | + } |
| 826 | + |
764 | 827 | public void testRecreateBlocksOnRestore() throws Exception { |
765 | 828 | Client client = client(); |
766 | 829 |
|
|
0 commit comments