mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #5606] Transaction rollback strands a stale-file mark without its paired dirty keys — the next flush can erase a misfiled row's only copy #3107
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#3107
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Aug 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5606
Originally assigned to: @kolacheee on GitHub.
What happens
A transaction rollback can erase a misfiled row's only on-disk copy. If a chat's shard file contains a row that belongs to a different chat (a stray — the state the store's self-healing exists to fix), and that chat's unit loads inside a transaction that later rolls back, the next flush rewrites the host file canonically (without the stray) while never writing the stray's own shard. The row then exists only in memory; a restart loses it.
Verified on current
staging(d660fffbf) with the lazy store as merged in #5597 — this is not an eviction (#5603) regression; it reproduces identically with eviction disabled.Why
Loading a shard that holds foreign rows creates two paired marks in the same synchronous block (
loadShardFileSyncinpackages/server/src/db/file-backed-store.ts): a stale-file mark for the host file (so the flush rewrites it canonically) and dirty keys for every row's real shard (so the strays get written to their own files first). The flush's write-then-unlink ordering is only safe because those two always travel together.Transaction rollback breaks the pairing: the rollback path restores
dirtyShardsfrom the pre-transaction snapshot (erasing the load's dirty keys) but does not touchstaleShardFiles— the stale mark survives alone. On the next flush, the host file is rewritten canonically without the stray, and the stray's own shard is skipped by the clean-shard fast path (!effectiveDirty.has(key) && known.has(encoded)) because its key is no longer dirty and its file already exists on disk.Try it yourself (repro shape; a regression-style script against
createFileNativeDBshows it directly)tables/messages/chat-a.jsonwith one chat-a row plus a row whosechatIdischat-b; seedtables/messages/chat-b.jsonwith a different chat-b row (the file must already exist — if it doesn't, the flush's recreate-if-missing branch happens to rescue the row).db.transaction, run any query that touches chat-a (the unit loads mid-transaction, healing marks are created), then throw to force a rollback.flush, restart, and list chat-b's messages: the misfiled row is gone from disk everywhere.Suggested direction
Load-created healing marks are not transaction mutations and should survive a rollback the same way the loaded rows themselves do (the row arrays are deliberately mirrored into the transaction snapshot for exactly this reason). Either re-create the load's dirty keys on rollback (track them per-transaction alongside the snapshot), or make the rollback restore
staleShardFilesanddirtyShardsas a consistent pair — the invariant to preserve is simply "a stale mark never reaches a flush without the dirty keys it was created with."How found
Adversarial verification of #5603 (durability lens, probe on both HEAD and the parent commit). Related machinery context in #5592.