-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) Today if we try to shrink or to split a searchable snapshot index using the Resize API a new index will be created but can't be assigned, and even if it was assigned it won't work as the number of shards can't be changed and must always match the number of shards from the snapshot. This commit adds some verification to prevent a snapshot backed indices to be resized and if an attempt is made, throw a better error message. Note that cloning is supported since #56595 and in this change we make sure that it is only used to convert the searchable snapshot index back to a regular index. Relates #74977 (comment)
- Loading branch information
Showing
2 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsResizeIntegTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.searchablesnapshots; | ||
|
||
import org.elasticsearch.action.admin.indices.shrink.ResizeType; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.IndexModule; | ||
import org.elasticsearch.repositories.fs.FsRepository; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; | ||
import org.elasticsearch.xpack.core.DataTier; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING; | ||
import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING; | ||
import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING; | ||
import static org.elasticsearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest.Storage; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
@ESIntegTestCase.ClusterScope(numDataNodes = 1) | ||
public class SearchableSnapshotsResizeIntegTests extends BaseFrozenSearchableSnapshotsIntegTestCase { | ||
|
||
@Before | ||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
createRepository("repository", FsRepository.TYPE); | ||
assertAcked( | ||
prepareCreate( | ||
"index", | ||
Settings.builder() | ||
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0) | ||
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 2) | ||
.put(INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey(), 4) | ||
.put(INDEX_SOFT_DELETES_SETTING.getKey(), true) | ||
) | ||
); | ||
indexRandomDocs("index", scaledRandomIntBetween(0, 1_000)); | ||
createSnapshot("repository", "snapshot", singletonList("index")); | ||
assertAcked(client().admin().indices().prepareDelete("index")); | ||
mountSnapshot("repository", "snapshot", "index", "mounted-index", Settings.EMPTY, randomFrom(Storage.values())); | ||
ensureGreen("mounted-index"); | ||
} | ||
|
||
@After | ||
@Override | ||
public void tearDown() throws Exception { | ||
assertAcked(client().admin().indices().prepareDelete("mounted-*")); | ||
assertAcked(client().admin().cluster().prepareDeleteSnapshot("repository", "snapshot").get()); | ||
assertAcked(client().admin().cluster().prepareDeleteRepository("repository")); | ||
super.tearDown(); | ||
} | ||
|
||
public void testShrinkSearchableSnapshotIndex() { | ||
final IllegalArgumentException exception = expectThrows( | ||
IllegalArgumentException.class, | ||
() -> client().admin() | ||
.indices() | ||
.prepareResizeIndex("mounted-index", "shrunk-index") | ||
.setResizeType(ResizeType.SHRINK) | ||
.setSettings(indexSettingsNoReplicas(1).build()) | ||
.get() | ||
); | ||
assertThat(exception.getMessage(), equalTo("can't shrink searchable snapshot index [mounted-index]")); | ||
} | ||
|
||
public void testSplitSearchableSnapshotIndex() { | ||
final IllegalArgumentException exception = expectThrows( | ||
IllegalArgumentException.class, | ||
() -> client().admin() | ||
.indices() | ||
.prepareResizeIndex("mounted-index", "split-index") | ||
.setResizeType(ResizeType.SPLIT) | ||
.setSettings(indexSettingsNoReplicas(4).build()) | ||
.get() | ||
); | ||
assertThat(exception.getMessage(), equalTo("can't split searchable snapshot index [mounted-index]")); | ||
} | ||
|
||
public void testCloneSearchableSnapshotIndex() { | ||
IllegalArgumentException exception = expectThrows( | ||
IllegalArgumentException.class, | ||
() -> client().admin().indices().prepareResizeIndex("mounted-index", "cloned-index").setResizeType(ResizeType.CLONE).get() | ||
); | ||
assertThat( | ||
exception.getMessage(), | ||
equalTo("can't clone searchable snapshot index [mounted-index]; setting [index.store.type] should be overridden") | ||
); | ||
|
||
exception = expectThrows( | ||
IllegalArgumentException.class, | ||
() -> client().admin() | ||
.indices() | ||
.prepareResizeIndex("mounted-index", "cloned-index") | ||
.setResizeType(ResizeType.CLONE) | ||
.setSettings(Settings.builder().putNull(IndexModule.INDEX_STORE_TYPE_SETTING.getKey()).build()) | ||
.get() | ||
); | ||
assertThat( | ||
exception.getMessage(), | ||
equalTo("can't clone searchable snapshot index [mounted-index]; setting [index.recovery.type] should be overridden") | ||
); | ||
|
||
assertAcked( | ||
client().admin() | ||
.indices() | ||
.prepareResizeIndex("mounted-index", "cloned-index") | ||
.setResizeType(ResizeType.CLONE) | ||
.setSettings( | ||
Settings.builder() | ||
.putNull(IndexModule.INDEX_STORE_TYPE_SETTING.getKey()) | ||
.putNull(IndexModule.INDEX_RECOVERY_TYPE_SETTING.getKey()) | ||
.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, DataTier.DATA_HOT) | ||
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0) | ||
.build() | ||
) | ||
); | ||
ensureGreen("cloned-index"); | ||
assertAcked(client().admin().indices().prepareDelete("cloned-index")); | ||
} | ||
} |