Skip to content

Commit ce99fe9

Browse files
Add restart upgrade BWC Tests (#377)
* Add restart upgrade BWC Tests Signed-off-by: Naveen Tatikonda <[email protected]> * Address review comments Signed-off-by: Naveen Tatikonda <[email protected]>
1 parent e5745de commit ce99fe9

14 files changed

+1058
-366
lines changed

qa/restart-upgrade/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ task testAgainstOldCluster(type: StandaloneRestIntegTestTask) {
3030
useCluster testClusters."${baseName}"
3131
systemProperty 'tests.rest.bwcsuite_cluster', 'old_cluster'
3232
systemProperty 'tests.is_old_cluster', 'true'
33+
systemProperty 'tests.skip_delete_model_index', 'true'
3334
systemProperty 'tests.plugin_bwc_version', knn_bwc_version
3435
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}")
3536
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}")
@@ -48,6 +49,7 @@ task testRestartUpgrade(type: StandaloneRestIntegTestTask) {
4849
testClusters."${baseName}".upgradeAllNodesAndPluginsToNextVersion([rootProject.tasks.bundlePlugin.archiveFile])
4950
}
5051
systemProperty 'tests.rest.bwcsuite_cluster', 'upgraded_cluster'
52+
systemProperty 'tests.skip_delete_model_index', 'true'
5153
systemProperty 'tests.is_old_cluster', 'false'
5254
systemProperty 'tests.plugin_bwc_version', knn_bwc_version
5355
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}")

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected final Settings restClientSettings() {
5151
.build();
5252
}
5353

54-
protected final boolean isRunningAgainstOldCluster() {
54+
protected static final boolean isRunningAgainstOldCluster() {
5555
return Boolean.parseBoolean(System.getProperty(RESTART_UPGRADE_OLD_CLUSTER));
5656
}
5757

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

+174-9
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,193 @@
55

66
package org.opensearch.knn.bwc;
77

8+
import org.opensearch.common.Strings;
9+
import org.opensearch.common.xcontent.XContentFactory;
10+
import org.opensearch.knn.index.SpaceType;
11+
12+
import java.util.Optional;
13+
14+
import static org.opensearch.knn.TestUtils.KNN_ALGO_PARAM_EF_CONSTRUCTION_MIN_VALUE;
15+
import static org.opensearch.knn.TestUtils.KNN_ALGO_PARAM_M_MIN_VALUE;
16+
import static org.opensearch.knn.TestUtils.KNN_VECTOR;
817
import static org.opensearch.knn.TestUtils.NODES_BWC_CLUSTER;
18+
import static org.opensearch.knn.TestUtils.PROPERTIES;
19+
import static org.opensearch.knn.TestUtils.VECTOR_TYPE;
20+
import static org.opensearch.knn.common.KNNConstants.DIMENSION;
21+
import static org.opensearch.knn.common.KNNConstants.FAISS_NAME;
22+
import static org.opensearch.knn.common.KNNConstants.KNN_METHOD;
23+
import static org.opensearch.knn.common.KNNConstants.METHOD_HNSW;
24+
import static org.opensearch.knn.common.KNNConstants.NAME;
25+
import static org.opensearch.knn.common.KNNConstants.PARAMETERS;
926

1027
public class IndexingIT extends AbstractRestartUpgradeTestCase {
1128
private static final String TEST_FIELD = "test-field";
1229
private static final int DIMENSIONS = 5;
30+
private static int DOC_ID = 0;
1331
private static final int K = 5;
14-
private static final int ADD_DOCS_CNT = 10;
32+
private static final int M = 50;
33+
private static final int EF_CONSTRUCTION = 1024;
34+
private static final int NUM_DOCS = 10;
35+
private static int QUERY_COUNT = 0;
1536

16-
public void testKnnDefaultIndexSettings() throws Exception {
37+
// Default Legacy Field Mapping
38+
// space_type : "l2", engine : "nmslib", m : 16, ef_construction : 512
39+
public void testKNNIndexDefaultLegacyFieldMapping() throws Exception {
1740
waitForClusterHealthGreen(NODES_BWC_CLUSTER);
1841

1942
if (isRunningAgainstOldCluster()) {
2043
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS));
21-
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 0, ADD_DOCS_CNT);
44+
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
45+
} else {
46+
validateKNNIndexingOnUpgrade();
47+
}
48+
}
49+
50+
// Custom Legacy Field Mapping
51+
// space_type : "linf", engine : "nmslib", m : 2, ef_construction : 2
52+
public void testKNNIndexCustomLegacyFieldMapping() throws Exception {
53+
54+
// When the cluster is in old version, create a KNN index with custom legacy field mapping settings
55+
// and add documents into that index
56+
if (isRunningAgainstOldCluster()) {
57+
createKnnIndex(
58+
testIndex,
59+
createKNNIndexCustomLegacyFieldMappingSettings(
60+
SpaceType.LINF,
61+
KNN_ALGO_PARAM_M_MIN_VALUE,
62+
KNN_ALGO_PARAM_EF_CONSTRUCTION_MIN_VALUE
63+
),
64+
createKnnIndexMapping(TEST_FIELD, DIMENSIONS)
65+
);
66+
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
67+
} else {
68+
validateKNNIndexingOnUpgrade();
69+
}
70+
}
71+
72+
// Default Method Field Mapping
73+
// space_type : "l2", engine : "nmslib", m : 16, ef_construction : 512
74+
public void testKNNIndexDefaultMethodFieldMapping() throws Exception {
75+
if (isRunningAgainstOldCluster()) {
76+
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKNNIndexMethodFieldMapping(TEST_FIELD, DIMENSIONS));
77+
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
78+
} else {
79+
validateKNNIndexingOnUpgrade();
80+
}
81+
}
82+
83+
// Custom Method Field Mapping
84+
// space_type : "inner_product", engine : "faiss", m : 50, ef_construction : 1024
85+
public void testKNNIndexCustomMethodFieldMapping() throws Exception {
86+
if (isRunningAgainstOldCluster()) {
87+
createKnnIndex(
88+
testIndex,
89+
getKNNDefaultIndexSettings(),
90+
createKNNIndexCustomMethodFieldMapping(TEST_FIELD, DIMENSIONS, SpaceType.INNER_PRODUCT, FAISS_NAME, M, EF_CONSTRUCTION)
91+
);
92+
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
93+
} else {
94+
validateKNNIndexingOnUpgrade();
95+
}
96+
}
97+
98+
// test null parameters
99+
public void testNullParametersOnUpgrade() throws Exception {
100+
101+
// Skip test if version is 1.2 or 1.3
102+
Optional<String> bwcVersion = getBWCVersion();
103+
if (bwcVersion.isEmpty() || bwcVersion.get().startsWith("1.2") || bwcVersion.get().startsWith("1.3")) {
104+
return;
105+
}
106+
if (isRunningAgainstOldCluster()) {
107+
String mapping = Strings.toString(
108+
XContentFactory.jsonBuilder()
109+
.startObject()
110+
.startObject(PROPERTIES)
111+
.startObject(TEST_FIELD)
112+
.field(VECTOR_TYPE, KNN_VECTOR)
113+
.field(DIMENSION, String.valueOf(DIMENSIONS))
114+
.startObject(KNN_METHOD)
115+
.field(NAME, METHOD_HNSW)
116+
.field(PARAMETERS, (String) null)
117+
.endObject()
118+
.endObject()
119+
.endObject()
120+
.endObject()
121+
);
122+
123+
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), mapping);
124+
} else {
125+
deleteKNNIndex(testIndex);
126+
}
127+
}
128+
129+
// test empty parameters
130+
public void testEmptyParametersOnUpgrade() throws Exception {
131+
132+
// Skip test if version is 1.2 or 1.3
133+
Optional<String> bwcVersion = getBWCVersion();
134+
if (bwcVersion.isEmpty() || bwcVersion.get().startsWith("1.2") || bwcVersion.get().startsWith("1.3")) {
135+
return;
136+
}
137+
if (isRunningAgainstOldCluster()) {
138+
String mapping = Strings.toString(
139+
XContentFactory.jsonBuilder()
140+
.startObject()
141+
.startObject(PROPERTIES)
142+
.startObject(TEST_FIELD)
143+
.field(VECTOR_TYPE, KNN_VECTOR)
144+
.field(DIMENSION, String.valueOf(DIMENSIONS))
145+
.startObject(KNN_METHOD)
146+
.field(NAME, METHOD_HNSW)
147+
.field(PARAMETERS, "")
148+
.endObject()
149+
.endObject()
150+
.endObject()
151+
.endObject()
152+
);
153+
154+
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), mapping);
22155
} else {
23-
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 10, K);
24-
cleanUpCache();
25-
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 10, ADD_DOCS_CNT);
26-
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 20, K);
27-
forceMergeKnnIndex(testIndex);
28-
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 20, K);
29156
deleteKNNIndex(testIndex);
30157
}
31158
}
159+
160+
// test no parameters
161+
public void testNoParametersOnUpgrade() throws Exception {
162+
if (isRunningAgainstOldCluster()) {
163+
String mapping = Strings.toString(
164+
XContentFactory.jsonBuilder()
165+
.startObject()
166+
.startObject(PROPERTIES)
167+
.startObject(TEST_FIELD)
168+
.field(VECTOR_TYPE, KNN_VECTOR)
169+
.field(DIMENSION, String.valueOf(DIMENSIONS))
170+
.startObject(KNN_METHOD)
171+
.field(NAME, METHOD_HNSW)
172+
.endObject()
173+
.endObject()
174+
.endObject()
175+
.endObject()
176+
);
177+
178+
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), mapping);
179+
} else {
180+
deleteKNNIndex(testIndex);
181+
}
182+
}
183+
184+
// KNN indexing tests when the cluster is upgraded to latest version
185+
public void validateKNNIndexingOnUpgrade() throws Exception {
186+
QUERY_COUNT = NUM_DOCS;
187+
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, QUERY_COUNT, K);
188+
cleanUpCache();
189+
DOC_ID = NUM_DOCS;
190+
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
191+
QUERY_COUNT = QUERY_COUNT + NUM_DOCS;
192+
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, QUERY_COUNT, K);
193+
forceMergeKnnIndex(testIndex);
194+
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, QUERY_COUNT, K);
195+
deleteKNNIndex(testIndex);
196+
}
32197
}

0 commit comments

Comments
 (0)