-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement] Make Merge in nativeEngine can Abort #2529
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.apache.lucene.index; | ||
|
||
public class KNNMergeHelper { | ||
|
||
private KNNMergeHelper() {} | ||
public static boolean isMergeAborted() { | ||
Thread mergeThread = Thread.currentThread(); | ||
if (mergeThread instanceof ConcurrentMergeScheduler.MergeThread) { | ||
return ((ConcurrentMergeScheduler.MergeThread) mergeThread).merge.isAborted(); | ||
} | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import lombok.extern.log4j.Log4j2; | ||
import org.apache.lucene.codecs.CodecUtil; | ||
import org.apache.lucene.index.FieldInfo; | ||
import org.apache.lucene.index.KNNMergeHelper; | ||
import org.apache.lucene.index.SegmentWriteState; | ||
import org.apache.lucene.store.IndexOutput; | ||
import org.opensearch.common.Nullable; | ||
|
@@ -46,6 +47,8 @@ | |
import static org.opensearch.knn.index.codec.util.KNNCodecUtil.initializeVectorValues; | ||
import static org.opensearch.knn.index.codec.util.KNNCodecUtil.buildEngineFileName; | ||
import static org.opensearch.knn.index.engine.faiss.Faiss.FAISS_BINARY_INDEX_DESCRIPTION_PREFIX; | ||
import static org.opensearch.knn.jni.JNIService.setMergeInterruptCallback; | ||
import static org.opensearch.knn.jni.JNIService.unsetMergeInterruptCallback; | ||
|
||
/** | ||
* Writes KNN Index for a field in a segment. This is intended to be used for native engines | ||
|
@@ -119,9 +122,18 @@ public void mergeIndex(final KNNVectorValues<?> knnVectorValues, int totalLiveDo | |
} | ||
|
||
long bytesPerVector = knnVectorValues.bytesPerVector(); | ||
startMergeStats(totalLiveDocs, bytesPerVector); | ||
buildAndWriteIndex(knnVectorValues, totalLiveDocs); | ||
endMergeStats(totalLiveDocs, bytesPerVector); | ||
final KNNEngine knnEngine = extractKNNEngine(fieldInfo); | ||
setMergeInterruptCallback(knnEngine); | ||
try { | ||
startMergeStats(totalLiveDocs, bytesPerVector); | ||
buildAndWriteIndex(knnVectorValues, totalLiveDocs); | ||
endMergeStats(totalLiveDocs, bytesPerVector); | ||
} catch (Exception ex) { | ||
//TODO handle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to catch this? |
||
log.debug("Merge may abort {}",KNNMergeHelper.isMergeAborted()); | ||
} finally { | ||
unsetMergeInterruptCallback(knnEngine); | ||
} | ||
} | ||
|
||
private void buildAndWriteIndex(final KNNVectorValues<?> knnVectorValues, int totalLiveDocs) throws IOException { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -463,4 +463,8 @@ public static native KNNQueryResult[] rangeSearchIndex( | |
int indexMaxResultWindow, | ||
int[] parentIds | ||
); | ||
|
||
public static native void setMergeInterruptCallback(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove these and just have one interrupt callback registered at the time of library initialization? I dont think these need to be in the interface. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just prefer not to do this when its a global, static callback. |
||
|
||
public static native void unsetMergeInterruptCallback(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we generalize this to include shard closed events? See this comment: opensearch-project/OpenSearch#8590 (comment). Im not sure if its possible or not to look up that kind of information. @shwetathareja do you have any ideas around here?