Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UnmodifiableOnRestore property to index.knn setting #2445

Merged
merged 4 commits into from
Jan 27, 2025

Conversation

anntians
Copy link
Contributor

Description

This PR builds on another PR. In the other PR we added a new Setting property UnmodifiableOnRestore to prevent settings from being modified on restore. So in this PR we're adding that new UnmodifiableOnRestore property to the index.knn setting to prevent it from being modified or removed on restore snapshot.

Related Issues

Resolves Issue #2334
Also resolves Issue 17019 in Core Opensearch repository opensearch-project/OpenSearch#17019

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: AnnTian Shao <[email protected]>
Copy link
Member

@kotwanikunal kotwanikunal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a changelog entry.

@anntians
Copy link
Contributor Author

@kotwanikunal This PR is a followup/part of a larger change to make index.knn setting immutable after index creation, and that change is already documented in the ChangeLog in this PR https://github.com/opensearch-project/k-NN/pull/2348/files. Could you help add the skip-changelog label to this PR? Thanks

public void testUnmodifiableOnRestoreSettingModifiedOnRestore() throws Exception {
setupSnapshotRestore();

// invalid restore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there are any existing helper methods in OpenSearchRestTestCase/upstream classes for restore snapshot that take in setting updates and throws back validation errors

Copy link

@sohami sohami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me, just a minor comment to update the test name.

createSnapshot(repository, snapshot, true);
}

public void testUnmodifiableOnRestoreSettingModifiedOnRestore() throws Exception {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: May be we should rename this test as testKnnSettingIsUnmodifiableOnRestore

assertThat(error.getMessage(), containsString("cannot modify UnmodifiableOnRestore setting [index.knn]" + " on restore"));
}

public void testUnmodifiableOnRestoreSettingIgnoredOnRestore() throws Exception {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testKnnSettingCannotBeIgnoredDuringRestore

Signed-off-by: AnnTian Shao <[email protected]>
Copy link

@sohami sohami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. Thanks!

createSnapshot(repository, snapshot, true);
}

public void testKnnSettingIsUnmodifiableOnRestore() throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion]
The way we create test names in k-NN in testABC_whenXYZ_then(Success/Failure).

repository = "repo";

// create index
Settings indexSettings = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 1).put("index.knn", true).build();
Copy link
Collaborator

@navneet1v navneet1v Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that tests run on 1 single node, having a replica will keep the index yellow. Lets not have 1 replica.

I think lets use the index setting already present in the base classes

Comment on lines 51 to 56
// create repo
Settings repoSettings = Settings.builder().put("compress", randomBoolean()).put("location", pathRepo).build();
registerRepository(repository, "fs", true, repoSettings);

// create snapshot
createSnapshot(repository, snapshot, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets move this to base class since we can start using this function for other tests.

createSnapshot(repository, snapshot, true);
}

public void testKnnSettingIsUnmodifiableOnRestore() throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use @SneakyThrows rather than exception in message signature

@navneet1v
Copy link
Collaborator

@anntians Please don't add the label skip-changelog and add correct entry in the changelog.

@navneet1v navneet1v added Features Introduces a new unit of functionality that satisfies a requirement and removed skip-changelog labels Jan 27, 2025
}

public void testKnnSettingIsUnmodifiableOnRestore() throws Exception {
setupSnapshotRestore();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we are not using the @setup function here?

import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.hasSize;

public class RestoreSnapshotIT extends OpenSearchRestTestCase {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add a test for happy path. In both the tests I am seeing the unhappy path. :)

import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.hasSize;

public class RestoreSnapshotIT extends OpenSearchRestTestCase {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the base class KNNRestTestCase which is there for all the IT of k-NN plugin

@anntians anntians force-pushed the unmodifiableOnRestore branch 3 times, most recently from 88b4beb to d5a4355 Compare January 27, 2025 20:43
@anntians anntians force-pushed the unmodifiableOnRestore branch from d5a4355 to b722a00 Compare January 27, 2025 21:26
@VijayanB VijayanB merged commit 1d2c4c0 into opensearch-project:2.x Jan 27, 2025
99 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to main failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-main main
# Navigate to the new working tree
cd .worktrees/backport-main
# Create a new branch
git switch --create backport/backport-2445-to-main
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 1d2c4c0c783428fdea7141ad069134a25b590c54
# Push it to GitHub
git push --set-upstream origin backport/backport-2445-to-main
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-main

Then, create a pull request where the base branch is main and the compare/head branch is backport/backport-2445-to-main.

anntians added a commit to anntians/k-NN that referenced this pull request Jan 27, 2025
…roject#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)
anntians added a commit to anntians/k-NN that referenced this pull request Jan 28, 2025
…roject#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)
anntians added a commit to anntians/k-NN that referenced this pull request Jan 30, 2025
…roject#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)
anntians added a commit to anntians/k-NN that referenced this pull request Jan 30, 2025
…roject#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)
anntians added a commit to anntians/k-NN that referenced this pull request Jan 30, 2025
…roject#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)
anntians added a commit to anntians/k-NN that referenced this pull request Jan 30, 2025
…roject#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport main Features Introduces a new unit of functionality that satisfies a requirement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants