-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UnmodifiableOnRestore property to index.knn setting (#2445)
* Add UnmodifiableOnRestore property to index.knn setting Signed-off-by: AnnTian Shao <[email protected]> * Update tests with helper methods Signed-off-by: AnnTian Shao <[email protected]> * Update test names Signed-off-by: AnnTian Shao <[email protected]> * Add to changeLog and fixes to tests Signed-off-by: AnnTian Shao <[email protected]> --------- Signed-off-by: AnnTian Shao <[email protected]> Co-authored-by: AnnTian Shao <[email protected]> (cherry picked from commit 1d2c4c0)
- Loading branch information
Showing
4 changed files
with
145 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
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
108 changes: 108 additions & 0 deletions
108
src/test/java/org/opensearch/knn/index/RestoreSnapshotIT.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,108 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.index; | ||
|
||
import org.opensearch.client.Request; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.client.ResponseException; | ||
import org.opensearch.common.xcontent.json.JsonXContent; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.knn.KNNRestTestCase; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import lombok.SneakyThrows; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
public class RestoreSnapshotIT extends KNNRestTestCase { | ||
|
||
private String index = "test-index";; | ||
private String snapshot = "snapshot-" + index; | ||
private String repository = "repo"; | ||
|
||
@Before | ||
@SneakyThrows | ||
public void setUp() { | ||
super.setUp(); | ||
setupSnapshotRestore(index, snapshot, repository); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void testKnnSettingIsModifiable_whenRestore_thenSuccess() { | ||
// valid restore | ||
XContentBuilder restoreCommand = JsonXContent.contentBuilder().startObject(); | ||
restoreCommand.field("indices", index); | ||
restoreCommand.field("rename_pattern", index); | ||
restoreCommand.field("rename_replacement", "restored-" + index); | ||
restoreCommand.startObject("index_settings"); | ||
{ | ||
restoreCommand.field("knn.model.index.number_of_shards", 1); | ||
} | ||
restoreCommand.endObject(); | ||
restoreCommand.endObject(); | ||
Request restoreRequest = new Request("POST", "/_snapshot/" + repository + "/" + snapshot + "/_restore"); | ||
restoreRequest.addParameter("wait_for_completion", "true"); | ||
restoreRequest.setJsonEntity(restoreCommand.toString()); | ||
|
||
final Response restoreResponse = client().performRequest(restoreRequest); | ||
assertEquals(200, restoreResponse.getStatusLine().getStatusCode()); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void testKnnSettingIsUnmodifiable_whenRestore_thenFailure() { | ||
// invalid restore | ||
XContentBuilder restoreCommand = JsonXContent.contentBuilder().startObject(); | ||
restoreCommand.field("indices", index); | ||
restoreCommand.field("rename_pattern", index); | ||
restoreCommand.field("rename_replacement", "restored-" + index); | ||
restoreCommand.startObject("index_settings"); | ||
{ | ||
restoreCommand.field("index.knn", false); | ||
} | ||
restoreCommand.endObject(); | ||
restoreCommand.endObject(); | ||
Request restoreRequest = new Request("POST", "/_snapshot/" + repository + "/" + snapshot + "/_restore"); | ||
restoreRequest.addParameter("wait_for_completion", "true"); | ||
restoreRequest.setJsonEntity(restoreCommand.toString()); | ||
final ResponseException error = expectThrows(ResponseException.class, () -> client().performRequest(restoreRequest)); | ||
assertThat(error.getMessage(), containsString("cannot modify UnmodifiableOnRestore setting [index.knn]" + " on restore")); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void testKnnSettingCanBeIgnored_whenRestore_thenSuccess() { | ||
// valid restore | ||
XContentBuilder restoreCommand = JsonXContent.contentBuilder().startObject(); | ||
restoreCommand.field("indices", index); | ||
restoreCommand.field("rename_pattern", index); | ||
restoreCommand.field("rename_replacement", "restored-" + index); | ||
restoreCommand.field("ignore_index_settings", "knn.model.index.number_of_shards"); | ||
restoreCommand.endObject(); | ||
Request restoreRequest = new Request("POST", "/_snapshot/" + repository + "/" + snapshot + "/_restore"); | ||
restoreRequest.addParameter("wait_for_completion", "true"); | ||
restoreRequest.setJsonEntity(restoreCommand.toString()); | ||
final Response restoreResponse = client().performRequest(restoreRequest); | ||
assertEquals(200, restoreResponse.getStatusLine().getStatusCode()); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void testKnnSettingCannotBeIgnored_whenRestore_thenFailure() { | ||
// invalid restore | ||
XContentBuilder restoreCommand = JsonXContent.contentBuilder().startObject(); | ||
restoreCommand.field("indices", index); | ||
restoreCommand.field("rename_pattern", index); | ||
restoreCommand.field("rename_replacement", "restored-" + index); | ||
restoreCommand.field("ignore_index_settings", "index.knn"); | ||
restoreCommand.endObject(); | ||
Request restoreRequest = new Request("POST", "/_snapshot/" + repository + "/" + snapshot + "/_restore"); | ||
restoreRequest.addParameter("wait_for_completion", "true"); | ||
restoreRequest.setJsonEntity(restoreCommand.toString()); | ||
final ResponseException error = expectThrows(ResponseException.class, () -> client().performRequest(restoreRequest)); | ||
assertThat(error.getMessage(), containsString("cannot remove UnmodifiableOnRestore setting [index.knn] on restore")); | ||
} | ||
} |
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