|
9 | 9 | import org.opensearch.knn.index.KNNSettings;
|
10 | 10 |
|
11 | 11 | import java.util.Collections;
|
| 12 | +import java.util.List; |
12 | 13 |
|
13 | 14 | import static org.opensearch.knn.TestUtils.NODES_BWC_CLUSTER;
|
14 | 15 |
|
15 | 16 | public class WarmupIT extends AbstractRollingUpgradeTestCase {
|
16 | 17 | private static final String TEST_FIELD = "test-field";
|
17 | 18 | private static final int DIMENSIONS = 5;
|
18 |
| - private static final int K = 5; |
19 | 19 | private static final int NUM_DOCS = 10;
|
20 | 20 |
|
21 | 21 | public void testKNNWarmup() throws Exception {
|
22 | 22 | waitForClusterHealthGreen(NODES_BWC_CLUSTER);
|
23 | 23 | switch (getClusterType()) {
|
24 | 24 | case OLD:
|
25 | 25 | createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS));
|
26 |
| - int docIdOld = 0; |
27 |
| - addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, docIdOld, NUM_DOCS); |
| 26 | + addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 0, NUM_DOCS); |
28 | 27 | break;
|
29 | 28 | case MIXED:
|
30 |
| - int totalDocsCountMixed; |
31 |
| - int docIdMixed; |
32 |
| - if (isFirstMixedRound()) { |
33 |
| - docIdMixed = NUM_DOCS; |
34 |
| - totalDocsCountMixed = 2 * NUM_DOCS; |
35 |
| - } else { |
36 |
| - docIdMixed = 2 * NUM_DOCS; |
37 |
| - totalDocsCountMixed = 3 * NUM_DOCS; |
38 |
| - } |
39 |
| - updateIndexSettings(testIndex, Settings.builder().put(KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, 0)); |
40 |
| - validateKNNWarmupOnUpgrade(totalDocsCountMixed, docIdMixed); |
| 29 | + int graphCount = getTotalGraphsInCache(); |
| 30 | + knnWarmup(Collections.singletonList(testIndex)); |
| 31 | + assertTrue(getTotalGraphsInCache() > graphCount); |
| 32 | + clearCache(List.of(testIndex)); |
41 | 33 | break;
|
42 | 34 | case UPGRADED:
|
43 |
| - int docIdUpgraded = 3 * NUM_DOCS; |
44 |
| - int totalDocsCountUpgraded = 4 * NUM_DOCS; |
45 |
| - validateKNNWarmupOnUpgrade(totalDocsCountUpgraded, docIdUpgraded); |
46 |
| - |
| 35 | + updateIndexSettings(testIndex, Settings.builder().put(KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, 0)); |
| 36 | + addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, NUM_DOCS, NUM_DOCS); |
| 37 | + int updatedGraphCount = getTotalGraphsInCache(); |
| 38 | + knnWarmup(Collections.singletonList(testIndex)); |
| 39 | + assertTrue(getTotalGraphsInCache() > updatedGraphCount); |
47 | 40 | deleteKNNIndex(testIndex);
|
48 | 41 | }
|
49 |
| - |
50 |
| - } |
51 |
| - |
52 |
| - // validation steps for KNN Warmup after upgrading each node from old version to new version |
53 |
| - public void validateKNNWarmupOnUpgrade(int totalDocsCount, int docId) throws Exception { |
54 |
| - int graphCount = getTotalGraphsInCache(); |
55 |
| - knnWarmup(Collections.singletonList(testIndex)); |
56 |
| - assertTrue(getTotalGraphsInCache() > graphCount); |
57 |
| - |
58 |
| - addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, docId, NUM_DOCS); |
59 |
| - |
60 |
| - int updatedGraphCount = getTotalGraphsInCache(); |
61 |
| - knnWarmup(Collections.singletonList(testIndex)); |
62 |
| - assertTrue(getTotalGraphsInCache() > updatedGraphCount); |
63 |
| - |
64 |
| - validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, totalDocsCount, K); |
65 | 42 | }
|
66 | 43 |
|
67 | 44 | }
|
0 commit comments