Skip to content

refactor: extract DConfig loading and add index-level mutex for thread safety#293

Closed
liyigang1 wants to merge 1 commit into
linuxdeepin:masterfrom
liyigang1:master
Closed

refactor: extract DConfig loading and add index-level mutex for thread safety#293
liyigang1 wants to merge 1 commit into
linuxdeepin:masterfrom
liyigang1:master

Conversation

@liyigang1
Copy link
Copy Markdown
Contributor

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. 测试索引目录动态变化时路径前缀查询优化的正确性

…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. 测试索引目录动态变化时路径前缀查询优化的正确性
@deepin-ci-robot
Copy link
Copy Markdown

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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@liyigang1 liyigang1 closed this May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants