Skip to content

Commit

Permalink
[Searchable Snapshot] Add Relevant Error handling for Restore API wit…
Browse files Browse the repository at this point in the history
…h remote_snapshot. (#11840)

* Add Relevant Error handling for Restore API with remote_snapshot.

Signed-off-by: Rishikesh1159 <[email protected]>

* update comment with more revelant info.

Signed-off-by: Rishikesh1159 <[email protected]>

* apply spotless check.

Signed-off-by: Rishikesh1159 <[email protected]>

* Add null check

Signed-off-by: Rishikesh1159 <[email protected]>

* apply spotless check.

Signed-off-by: Rishikesh1159 <[email protected]>

* fix error message in test.

Signed-off-by: Rishikesh1159 <[email protected]>

* apply spotless check.

Signed-off-by: Rishikesh1159 <[email protected]>

---------

Signed-off-by: Rishikesh1159 <[email protected]>
Signed-off-by: Rishikesh Pasham <[email protected]>
  • Loading branch information
Rishikesh1159 authored Jan 24, 2024
1 parent 30aa8be commit 7da8628
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import static org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.FS;
import static org.opensearch.core.common.util.CollectionUtils.iterableAsArrayList;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -789,6 +790,47 @@ public void testDefaultShardPreference() throws Exception {
}
}

public void testRestoreSearchableSnapshotWithIndexStoreTypeThrowsException() throws Exception {
final String snapshotName = "test-snap";
final String repoName = "test-repo";
final String indexName1 = "test-idx-1";
final int numReplicasIndex1 = randomIntBetween(1, 4);
final Client client = client();

internalCluster().ensureAtLeastNumDataNodes(numReplicasIndex1 + 1);
createIndexWithDocsAndEnsureGreen(numReplicasIndex1, 100, indexName1);

createRepositoryWithSettings(null, repoName);
takeSnapshot(client, snapshotName, repoName, indexName1);
deleteIndicesAndEnsureGreen(client, indexName1);

internalCluster().ensureAtLeastNumSearchNodes(numReplicasIndex1 + 1);

// set "index.store.type" to "remote_snapshot" in index settings of restore API and assert appropriate exception with error message
// is thrown.
final SnapshotRestoreException error = expectThrows(
SnapshotRestoreException.class,
() -> client.admin()
.cluster()
.prepareRestoreSnapshot(repoName, snapshotName)
.setRenamePattern("(.+)")
.setRenameReplacement("$1-copy")
.setIndexSettings(
Settings.builder()
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), RestoreSnapshotRequest.StorageType.REMOTE_SNAPSHOT)
)
.setWaitForCompletion(true)
.execute()
.actionGet()
);
assertThat(
error.getMessage(),
containsString(
"cannot restore remote snapshot with index settings \"index.store.type\" set to \"remote_snapshot\". Instead use \"storage_type\": \"remote_snapshot\" as argument to restore."
)
);
}

/**
* Asserts the cache folder count to match the number of shards and the number of indices within the cache folder
* as provided.
Expand Down
11 changes: 11 additions & 0 deletions server/src/main/java/org/opensearch/snapshots/RestoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_VERSION_UPGRADED;
import static org.opensearch.common.util.FeatureFlags.SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY;
import static org.opensearch.common.util.set.Sets.newHashSet;
import static org.opensearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
import static org.opensearch.index.store.remote.directory.RemoteSnapshotDirectory.SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_MINIMUM_VERSION;
import static org.opensearch.index.store.remote.filecache.FileCache.DATA_TO_FILE_CACHE_SIZE_RATIO_SETTING;
import static org.opensearch.node.Node.NODE_SEARCH_CACHE_SIZE_SETTING;
Expand Down Expand Up @@ -226,6 +227,16 @@ public RestoreService(
*/
public void restoreSnapshot(final RestoreSnapshotRequest request, final ActionListener<RestoreCompletionResponse> listener) {
try {
// Setting INDEX_STORE_TYPE_SETTING as REMOTE_SNAPSHOT is intended to be a system-managed index setting that is configured when
// restoring a snapshot and should not be manually set by user.
String storeTypeSetting = request.indexSettings().get(INDEX_STORE_TYPE_SETTING.getKey());
if (storeTypeSetting != null && storeTypeSetting.equals(RestoreSnapshotRequest.StorageType.REMOTE_SNAPSHOT.toString())) {
throw new SnapshotRestoreException(
request.repository(),
request.snapshot(),
"cannot restore remote snapshot with index settings \"index.store.type\" set to \"remote_snapshot\". Instead use \"storage_type\": \"remote_snapshot\" as argument to restore."
);
}
// Read snapshot info and metadata from the repository
final String repositoryName = request.repository();
Repository repository = repositoriesService.repository(repositoryName);
Expand Down

0 comments on commit 7da8628

Please sign in to comment.