Skip to content

Commit 38c4b39

Browse files
[Searchable Snapshot] Add Relevant Error handling for Restore API with remote_snapshot. (#11840) (#12011)
* Add Relevant Error handling for Restore API with remote_snapshot. * update comment with more revelant info. * apply spotless check. * Add null check * apply spotless check. * fix error message in test. * apply spotless check. --------- (cherry picked from commit 7da8628) Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> Signed-off-by: Rishikesh Pasham <62345295+Rishikesh1159@users.noreply.github.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 5efb12c commit 38c4b39

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
@@ -54,6 +54,7 @@
5454
import static org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.FS;
5555
import static org.opensearch.core.common.util.CollectionUtils.iterableAsArrayList;
5656
import static org.hamcrest.Matchers.contains;
57+
import static org.hamcrest.Matchers.containsString;
5758
import static org.hamcrest.Matchers.equalTo;
5859
import static org.hamcrest.Matchers.greaterThan;
5960
import static org.hamcrest.Matchers.is;
@@ -722,6 +723,47 @@ public void testDefaultShardPreference() throws Exception {
722723
}
723724
}
724725

726+
public void testRestoreSearchableSnapshotWithIndexStoreTypeThrowsException() throws Exception {
727+
final String snapshotName = "test-snap";
728+
final String repoName = "test-repo";
729+
final String indexName1 = "test-idx-1";
730+
final int numReplicasIndex1 = randomIntBetween(1, 4);
731+
final Client client = client();
732+
733+
internalCluster().ensureAtLeastNumDataNodes(numReplicasIndex1 + 1);
734+
createIndexWithDocsAndEnsureGreen(numReplicasIndex1, 100, indexName1);
735+
736+
createRepositoryWithSettings(null, repoName);
737+
takeSnapshot(client, snapshotName, repoName, indexName1);
738+
deleteIndicesAndEnsureGreen(client, indexName1);
739+
740+
internalCluster().ensureAtLeastNumSearchNodes(numReplicasIndex1 + 1);
741+
742+
// set "index.store.type" to "remote_snapshot" in index settings of restore API and assert appropriate exception with error message
743+
// is thrown.
744+
final SnapshotRestoreException error = expectThrows(
745+
SnapshotRestoreException.class,
746+
() -> client.admin()
747+
.cluster()
748+
.prepareRestoreSnapshot(repoName, snapshotName)
749+
.setRenamePattern("(.+)")
750+
.setRenameReplacement("$1-copy")
751+
.setIndexSettings(
752+
Settings.builder()
753+
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), RestoreSnapshotRequest.StorageType.REMOTE_SNAPSHOT)
754+
)
755+
.setWaitForCompletion(true)
756+
.execute()
757+
.actionGet()
758+
);
759+
assertThat(
760+
error.getMessage(),
761+
containsString(
762+
"cannot restore remote snapshot with index settings \"index.store.type\" set to \"remote_snapshot\". Instead use \"storage_type\": \"remote_snapshot\" as argument to restore."
763+
)
764+
);
765+
}
766+
725767
/**
726768
* Asserts the cache folder count to match the number of shards and the number of indices within the cache folder
727769
* as provided.

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

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

0 commit comments

Comments
 (0)