Skip to content

fix(knowledge): 文档上传失败时清理存储文件 - #96

Open
KDB-Wind wants to merge 1 commit into
nageoffer:mainfrom
KDB-Wind:codex/fix-upload-orphan-file
Open

fix(knowledge): 文档上传失败时清理存储文件#96
KDB-Wind wants to merge 1 commit into
nageoffer:mainfrom
KDB-Wind:codex/fix-upload-orphan-file

Conversation

@KDB-Wind

@KDB-Wind KDB-Wind commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #94

问题

当前 main 已在写入对象存储前完成处理模式校验。对象写入成功后,如果文档插入抛出异常或返回 0,上传对象仍可能没有对应的文档记录。

修改

  • 将插入返回值 <= 0 视为失败
  • 插入失败后,仅在有文档 ID 且确认记录不存在时删除对象
  • 无法确认插入结果时保留对象
  • 清理失败不覆盖原始异常

上传成功路径和已有的不支持 MIME 类型清理逻辑不变。

测试

KnowledgeDocumentServiceImplUploadTest 覆盖 FILE、URL 配置错误,以及插入失败、结果不明确、清理失败、正常上传和不支持的文件类型。

KnowledgeDocumentServiceImplUploadTest: 11/11 通过
Spotless: 通过
git diff --check: 通过

连接中断或超时时,数据库提交状态仍可能不明确。本次只提供 best-effort 补偿,不处理历史孤儿对象,也不引入分布式事务。

@KDB-Wind
KDB-Wind force-pushed the codex/fix-upload-orphan-file branch from 1102344 to d9ee046 Compare August 1, 2026 11:11
对象写入成功后,文档插入异常或返回 0 会留下没有数据库记录的文件。插入失败时按已生成 ID 复核记录,仅在确认不存在时删除;无法确认提交结果或清理失败时保留原异常。
@KDB-Wind
KDB-Wind force-pushed the codex/fix-upload-orphan-file branch from d9ee046 to 118c40a Compare August 3, 2026 13:34
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.

文档上传在配置校验或落库失败时可能遗留对象存储文件

1 participant