Skip to content

feat: optional edit log with as-of replay - #21

Merged
tofarr merged 2 commits into
mainfrom
feat/journal-edit-log
Sep 4, 2026
Merged

tofarr merged 2 commits into
mainfrom
feat/journal-edit-log

Conversation

@tofarr

@tofarr tofarr commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds the optional edit log (FUSEY_JOURNAL_ENABLED) to Fusey, supporting two new features:

  • fusey journal-dump — a debug subcommand that prints every recorded edit (with timestamp, sequence number, and full op fields) in either human-readable or JSON form. Useful for auditing "what changed?" without leaving the CLI.
  • fusey mount <mp> --as-of=<ts> — a read-only mount of the filesystem as it existed at wall-clock time ts (RFC 3339, with optional sub-second precision). Lets you answer "what was the state at 10:00?" and copy historical files out via cp -a.

Design decisions (locked in up-front with the user)

  1. TouchAtime is NOT journaled. Read access is too high-frequency and has no replay value. The journal only records writes (create, delete, rename, setattr, write, truncate, xattr, symlink).
  2. Sharded, append-only. Each flush writes a new shard named {prefix}journal-NNNNNNNNN.cbor where N is the starting sequence number of the batch. Existing shards are never overwritten — same shape as the chunk store's RecoverNextSeq.
  3. fusey compact deletes the journal at the START of its cycle, before any chunk remap. If compact crashes mid-cycle, the next mount has an empty journal but the index+chunks are in a consistent post-remap state; as-of mounts simply error during that window. A fresh base snapshot is written at the end.
  4. As-of mounts are read-only. The FUSE mount is opened with -o ro, so the kernel rejects all writes with EROFS. Recovery is cp -a <as-of-mp>/path /live-mp/path.
  5. Base snapshot. Stored as {prefix}index-base.cbor. As-of replay = base + journal entries with ts <= targetTs.

Code layout

internal/journal/
  event.go         — JournalEvent variants + Entry (tagged-union on Op)
  journal.go       — In-memory buffer + SetNextSeqAfter (durable replay)
  persist.go       — CBOR shard encoding, Flush, LoadAll, Clear, base snapshot
  apply.go         — Replay a single entry to a fresh in-memory index
  dump.go          — Human-readable and JSON dump formats
  wrap.go          — JournaledIndex wrapper (paired mutations)
  journal_test.go  — 14 unit tests (roundtrip, replay equality, dump, etc.)

specs/
  types.qnt        — +JournalEvent variants
  journal.qnt      — New state machine (append, flush, clear, replay)
  filesystem.qnt   — Re-declared journal state + journalAppend calls in
                     create/mkdir/symlink/link/unlink/rmdir/rename/setattr/write

Wiring

  • cmd/fusey/main.go: builds a JournaledIndex when the flag is on; buildPersistFn flushes journal shards alongside the existing local + remote index flushes (order: index, chunk, journal, remote index). runCompact calls journal.Clear at the start and journal.SaveBase at the end. New subcommand fusey journal-dump [--json]. New fusey mount <mp> [--as-of=<ts>] flag.
  • internal/fuse/fs.go: switched to an FSIndex interface so the FUSE layer is agnostic to whether it holds a bare *index.Index or a *journal.JournaledIndex. The readOnly flag is plumbed through to the FUSE mount options.
  • internal/chunks/store.go: ObjectStore interface extended with JournalKey, DeleteJournalKey, and Prefix so the journal works correctly under both S3 (with prefix) and broker (flat namespace) stores.

Build & test

  • go build ./... — clean
  • go test ./... — all packages green, including the 14 new journal tests
  • go vet ./... — clean

Test coverage highlights

  • TestJournalFlushAndLoad — roundtrip via the object store
  • TestJournalMultipleShardsOrderedBySeq — multiple shards sorted correctly on load
  • TestJournalClearRemovesShards — Clear removes every shard
  • TestApplyReplayMatchesLiveOps — the journal + Apply produces the same state as the live index
  • TestReplayUpToFiltersByTimestamp — ts <= targetTs boundary
  • TestJournaledIndexRemoveDirEntryEmitsDeleteInodeOnNlinkZero — wrapper emits both ops
  • TestJournaledIndexRenameEmitsDeleteInodeOnReplace — replacement at rename time
  • TestDumpHumanReadable / TestDumpJSON — both formats

Operator notes

  • The first time you mount with FUSEY_JOURNAL_ENABLED=true, the next fusey compact will write a base snapshot so as-of mounts work. Until that happens, as-of mounts error with "no base snapshot found".
  • Storage cost: grows with write activity between compactions. Typical < 1% of total data size for write-light workloads; can dominate for write-heavy ones. Operators who enable it should size their object store budget accordingly.
  • As-of mounts do not write a daemon.pid file, so fusey unmount does not see them — kill the parent fusey mount process to stop one.

Documentation

Not in this PR

  • A small window exists between an in-memory index mutation and the journal append. A crash in that window would leave the index in the post-mutation state but the journal without the entry; the next as-of mount would replay to the pre-mutation state. This is acceptable because the journal is a debugging / replay aid, not a correctness primitive. Documented in internal/journal/wrap.go.
  • The spec has the same pre-existing action-body parser limitation as index.qnt and chunks.qnt against the latest Quint. The Go implementation is the source of truth; the spec models the design. Per AGENTS.md, specs may need minor corrections against the actual Quint compiler.

Adds the optional journal feature (FUSEY_JOURNAL_ENABLED), supporting two
new subcommands / mount modes:

- `fusey journal-dump` prints the recorded edit log in human-readable
  (or JSON) form.
- `fusey mount <mp> --as-of=<ts>` mounts the filesystem as it existed at
  wall-clock time ts, read-only.

Design choices:

- TouchAtime is deliberately NOT journaled (high-frequency, no replay
  value). All other mutating operations on the index are recorded.
- Shards are append-only and named by their starting sequence number,
  matching the chunk store's RecoverNextSeq pattern.
- `fusey compact` deletes the journal at the START of its cycle, BEFORE
  any chunk remap. A fresh base snapshot is written at the END.
- As-of mounts use `-o ro` so the kernel rejects writes with EROFS.
- The base snapshot is stored as {prefix}index-base.cbor.

Code layout:
- `internal/journal/{event,journal,persist,apply,dump,wrap}.go` — Go
  implementation. `JournaledIndex` wraps *index.Index and pairs every
  mutating call with a journal append.
- `specs/journal.qnt` + new `JournalEvent` variants in types.qnt,
  re-declared in filesystem.qnt alongside the existing index/chunks state.
- `ObjectStore` interface extended with `JournalKey`, `DeleteJournalKey`,
  and `Prefix` so the journal works with both S3 and broker stores.
- FUSE layer takes an `FSIndex` interface so the same code path serves
  both the bare index (journal disabled) and the wrapper (enabled).
Resolve merge conflicts in README.md, cmd/fusey/main.go, and
internal/config/config.go by keeping both sides' additions:
- Journal edit-log feature (FUSEY_JOURNAL_ENABLED, journal-dump, --as-of)
- AllowOther mount option (FUSEY_ALLOW_OTHER, version subcommand)

The mount path now uses cfg.AllowOther instead of a hardcoded false,
while preserving the journal wiring and read-only as-of mode.

Co-authored-by: openhands <openhands@all-hands.dev>

@hieptl hieptl left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🙏

@tofarr
tofarr merged commit c09461a into main Sep 4, 2026
1 check passed
@tofarr
tofarr deleted the feat/journal-edit-log branch September 4, 2026 12:28
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.

3 participants