Repository navigation
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cqy123456 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Tick the box to add this pull request to the merge queue (same as
|
2bb25c9 to
80d9c9b
Compare
| return quant_res; | ||
| } | ||
| // refine | ||
| checkCancellation(op_context); |
There was a problem hiding this comment.
[MEDIUM] Both checkCancellation(op_context) calls here (line 517) and after the try/catch block (line 532) sit outside the exception handler, so IndexNodeWithDataViewRefiner::Search throws folly::FutureCancellation directly instead of returning expected<DataSetPtr>::Err(Status::cancelled, ...). That differs from cancellations caught inside SearchWithIds (lines 526–531), CalcDistByStorageIds, and other IndexNode::Search implementations (e.g. IvfIndexNode::Search), and breaks direct IndexNode::Search callers such as index.Node()->Search(...), IndexNodeThreadPoolWrapper::Search, and emb-list strategies that inspect expected::error(). The added [dvr_base_search][cancel] test currently passes only because Index<T>::Search masks the escaping exception in GuardedCall (which also skips the search-latency and top-k metric observations in src/index/index.cc:564-567).
To preserve the expected return contract without widening the try block over the buffer allocations (which would recode std::bad_alloc as faiss_inner_error), return Status::cancelled explicitly at line 517 and move the line 532 check inside the try block (or into DataViewIndexFlat::SearchWithIds right after WaitAllSuccess so SearchWithIds matches CalcDistByIDs):
if (op_context != nullptr && op_context->cancellation_token.isCancellationRequested()) {
return expected<DataSetPtr>::Err(Status::cancelled, "cancelled by the caller");
}try {
refine_offset_index_->SearchWithIds(nq, dataset->GetTensor(), queries_lims.data(), refine_ids, topk,
distances.get(), labels.get(), refine_with_quant, {}, op_context);
checkCancellation(op_context);
} catch (const std::exception& e) {
return RefinementError(e);
}Please also assert index.Node()->Search(...) directly in [dvr_base_search][cancel] (in addition to index.Search(...)) so GuardedCall cannot hide an escaping cancellation exception.
There was a problem hiding this comment.
Fixed in 6eedde9. Search now returns Status::cancelled if cancellation occurs before refinement, and the post-refinement check is inside the existing try block. I added a direct index.Node()->Search() regression test that reproduced the escaping exception before the fix. It now verifies Status::cancelled with zero refinement reads.
Pass the operation context through candidate search and exact scoring. Poll while visiting candidate IDs, preserving the original distance scan when there is no context. Map data-view cancellation consistently in Search and CalcDistByIDs. Cover cancellation inside the ScaNN coarse quantizer and on the first or final refinement read. Verify every exact distance with both a null and a live context. Signed-off-by: cqy123456 <39671710+cqy123456@users.noreply.github.com>
80d9c9b to
6eedde9
Compare
|
/lgtm |
Related issue: #2006
What changed
SCANN_DVR passed the query's
OpContextto ScaNN candidate search, then dropped it before exact refinement. A cancellation during recall could still lead to raw-vector reads and a successful result. During refinement, a cancellation raised by the data view could also be reported as a Faiss error.DVR checks for cancellation after candidate search and while Faiss visits the candidate IDs during exact scoring. It polls every 256 IDs and once after the scan to catch a cancellation on the final read. A null
OpContextuses the original distance calculation. An in-flight Faiss call can finish its current query.Regression tests
[dvr_base_search]requests cancellation inside the ScaNN coarse quantizer. Standalone ScaNN finished the query. On the same input, SCANN_DVR at8af2dcc2returned success and performed one refinement read. With this fix it returned cancelled with zero reads (6 assertions).[dvr_refinement][cancel]exercises bothSearchandCalcDistByIDs. Each returns all 1,024 expected distances with a null context and with a live context. Cancellation on the first or last read returnsStatus::cancelled, including when the data-view callback throws a cancellation exception.