Documentation
¶
Overview ¶
Package vfs is a filesystem on an object store: a Volume.
On-disk layout ¶
A Volume is a prefix of a bucket holding three kinds of object, all sealed by the Volume's Cipher:
head the one mutable object: names the root shard meta/<2 hex>/<hash> metadata shards, immutable, named by the hash of their bytes pack/<2 hex>/<id> packs of file chunks, immutable, named by a random id
File bytes are cut into content-defined chunks of 64 KiB to 4 MiB (chunk.go). Each chunk is sealed on its own, and sealed chunks are packed together into objects of about 16 MiB, so a tree of 150 GiB is a few thousand PUTs rather than one per chunk. Files of at most 16 KiB are not chunked at all: their bytes are a record in the metadata shard, beside their inode. A hole in a file is no record at all: a file's size is its inode's, and only the runs of bytes that were written have chunks, so the cost of a file follows what was written and not how large it was declared.
All metadata (inodes, directory entries, chunk references, the table saying where each chunk lives) is records in one ordered Merkle tree (tree.go), cut into shards. The Head holds the tree's root ref, the next inode number, the Volume's identity and the seed of its chunking table.
Every object is sealed together with what it is: shards and chunks to their Volume, a Head to the Volume's place (Backend.String). An object copied in from another Volume, or a Volume copied to another place, does not open.
Objects are written once, under names that are a hash of their content or a random id: a write that is repeated, or that completes after its caller gave up, puts the same bytes at the same name. The Head is the only object that changes, and only by compare-and-swap.
Commit ¶
A Volume that is written keeps a journal on its node's disk (journal/, docs/journal.md). A change (a write, a truncate, a create, a remove) is built from what the Volume holds in memory, sealed, appended to the journal, and applied, in that order and with no other change between. Nothing in that path waits for the store.
A publisher, a goroutine of the Volume, takes everything applied up to one journal sequence at an instant (a generation: immutable from then on; changes made after it belong to the next), settles the files' writes into chunks and seals them into packs, writes the packs and the shards the generation touched (and no others) to the store in parallel, and then replaces the Head with one conditional write that names the new tree and carries the journal's sequence. Only that write changes any object a reader can reach. A crash, or a failure, before it leaves the previous Head and so the previous tree whole; the chunks, packs and shards already written are unreferenced garbage, never corruption. After it the journal is told the store has the sequence and reclaims its space. A generation is published within the bound (Config.Bound, 5 s) of the oldest change it holds, by a timer set for that change's own acknowledgement, and earlier when memory or the journal holds enough to make it worth doing, when Flush asks, and when the Volume is closed down by a mount.
Durability ¶
What is durable, and where, when a call returns. "Journal" is this node's disk: the journal's sync has returned for the change. "Store" is the Head advancing in the store: the conditional PUT of the Head has returned success.
call durable when it returns
File.WriteAt, Truncate, Punch, Create, nothing. The change is in memory and in the journal's
Mkdir, Remove, Rename, Link, Symlink, buffer: it survives the process ending only if the
Mknod, SetAttr journal had written it, and a machine ending only if the
journal had synced it. Visible to every reader at once.
Each operation is atomic in a generation: a Head holds
all of it or none.
File.Sync, Volume.SyncInode, the journal, for the changes the file depends on (all of
Volume.Sync them, for a directory or the Volume): they survive a crash
of the process and of the machine. Concurrent callers
share one disk sync. The store is not asked.
File.Close nothing, and no request of the store: it releases the
handle. A handle that only read touches nothing.
Volume.Flush the store, for everything changed before the call: it
returns after a Head that carries it has committed.
FUSE flush (every close(2)) nothing, and no request: constant time.
FUSE fsync the journal.
publication by the Volume the store, within Config.Bound of each change's own
acknowledgement while the store answers.
end of a mount (SIGTERM, detach) the kernel hands its cached writes to the daemon (syncfs),
then one Flush; if the store does not answer in time what
it lacks stays in the journal and the next mount of the
Volume on this node publishes it.
Volume.Close the journal, whatever was changed and not published; no
request. It does not flush: a caller that hands the Volume
over calls Flush first (the detach sequence is Flush, Close).
A journal with nothing left in it is removed.
Attach, the same node every change the previous owner acknowledged with Sync (and
every one its journal had written) is replayed from the
journal, published under the new Round, and in the new
owner's tree before Attach returns.
Attach, another node or a lost disk the last Head. What the previous owner acknowledged and had
not published is not here: Recovery reports Lost, and a
caller must not tell its users those changes are durable.
A node that is lost for good loses at most the changes of the last Bound (5 s) that its journal held and the store did not; a process that crashes loses none that a Sync returned for. The change from the earlier rule, that a call is durable only when the Head advanced in the store, is deliberate and is for coding and development workloads; a policy that has fsync return after the Head commits (remote durability) needs a Sync that asks for a Flush, and no other change.
Backpressure and the state. A change that finds the journal three quarters full is slowed; one that finds it full, or memory full while the store is not taking publications, is refused with ErrFull (the mount answers ENOSPC) and changes nothing. When the journal fails the Volume takes no more changes (ErrJournal, EROFS). State reports whether the bound can be trusted: Degraded, the age of the oldest change the store lacks, and the bytes of journal behind it. The writes the kernel itself holds back from the daemon are the caller's to fsync, as on any file system; the bound runs from a change's entry into the journal.
Interrupts on the mount. A signal that reaches a caller while it waits on the mount (Go's runtime sends one every few milliseconds) makes the kernel interrupt the request, and no request is answered EINTR: every call waits and returns its own result. Callers do not restart it: SQLite reports an fsync answered EINTR as an I/O error, a stat answered EINTR is an error to a C caller whether or not it set SA_RESTART, a read answered EINTR reaches its caller as EIO, close is never restarted, and a restarted create(2) with O_EXCL would meet its own file. Nothing a caller's interrupt does cancels a journal sync or a fetch. The cost is that a call waits as long as the store takes when it needs it (a read of a chunk not held, a lookup of a shard not held): store requests have no deadline yet (docs/SPECIFICATION.md, section 11.2).
What a failed Flush tells the caller. nil: published. Any other error: the outcome of that attempt is unknown to the caller (a reply can be lost after the write landed; the publisher reads the Head back and, if its own generation is in it, says nil), and the changes stay in memory and in the journal for the next attempt. ErrStaleRound: this Volume was fenced and can never publish again; changes it had not published will never land, but a commit whose acknowledgement was lost may already be in the successor's tree, and Flush reports nil when the store's Head is exactly this Volume's tree.
The crash matrix the tests cover (a process killed by SIGKILL, or a call made to fail, at each point of a publication, then the store read from another process, and the Volume attached again on the same journal):
point test before the first pack upload TestSigkill/pack after the first pack upload TestSigkill/packed before the first shard upload TestSigkill/shard after the first shard upload TestSigkill/sharded before the Head write TestSigkill/head after the Head write TestSigkill/landed each write of a publication failing TestFailureAtEveryWrite Head landed, reply lost, then retry TestLostAcknowledgementOfHead, TestLostAckNoLostUpdateNoDuplicate Head landed, reply lost, takeover TestLostAckThenTakeoverIsNotReportedLost process ends with an unpublished tail TestProcessCrashReplays, TestFUSEFsyncSurvivesKill replay interrupted, replayed again TestReplayTwice takeover on another node TestTakeoverOnAnotherNodeSaysWhatItCannotKnow takeover during a publication TestTakeoverDuringPublication concurrent writes, Flushes, syncs TestGenerationOrdering the bound, with a clock the test moves TestBoundIsKeptFromEachAcknowledgement the store down, journal full TestBackpressureAndRecovery, TestMemoryBoundWaitsThenRefuses a request held for 2 s TestStalledCommitStallsNobody kill at a random moment, real server TestKillOverRealServer
In every row, a fresh view of the store is the last published generation, whole.
Fence ¶
Attach claims the Volume at a Round, a number that only grows. The claim is a conditional write of the Head that also carries forward the previous owner's last committed Head, so no acknowledged commit is lost, and from then on a commit by any older Round is refused with ErrStaleRound. A claim whose write landed but whose reply was lost is recognised as the claimant's own. Round 2^64-1 is refused, since no Round could follow it.
The store is trusted to return the Head it holds. A store that returns an older Head it once held cannot be told from the current one by this library: a caller that must notice a rollback keeps the Seq of the last Head it saw and compares.
Keys ¶
Every object goes through a Cipher (cipher.go); the library never reads a key from a file or the environment and never stores one.
Index ¶
- Constants
- Variables
- func Create(ctx context.Context, cfg Config) error
- func Reseal(ctx context.Context, cfg Config, from string) error
- type Budget
- type Change
- type Cipher
- type Config
- type DirEntry
- type File
- func (h *File) Close() error
- func (h *File) Punch(ctx context.Context, off, n uint64) error
- func (h *File) ReadAt(ctx context.Context, p []byte, off int64) (int, error)
- func (h *File) Stat(ctx context.Context) (Inode, error)
- func (h *File) Sync(ctx context.Context) error
- func (h *File) Truncate(ctx context.Context, size uint64) error
- func (h *File) WriteAt(ctx context.Context, p []byte, off int64) (int, error)
- type Head
- type Inode
- type InodeID
- type Option
- type Provider
- type Recovery
- type RenameFlags
- type State
- type Stats
- type Usage
- type Volume
- func (v *Volume) Check(ctx context.Context) error
- func (v *Volume) Close() error
- func (v *Volume) Create(ctx context.Context, dir InodeID, name string, perm fs.FileMode, ...) (Inode, error)
- func (v *Volume) ExtKey(name string, key []byte) (string, error)
- func (v *Volume) Flush(ctx context.Context) error
- func (v *Volume) GetExt(ctx context.Context, name string, key []byte) ([]byte, error)
- func (v *Volume) Link(ctx context.Context, ino, dir InodeID, name string) (Inode, error)
- func (v *Volume) Lookup(ctx context.Context, dir InodeID, name string) (Inode, error)
- func (v *Volume) Mkdir(ctx context.Context, dir InodeID, name string, perm fs.FileMode, ...) (Inode, error)
- func (v *Volume) Mknod(ctx context.Context, dir InodeID, name string, mode fs.FileMode, ...) (Inode, error)
- func (v *Volume) Now() time.Time
- func (v *Volume) Open(ctx context.Context, ino InodeID) (*File, error)
- func (v *Volume) Parent(ctx context.Context, dir InodeID) (InodeID, error)
- func (v *Volume) PutExt(ctx context.Context, name string, key, data []byte) error
- func (v *Volume) ReadDir(ctx context.Context, dir InodeID) ([]DirEntry, error)
- func (v *Volume) Readlink(ctx context.Context, ino InodeID) (string, error)
- func (v *Volume) Recovery() Recovery
- func (v *Volume) Remove(ctx context.Context, dir InodeID, name string) error
- func (v *Volume) Rename(ctx context.Context, oldDir InodeID, oldName string, newDir InodeID, ...) error
- func (v *Volume) Resolve(ctx context.Context, p string) (Inode, error)
- func (v *Volume) SetAttr(ctx context.Context, ino InodeID, c Change) (Inode, error)
- func (v *Volume) Stat(ctx context.Context, ino InodeID) (Inode, error)
- func (v *Volume) State() State
- func (v *Volume) Stats() Stats
- func (v *Volume) Symlink(ctx context.Context, dir InodeID, name, target string, opts ...Option) (Inode, error)
- func (v *Volume) Sync(ctx context.Context) error
- func (v *Volume) SyncInode(ctx context.Context, ino InodeID) error
- func (v *Volume) Truncate(ctx context.Context, ino InodeID, size uint64) error
- func (v *Volume) Usage() Usage
Constants ¶
const MaxSize = 1 << 62
MaxSize is the largest a file can be: 4 EiB, far past anything a store holds, chosen so offsets and lengths never overflow a signed 64-bit integer. A file may be declared much larger than the bytes written to it. What it costs follows the runs of bytes written, not its size: a hole has no chunks, no records and no memory.
Variables ¶
var ( // ErrUnknownKey is returned by Open when an object was sealed under a key the // Cipher does not hold: the wrong Volume key, or a retired key already dropped. ErrUnknownKey = errors.New("vfs: object is sealed under a key this cipher does not hold") // ErrBadCipher is returned when a Cipher fails the check made when a Volume is // configured. ErrBadCipher = errors.New("vfs: cipher does not seal") )
var ( // ErrNameTooLong is returned for a name of more than 255 bytes and for a symbolic // link target of more than 4095. It also satisfies errors.Is(err, fs.ErrInvalid). ErrNameTooLong = errors.New("vfs: name too long") // ErrNoSpace is returned by a write that would take the Volume past Config.Capacity. ErrNoSpace = errors.New("vfs: no space left on the Volume") // ErrTooManyLinks is returned by Link for an inode that has maxLinks names. ErrTooManyLinks = errors.New("vfs: too many links") )
var ( // ErrStaleRound is returned when the Round does not hold the Volume: a commit by // a Round below the recorded one (this writer was fenced, and changes it had not // committed will never land), or an Attach at a Round that does not exceed the // recorded one. A commit whose acknowledgement was lost may nevertheless be in // the successor's tree; see the package documentation. ErrStaleRound = fence.ErrStaleRound // ErrTooBig is returned for a file larger than MaxSize. ErrTooBig = errors.New("vfs: file too large") // ErrReadOnly is returned by a write on a Volume that was Opened, not Attached. ErrReadOnly = errors.New("vfs: volume is read-only") // ErrFull is returned by a change that cannot be accepted now: the node's journal is // full of changes the store does not have yet, or memory is, and the store is not taking // them. Nothing was changed. The mount answers it ENOSPC. The journal's own error is the // same value, so a caller tests for one. ErrFull = journal.ErrFull // ErrJournal is returned by every change after the node's journal has failed: no later // change can be made durable, so the Volume writes no more (the mount answers EROFS). // What was acknowledged before is on the disk, and in the store once published. ErrJournal = errors.New("vfs: the journal failed: the volume takes no more changes") // ErrClosed is returned by a change or a Flush of a Volume that was closed. ErrClosed = errors.New("vfs: volume is closed") ErrNotDir = errors.New("vfs: not a directory") ErrIsDir = errors.New("vfs: is a directory") ErrNotEmpty = errors.New("vfs: directory not empty") )
var ErrCorrupt = errors.New("vfs: object is corrupt")
ErrCorrupt is returned when an object fails to authenticate, hash to its name, or decode: it was damaged, swapped or forged. A Volume never guesses past it.
var ErrNeeds = errors.New("vfs: the Volume needs a feature this build does not have")
ErrNeeds is returned for a Volume whose Head announces a feature this build does not have. Nothing was read or changed.
Functions ¶
func Create ¶ added in v0.7.0
Create makes an empty Volume at the Backend's prefix: a tree holding the root directory, and a Head naming it, written only if no Head exists. It returns an error wrapping fs.ErrExist if the prefix already holds a Volume.
func Reseal ¶ added in v0.7.0
Reseal rewrites the Head of the Volume at cfg.Backend so that it is sealed to that place, and claims the Volume there at cfg.Round, which must exceed the recorded Round and be above 0 and below 2^64-1. A Head is bound to its place, and every other object to the Volume, so moving a Volume to another bucket or prefix is: copy every object, then Reseal. It fences the copy only; a writer still attached at the old place is not told, so stop it first (a writer that commits without pause can also make Reseal lose the race for the Head, which is then retried at a higher Round).
from is the place the Head is sealed to now: the String of the Backend it was last written through. If the Head is already sealed to cfg.Backend, a Reseal whose reply was lost for instance, it is left as it is and only the Round is claimed, so a Reseal can always be repeated at a higher Round.
from may be empty when the old place is not remembered. The Head is then opened with the key alone, whatever place it was sealed to. That trusts the key (only a holder can have written a Head that opens) and that the Head at cfg.Backend is the newest Head of the Volume the caller means: it cannot tell a Head from before the newest commit from the newest, as no one can without the place.
However the Head was opened, the copy is checked before anything is written: the root shard the Head names must open at cfg.Backend sealed to the Volume the Head names and hold the root directory, which refuses a copy that lacks its objects, a Head of another Volume, and an object of another kind that a store writer put where the Head goes. cfg.Verify reads every shard the Head reaches and checks that every pack a chunk is in is there and long enough; chunks are checked when a file is read.
Types ¶
type Budget ¶ added in v0.7.0
type Budget struct {
// contains filtered or unexported fields
}
Budget bounds the memory a process holds for changes the store does not have yet: the writes of every Volume that was given it, and the packs on their way to the store. A node runs many Volumes, and a limit on each multiplies into a limit on none; with one Budget in Config the sum is bounded. A change that finds the Budget full waits for a publication of any Volume to free memory, and is refused (ErrFull) when its own Volume's publication is failing. Memory is counted when a change is applied and when a pack is made. What the Budget admits stops at it, plus one change of each Volume that held nothing (such a Volume is always let in); a pack is made from changes already counted, lives beside them until the store has it, and is made only when the Budget is not spent or the Volume has no other on its way, so the memory held is at most twice the Budget and one change per Volume.
type Change ¶ added in v0.7.0
type Change struct {
Mode *fs.FileMode // the permission, setuid, setgid and sticky bits; the type does not change
UID *uint32
GID *uint32
Size *uint64 // a regular file only
Atime *time.Time
Mtime *time.Time
}
Change is a set of attribute changes: a nil field is left as it is.
type Cipher ¶ added in v0.7.0
type Cipher interface {
Seal(plaintext []byte) (sealed []byte, keyID string, err error)
Open(sealed []byte, keyID string) (plaintext []byte, err error)
}
Cipher seals and opens every object a Volume writes: chunks, metadata shards and the Head. It is the only door to key material: a Volume is handed a Cipher and never reads a key from a file or the environment, never stores one, and never sees the key itself.
Seal must authenticate as well as encrypt (a tampered object must fail Open) and returns the id of the key it used. The Volume writes that id next to the sealed bytes, and hands it back to Open, so a Cipher that holds several keys can keep reading old objects while it seals new ones under the current key: that is rotation, with no bulk re-encryption.
A Volume checks its Cipher when it is configured: a Cipher whose output contains its input, that does not open what it sealed, or that opens bytes that were altered, is refused.
Implementations must be safe for concurrent use.
func Hybrid ¶ added in v0.7.0
func Hybrid(current *age.HybridIdentity, retired ...*age.HybridIdentity) Cipher
Hybrid returns the default Cipher. New objects are sealed to current; objects sealed to any of retired still open. Each key is an independent identity, so a Volume's key is per Volume by construction: nothing is shared across Volumes, and dedupe never crosses one.
type Config ¶
type Config struct {
Backend backend.Backend // the Volume's prefix; the Volume owns it and Close closes it
Cipher Cipher // seals and opens every object
Round uint64 // Attach, Reseal: the Round to claim; must exceed the recorded one, and be above 0
Verify bool // Reseal: read every shard the Head reaches and check every pack it needs is there, not only the root
Capacity int64 // bytes the Volume may hold: a write past it is refused with ErrNoSpace; 0 for no limit
Cache int64 // bytes of shards and chunks kept decoded; default 256 MiB
Dirty int64 // bytes of changes held in memory that the store does not have yet; past it a change waits for a publication; default 1 GiB
Overlay int // metadata changes held in memory that the store does not have yet, with the same effect; default 262144
// Journal is a directory on this node's disk where Attach keeps the Volume's journal:
// every change is appended to it before it is applied, so a call that returns from
// Sync survives the process and the machine, and the store has the change within Bound.
// It must not be on memory (the journal refuses it), and is required to Attach.
Journal string
// JournalCapacity is the most disk the journal uses, in bytes; default 4 GiB. When the
// changes the store has not taken fill it, a change is refused with ErrFull; from three
// quarters full a change is slowed.
JournalCapacity int64
// Bound is how long a change may wait to be published while the store answers;
// default 5 s. The clock starts at the change's own acknowledgement and no later
// change moves it. When the store does not answer it cannot be kept, and State says so.
Bound time.Duration
// Clock supplies the times of changes and the timers of the bound: nil is the wall clock.
Clock journal.Clock
// Disk makes the journal's file layer for a directory: nil is the operating system's files. A
// caller wraps journal.Files to observe, count or hold what the journal does to its files.
Disk func(dir string) (journal.Disk, error)
// Budget bounds, across every Volume that is given it, the memory held for changes the store
// does not have yet. Nil: each Volume is bounded by Dirty alone.
Budget *Budget
Workers int // chunks, hashes and seals in parallel; default the number of CPUs, at most 16
Streams int // objects written to the store in parallel; default 8
}
Config says where a Volume is, how it is sealed, and how much memory and disk it may use.
type DirEntry ¶ added in v0.7.0
DirEntry is one name in a directory. Mode carries the type bits only; Stat the child for permissions and size.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is an open file. Its methods are safe for concurrent use.
func (*File) Close ¶
Close releases the handle. It makes no request and changes nothing but the count of holders: what the handle wrote is in the Volume's memory and journal whether it is closed or not. The last handle of a file that was unlinked takes the file with it.
func (*File) Punch ¶ added in v0.7.0
Punch deallocates [off, off+n) of the file: those bytes read as zero from now on, the size is unchanged, and once settled the range costs no chunk, record or object. A range past the end of the file is clipped to it.
func (*File) ReadAt ¶
ReadAt reads up to len(p) bytes at off. Like io.ReaderAt it returns io.EOF with the bytes it has when the file ends inside the range.
func (*File) Sync ¶
Sync makes every change the file depends on durable in this node's journal. It does not ask the store for anything: the store has the change within the Volume's bound, or when Flush returns.
func (*File) Truncate ¶
Truncate sets the file's length. Shrinking discards the bytes past it for good; growing adds zeros.
type Head ¶ added in v0.7.0
type Head struct {
// Seq numbers commit attempts, strictly increasing. It names a state: no two
// Heads a Volume writes share one. It can skip, since an attempt whose reply
// was lost may or may not have landed, and the next attempt takes the next
// number either way.
Seq uint64
Root ref // root of the metadata tree
Next uint64 // next inode number to assign
// ID names the Volume. Every shard and chunk is sealed to it, so an object
// copied in from another Volume does not open. Seed draws the Volume's
// chunking table, which is why chunk lengths are not comparable across Volumes.
ID volumeID
Seed [32]byte
// Journal is the highest sequence of the node journal (docs/journal.md) whose
// effects this Head includes: what the store holds of it. 0 when there is none.
Journal uint64
// Needs is a set of feature bits a reader must know to read the Volume at all. A
// build refuses a Head with a bit it does not know (ErrNeeds), so a change that
// every writer must honour, or every collector, is announced by a bit and never
// reaches a build that would break it. Bit 2 (links) is the one defined.
Needs uint64
// Tail is what follows Needs: fields that later builds append, each [tag][length]
// [value] with tags strictly increasing (SPECIFICATION 5.1). This build understands
// none, skips every one and writes them back unchanged.
Tail string
}
Head names the committed state of a Volume: the root of its metadata tree, the next inode number, and the Volume's identity. It is small and is replaced by one conditional write, the commit: the tree it names is exactly what the Volume was at that instant, so a crash before the write leaves the previous Head, and so the previous tree, intact. The Round that owns the Volume rides in the fence header around the sealed Head, where the store's conditional write can enforce it.
type Inode ¶
type Inode struct {
ID InodeID
Mode fs.FileMode // type, permission, setuid, setgid and sticky bits
Size uint64 // bytes, exact
Mtime time.Time
Atime time.Time
Ctime time.Time
// UID and GID own the inode. An inode with no owner record belongs to whoever runs
// the mount, which a Volume does not know: both read as zero then, and Owned says so.
UID, GID uint32
Owned bool
// Nlink is the number of names the inode has: for a directory 2 and one more for each
// subdirectory, for anything else the directory entries that name it. It is 0 for an
// inode that was unlinked while a handle still held it. A directory's is computed
// when it is asked for (Stat, Lookup); it is not stored.
Nlink uint32
// Parent is the directory that names a directory, 0 for the root and for anything
// that is not a directory.
Parent InodeID
// contains filtered or unexported fields
}
Inode is the attributes of a file or directory.
type InodeID ¶
type InodeID uint64
InodeID names a file or directory in a Volume. IDs are assigned in increasing order and never reused within a Volume.
const RootInode InodeID = 1
RootInode is the root directory of every Volume.
type Provider ¶ added in v0.7.0
Provider yields the Cipher for a Volume, from wherever the caller keeps keys: a key service, or the command line's standard input.
type Recovery ¶ added in v0.7.0
type Recovery struct {
// Replayed is how many changes were read back from this node's journal, applied and
// published.
Replayed uint64
// Lost is true when changes the previous owner acknowledged and did not publish may be
// missing: there is no journal of that Round on this node, or there is and it could not
// be used. The Volume is what the last Head says; Why says which.
Lost bool
Why string
// Report is what the journal's own recovery kept and gave up. Dropped lists records
// that were intact and had to be given up; Warnings name risks of the disk.
Report journal.Report
}
Recovery is what Attach found of the journal of the Round that owned the Volume before.
type RenameFlags ¶ added in v0.7.0
type RenameFlags uint32
RenameFlags are the flags of renameat2(2) that a Volume honours.
const ( // RenameNoReplace refuses a rename whose new name exists (fs.ErrExist). RenameNoReplace RenameFlags = 1 << 0 // RenameExchange swaps two names that both exist; neither is removed. RenameExchange RenameFlags = 1 << 1 )
type State ¶ added in v0.7.0
type State struct {
// Degraded is true when the promise cannot be trusted: the oldest change the store
// does not have is older than the bound, the journal is slowing changes because it is
// nearly full, or it has failed.
Degraded bool
// Age is how long the oldest change the store does not have has been acknowledged.
Age time.Duration
// Backlog is the bytes of journal that the store does not have.
Backlog int64
// Err is why the journal stopped, if it did.
Err error
// Publishing is why the publisher's last attempt failed, until one succeeds.
Publishing error
// Visible, Durable and Published are the journal's three watermarks: the last change
// applied, the last made durable on this node, and the last the store holds.
Visible, Durable, Published uint64
}
State is what an operator or an agent reads to learn whether the Volume's promise, that the store has every change within Bound, can be trusted. It is the journal's state.
type Stats ¶
type Stats struct {
Backend string
Round uint64 // 0 when read-only
Seq uint64 // the Seq of the committed Head: it counts commit attempts and can skip, so it is not a count of commits
Inodes uint64 // inode numbers handed out
CacheBytes int64
CacheMax int64
Pending int // metadata changes the store does not have yet
Dirty int64
}
Stats is a snapshot of a Volume for observability.
type Usage ¶ added in v0.7.0
type Usage struct {
Files uint64 // inodes: files, directories, symbolic links, pipes and sockets
Bytes uint64 // bytes stored for files and symbolic links; a hole costs none
Pending uint64 // bytes written and not yet stored: an upper bound, an overwrite counts again
Capacity int64 // Config.Capacity: 0 for none
}
Usage is what a Volume holds, as its Head says it (SPECIFICATION 5.1, the usage field) and as the changes since have moved it.
type Volume ¶ added in v0.7.0
type Volume struct {
// contains filtered or unexported fields
}
Volume is a mounted filesystem. All methods are safe for concurrent use. A Volume that was Attached may write; one that was Opened may only read.
What a Volume does, in order, with a change: it is built from what the Volume holds in memory, sealed, appended to the node's journal, and applied; the call returns. The journal's sync, which a caller asks for with Sync, makes it durable on this node. A publisher, a goroutine of the Volume, takes what has been applied up to a point (a generation), turns it into chunks, packs and shards, writes them to the store in parallel, and commits the Head that names them and carries the journal's sequence; and it does so within Bound of the oldest change it holds. No call waits for it, except Flush, which asks for a publication and returns when the Head has it; and no call holds the Volume's lock across a request to the store or a call to the journal.
func Attach ¶ added in v0.7.0
Attach claims the Volume at cfg.Round and returns it ready to write. The claim is refused with ErrStaleRound unless cfg.Round exceeds the Round recorded; it seals the predecessor's last committed Head at the new Round, atomically, and opens the Volume at that Head, so nothing the predecessor committed is lost and nothing it tries to commit afterwards lands.
What the predecessor acknowledged and did not commit is another matter. If it ran on this node and left its journal here, Attach replays the journal, publishes what it held under the new Round, and goes on. If it did not (another node took over, or the disk was lost), that tail is not here and nothing can say how much there was: Recovery reports Lost, and the Volume is what the last Head says. The same is reported when the journal is here and cannot be used (it belongs to another history, or is damaged), and the files are left as they are for an operator.
After any error from Attach other than a refusal for a Round that is too low, the claim may or may not have landed (a reply can be lost). A caller that retries MUST use a higher Round: a retry at the same Round is told ErrStaleRound, since the Round is by then recorded, and only a claim whose own retry finds its own bytes within one call is recognised as landed.
func Open ¶ added in v0.7.0
Open returns a read-only Volume at the committed Head. It claims nothing and fences no one.
func (*Volume) Check ¶ added in v0.7.0
Check reads the whole namespace of the Volume as it is now, changes not yet committed included, and returns the first way in which it is not a namespace: a directory entry that names no inode, or one of another type; an inode that no entry names, or that a directory names twice; a link count that is not the number of names; a directory whose parent is not the directory that names it; data that belongs to no inode; or counters, in the Head's usage and links fields, that are not what the tree holds. It is for tests and for a tool run on a Volume that nothing writes: it reads every record.
func (*Volume) Close ¶ added in v0.7.0
Close stops the publisher and closes the journal and the backend. It does not publish: what was changed and not flushed stays in the journal on this node, and the next Attach of the Volume on it publishes that (a Volume that must hand over what it has calls Flush first). A journal with nothing left in it is removed.
func (*Volume) Create ¶ added in v0.7.0
func (v *Volume) Create(ctx context.Context, dir InodeID, name string, perm fs.FileMode, opts ...Option) (Inode, error)
Create creates an empty regular file in dir.
func (*Volume) ExtKey ¶ added in v0.7.0
ExtKey is where the object that the extension name keeps under key is in the store, from the prefix of the Volume: ext/<name>/<64 hex digits>, the digits of a hash keyed from the Volume's Seed, so it is not the name of the same key in another Volume.
func (*Volume) Flush ¶ added in v0.7.0
Flush makes everything changed before the call durable in the store: it returns after a Head that carries it has been committed. If it returns an error the outcome of the attempt it asked for is unknown to the caller (a reply can be lost after the write landed), the changes are still held and still in the journal, and the next publication, the Volume's own or a Flush, makes the next attempt. ErrStaleRound means this Volume was fenced and can never commit again; see the package documentation for what that does and does not say about earlier attempts.
func (*Volume) GetExt ¶ added in v0.7.0
GetExt returns what the extension name stored under key. The error wraps fs.ErrNotExist when nothing is stored there, and ErrCorrupt when the object does not open as this Volume's.
func (*Volume) Link ¶ added in v0.7.0
Link names the inode ino a second time, as name in dir. A directory cannot be linked (fs.ErrPermission). The first hard link a Volume has makes the commit that holds it announce link counts in the Head, and every commit after (SPECIFICATION 5.1).
func (*Volume) Mkdir ¶ added in v0.7.0
func (v *Volume) Mkdir(ctx context.Context, dir InodeID, name string, perm fs.FileMode, opts ...Option) (Inode, error)
Mkdir creates a directory in dir.
func (*Volume) Mknod ¶ added in v0.7.0
func (v *Volume) Mknod(ctx context.Context, dir InodeID, name string, mode fs.FileMode, opts ...Option) (Inode, error)
Mknod creates a regular file, a named pipe or a socket in dir: mode names the type (none, fs.ModeNamedPipe or fs.ModeSocket) and the permissions. A device cannot be made on a Volume (fs.ErrPermission).
func (*Volume) Now ¶ added in v0.7.0
Now is the time every change is stamped with: Config.Clock, or the time of day.
func (*Volume) Open ¶ added in v0.7.0
Open opens a regular file for reading and writing. Writes are visible to every handle at once; they are durable in this node's journal after Sync, and in the store when the Volume's generation that holds them is published (Flush).
func (*Volume) Parent ¶ added in v0.7.0
Parent returns the directory that names the directory dir; the root is its own parent.
func (*Volume) PutExt ¶ added in v0.7.0
PutExt stores data under key for the extension name: it creates the object, or replaces what is there, whole, so a reader finds the old object or the new. A Volume that was only Opened cannot; one that was fenced out can, since the Round orders the commits of the tree and not these. data is at most 32 MiB.
func (*Volume) Remove ¶ added in v0.7.0
Remove deletes a file or an empty directory from dir. A file with other names keeps them. A file that a handle still holds open stays readable and writable through that handle, and is gone for everyone else; its bytes go when the last handle closes.
func (*Volume) Rename ¶ added in v0.7.0
func (v *Volume) Rename(ctx context.Context, oldDir InodeID, oldName string, newDir InodeID, newName string, flags RenameFlags) error
Rename gives the inode named oldName in oldDir the name newName in newDir, in one atomic step: a crash leaves the old state or the new one, never both names, never neither.
A new name that exists is replaced when both are directories (the new one must be empty) or neither is. Two names of the same inode are left as they are and Rename succeeds. A directory cannot move into itself or below itself (fs.ErrInvalid). The directories that gain and lose an entry take the time as their modification and change times, and so does the inode that moved.
func (*Volume) SetAttr ¶ added in v0.7.0
SetAttr changes the attributes of an inode and returns it as it is after. The change time becomes now whatever changed, as POSIX has it. An owner is a pair: an inode that has none takes both a user and a group, which a caller that knows only one fills in with the one the inode appears to have.
A Volume checks no permission: who may change what is the mount's to decide, and the kernel decides it for a mount made with default_permissions.
func (*Volume) State ¶ added in v0.7.0
State returns the state of the Volume's journal. A Volume that was only opened has none.
func (*Volume) Symlink ¶ added in v0.7.0
func (v *Volume) Symlink(ctx context.Context, dir InodeID, name, target string, opts ...Option) (Inode, error)
Symlink creates a symbolic link in dir that holds target. The target is bytes that the Volume never interprets.
func (*Volume) Sync ¶ added in v0.7.0
Sync makes every change made before the call durable in this node's journal: it survives a crash of the process and of the machine. The store has them within Bound, or when Flush returns; a node lost for good loses what the store has not taken.
func (*Volume) SyncInode ¶ added in v0.7.0
SyncInode makes every change the file with inode ino depends on durable in this node's journal, as File.Sync does for a handle: for a directory, or a file nobody holds open, everything changed before the call.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
vfs
command
Command vfs creates, fills, reads and mounts a Volume.
|
Command vfs creates, fills, reads and mounts a Volume. |
|
vfs-cost
command
vfs-cost — print backend cost comparison for a workload.
|
vfs-cost — print backend cost comparison for a workload. |
|
internal
|
|
|
blake3
Package blake3 is the BLAKE3 hash function with SIMD kernels.
|
Package blake3 is the BLAKE3 hash function with SIMD kernels. |
|
bufpool
Package bufpool recycles the large byte slices of a write pipeline: the plaintext of a chunk, the sealed frame, the pack that is uploaded.
|
Package bufpool recycles the large byte slices of a write pipeline: the plaintext of a chunk, the sealed frame, the pack that is uploaded. |
|
storetest
Package storetest holds the test doubles and the conformance suite for backend.Backend: an in-memory store with S3's conditional-write semantics and counters, an S3 protocol server for the real S3 backend to talk to, and the suite every backend must pass.
|
Package storetest holds the test doubles and the conformance suite for backend.Backend: an in-memory store with S3's conditional-write semantics and counters, an S3 protocol server for the real S3 backend to talk to, and the suite every backend must pass. |
|
Package journal is an append-only log on local disk that makes a write acknowledgement and an fsync run at the speed of the local NVMe, while a slower publisher (the object store) catches up behind it.
|
Package journal is an append-only log on local disk that makes a write acknowledgement and an fsync run at the speed of the local NVMe, while a slower publisher (the object store) catches up behind it. |
|
bench
command
Command bench measures the journal against plain files on the same disk.
|
Command bench measures the journal against plain files on the same disk. |
|
crash
Package crash is a journal.Disk in memory that logs every persistence point and can rebuild the disk a crash would have left behind after any prefix of that log.
|
Package crash is a journal.Disk in memory that logs every persistence point and can rebuild the disk a crash would have left behind after any prefix of that log. |
|
pkg
|
|
|
backend
Package backend defines the object-store interface that a Volume stores its sealed objects in.
|
Package backend defines the object-store interface that a Volume stores its sealed objects in. |
|
backend/file
Package file is a filesystem-backed Backend for local dev and tests.
|
Package file is a filesystem-backed Backend for local dev and tests. |
|
backend/s3
Package s3 is an S3 Backend on Hanzo S3.
|
Package s3 is an S3 Backend on Hanzo S3. |
|
cost
Package cost computes operational cost for VFS workloads across the pluggable backends VFS supports.
|
Package cost computes operational cost for VFS workloads across the pluggable backends VFS supports. |
|
fence
Package fence turns the unconditional Put of an object store, whose contract is literally "overwriting is allowed", into a round-fenced write, so a deposed or partitioned writer can no longer clobber a newer owner's object.
|
Package fence turns the unconditional Put of an object store, whose contract is literally "overwriting is allowed", into a round-fenced write, so a deposed or partitioned writer can no longer clobber a newer owner's object. |
|
mount
Package mount serves a *vfs.Volume to the kernel over FUSE.
|
Package mount serves a *vfs.Volume to the kernel over FUSE. |
|
Package replica is the ONE shared HA-SQLite substrate every Hanzo service uses (HIP-0107): per-org SQLite on the local disk for speed, its durable copy in hanzoai/vfs (SeaweedFS-backed object store), a deterministic single-writer election (Rendezvous/HRW over IAM membership — no coordinator, no lock service, no Postgres, no Redis), and per-org at-rest encryption via KMS.
|
Package replica is the ONE shared HA-SQLite substrate every Hanzo service uses (HIP-0107): per-org SQLite on the local disk for speed, its durable copy in hanzoai/vfs (SeaweedFS-backed object store), a deterministic single-writer election (Rendezvous/HRW over IAM membership — no coordinator, no lock service, no Postgres, no Redis), and per-org at-rest encryption via KMS. |
|
tools
|
|
|
fusemount
command
Command fusemount stands in for fusermount3 where there is no setuid helper to mount with.
|
Command fusemount stands in for fusermount3 where there is no setuid helper to mount with. |
|
gitbench
command
Command gitbench measures git the way a coding run uses it: a shallow partial clone, a branch switch that touches thousands of files, status, add, commit, maintenance and a push, repeated, with the wall time, CPU and the system calls that matter to a disk that charges per call.
|
Command gitbench measures git the way a coding run uses it: a shallow partial clone, a branch switch that touches thousands of files, status, add, commit, maintenance and a push, repeated, with the wall time, CPU and the system calls that matter to a disk that charges per call. |
|
iotrace
command
iotrace records the file accesses of a command and measures whether a prefetcher could have predicted them.
|
iotrace records the file accesses of a command and measures whether a prefetcher could have predicted them. |
|
mutate
command
Command mutate checks that the tests catch what they claim to.
|
Command mutate checks that the tests catch what they claim to. |