Skip to content

Commit

Permalink
Adds index and query BWC tests for missing engines (opensearch-projec…
Browse files Browse the repository at this point in the history
…t#2035)

This is done to make sure that KNN80DocsValueConsumer code path is hit

Signed-off-by: Tejas Shah <[email protected]>
(cherry picked from commit e320026)
  • Loading branch information
shatejas committed Sep 12, 2024
1 parent e4a5914 commit 37a7fa8
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 16 deletions.
30 changes: 30 additions & 0 deletions qa/restart-upgrade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ testClusters {
}
}

def versionsBelow1_3 = ["1.1.", "1.2."]
def versionsBelow2_3 = ["1.", "2.0.", "2.1.", "2.2."]
// Task to run BWC tests against the old cluster
task testAgainstOldCluster(type: StandaloneRestIntegTestTask) {
dependsOn "zipBwcPlugin"
Expand Down Expand Up @@ -81,6 +83,20 @@ testClusters {
}
}

if (versionsBelow2_3.any { knn_bwc_version.startsWith(it) }) {
filter {
excludeTestsMatching "org.opensearch.knn.bwc.QueryANNIT.testQueryOnLuceneIndex"
excludeTestsMatching "org.opensearch.knn.bwc.IndexingIT.testKNNIndexLuceneForceMerge"
}
}

if (versionsBelow1_3.any { knn_bwc_version.startsWith(it) }) {
filter {
excludeTestsMatching "org.opensearch.knn.bwc.QueryANNIT.testQueryOnFaissIndex"
excludeTestsMatching "org.opensearch.knn.bwc.IndexingIT.testKNNIndexFaissForceMerge"
}
}

nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}")
systemProperty 'tests.security.manager', 'false'
Expand Down Expand Up @@ -147,6 +163,20 @@ testClusters {
}
}

if (versionsBelow2_3.any {knn_bwc_version.startsWith(it) }) {
filter {
excludeTestsMatching "org.opensearch.knn.bwc.QueryANNIT.testQueryOnLuceneIndex"
excludeTestsMatching "org.opensearch.knn.bwc.IndexingIT.testKNNIndexLuceneForceMerge"
}
}

if (versionsBelow1_3.any { knn_bwc_version.startsWith(it) }) {
filter {
excludeTestsMatching "org.opensearch.knn.bwc.QueryANNIT.testQueryOnFaissIndex"
excludeTestsMatching "org.opensearch.knn.bwc.IndexingIT.testKNNIndexFaissForceMerge"
}
}

nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}")
systemProperty 'tests.security.manager', 'false'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.opensearch.knn.common.KNNConstants.FAISS_NAME;
import static org.opensearch.knn.common.KNNConstants.KNN_ENGINE;
import static org.opensearch.knn.common.KNNConstants.KNN_METHOD;
import static org.opensearch.knn.common.KNNConstants.LUCENE_NAME;
import static org.opensearch.knn.common.KNNConstants.METHOD_HNSW;
import static org.opensearch.knn.common.KNNConstants.METHOD_PARAMETER_EF_CONSTRUCTION;
import static org.opensearch.knn.common.KNNConstants.METHOD_PARAMETER_EF_SEARCH;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void testKNNIndexDefaultLegacyFieldMapping() throws Exception {
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS));
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
} else {
validateKNNIndexingOnUpgrade();
validateKNNIndexingOnUpgrade(NUM_DOCS);
}
}

Expand All @@ -65,8 +66,41 @@ public void testKNNIndexDefaultLegacyFieldMappingForceMerge() throws Exception {
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, 100);
// Flush to ensure that index is not re-indexed when node comes back up
flush(testIndex, true);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 100, K);
} else {
forceMergeKnnIndex(testIndex);
validateKNNIndexingOnUpgrade(100);
}
}

public void testKNNIndexFaissForceMerge() throws Exception {
waitForClusterHealthGreen(NODES_BWC_CLUSTER);

if (isRunningAgainstOldCluster()) {
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS, METHOD_HNSW, FAISS_NAME));
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, 100);
// Flush to ensure that index is not re-indexed when node comes back up
flush(testIndex, true);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 100, K);
} else {
validateKNNIndexingOnUpgrade(100);
}
}

public void testKNNIndexLuceneForceMerge() throws Exception {
waitForClusterHealthGreen(NODES_BWC_CLUSTER);

if (isRunningAgainstOldCluster()) {
createKnnIndex(
testIndex,
getKNNDefaultIndexSettings(),
createKnnIndexMapping(TEST_FIELD, DIMENSIONS, METHOD_HNSW, LUCENE_NAME)
);
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, 100);
// Flush to ensure that index is not re-indexed when node comes back up
flush(testIndex, true);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 100, K);
} else {
validateKNNIndexingOnUpgrade(100);
}
}

Expand Down Expand Up @@ -115,7 +149,7 @@ public void testKNNIndexCustomLegacyFieldMapping() throws Exception {
);
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
} else {
validateKNNIndexingOnUpgrade();
validateKNNIndexingOnUpgrade(NUM_DOCS);
}
}

Expand All @@ -126,7 +160,7 @@ public void testKNNIndexDefaultMethodFieldMapping() throws Exception {
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKNNIndexMethodFieldMapping(TEST_FIELD, DIMENSIONS));
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
} else {
validateKNNIndexingOnUpgrade();
validateKNNIndexingOnUpgrade(NUM_DOCS);
}
}

Expand All @@ -150,7 +184,7 @@ public void testKNNIndexCustomMethodFieldMapping() throws Exception {
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
} else {
validateCustomMethodFieldMappingAfterUpgrade();
validateKNNIndexingOnUpgrade();
validateKNNIndexingOnUpgrade(NUM_DOCS);
}
}

Expand Down Expand Up @@ -240,11 +274,11 @@ public void testNoParametersOnUpgrade() throws Exception {
}

// KNN indexing tests when the cluster is upgraded to latest version
public void validateKNNIndexingOnUpgrade() throws Exception {
QUERY_COUNT = NUM_DOCS;
public void validateKNNIndexingOnUpgrade(int numOfDocs) throws Exception {
QUERY_COUNT = numOfDocs;
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, QUERY_COUNT, K);
cleanUpCache();
DOC_ID = NUM_DOCS;
DOC_ID = numOfDocs;
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
QUERY_COUNT = QUERY_COUNT + NUM_DOCS;
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, QUERY_COUNT, K);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.bwc;

import java.util.Map;

import static org.opensearch.knn.common.KNNConstants.LUCENE_NAME;
import static org.opensearch.knn.common.KNNConstants.METHOD_PARAMETER_EF_SEARCH;
import static org.opensearch.knn.common.KNNConstants.NMSLIB_NAME;

/**
* Use case: Test queries on indexes created on older versions
*/
public class QueryANNIT extends AbstractRestartUpgradeTestCase {

private static final String TEST_FIELD = "test-field";
private static final int DIMENSIONS = 5;
private static final int K = 5;
private static final Integer EF_SEARCH = 10;
private static final int NUM_DOCS = 10;
private static final String ALGORITHM = "hnsw";

public void testQueryANN() throws Exception {
public void testQueryOnFaissIndex() throws Exception {
if (isRunningAgainstOldCluster()) {
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS));
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 0, NUM_DOCS);
Expand All @@ -34,4 +34,28 @@ public void testQueryANN() throws Exception {
deleteKNNIndex(testIndex);
}
}

public void testQueryOnNmslibIndex() throws Exception {
if (isRunningAgainstOldCluster()) {
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGORITHM, NMSLIB_NAME));
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 0, NUM_DOCS);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K);
} else {
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K, Map.of(METHOD_PARAMETER_EF_SEARCH, EF_SEARCH));
deleteKNNIndex(testIndex);
}
}

public void testQueryOnLuceneIndex() throws Exception {
if (isRunningAgainstOldCluster()) {
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS, ALGORITHM, LUCENE_NAME));
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 0, NUM_DOCS);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K);
} else {
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K);
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, K, Map.of(METHOD_PARAMETER_EF_SEARCH, EF_SEARCH));
deleteKNNIndex(testIndex);
}
}
}

0 comments on commit 37a7fa8

Please sign in to comment.