Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

compact: build the successor in a private directory and publish it atomically

未关闭
#59 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
backend, databases

调研方向

Start with okf/faces/lib/compact.js and read guardCompactPaths(), claimDir(), and the staging and cleanup flow. The issue also identifies Bundle.init and the sign callback as key points to trace. Add the three listed race tests, then verify that compaction refuses a changed destination and cleanup preserves replacement directories and files.

由索引模型根据 Issue 内容生成。

描述

Summary

compact() in okf/faces/lib/compact.js (branch feat/okf-autobee-v2) checks its paths once, then writes into them in place. Another process that writes into the out-dir or the staging path while a compaction runs can lose its files. The review of the compaction hardening (T13 to T18) found two such races. The owner accepted both for the first release, as a fast follow after the branch lands.

The two races

  1. The out-dir check expires before the store opens. guardCompactPaths() refuses a non-empty out-dir before the face step. Compaction then materializes, stages and awaits the sign callback. If another process creates the out-dir and writes a file into it during that window, claimDir() accepts the directory, and Bundle.init (Corestore) clears it. The foreign file is gone, and compaction reports success.
  2. Cleanup equates a path name with ownership. On a failure, compaction removes the stage when ownStage is true, and claimDir().release() removes the out-dir or the entries that it did not see at claim time. If another process replaced the stage directory, or added a file to the out-dir after the claim, cleanup deletes that directory or file.

Both races need a concurrent writer on the same paths. A single user on one machine who runs one compaction at a time does not meet them.

The full fix

  • Build the successor in a private directory that compaction creates exclusively, for example mkdtemp(<out-dir>.compact-build-), beside the out-dir.
  • Stage, ingest and verify there. Close the successor vault.
  • Publish with an atomic rename onto the out-dir. On POSIX, rename(2) of a directory fails with ENOTEMPTY or EEXIST when the destination is not empty, so a changed destination is refused, never cleared.
  • Reopen the published vault at the out-dir and return it. compact() then returns a vault that it reopened, not the one that it built. That is an API change for callers that hold the build path.
  • Cleanup removes only the private build directory and the stage that this run created. Record the device and inode of each created directory, and refuse to remove a path whose identity changed.

Tests to add

  • A sign callback that creates the out-dir and writes a file into it: compaction refuses, and the file stays.
  • A stage replaced between staging and a failure: the replacement stays.
  • A file added to the out-dir after the claim, then an init failure: the file stays.
主要语言
JavaScript
星标
0
派生
0
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

indexzero/hyperdown 的其他 Issue

查看 indexzero/hyperdown 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。