From 482cb017f3605c973f9503e75bd79151760fe07f Mon Sep 17 00:00:00 2001 From: AnnTian Shao Date: Fri, 20 Dec 2024 14:50:52 -0800 Subject: [PATCH 1/2] Change index.knn setting to FINAL, immutable after index creation Signed-off-by: AnnTian Shao --- .../org/opensearch/knn/index/KNNSettings.java | 3 ++- .../knn/index/KNNESSettingsTestIT.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opensearch/knn/index/KNNSettings.java b/src/main/java/org/opensearch/knn/index/KNNSettings.java index b81a54124..fb7b48d28 100644 --- a/src/main/java/org/opensearch/knn/index/KNNSettings.java +++ b/src/main/java/org/opensearch/knn/index/KNNSettings.java @@ -43,6 +43,7 @@ import static org.opensearch.common.settings.Setting.Property.Dynamic; import static org.opensearch.common.settings.Setting.Property.IndexScope; import static org.opensearch.common.settings.Setting.Property.NodeScope; +import static org.opensearch.common.settings.Setting.Property.Final; import static org.opensearch.common.unit.MemorySizeValue.parseBytesSizeValueOrHeapRatio; import static org.opensearch.core.common.unit.ByteSizeValue.parseBytesSizeValue; import static org.opensearch.knn.common.featureflags.KNNFeatureFlags.getFeatureFlags; @@ -268,7 +269,7 @@ public class KNNSettings { /** * This setting identifies KNN index. */ - public static final Setting IS_KNN_INDEX_SETTING = Setting.boolSetting(KNN_INDEX, false, IndexScope); + public static final Setting IS_KNN_INDEX_SETTING = Setting.boolSetting(KNN_INDEX, false, IndexScope, Final); /** * index_thread_quantity - the parameter specifies how many threads the nms library should use to create the graph. diff --git a/src/test/java/org/opensearch/knn/index/KNNESSettingsTestIT.java b/src/test/java/org/opensearch/knn/index/KNNESSettingsTestIT.java index b6bbb748a..584a9f8e0 100644 --- a/src/test/java/org/opensearch/knn/index/KNNESSettingsTestIT.java +++ b/src/test/java/org/opensearch/knn/index/KNNESSettingsTestIT.java @@ -124,6 +124,28 @@ public void testUpdateIndexSetting() throws IOException { assertThat(ex.getMessage(), containsString("Failed to parse value [1] for setting [index.knn.algo_param.ef_search] must be >= 2")); } + public void testUpdateIndexSettingKnnFlagImmutable() throws IOException { + Settings settings = Settings.builder() + .put(KNNSettings.KNN_INDEX, true) + .build(); + createKnnIndex(INDEX_NAME, settings, createKnnIndexMapping(FIELD_NAME, 2)); + + Exception ex = expectThrows( + ResponseException.class, + () -> updateIndexSettings(INDEX_NAME, Settings.builder().put(KNNSettings.KNN_INDEX, false)) + ); + assertThat(ex.getMessage(), containsString("Can't update non dynamic settings [[index.knn]] for open indices")); + + closeIndex(INDEX_NAME); + + ex = expectThrows( + ResponseException.class, + () -> updateIndexSettings(INDEX_NAME, Settings.builder().put(KNNSettings.KNN_INDEX, false)) + ); + assertThat(ex.getMessage(), containsString(String.format("final %s setting [index.knn], not updateable", INDEX_NAME))); + + } + @SuppressWarnings("unchecked") public void testCacheRebuiltAfterUpdateIndexSettings() throws Exception { createKnnIndex(INDEX_NAME, getKNNDefaultIndexSettings(), createKnnIndexMapping(FIELD_NAME, 2)); From 7ce69bba406d256fb7cfddaf9f2f30e13b08088c Mon Sep 17 00:00:00 2001 From: AnnTian Shao Date: Fri, 20 Dec 2024 16:09:43 -0800 Subject: [PATCH 2/2] Add to ChangeLog the description of bug fix Signed-off-by: AnnTian Shao --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a5fda2a2..0c2fa09f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Bug Fixes * Fixing the bug when a segment has no vector field present for disk based vector search (#2282)[https://github.com/opensearch-project/k-NN/pull/2282] * Allow validation for non knn index only after 2.17.0 (#2315)[https://github.com/opensearch-project/k-NN/pull/2315] +* Fixing the bug to prevent updating the index.knn setting after index creation(#2348)[https://github.com/opensearch-project/k-NN/pull/2348] ### Infrastructure * Updated C++ version in JNI from c++11 to c++17 [#2259](https://github.com/opensearch-project/k-NN/pull/2259) * Upgrade bytebuddy and objenesis version to match OpenSearch core and, update github ci runner for macos [#2279](https://github.com/opensearch-project/k-NN/pull/2279)