The vfs package provides a small filesystem abstraction used by WAL, manifest, SST, value-log, and raftstore paths.
vfs.FS includes:
- file open/create:
OpenHandle,OpenFileHandle - path ops:
MkdirAll,Remove,RemoveAll,Rename,RenameNoReplace,Stat,ReadDir,Glob - helpers:
ReadFile,WriteFile,Truncate,Hostname
vfs.File includes:
- read/write/seek APIs
Sync,Truncate,Close,Stat,Name
vfs.Ensure(fs) maps nil to OSFS.
Rename:
- normal rename/move semantics.
- target replacement behavior is platform-dependent (
os.Renamebehavior).
RenameNoReplace:
- contract: fail with
os.ErrExistwhen destination already exists. - on Linux, uses
renameat2(..., RENAME_NOREPLACE). - on macOS, uses
renamex_np(..., RENAME_EXCL). - when atomic no-replace rename is unsupported by platform/filesystem, returns
vfs.ErrRenameNoReplaceUnsupported(no non-atomic fallback).
vfs.SyncDir(fs, dir) fsyncs directory metadata to persist entry updates (create/rename/remove).
This is used in strict durability paths (for example SST install before manifest publication) to guarantee directory entry persistence.
FaultFS wraps an underlying FS and can inject failures by operation/path.
- Rule helpers:
FailOnceRule,FailOnNthRule,FailAfterNthRule,FailOnceRenameRule - File-handle faults: write/sync/close/truncate
- Rename fault matching supports
src/dsttargeting
Used to test manifest/WAL/recovery failure paths deterministically.
OSFS: production implementation (Goospackage).FaultFS: failure-injection wrapper over anyFS.
No in-memory FS is included yet.
- Keep storage code decoupled from direct
os.*calls. - Make crash/failure tests reproducible.
- Keep API minimal and only add operations required by real storage call sites.
References:
- Pebble VFS: https://pkg.go.dev/github.com/cockroachdb/pebble/vfs
- Pebble errorfs: https://pkg.go.dev/github.com/cockroachdb/pebble/vfs/errorfs