zhiqiang-hhhh opened a new pull request, #62442:
URL: https://github.com/apache/doris/pull/62442

   ## Summary
   
   - Add double-check locking pattern to `CachedRandomAccessReader::borrow()` 
to prevent concurrent threads from redundantly reading the same IVF list data 
from disk (cache stampede)
   - Eliminate ghost memory caused by LRU cache entry replacement under high 
concurrency, reducing usage ratio fluctuations
   - Zero overhead on the fast path (cache hit); reuses the existing 
`_io_mutex` without introducing new synchronization primitives
   
   ## Proposed Changes
   
   When multiple threads concurrently miss the `AnnIndexIVFListCache` for the 
same key, they all independently read the same data from disk and insert it 
into the cache. The LRU cache silently replaces duplicate entries (counted as 
"stampede"), causing:
   
   1. **Redundant disk I/O**: N concurrent misses produce N identical reads 
instead of 1
   2. **Ghost memory**: replaced entries whose handles are still pinned consume 
memory not tracked by cache `_usage`, leading to usage ratio fluctuations 
(observed 87%→50% under high concurrency)
   3. **Lower cache hit ratio**: unnecessary evictions caused by inflated 
insertion volume
   
   The fix leverages the existing `_io_mutex` (required because CLucene 
`IndexInput` is stateful) by moving its acquisition before the disk read and 
adding a cache re-check after acquiring the lock. If a preceding thread already 
loaded the same key, subsequent threads skip the disk I/O entirely.
   
   ### What problem does this PR solve?
   
   Problem Summary: Under high concurrency (e.g., vectordb_bench with 10-90 
concurrent threads), the AnnIndexIVFListCache exhibits excessive stampede 
events, redundant disk I/O, and usage ratio fluctuations due to the TOCTOU gap 
between cache lookup and insert.
   
   ### Release note
   
   Reduced redundant disk I/O and memory waste for IVF on-disk vector index 
cache under concurrent queries by adding stampede protection (double-check 
locking pattern) to CachedRandomAccessReader::borrow().
   
   ### Check List (For Author)
   
   - Test: Manual test with vectordb_bench concurrency benchmark
   - Behavior changed: No
   - Does this need documentation: No


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to