Skip to content

Commit 691f8cf

Browse files
Rishikesh1159shiv0408
authored andcommitted
[Searchable Snapshot] Add Relevant Error handling for Restore API with remote_snapshot. (opensearch-project#11840)
* Add Relevant Error handling for Restore API with remote_snapshot. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * update comment with more revelant info. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * apply spotless check. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Add null check Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * apply spotless check. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * fix error message in test. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * apply spotless check. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> --------- Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> Signed-off-by: Rishikesh Pasham <62345295+Rishikesh1159@users.noreply.github.com> Signed-off-by: Shivansh Arora <hishiv@amazon.com>
1 parent 252db84 commit 691f8cf

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

server/src/internalClusterTest/java/org/opensearch/snapshots/SearchableSnapshotIT.java

+42
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import static org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.FS;
6161
import static org.opensearch.core.common.util.CollectionUtils.iterableAsArrayList;
6262
import static org.hamcrest.Matchers.contains;
63+
import static org.hamcrest.Matchers.containsString;
6364
import static org.hamcrest.Matchers.equalTo;
6465
import static org.hamcrest.Matchers.greaterThan;
6566
import static org.hamcrest.Matchers.is;
@@ -789,6 +790,47 @@ public void testDefaultShardPreference() throws Exception {
789790
}
790791
}
791792

793+
public void testRestoreSearchableSnapshotWithIndexStoreTypeThrowsException() throws Exception {
794+
final String snapshotName = "test-snap";
795+
final String repoName = "test-repo";
796+
final String indexName1 = "test-idx-1";
797+
final int numReplicasIndex1 = randomIntBetween(1, 4);
798+
final Client client = client();
799+
800+
internalCluster().ensureAtLeastNumDataNodes(numReplicasIndex1 + 1);
801+
createIndexWithDocsAndEnsureGreen(numReplicasIndex1, 100, indexName1);
802+
803+
createRepositoryWithSettings(null, repoName);
804+
takeSnapshot(client, snapshotName, repoName, indexName1);
805+
deleteIndicesAndEnsureGreen(client, indexName1);
806+
807+
internalCluster().ensureAtLeastNumSearchNodes(numReplicasIndex1 + 1);
808+
809+
// set "index.store.type" to "remote_snapshot" in index settings of restore API and assert appropriate exception with error message
810+
// is thrown.
811+
final SnapshotRestoreException error = expectThrows(
812+
SnapshotRestoreException.class,
813+
() -> client.admin()
814+
.cluster()
815+
.prepareRestoreSnapshot(repoName, snapshotName)
816+
.setRenamePattern("(.+)")
817+
.setRenameReplacement("$1-copy")
818+
.setIndexSettings(
819+
Settings.builder()
820+
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), RestoreSnapshotRequest.StorageType.REMOTE_SNAPSHOT)
821+
)
822+
.setWaitForCompletion(true)
823+
.execute()
824+
.actionGet()
825+
);
826+
assertThat(
827+
error.getMessage(),
828+
containsString(
829+
"cannot restore remote snapshot with index settings \"index.store.type\" set to \"remote_snapshot\". Instead use \"storage_type\": \"remote_snapshot\" as argument to restore."
830+
)
831+
);
832+
}
833+
792834
/**
793835
* Asserts the cache folder count to match the number of shards and the number of indices within the cache folder
794836
* as provided.

server/src/main/java/org/opensearch/snapshots/RestoreService.java

+11
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_VERSION_UPGRADED;
122122
import static org.opensearch.common.util.FeatureFlags.SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY;
123123
import static org.opensearch.common.util.set.Sets.newHashSet;
124+
import static org.opensearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
124125
import static org.opensearch.index.store.remote.directory.RemoteSnapshotDirectory.SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_MINIMUM_VERSION;
125126
import static org.opensearch.index.store.remote.filecache.FileCache.DATA_TO_FILE_CACHE_SIZE_RATIO_SETTING;
126127
import static org.opensearch.node.Node.NODE_SEARCH_CACHE_SIZE_SETTING;
@@ -226,6 +227,16 @@ public RestoreService(
226227
*/
227228
public void restoreSnapshot(final RestoreSnapshotRequest request, final ActionListener<RestoreCompletionResponse> listener) {
228229
try {
230+
// Setting INDEX_STORE_TYPE_SETTING as REMOTE_SNAPSHOT is intended to be a system-managed index setting that is configured when
231+
// restoring a snapshot and should not be manually set by user.
232+
String storeTypeSetting = request.indexSettings().get(INDEX_STORE_TYPE_SETTING.getKey());
233+
if (storeTypeSetting != null && storeTypeSetting.equals(RestoreSnapshotRequest.StorageType.REMOTE_SNAPSHOT.toString())) {
234+
throw new SnapshotRestoreException(
235+
request.repository(),
236+
request.snapshot(),
237+
"cannot restore remote snapshot with index settings \"index.store.type\" set to \"remote_snapshot\". Instead use \"storage_type\": \"remote_snapshot\" as argument to restore."
238+
);
239+
}
229240
// Read snapshot info and metadata from the repository
230241
final String repositoryName = request.repository();
231242
Repository repository = repositoriesService.repository(repositoryName);

0 commit comments

Comments
 (0)