yiguolei opened a new pull request, #70428:
URL: https://github.com/apache/doris/pull/70428

   ### Background
   
   KVCache stores file-scan objects by key and value type, and ShardedKVCache 
shares them across scanners. Each entry serializes factory calls while 
unrelated entries can load concurrently.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: None
   PR Type: Bugfix
   
   Problem Summary:
   
   KVCache returns raw pointers whose objects are deleted when their entries 
lose their last owner. Callers can therefore retain dangling pointers after 
entry removal or cache destruction, including when erase overlaps a factory 
call. Return shared ownership and retain it in the cache and callers so active 
users keep the objects alive.
   
   ### Details
   
   - **Frequency:** When a caller outlives an erased entry or its cache; an 
in-flight factory can also return a dangling pointer after concurrent erase. No 
production incident frequency has been established.
   - **Root cause:** The shared Entry handle protects only the get call, while 
the returned raw pointer does not retain the cached value.
   - **Why existing tests missed it:** Existing tests cover concurrent loading, 
failed factories, and type isolation while the cache remains alive, but do not 
remove entries during use.
   - **Fix:** Return shared_ptr<T>, accept factories returning shared_ptr<T>, 
store shared_ptr<void> in Entry, and remove manual deletion. Add lifetime and 
erase coverage.
   - **Other paths and branches:** Adapt ShardedKVCache, deletion-vector 
ownership in TableReader, Iceberg delete caches, Fluss suppression keys, and 
Lance runtime filters. Preserve Lance's non-null wrapper for cached empty 
results. Other branches are not modified.
   - **Behavior change:** Erasing an entry or destroying the cache releases its 
reference; objects with active callers are destroyed after their last owner 
releases them. Cache-hit, retry, and type-isolation semantics remain unchanged.
   
   ### Testing
   
   - Passed locally: build-support/check-build-hygiene.sh, git diff --check, 
and build-support/check-format.sh with clang-format 16.0.6.
   - Formatting: build-support/clang-format.sh initially stopped because 
Homebrew llvm@16 is absent. Used its repository run_clang_format.py 
implementation with a temporary clang-format 16.0.6 installation on the seven 
changed files; both changed-file and full-tree format checks passed.
   - Added four KVCache unit tests covering retained values after erase, 
retained values after sharded-cache destruction and final destruction, erase 
during factory execution with replacement, and erase isolation by value type. 
Adapted the four existing tests to shared ownership.
   - Attempted ./run-be-ut.sh --run --filter='KVCacheTest.*' -j 4 and 
./build.sh --be -j 4. Both exited during Java environment initialization before 
compilation; no usable JDK 17 is configured and BE third-party dependencies are 
absent. Unit tests have not run, and no before/after runtime result is claimed.
   - Attempted build-support/run-clang-tidy.sh; clang-tidy is not installed and 
no compilation database is available.
   
   ### Release note
   
   Keep cached file-scan objects alive while callers still hold them after 
cache entry removal or cache destruction.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No
   - Pre-submission status: Partially verified: BE compilation, unit tests, and 
clang-tidy require a configured build environment.
   
   ### AI Disclosure
   
   - Tool: Codex (GPT-6)
   - Generated: Code, tests, and this description.
   - Human review: Pending.
   
   


-- 
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