Documentation
¶
Overview ¶
Package upperstore holds the durable state of the upper of the macOS merged file system: a redo log of records plus immutable version files. It reaches the disk only through Disk.
Index ¶
- Constants
- Variables
- func Pending(i int) uint64
- type Attr
- type AttrUpdate
- type Base
- type Blob
- type CrashMode
- type DirEntry
- type Disk
- type Entry
- type FakeDisk
- func (d *FakeDisk) Crash(mode CrashMode, seed int64)
- func (d *FakeDisk) CrashAt(n int, mode CrashMode, seed int64)
- func (d *FakeDisk) Create(path string) (File, error)
- func (d *FakeDisk) FailOpen(match string, err error)
- func (d *FakeDisk) FailSyncDir(path string, err error)
- func (d *FakeDisk) Hits() []string
- func (d *FakeDisk) Hook(f func(name string))
- func (d *FakeDisk) Lock(path string) (io.Closer, error)
- func (d *FakeDisk) Mkdir(path string) error
- func (d *FakeDisk) MkdirAll(path string) error
- func (d *FakeDisk) Open(path string) (File, error)
- func (d *FakeDisk) OpenFiles() int
- func (d *FakeDisk) Point(name string) error
- func (d *FakeDisk) ReadDir(path string) ([]Entry, error)
- func (d *FakeDisk) Remove(path string) error
- func (d *FakeDisk) Rename(oldPath, newPath string) error
- func (d *FakeDisk) Restart()
- func (d *FakeDisk) SetFineTear(on bool)
- func (d *FakeDisk) SyncDir(path string) error
- type File
- type Kind
- type NewNode
- type OSDisk
- func (OSDisk) Create(path string) (File, error)
- func (OSDisk) Lock(path string) (io.Closer, error)
- func (OSDisk) Mkdir(path string) error
- func (OSDisk) MkdirAll(path string) error
- func (OSDisk) Open(path string) (File, error)
- func (OSDisk) Point(string) error
- func (OSDisk) ReadDir(path string) ([]Entry, error)
- func (OSDisk) Remove(path string) error
- func (OSDisk) Rename(oldPath, newPath string) error
- func (OSDisk) SyncDir(path string) error
- type Options
- type Record
- type Snapshot
- type Step
- type Store
- func (s *Store) Checkpoint() error
- func (s *Store) Close() error
- func (s *Store) Create(dir uint64, name string, nn NewNode) (uint64, error)
- func (s *Store) Flush() error
- func (s *Store) GetAttr(unode uint64) (Attr, error)
- func (s *Store) GetXattr(unode uint64, name string) ([]byte, bool, error)
- func (s *Store) Health() error
- func (s *Store) ListXattr(unode uint64) ([]string, error)
- func (s *Store) Lookup(dir uint64, name string) (DirEntry, error)
- func (s *Store) Pin(unode uint64) error
- func (s *Store) Read(unode uint64, off int64, n int) ([]byte, error)
- func (s *Store) ReadDir(dir uint64) ([]DirEntry, error)
- func (s *Store) Remove(dir uint64, name string, whiteout bool) error
- func (s *Store) RemoveXattr(unode uint64, name string) error
- func (s *Store) Rename(oldDir uint64, oldName string, newDir uint64, newName string, inBase bool) error
- func (s *Store) RenameBase(oldDir uint64, oldName string, nn NewNode, newDir uint64, newName string) error
- func (s *Store) Seq() uint64
- func (s *Store) SetAttr(unode uint64, u AttrUpdate) error
- func (s *Store) SetOpaque(dir uint64) error
- func (s *Store) SetXattr(unode uint64, name string, value []byte) error
- func (s *Store) Snapshot() *Snapshot
- func (s *Store) Token() string
- func (s *Store) Tx(plan []Step) *Tx
- func (s *Store) Unpin(unode uint64) error
- func (s *Store) Write(unode uint64, off int64, p []byte) error
- type Tx
- func (t *Tx) Create(dir uint64, name string, nn NewNode) (uint64, error)
- func (t *Tx) Remove(dir uint64, name string, whiteout bool) error
- func (t *Tx) RemoveXattr(unode uint64, name string) error
- func (t *Tx) Rename(oldDir uint64, oldName string, newDir uint64, newName string, inBase bool) error
- func (t *Tx) RenameBase(oldDir uint64, oldName string, nn NewNode, newDir uint64, newName string) error
- func (t *Tx) SetAttr(unode uint64, u AttrUpdate) error
- func (t *Tx) SetXattr(unode uint64, name string, value []byte) error
- func (t *Tx) Write(unode uint64, off int64, p []byte) error
- type Type
Constants ¶
const ( PointBeforeAppend = "before-append" PointAfterAppend = "after-append" PointBeforeVersionFsync = "before-version-fsync" PointAfterVersionFsync = "after-version-fsync" PointBeforeDirFsync = "before-dir-fsync" PointBeforeSegmentFsync = "before-segment-fsync" PointAfterSegmentFsync = "after-segment-fsync" PointAfterCapture = "after-capture" PointBeforeSnapshotRename = "before-snapshot-rename" PointAfterSnapshotRename = "after-snapshot-rename" PointBeforeSnapshotCheck = "before-snapshot-check" PointBeforeEncode = "before-encode" PointBeforeSwap = "before-swap" PointBeforeOldSnapshotDelete = "before-old-snapshot-delete" PointBeforeOldSegmentDelete = "before-old-segment-delete" PointBeforeVersionDelete = "before-version-delete" PointAfterCleanup = "after-cleanup" PointReadReferenced = "read-referenced" )
Names of the interruption points that the store passes to Disk.Point.
const (
// MaxFileSize is the largest file that the store holds, the limit of the shim.
MaxFileSize = 256 << 20
)
const (
// MaxWrite is the most bytes that one write record carries.
MaxWrite = 1 << 20
)
const RootUnode = 1
RootUnode is the unode of the root directory.
Variables ¶
var ( ErrDirGone = fmt.Errorf("upperstore: directory removed: %w", fs.ErrNotExist) ErrNotDir = errors.New("upperstore: not a directory") ErrNotFile = errors.New("upperstore: not a regular file") ErrNotEmpty = errors.New("upperstore: directory not empty") ErrInvalid = errors.New("upperstore: invalid argument") ErrTooBig = errors.New("upperstore: name, path or value too long") ErrCorrupt = errors.New("upperstore: the journal does not continue from the recovery state") )
var ErrClosed = errors.New("upperstore: store is closed")
var ErrCrashed = errors.New("upperstore: fake disk crashed")
ErrCrashed is the answer of every call of FakeDisk between a crash and Restart.
var ErrNoXattr = errors.New("upperstore: no such extended attribute")
ErrNoXattr is the answer for an extended attribute that the node lacks.
Functions ¶
Types ¶
type Attr ¶
type Attr struct {
Unode uint64
Kind Kind
Mode uint32
Size int64
Atime, Mtime int64
Ctime int64
// AtimeSet, MtimeSet and CtimeSet say that the store recorded the time. An unset time is the time of the base
// commit, and a recorded zero is the epoch.
AtimeSet, MtimeSet, CtimeSet bool
// FileID is the identity that the caller recorded when it made the node; zero when it recorded none.
FileID uint64
Origin string
Target string
Opaque bool
// Copied is true when the content is a version file of the store and not the base blob.
Copied bool
}
Attr is the state of a node. Origin names the base path whose blob is the content, or whose directory the node merges.
type AttrUpdate ¶
AttrUpdate lists the attributes that SetAttr changes. A change of Size to another value cuts or extends.
type CrashMode ¶
type CrashMode int
CrashMode says what a crash of FakeDisk keeps of the state that no flush made durable.
const ( // KeepAll is a kill of the process: the OS still holds every written byte and entry. KeepAll CrashMode = iota // DropUnflushed is a power loss that keeps only flushed state. DropUnflushed // RandomSubset is a power loss that also keeps a seeded random subset of the unflushed state. RandomSubset )
type Disk ¶
type Disk interface {
MkdirAll(path string) error
Mkdir(path string) error
// Create makes a new empty file and fails when the name exists.
Create(path string) (File, error)
Open(path string) (File, error)
Rename(oldPath, newPath string) error
Remove(path string) error
ReadDir(path string) ([]Entry, error)
// SyncDir makes the entries of a directory durable.
SyncDir(path string) error
// Lock takes an exclusive lock on a file that it creates, and fails when another holder has it.
Lock(path string) (io.Closer, error)
// Point names a place in the store where a fault can stop it. The real disk answers nil.
Point(name string) error
}
Disk is every call that the store makes to the file system. A missing name answers an error that matches fs.ErrNotExist, and an existing one fs.ErrExist.
type FakeDisk ¶
type FakeDisk struct {
// contains filtered or unexported fields
}
FakeDisk is an in-memory Disk. For each file and directory it keeps the state that a flush made durable apart from the live state, as F_FULLFSYNC does.
func NewFakeDisk ¶
func NewFakeDisk() *FakeDisk
NewFakeDisk returns an empty disk with a root directory.
func (*FakeDisk) CrashAt ¶
CrashAt arms a crash at the nth call of Point, or of the torn write inside a WriteAt, counted from the call.
func (*FakeDisk) FailOpen ¶
FailOpen makes Open fail with err for a path that contains match, until it is called with a nil err.
func (*FakeDisk) FailSyncDir ¶
FailSyncDir makes SyncDir fail with err for the path, until it is called with a nil err.
func (*FakeDisk) Hook ¶
Hook sets a function that Point calls, without the disk lock, after it counts a point that did not crash.
func (*FakeDisk) Restart ¶
func (d *FakeDisk) Restart()
Restart makes the disk usable after a crash. It frees the locks and invalidates every open file.
func (*FakeDisk) SetFineTear ¶
SetFineTear makes a WriteAt stop at more places: inside a record header, at each 512-byte sector of a small write, and one byte before its end. The default is the middle only.
type File ¶
type File interface {
io.ReaderAt
io.WriterAt
io.Closer
Truncate(size int64) error
Sync() error
Size() (int64, error)
}
File is an open file. Sync makes the data durable: F_FULLFSYNC on darwin, fsync elsewhere.
type NewNode ¶
type NewNode struct {
Kind Kind
Mode uint32
Origin, Target string
// Opaque makes a new directory hide the base entries below it, in the same operation as its create.
Opaque bool
// FromBase says that the node is a promotion of an entry of the base tree. It keeps the base time, and the
// store records none.
FromBase bool
// FileID is recorded with the node and read back by GetAttr.
FileID uint64
}
NewNode describes the node that Create makes.
type Options ¶
type Options struct {
Disk Disk
Dir string
Base Base
BaseCommit string
// Root is the state directory: Dir and every directory between Dir and Root are made durable at Open.
// The default is the parent of Dir.
Root string
// Boot names this daemon process; it is the first half of the token.
Boot string
Clock clock.Clock
// SegmentLimit is the size at which the next operation starts a new segment. The default is 64 MiB.
SegmentLimit int64
// CheckpointBytes and CheckpointRecords are the journal size and the record count above the recovery
// snapshot that start a background checkpoint. The defaults are 64 MiB and 200,000.
CheckpointBytes int64
CheckpointRecords int
}
Options configures Open. Disk, Dir, BaseCommit and Boot are required.
type Record ¶
type Record struct {
Seq uint64
More bool
Type Type
Payload []byte
// Time is the time of the operation in nanoseconds, or zero when the record carries none.
Time int64
}
Record is a decoded journal record.
type Snapshot ¶
type Snapshot struct {
Seq uint64
// contains filtered or unexported fields
}
Snapshot is a copy of the index at one sequence. A later operation does not change it, so a caller reads it without any lock.
type Step ¶
type Step struct {
Parent uint64
Name string
New NewNode
// Pin pins the node as the group applies it, for a caller that holds the node open.
Pin bool
}
Step makes one node of a plan under Parent: an upper directory, or Pending(i) for the node of an earlier step.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the upper store of one workspace.
func (*Store) Checkpoint ¶
Checkpoint compacts the journal: it writes a version file for each node that has extents at the current sequence, writes a snapshot of the index, and then deletes what the snapshot makes redundant. Only one checkpoint runs at a time; a call that arrives during one waits for it.
func (*Store) Close ¶
Close refuses new mutations, flushes, and only when the flush succeeds closes the files and releases the lock. A failed flush releases nothing and the store keeps refusing mutations; the failure is kept, so a later Close fails the same way. It leaves the data on disk.
func (*Store) GetXattr ¶
GetXattr returns the value of an extended attribute and whether the node has it.
func (*Store) Health ¶
Health returns the error of the last checkpoint, or nil when the last one succeeded.
func (*Store) Lookup ¶
Lookup answers ErrDirGone when dir is removed or unknown, and fs.ErrNotExist when only the name is missing.
func (*Store) Pin ¶
Pin keeps a node alive for a caller that holds it open. A pinned node that Remove or Rename detaches stays readable and writable until the last Unpin; nothing of it survives a restart.
func (*Store) Read ¶
Read returns up to n bytes of the logical content of a file at off: the version file or the base blob, the extents above it in order, the holes as zeros. It returns fewer bytes only at the end of the file. The read holds a reference on the files of its backing, so that a checkpoint does not delete them under it.
func (*Store) Remove ¶
Remove deletes an entry. With whiteout it also hides the entry of the base tree, and then the entry may be absent from the upper.
func (*Store) RemoveXattr ¶
RemoveXattr deletes an extended attribute. A value that is empty is a value, not a removal.
func (*Store) Rename ¶
func (s *Store) Rename(oldDir uint64, oldName string, newDir uint64, newName string, inBase bool) error
Rename moves an entry and replaces the target. When the old name is also in the base tree (inBase), the operation leaves a whiteout there, so the base entry does not show again.
func (*Store) RenameBase ¶
func (s *Store) RenameBase(oldDir uint64, oldName string, nn NewNode, newDir uint64, newName string) error
RenameBase moves an entry that only the base tree shows. In one operation it makes the entry in the upper at its old name (nn names the base path), moves it, replaces the target, and leaves a whiteout at the old name.
func (*Store) Seq ¶
Seq is the sequence of the last record. Token is the change token: the boot ID of this process and Seq.
func (*Store) SetAttr ¶
func (s *Store) SetAttr(unode uint64, u AttrUpdate) error
SetAttr changes attributes. A size change copies a base file up first, in the same operation.
type Tx ¶
type Tx struct {
// Unodes holds the unode of each step after the call succeeded.
Unodes []uint64
// contains filtered or unexported fields
}
Tx is a call with a plan: the steps make their nodes in the same operation group as the call, so a call that fails appends nothing, not even the steps.