Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Fix casting issue with cache expiration during cache initialization (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jmazanec15 committed Sep 8, 2020
1 parent 1573e87 commit 3069351
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.watcher.FileChangesListener;
import org.elasticsearch.watcher.FileWatcher;
import org.elasticsearch.watcher.ResourceWatcherService;
Expand Down Expand Up @@ -99,7 +100,8 @@ private void initCache() {
/**
* If the hnsw index is not accessed for knn.cache.item.expiry.minutes, it would be garbage collected.
*/
long expiryTime = KNNSettings.state().getSettingValue(KNNSettings.KNN_CACHE_ITEM_EXPIRY_TIME_MINUTES);
long expiryTime = ((TimeValue) KNNSettings.state()
.getSettingValue(KNNSettings.KNN_CACHE_ITEM_EXPIRY_TIME_MINUTES)).getMinutes();
cacheBuilder.expireAfterAccess(expiryTime, TimeUnit.MINUTES);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ public void testQueriesPluginDisabled() throws Exception {
searchKNNIndex(INDEX_NAME, new KNNQueryBuilder(FIELD_NAME, qvector, 1), 1);
}

public void testItemRemovedFromCache_expiration() throws Exception {
createKnnIndex(INDEX_NAME, createKnnIndexMapping(FIELD_NAME, 2));
updateClusterSettings(KNNSettings.KNN_CACHE_ITEM_EXPIRY_ENABLED, true);
updateClusterSettings(KNNSettings.KNN_CACHE_ITEM_EXPIRY_TIME_MINUTES, "1m");

Float[] vector = {6.0f, 6.0f};
addKnnDoc(INDEX_NAME, "1", FIELD_NAME, vector);

float[] qvector = {1.0f, 2.0f};
Response response = searchKNNIndex(INDEX_NAME, new KNNQueryBuilder(FIELD_NAME, qvector, 1), 1);
assertEquals("knn query failed", RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode()));
assertEquals(1, getTotalGraphsInCache());

Thread.sleep(65 * 1000);

assertEquals(0, getTotalGraphsInCache());

updateClusterSettings(KNNSettings.KNN_CACHE_ITEM_EXPIRY_ENABLED, false);
}

public void testCreateIndexWithInvalidSpaceType() throws IOException {
String invalidSpaceType = "bar";
Settings invalidSettings = Settings.builder()
Expand Down

0 comments on commit 3069351

Please sign in to comment.