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) (#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 <[email protected]>
Signed-off-by: Rishikesh Pasham <[email protected]>
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>
  • Loading branch information
1 parent 5efb12c commit 38c4b39
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 @@ -54,6 +54,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 @@ -722,6 +723,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 @@ -122,6 +122,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 @@ -227,6 +228,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(),

Check warning on line 237 in server/src/main/java/org/opensearch/snapshots/RestoreService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/snapshots/RestoreService.java#L235-L237

Added lines #L235 - L237 were not covered by tests
"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 38c4b39

Please sign in to comment.