Skip to content

refactor(writer): make the file-handle decision a pure function - #13

Merged
wt159 merged 1 commit into
mainfrom
refactor/file-action-policy
Nov 9, 2026
Merged

wt159 merged 1 commit into
mainfrom
refactor/file-action-policy

Conversation

@wt159

@wt159 wt159 commented Nov 9, 2026

Copy link
Copy Markdown
Owner

上一个 PR 的驱逐修复没有回归测试:端到端复现需要句柄空闲超过 1s,同时第二次写又必须落在 2s rollover 窗口内,CI 上不稳定。

这次把决策抽出来:

session_file_action(session, handle_tracked, size_limit)
  -> 句柄为空 / 句柄已被文件管理器回收 => REOPEN
  -> 达到分片上限                       => ROLLOVER
  -> 否则                                => USE

写线程只负责把结果映射成动作,四种情况(含曾经会被直接写入的 untracked 句柄)现在由纯单测覆盖,不涉及线程和时间。

行为不变。

The eviction fix from the previous commit had no regression test: exercising it
end to end needs a handle idle past IDLE_TIMEOUT_SEC and a rewrite inside the
2s rollover window, which is unstable on CI.

Extract the decision into session_file_action(session, handle_tracked, limit):
missing handle or evicted handle -> reopen, size limit -> roll over, otherwise
reuse. The writer maps the result to operations, and a plain unit test now
covers all four cases, including the untracked handle that used to be written
through.

No behaviour change beyond the existing guard.
@wt159
wt159 merged commit 905f64f into main Nov 9, 2026
2 checks passed
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