airborne12 opened a new pull request, #62722:
URL: https://github.com/apache/doris/pull/62722
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
The CLucene-facing wrapper readers in the inverted-index store
(`CSIndexInput`, `FSIndexInput`) serialize every `read_at` through a per-input
mutex (`_this_lock`) plus a shared position cursor (`_fpos` / `_shared_lock`).
When a cached `IndexSearcher` is reused across concurrent queries, all reads on
the same sub-file queue up behind that single lock, severely limiting
throughput on multi-threaded scans (observed as contention between sibling
`IndexSearcher` reuses and between clones of the same `FSIndexInput`).
This PR removes the wrapper-level lock and moves to per-input deep clones
with private state, so sibling readers on the same compound file or the same
segment file no longer contend:
- `CSIndexInput` base: deep-clone the underlying `IndexInput` and own it via
`std::unique_ptr` (with a CLucene `_CLDELETE`-aware deleter). Drop `_this_lock`
from the read path.
- `FSIndexInput::read_at` runs without the wrapper lock; the clone cursor is
preserved via a new `SharedHandle` indirection. `_this_lock` / `_shared_lock` /
`_fpos` are removed. `SharedHandle::_shared_lock` is re-added under
`!USE_HADOOP_HDFS` to keep the non-Hadoop HDFS path safe.
- `FSIndexInput::clone` no longer inherits the creating query's per-query
`IOContext`, matching the `MATCH` path and preventing use-after-free when the
cached `IndexSearcher` is reused from a different query.
### Release note
BE: Remove the per-input wrapper lock on inverted index `CSIndexInput` /
`FSIndexInput` so concurrent queries no longer serialize behind a single mutex
when a cached `IndexSearcher` is reused. Also fixes a use-after-free where
`FSIndexInput::clone` inherited the creating query's `IOContext`.
### Check List (For Author)
- Test
- [ ] Regression test
- [x] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason
New unit tests, all passing under ASAN (`BUILD_TYPE_UT=ASAN`,
`./run-be-ut.sh --run
--filter='DorisCompoundReaderTest.*:DorisFSDirectoryTest.*:CollectionStatisticsTest.*'`
— 91 tests, 91 passed):
- Deep-clone independence / data correctness / lifecycle / multi-level
clone chain: `DorisCompoundReaderTest.CSIndexInputCloneIsIndependent`,
`CSIndexInputCloneReadsCorrectly`, `CSIndexInputCloneOutlivesSource`,
`CSIndexInputCloneChainIsIndependent`, `CloneReturnsDistinctUsableInput`.
- Concurrent read across sibling `CSIndexInput`s and across clone
chains: `ConcurrentReadAcrossSubFiles`, `ConcurrentReadStressAcrossClones`,
`FSIndexInputConcurrentReadAcrossClones`,
`FSIndexInputCloneChainOutlivesSource`.
- Buffer-boundary behavior: `ClonesRefillBuffersIndependently`,
`OpenInputProducesIndependentBases`.
- `CollectionStatisticsTest` callers adjusted to pass the `io_ctx`
argument.
- Behavior changed:
- [ ] No.
- [x] Yes. Concurrent scans that share a cached `IndexSearcher` no
longer serialize behind `_this_lock`; throughput on multi-threaded
inverted-index reads improves. Functional behavior of individual reads is
unchanged.
- Does this need documentation?
- [x] No.
- [ ] Yes.
--
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]