Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: John Mazanec <[email protected]>
  • Loading branch information
jmazanec15 committed Mar 18, 2024
1 parent 730381e commit c1c39d2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/opensearch/knn/index/IndexUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static boolean isVersionOnOrAfterMinRequiredVersion(Version version, Stri
* @return true if state can be shared; false otherwise
*/
public static boolean isSharedIndexStateRequired(KNNEngine knnEngine, String modelId, long indexAddr) {
if (StringUtils.isEmpty(modelId) || KNNEngine.FAISS != knnEngine) {
if (StringUtils.isEmpty(modelId)) {
return false;
}
return JNIService.isSharedIndexStateRequired(indexAddr, knnEngine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ public void release(SharedIndexState sharedIndexState) {
this.readWriteLock.writeLock().lock();

try {
if (!sharedIndexStateCache.containsKey(sharedIndexState.getModelId())) {
SharedIndexStateEntry sharedIndexStateEntry;
if ((sharedIndexStateEntry = sharedIndexStateCache.get(sharedIndexState.getModelId())) == null) {
// This should not happen. Will log the error and return to prevent crash
log.error("Attempting to evict model from cache but it is not present: {}", sharedIndexState.getModelId());
this.readWriteLock.writeLock().unlock();
return;

Check warning on line 105 in src/main/java/org/opensearch/knn/index/memory/SharedIndexStateManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/knn/index/memory/SharedIndexStateManager.java#L103-L105

Added lines #L103 - L105 were not covered by tests
}

long refCount = sharedIndexStateCache.get(sharedIndexState.getModelId()).decRef();
if (refCount <= 0) {
if (sharedIndexStateEntry.decRef() <= 0) {
log.info("Evicting entry from shared index state cache for key {}", sharedIndexState.getModelId());
sharedIndexStateCache.remove(sharedIndexState.getModelId());
JNIService.freeSharedIndexState(sharedIndexState.getSharedIndexStateAddress(), sharedIndexState.getKnnEngine());
Expand Down
6 changes: 0 additions & 6 deletions src/test/java/org/opensearch/knn/index/IndexUtilTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,6 @@ public void testIsShareableStateContainedInIndex_whenIndexNotModelBased_thenRetu
assertFalse(IndexUtil.isSharedIndexStateRequired(knnEngine, modelId, TEST_INDEX_ADDRESS));
}

public void testIsShareableStateContainedInIndex_whenEngineIsNotFaiss_thenReturnFalse() {
String modelId = "test-model";
KNNEngine knnEngine = KNNEngine.NMSLIB;
assertFalse(IndexUtil.isSharedIndexStateRequired(knnEngine, modelId, TEST_INDEX_ADDRESS));
}

public void testIsShareableStateContainedInIndex_whenFaissHNSWIsUsed_thenReturnFalse() {
jniServiceMockedStatic.when(() -> JNIService.isSharedIndexStateRequired(anyLong(), any())).thenReturn(false);
String modelId = "test-model";
Expand Down

0 comments on commit c1c39d2

Please sign in to comment.