refactor: extract DConfig loading and add index-level mutex for thread safety#293
Closed
liyigang1 wants to merge 1 commit into
Closed
refactor: extract DConfig loading and add index-level mutex for thread safety#293liyigang1 wants to merge 1 commit into
liyigang1 wants to merge 1 commit into
Conversation
…d safety Extracted all DConfig loading logic from searchutility.cpp into a dedicated SearchDConfig class with a SearchDConfigSnapshot struct. DConfig reads via DBus are not thread-safe, so all reads are now performed on the main thread and the resulting snapshot is passed to worker threads via custom options. Added IndexMutexGuard to provide per-index-directory mutual exclusion, preventing concurrent access to the same Lucene index directory since FSDirectory::open() returns cached instances sharing underlying buffers. These changes enable: 1. Thread-safe DConfig access by restricting reads to the main thread 2. Safe concurrent searching across multiple index directories 3. Cleaner separation of configuration loading concerns Influence: 1. Verify multi-threaded search scenarios no longer cause index corruption 2. Ensure DConfig snapshot is correctly propagated to all search strategies 3. Test path prefix query optimization with dynamic indexed directory changes refactor: 提取 DConfig 加载逻辑并添加索引级互斥锁以保障线程安全 Bug: https://pms.uniontech.com/bug-view-361809.html 将 searchutility.cpp 中所有 DConfig 加载逻辑提取到独立的 SearchDConfig 类, 使用 SearchDConfigSnapshot 结构体承载配置快照。DConfig 通过 DBus 读取, 非线程安全,因此所有读取操作限定在主线程执行,生成的快照通过自定义选项 传递给工作线程。 新增 IndexMutexGuard 提供按索引目录的互斥机制,防止多线程并发访问同一 Lucene 索引目录,因为 FSDirectory::open() 对相同路径返回缓存实例, 底层 IndexInput 缓冲区共享。 这些改动实现了: 1. 通过将 DConfig 读取限制在主线程来保障线程安全 2. 支持多索引目录间的安全并发搜索 3. 配置加载职责的清晰分离 Influence: 1. 验证多线程搜索场景不再导致索引损坏 2. 确保 DConfig 快照正确传递到所有搜索策略 3. 测试索引目录动态变化时路径前缀查询优化的正确性
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: liyigang1 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extracted all DConfig loading logic from searchutility.cpp into a dedicated SearchDConfig class with a SearchDConfigSnapshot struct. DConfig reads via DBus are not thread-safe, so all reads are now performed on the main thread and the resulting snapshot is passed to worker threads via custom options.
Added IndexMutexGuard to provide per-index-directory mutual exclusion, preventing concurrent access to the same Lucene index directory since FSDirectory::open() returns cached instances sharing underlying buffers.
These changes enable:
Influence:
refactor: 提取 DConfig 加载逻辑并添加索引级互斥锁以保障线程安全
Bug: https://pms.uniontech.com/bug-view-361809.html
将 searchutility.cpp 中所有 DConfig 加载逻辑提取到独立的 SearchDConfig 类, 使用 SearchDConfigSnapshot 结构体承载配置快照。DConfig 通过 DBus 读取, 非线程安全,因此所有读取操作限定在主线程执行,生成的快照通过自定义选项
传递给工作线程。
新增 IndexMutexGuard 提供按索引目录的互斥机制,防止多线程并发访问同一
Lucene 索引目录,因为 FSDirectory::open() 对相同路径返回缓存实例,
底层 IndexInput 缓冲区共享。
这些改动实现了:
Influence: