Skip to content

Commit a875eb8

Browse files
anntiansAnnTian Shao
and
AnnTian Shao
authored
Fixed a bug to prevent updating index.knn setting after index creation (#2348)
* Change index.knn setting to FINAL, immutable after index creation Signed-off-by: AnnTian Shao <anntians@amazon.com> * Add to ChangeLog the description of bug fix Signed-off-by: AnnTian Shao <anntians@amazon.com> * Add restart upgrade test for checking immutability of knn.index setting after version upgrade Signed-off-by: Tommy Shao <anntians@amazon.com> --------- Signed-off-by: AnnTian Shao <anntians@amazon.com> Signed-off-by: Tommy Shao <69884021+anntians@users.noreply.github.com> Signed-off-by: Tommy Shao <anntians@amazon.com> Co-authored-by: AnnTian Shao <anntians@amazon.com>
1 parent 405e5e2 commit a875eb8

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2929
* 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]
3030
* Fix for NPE while merging segments after all the vector fields docs are deleted (#2365)[https://github.com/opensearch-project/k-NN/pull/2365]
3131
* Allow validation for non knn index only after 2.17.0 (#2315)[https://github.com/opensearch-project/k-NN/pull/2315]
32+
* Fixing the bug to prevent updating the index.knn setting after index creation(#2348)[https://github.com/opensearch-project/k-NN/pull/2348]
3233
* Release query vector memory after execution (#2346)[https://github.com/opensearch-project/k-NN/pull/2346]
3334
* Fix shard level rescoring disabled setting flag (#2352)[https://github.com/opensearch-project/k-NN/pull/2352]
3435
* Fix filter rewrite logic which was resulting in getting inconsistent / incorrect results for cases where filter was getting rewritten for shards (#2359)[https://github.com/opensearch-project/k-NN/pull/2359]

qa/restart-upgrade/src/test/java/org/opensearch/knn/bwc/IndexingIT.java

+24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.apache.hc.core5.http.io.entity.EntityUtils;
99
import org.junit.Assert;
1010
import org.opensearch.client.Response;
11+
import org.opensearch.client.ResponseException;
1112
import org.opensearch.common.settings.Settings;
1213
import org.opensearch.common.xcontent.XContentFactory;
1314
import org.opensearch.knn.KNNResult;
@@ -20,6 +21,7 @@
2021
import java.util.List;
2122
import java.util.Map;
2223

24+
import static org.hamcrest.Matchers.containsString;
2325
import static org.opensearch.knn.TestUtils.KNN_ALGO_PARAM_EF_CONSTRUCTION_MIN_VALUE;
2426
import static org.opensearch.knn.TestUtils.KNN_ALGO_PARAM_M_MIN_VALUE;
2527
import static org.opensearch.knn.TestUtils.KNN_VECTOR;
@@ -132,6 +134,28 @@ public void testKNNIndexLuceneForceMerge() throws Exception {
132134
}
133135
}
134136

137+
public void testKNNIndexSettingImmutableAfterUpgrade() throws Exception {
138+
waitForClusterHealthGreen(NODES_BWC_CLUSTER);
139+
140+
if (isRunningAgainstOldCluster()) {
141+
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS));
142+
} else {
143+
Exception ex = expectThrows(
144+
ResponseException.class,
145+
() -> updateIndexSettings(testIndex, Settings.builder().put(KNNSettings.KNN_INDEX, false))
146+
);
147+
assertThat(ex.getMessage(), containsString("Can't update non dynamic settings [[index.knn]] for open indices"));
148+
149+
closeIndex(testIndex);
150+
151+
ex = expectThrows(
152+
ResponseException.class,
153+
() -> updateIndexSettings(testIndex, Settings.builder().put(KNNSettings.KNN_INDEX, false))
154+
);
155+
assertThat(ex.getMessage(), containsString(String.format("final %s setting [index.knn], not updateable", testIndex)));
156+
}
157+
}
158+
135159
public void testKNNIndexLuceneByteVector() throws Exception {
136160
waitForClusterHealthGreen(NODES_BWC_CLUSTER);
137161

src/main/java/org/opensearch/knn/index/KNNSettings.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static org.opensearch.common.settings.Setting.Property.Dynamic;
4444
import static org.opensearch.common.settings.Setting.Property.IndexScope;
4545
import static org.opensearch.common.settings.Setting.Property.NodeScope;
46+
import static org.opensearch.common.settings.Setting.Property.Final;
4647
import static org.opensearch.common.unit.MemorySizeValue.parseBytesSizeValueOrHeapRatio;
4748
import static org.opensearch.core.common.unit.ByteSizeValue.parseBytesSizeValue;
4849
import static org.opensearch.knn.common.featureflags.KNNFeatureFlags.getFeatureFlags;
@@ -268,7 +269,7 @@ public class KNNSettings {
268269
/**
269270
* This setting identifies KNN index.
270271
*/
271-
public static final Setting<Boolean> IS_KNN_INDEX_SETTING = Setting.boolSetting(KNN_INDEX, false, IndexScope);
272+
public static final Setting<Boolean> IS_KNN_INDEX_SETTING = Setting.boolSetting(KNN_INDEX, false, IndexScope, Final);
272273

273274
/**
274275
* index_thread_quantity - the parameter specifies how many threads the nms library should use to create the graph.

src/test/java/org/opensearch/knn/index/KNNESSettingsTestIT.java

+20
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,26 @@ public void testUpdateIndexSetting() throws IOException {
124124
assertThat(ex.getMessage(), containsString("Failed to parse value [1] for setting [index.knn.algo_param.ef_search] must be >= 2"));
125125
}
126126

127+
public void testUpdateIndexSettingKnnFlagImmutable() throws IOException {
128+
Settings settings = Settings.builder().put(KNNSettings.KNN_INDEX, true).build();
129+
createKnnIndex(INDEX_NAME, settings, createKnnIndexMapping(FIELD_NAME, 2));
130+
131+
Exception ex = expectThrows(
132+
ResponseException.class,
133+
() -> updateIndexSettings(INDEX_NAME, Settings.builder().put(KNNSettings.KNN_INDEX, false))
134+
);
135+
assertThat(ex.getMessage(), containsString("Can't update non dynamic settings [[index.knn]] for open indices"));
136+
137+
closeIndex(INDEX_NAME);
138+
139+
ex = expectThrows(
140+
ResponseException.class,
141+
() -> updateIndexSettings(INDEX_NAME, Settings.builder().put(KNNSettings.KNN_INDEX, false))
142+
);
143+
assertThat(ex.getMessage(), containsString(String.format("final %s setting [index.knn], not updateable", INDEX_NAME)));
144+
145+
}
146+
127147
@SuppressWarnings("unchecked")
128148
public void testCacheRebuiltAfterUpdateIndexSettings() throws Exception {
129149
createKnnIndex(INDEX_NAME, getKNNDefaultIndexSettings(), createKnnIndexMapping(FIELD_NAME, 2));

0 commit comments

Comments
 (0)