Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

purgeLogs({destroy:true}) continuing past a refused unlink can strand readers or leave stale flushed-state generation

Open
#883 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
32/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp
Domain
databases

Research direction

Read transaction_log_store.cpp around the sequenceFiles.empty() check in doPurge(), then inspect removeFileLocked() in transaction_log_file_posix.cpp and transaction_log_file_windows.cpp at the referenced ranges. Decide which refusal contract applies, trace both destroy:true hazards, and validate that the chosen behavior preserves reader mappings and flushed-state state consistently.

Written by the indexing model from the issue text.

Description

bug

Problem

TransactionLogStore::doPurge()'s destructive path (purgeLogs({ destroy: true }), all=true) continues past a segment whose unlink is refused (EACCES, or a Windows sharing violation while a bound transaction keeps the store alive) instead of stopping. That non-throwing continue-past-refusal behavior (introduced in HarperFast/rocksdb-js#820 to make Windows purge-vs-mapping convergence testable) creates two independent hazards, both destroy: true-only:

  1. A refused unlink of the current segment strands a reader on a stale mapping. removeFileLocked() (transaction_log_file_posix.cpp / transaction_log_file_windows.cpp) drops the strong memoryMap and closes the fd before it knows whether the unlink succeeded. If the current segment's unlink is refused while a bound transaction keeps the store alive, the next append reopens the file into a new MemoryMap; a reader still holding the old buffer never sees the new entries, because its extent and overlay stop advancing.

  2. A refused unlink of an older segment can leave a stale flushed-state generation authoritative. The flushed-state generation bump, correlation-ring reset, and txn.state clear (transaction_log_store.cpp, around the sequenceFiles.empty() check in doPurge()) only run when the destructive purge empties the registered set entirely. If one older segment's unlink is refused (leaving sequenceFiles non-empty) while a later, already-flushed segment is still successfully deleted, that whole invalidation block is skipped — txn.state survives naming the deleted segment's sequence number. After a restart, the refused segment becomes current, a later append can reuse the now-vacant sequence number txn.state still names, and retention can then delete that reused segment as "already flushed" before it reaches RocksDB.

Impact

Both require purgeLogs({ destroy: true }), which Harper does not call in production, so neither is currently reachable in the field. But they are real correctness gaps in a public API: #1 silently truncates a reader's view of committed history; #2 can cause retention to delete unflushed, acknowledged data after a restart.

Expected behavior

Pick one destroy-refusal contract and apply it consistently to both hazards:

  • Stop-at-first-refusal — restore main's pre-#820 effective behavior (throw on a refused unlink during a destructive purge) so a partial destroy can never leave state describing an inconsistent segment set. Simple, but means one stuck segment blocks the whole destroy.
  • Fine-grained invalidation — invalidate the flushed-state generation whenever the specific segment txn.state names is removed (not only when the whole registered set empties), and retain/restore the tracked mapping for a segment whose unlink failed (don't drop memoryMap until the unlink actually succeeds). Lets destroy continue past an unrelated stuck segment, at the cost of more state to keep consistent.

Notes

Surfaced during independent review (codex + harper-domain, multiple rounds) while maintaining #820. Deliberately not fixed inside that PR: #820 is scoped to the purge/read-coherence contract for the retention path Harper actually uses, and prior attempts at hardening the destroy: true path inside that PR repeatedly surfaced new races (documented there as a scope correction). Decision recorded: defer, track here — HarperFast/rocksdb-js#820 (comment thread) has the fuller review trail and code references (transaction_log_store.cpp:842, transaction_log_file_posix.cpp:510-534, transaction_log_file_windows.cpp:523-565).

Dominant language
C++
Stars
24
Forks
3
Avg merge
1d 7h
Merged PRs (30d)
46

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from HarperFast/rocksdb-js

All issues in HarperFast/rocksdb-js

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.