Skip to content

fix(storage): 修复快速重启时向量存储锁竞争问题#343

Merged
qin-ctx merged 1 commit intomainfrom
fix/vector_lock
Feb 28, 2026
Merged

fix(storage): 修复快速重启时向量存储锁竞争问题#343
qin-ctx merged 1 commit intomainfrom
fix/vector_lock

Conversation

@qin-ctx
Copy link
Collaborator

@qin-ctx qin-ctx commented Feb 28, 2026

Description

修复快速重启场景下,队列 worker 仍在 drain 消息并尝试写入向量存储时,与正在关闭的后端产生 LOCK 文件竞争的问题。

Related Issue

N/A

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • VikingDBManager 提取 mark_closing() 方法,支持在 close() 之前提前标记关闭状态
  • OpenVikingService.shutdown() 在停止队列之前先调用 mark_closing(),避免队列 worker 写入已关闭的向量存储
  • TextEmbeddingHandler 在 dequeue 入口和 upsert 异常捕获处检查 is_closing 标志,shutdown 期间跳过写入并标记为成功
  • 新增 tests/storage/test_collection_schemas.py,覆盖 shutdown 期间跳过 embedding 和 upsert 锁冲突两种场景

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Additional Notes

在 shutdown 流程中,mark_closing() 被提前调用(在停止队列之前),这样队列 worker 在 drain 剩余消息时能感知到关闭状态,主动跳过向量写入操作,避免与 VikingDBManager.close() 产生锁竞争。

在 shutdown 流程中,队列 worker 可能仍在 drain 消息并尝试写入向量存储,
导致与正在关闭的后端产生锁竞争。提前标记 closing 状态,让 embedding handler
在 shutdown 期间跳过写入操作,避免 LOCK 文件冲突。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

embedding_msg = EmbeddingMsg.from_dict(queue_data)
inserted_data = embedding_msg.context_data

if getattr(self._vikingdb, "is_closing", False):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么是通过 getattr 访问属性

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多此一举,待会去掉

@qin-ctx qin-ctx merged commit 976a045 into main Feb 28, 2026
5 of 6 checks passed
@qin-ctx qin-ctx deleted the fix/vector_lock branch February 28, 2026 06:22
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants