Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ Core design: log-structured storage (Haystack / Bitcask pattern) where:

```
specs/ Quint formal specifications (written first, before Go)
types.qnt Shared types: Inode, Extent, DirEntry, Chunk, IndexSnapshot
types.qnt Shared types: Inode, Extent, DirEntry, Chunk, IndexSnapshot, JournalEvent
index.qnt Index state machine: mutations, persistence, invariants
chunks.qnt Chunk store: append, seal, rotate, readRange
compaction.qnt Compaction: target selection, remap, commit, safety proof
filesystem.qnt Full POSIX operations composing index + chunks
cmd/fusey/ Go binary entry point (to be implemented)
journal.qnt Optional edit log: append, flush, clear, as-of replay
filesystem.qnt Full POSIX operations composing index + chunks + journal
cmd/fusey/ Go binary entry point (subcommands: mount, unmount, compact, journal-dump)
internal/
config/ Environment variable parsing (FUSEY_* vars)
index/ In-memory index + disk persistence
chunks/ Active chunk buffer + S3 sealed chunk I/O
fuse/ FUSE layer (go-fuse bindings)
compaction/ Background compactor goroutine
journal/ Optional edit log: in-memory buffer, sharded flusher, replay, dump
```

## Key design decisions
Expand Down Expand Up @@ -98,6 +100,9 @@ internal/
used to share one bucket across multiple Fusey instances
- `FUSEY_COMPACTION_THRESHOLD` (default 0.3) — orphan fraction trigger for `fusey compact`
- `FUSEY_PERSIST_INTERVAL` (default 30s)
- `FUSEY_JOURNAL_ENABLED` (default false) — when true, every state-mutating
op is recorded to the optional edit log; required for `fusey journal-dump`
and `fusey mount <mp> --as-of=<ts>`

10. **Invariants to preserve** (from specs, enforced in implementation):
- `nlinkConsistency`: nlink == number of DirEntries pointing at inode (+1 for dirs)
Expand All @@ -113,6 +118,41 @@ internal/
- Recovering from crash-before-delete: old chunks still exist, re-deleting is idempotent
- Recovering from crash-before-persist: replay from backing store index (not disk cache)

12. **Journal (optional edit log)** — `FUSEY_JOURNAL_ENABLED`:
- When enabled, every state-mutating op on the index is also appended to
an in-memory journal buffer, which is flushed to the object store as
sharded append-only files `{prefix}journal-NNNNNNNNN.cbor` (one per
flush batch, named by the starting sequence number).
- TouchAtime is deliberately NOT journaled: high-frequency, no replay
value, matches the existing `remoteStoreDirty` exclusion in index.qnt.
- The journal supports two features: `fusey journal-dump` (a debug tool
that prints every recorded edit) and `fusey mount <mp> --as-of=<ts>`
(a read-only mount of the filesystem as it existed at wall-clock
time `ts`; errors if the journal is missing or the timestamp is
outside the recorded range).
- As-of mounts use `-o ro` on the underlying FUSE mount so the kernel
rejects all writes with EROFS. The Go FUSE layer additionally carries
a `readOnly` flag for explicit EROFS messages.
- The base snapshot is stored as `{prefix}index-base.cbor` (and
`<cacheDir>/index-base.cbor` locally). It is the state at the START
of the current journal period. As-of replay = base + journal entries
with `ts <= targetTs`.
- **`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 a consistent post-remap index+chunks; as-of
mounts simply error during that window. A fresh base snapshot is
written at the END of compact so subsequent as-of mounts have a
clean starting point.
- CLI shape: `fusey mount <mp> --as-of=<RFC3339-timestamp>` (flag AFTER
positional mountpoint). Sub-second precision is supported in
RFC3339Nano form. As-of mounts do not write a `daemon.pid`, so
`fusey unmount` does not see them — kill the parent `fusey mount`
process to stop one.
- Storage cost: grows with write activity between compactions. Typical
overhead is < 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.

## Quint spec notes

- Specs use module-level `const` for configuration (BLOCK_SIZE, MAX_CHUNK_SIZE, ROOT_INO).
Expand Down
68 changes: 66 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,67 @@ spec:
restartPolicy: OnFailure
```

### Journal (optional edit log)

Fusey can optionally record every state-mutating operation to an append-only
edit log in the object store. This enables two additional features:

- **`fusey journal-dump`** — a debug subcommand that prints every recorded
edit (with timestamp, sequence number, and full op fields) for auditing.
- **`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). Useful for "what was the state at 10:00?" style queries and
for recovering from a bad write by `cp`-ing the historical state out.

The journal is enabled by setting `FUSEY_JOURNAL_ENABLED=true` on the
mount/daemon. When disabled, no journal entries are recorded and as-of
mounts fail with a clear error.

Design choices (set during design review, see `AGENTS.md`):

- **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).
- **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 — recovery
is the same shape as the chunk store's `RecoverNextSeq`.
- **Wiped on compact.** `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 and 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 of compact so
subsequent as-of mounts can replay against the post-compact state.
- **As-of mounts are read-only.** The FUSE mount is opened with `-o ro`,
so the kernel rejects all writes with `EROFS`. Recovery from a
historical state is `cp -a <as-of-mp>/path /live-mp/path` to copy
the desired files into a live mount.
- **Storage cost.** The journal grows with write activity between
compactions. Operators who enable it should size their object store
budget accordingly (typical: < 1% of total data size for write-light
workloads; can dominate for write-heavy ones).

Examples:

```bash
# Mount with the journal enabled (live mode)
export FUSEY_JOURNAL_ENABLED=true
./fusey mount /mnt/fusey

# Inspect the journal
./fusey journal-dump
./fusey journal-dump --json | jq '.[].op.kind' | sort | uniq -c

# Mount a historical snapshot read-only
./fusey mount /mnt/fusey-asof --as-of=2026-01-15T10:00:00Z
ls /mnt/fusey-asof/ # shows the state at that timestamp
diff -r /mnt/fusey-asof/ /mnt/fusey/ # shows what changed since
```

The journal requires a base snapshot to be useful for as-of replay. The
first time you mount with `FUSEY_JOURNAL_ENABLED=true`, the next run of
`fusey compact` will write a base snapshot so as-of mounts work.

## Formal specification

The `specs/` directory contains a [Quint](https://quint-lang.org/) formal
Expand All @@ -145,11 +206,12 @@ invariants and temporal properties of the design.

| File | What it specifies |
|---|---|
| `specs/types.qnt` | Shared data types (Inode, Extent, DirEntry, Chunk, …) |
| `specs/types.qnt` | Shared data types (Inode, Extent, DirEntry, Chunk, JournalEvent, …) |
| `specs/index.qnt` | Index state machine: mutations, persistence, invariants |
| `specs/chunks.qnt` | Chunk store: append, seal, rotate, read-range |
| `specs/compaction.qnt` | Compaction: target selection, remap, commit, safety |
| `specs/filesystem.qnt` | Full POSIX operations composing index + chunks |
| `specs/journal.qnt` | Optional edit log: append, flush, clear, as-of replay |
| `specs/filesystem.qnt` | Full POSIX operations composing index + chunks + journal |

### Running the specs

Expand Down Expand Up @@ -199,6 +261,7 @@ as a Kubernetes container without config files.
| `FUSEY_PREFIX` | _(none)_ | Key prefix for all objects in the bucket (e.g. `pod-abc/`). Use this to share one bucket across multiple Fusey instances |
| `FUSEY_COMPACTION_THRESHOLD` | `0.3` | Orphan fraction above which a chunk is targeted by `fusey compact` |
| `FUSEY_PERSIST_INTERVAL` | `30s` | How often the index is flushed to disk and the object store |
| `FUSEY_JOURNAL_ENABLED` | `false` | Set to `true` to record every state-mutating operation to the optional edit log. Required for `fusey journal-dump` and `fusey mount <mp> --as-of=<ts>`. |
| `FUSEY_ALLOW_OTHER` | `true` | When `true`, fusey mounts with the FUSE `allow_other` option so any user on the host can access the mountpoint. When `false`, only the UID that called `mount(2)` (the fusey daemon) can access it (the FUSE default). The default is `true` because fusey's typical deployment runs the daemon as root while the consumer (e.g. an agent-server) runs as a non-root user; without `allow_other` the kernel rejects the consumer's VFS operations before fusey's permission code runs. Set `FUSEY_ALLOW_OTHER=false` to restore the FUSE default if you need to restrict access to the mounter's UID. |

### Broker store (alternative to direct S3)
Expand All @@ -221,6 +284,7 @@ A reference broker implementation is in [`broker/`](broker/). It stores objects
- [x] `statfs` support (`FUSEY_MAX_SIZE`)
- [x] S3 chunk store backend (`aws-sdk-go-v2`, S3-compatible)
- [x] Cold-start recovery (local cache → S3 → fresh)
- [x] Optional edit log (`FUSEY_JOURNAL_ENABLED`) with as-of replay and `journal-dump`
- [ ] Kubernetes deployment guide

## Development
Expand Down
Loading
Loading