Documentation
¶
Index ¶
- Constants
- Variables
- func CompactBoltFile(ctx context.Context, filename string) (previous string, err error)
- func CompactMetadata(ctx context.Context, options Options) (string, error)
- func EngineName(engine Engine) string
- func EnsureFormat(ctx context.Context, engine Engine, expected fsformat.Volume) (fsformat.Volume, error)
- func Import(ctx context.Context, image string, destination Options) error
- func NormalizeEngine(engine string) (string, error)
- func ReadFormat(ctx context.Context, engine Engine) (volume fsformat.Volume, found bool, err error)
- func RestoreBackup(ctx context.Context, objects backend.Backend, info BackupInfo, ...) (string, error)
- func RestoreBoltBackup(ctx context.Context, objects backend.Backend, info BackupInfo, ...) (string, error)
- func RewriteBoltReferences(ctx context.Context, filename string, fn func(chunk.Ref) (chunk.Ref, error)) error
- func StagedBoltReferences(ctx context.Context, filename string) ([]chunk.Ref, error)
- func ValidateTransferPaths(source, destination string) error
- type AsyncUpdater
- type BackupInfo
- type BackupOptions
- type BackupService
- type BackupStats
- type BackupStore
- type Barrier
- type BoltEngine
- func (e *BoltEngine) Barrier(ctx context.Context) error
- func (e *BoltEngine) Close() error
- func (*BoltEngine) Name() string
- func (e *BoltEngine) Snapshot(ctx context.Context, w io.Writer) error
- func (e *BoltEngine) Sync(ctx context.Context) error
- func (e *BoltEngine) Update(ctx context.Context, fn func(Tx) error) error
- func (e *BoltEngine) UpdateAsync(ctx context.Context, fn func(Tx) error) error
- func (e *BoltEngine) View(ctx context.Context, fn func(ReadTx) error) error
- type BoltInspection
- type BoltOptions
- type BucketReadTx
- type Compactor
- type Engine
- type EngineStore
- type Entry
- type FileChunkUpdate
- type ImageInfo
- type Kind
- type LogEngine
- func (e *LogEngine) Close() error
- func (e *LogEngine) Compact(ctx context.Context) error
- func (e *LogEngine) CompactAsync(ctx context.Context) <-chan error
- func (e *LogEngine) Sync(ctx context.Context) error
- func (e *LogEngine) Update(ctx context.Context, fn func(Tx) error) error
- func (e *LogEngine) View(ctx context.Context, fn func(ReadTx) error) error
- type LogOptions
- type MemoryEngine
- type Namespace
- func (n *Namespace) ClearChunks(ctx context.Context, inode uint64, first, count int) ([]chunk.Ref, error)
- func (n *Namespace) Create(ctx context.Context, parent uint64, name string, kind Kind, mode uint32, ...) (Entry, error)
- func (n *Namespace) Get(inode uint64) (Entry, error)
- func (n *Namespace) GetChunk(inode uint64, index int) (Entry, chunk.Ref, error)
- func (n *Namespace) List(parent uint64) ([]Entry, error)
- func (n *Namespace) Load(ctx context.Context) error
- func (n *Namespace) Lookup(parent uint64, name string) (Entry, error)
- func (n *Namespace) LookupAttr(parent uint64, name string) (Entry, error)
- func (n *Namespace) Modify(ctx context.Context, inode uint64, change func(*Entry) error) (Entry, error)
- func (n *Namespace) ReadDirPage(ctx context.Context, parent uint64, cursor string, limit int) ([]Entry, error)
- func (n *Namespace) Remove(ctx context.Context, inode uint64) error
- func (n *Namespace) Rename(ctx context.Context, inode, newParent uint64, newName string) error
- func (n *Namespace) RenameReplace(ctx context.Context, inode, newParent uint64, newName string) (Entry, error)
- func (n *Namespace) ReplaceChunk(ctx context.Context, inode uint64, index int, expected, replacement chunk.Ref) (bool, error)
- func (n *Namespace) Snapshot() Snapshot
- func (n *Namespace) Store() *EngineStore
- func (n *Namespace) Update(ctx context.Context, entry Entry) error
- func (n *Namespace) UpdateFileChunk(ctx context.Context, inode uint64, update FileChunkUpdate) ([]chunk.Ref, error)
- func (n *Namespace) VolumeID() string
- type Options
- type PebbleEngine
- func (e *PebbleEngine) Barrier(ctx context.Context) error
- func (e *PebbleEngine) Close() error
- func (e *PebbleEngine) Compact(ctx context.Context) error
- func (*PebbleEngine) Name() string
- func (e *PebbleEngine) Snapshot(ctx context.Context, w io.Writer) error
- func (e *PebbleEngine) Sync(ctx context.Context) error
- func (e *PebbleEngine) Update(ctx context.Context, fn func(Tx) error) error
- func (e *PebbleEngine) View(ctx context.Context, fn func(ReadTx) error) error
- type PebbleOptions
- type RangeReadTx
- type ReadTx
- type Snapshot
- type Snapshotter
- type Store
- type SyncPolicy
- type Syncer
- type Tx
Constants ¶
const ( DefaultDirectoryPageSize = 256 MaxDirectoryPageSize = 4096 )
const ( EngineAuto = "auto" EngineBolt = "bbolt" EnginePebble = "pebble" )
const CurrentVersion = 3
const DefaultBackupPrefix = "metadata/backups"
Variables ¶
var ( ErrExists = errors.New("metadata entry already exists") ErrNotDirectory = errors.New("metadata parent is not a directory") ErrIsDirectory = errors.New("metadata entry is a directory") ErrNotEmpty = errors.New("metadata directory is not empty") ErrInvalidName = errors.New("metadata entry name is invalid") ErrRootMutation = errors.New("metadata root cannot be mutated") ErrInvalidMove = errors.New("metadata directory cannot be moved into itself") )
var ErrLegacyVolume = errors.New("metadata predates versioned compactfs volume format")
ErrLegacyVolume means chunk refs exist without the versioned volume-format marker. Such a volume cannot be assigned a chunk size or codec registry safely from current defaults.
var ErrNotFound = errors.New("metadata record not found")
Functions ¶
func CompactBoltFile ¶ added in v1.0.1
CompactBoltFile reclaims free pages into a new file and atomically replaces the original. The caller must hold storage ownership and stop every opener. A pre-compact copy is retained until explicitly removed by the operator.
func CompactMetadata ¶ added in v1.0.1
CompactMetadata uses each engine's native reclaim implementation.
func EngineName ¶ added in v1.0.1
EngineName describes a production engine; injected implementations may return their own name through this optional interface.
func EnsureFormat ¶ added in v1.0.1
func EnsureFormat(ctx context.Context, engine Engine, expected fsformat.Volume) (fsformat.Volume, error)
EnsureFormat creates the volume-format record once and verifies every later open against it. The metadata writer lock must already be held. A missing marker with existing chunks is rejected instead of guessing their geometry.
func Import ¶ added in v1.0.1
Import validates and builds a new native database beside destination, then publishes it atomically. Existing paths are never overwritten. The caller excludes active writers with the same ownership lock used for mounting.
func NormalizeEngine ¶ added in v1.0.1
func ReadFormat ¶ added in v1.0.1
ReadFormat returns the structural format of an initialized volume. A new or legacy metadata engine reports found=false.
func RestoreBackup ¶ added in v1.0.1
func RestoreBackup(ctx context.Context, objects backend.Backend, info BackupInfo, destination Options) (string, error)
RestoreBackup verifies checksum, volume ID and backend dependencies before replacing a stopped native database. The previous database is retained.
func RestoreBoltBackup ¶ added in v1.0.1
func RestoreBoltBackup(ctx context.Context, objects backend.Backend, info BackupInfo, destination string) (string, error)
RestoreBoltBackup restores a selected standalone snapshot after checking its SHA-256, pages, namespace, volume ID, and the existence of its backend objects. An existing database is preserved; the caller holds the storage ownership lock.
func RewriteBoltReferences ¶ added in v1.0.1
func RewriteBoltReferences(ctx context.Context, filename string, fn func(chunk.Ref) (chunk.Ref, error)) error
RewriteBoltReferences rewrites references in an OFFLINE snapshot only. The callback resolves local raw references into immutable backend objects.
func StagedBoltReferences ¶ added in v1.0.1
StagedBoltReferences enumerates local-cache dependencies of a freshly generated snapshot; full page/namespace validation is done before publishing.
func ValidateTransferPaths ¶ added in v1.0.1
ValidateTransferPaths rejects equal or nested source/destination paths, resolving existing symlink parents. Call before acquiring maintenance locks.
Types ¶
type AsyncUpdater ¶ added in v1.0.1
AsyncUpdater accepts an atomic metadata mutation without waiting for the storage commit. Callers use Sync as the durability barrier. The function must remain idempotent because a grouped implementation may retry a batch after a different callback fails.
type BackupInfo ¶ added in v1.0.1
type BackupOptions ¶ added in v1.0.1
type BackupService ¶ added in v1.0.1
type BackupService struct {
// contains filtered or unexported fields
}
BackupService runs one backup at a time, initially, periodically, and on orderly shutdown. Failures are retried on the next interval and observable.
func StartBackup ¶ added in v1.0.1
func StartBackup(store BackupStore, source Snapshotter, opts BackupOptions) (*BackupService, error)
func (*BackupService) Close ¶ added in v1.0.1
func (s *BackupService) Close() error
func (*BackupService) Stats ¶ added in v1.0.1
func (s *BackupService) Stats() BackupStats
func (*BackupService) Stop ¶ added in v1.0.1
func (s *BackupService) Stop()
Stop ends periodic work without taking the final shutdown snapshot yet.
type BackupStats ¶ added in v1.0.1
type BackupStats struct {
VolumeID string `json:"volume_id"`
Running bool `json:"running"`
Completed uint64 `json:"completed"`
Errors uint64 `json:"errors"`
LastKey string `json:"last_key,omitempty"`
LastSuccess time.Time `json:"last_success,omitempty"`
LastError string `json:"last_error,omitempty"`
}
type BackupStore ¶ added in v1.0.1
type BackupStore struct {
Backend backend.Backend
VolumeID string // required to create/prune; empty lists every volume
Prefix string
Retention int // zero selects seven completed snapshots
TempDir string
}
BackupStore stores independent binary bbolt snapshots. Each object name includes a volume ID and SHA-256; failed uploads never replace a good image. A backend prefix belongs to one active writer per volume.
func (BackupStore) Create ¶ added in v1.0.1
func (b BackupStore) Create(ctx context.Context, source Snapshotter) (BackupInfo, error)
Create generates a local consistent image before uploading, so slow backend transfers do not hold an old bbolt read transaction or prevent page reuse.
func (BackupStore) List ¶ added in v1.0.1
func (b BackupStore) List(ctx context.Context) ([]BackupInfo, error)
type Barrier ¶ added in v1.0.1
Barrier applies previously accepted updates without promising an fsync. Namespace holds its mutation lock while crossing this boundary for paging.
type BoltEngine ¶ added in v1.0.1
type BoltEngine struct {
// contains filtered or unexported fields
}
BoltEngine stores each metadata key as a native bbolt B+tree record. Startup loads the live keyspace directly rather than replaying operation history.
func OpenBolt ¶ added in v1.0.1
func OpenBolt(path string, options BoltOptions) (*BoltEngine, error)
OpenBolt opens or creates an embedded metadata database.
func (*BoltEngine) Barrier ¶ added in v1.0.1
func (e *BoltEngine) Barrier(ctx context.Context) error
Barrier makes accepted updates visible to database readers without fsync. It is cheap on an idle engine; callers must exclude namespace mutations if they need the persistent dentry index and the RAM namespace at one boundary.
func (*BoltEngine) Close ¶ added in v1.0.1
func (e *BoltEngine) Close() error
func (*BoltEngine) Name ¶ added in v1.0.1
func (*BoltEngine) Name() string
func (*BoltEngine) Snapshot ¶ added in v1.0.1
Snapshot writes a transactionally consistent copy of the live database. It first applies queued updates and fsyncs the database, then streams a read transaction to w so callers can upload it without copying a live mmap file.
func (*BoltEngine) Update ¶ added in v1.0.1
Update commits one atomic bbolt transaction. Independent callers are grouped into one writer transaction for a short window so concurrent FUSE creates do not each pay for a B+tree root update.
func (*BoltEngine) UpdateAsync ¶ added in v1.0.1
UpdateAsync queues a mutation for the next grouped bbolt transaction. The namespace publishes its in-memory view after this call succeeds; Sync waits for every queued mutation and drives the database fsync barrier.
type BoltInspection ¶ added in v1.0.1
func InspectBoltFile ¶ added in v1.0.1
func InspectBoltFile(ctx context.Context, filename string) (result BoltInspection, err error)
InspectBoltFile checks bbolt pages, the namespace, format marker, codecs and the volume ID without creating or modifying a database.
type BoltOptions ¶ added in v1.0.1
type BoltOptions struct {
Mode os.FileMode
Timeout time.Duration
SyncPolicy SyncPolicy
SyncInterval time.Duration
InitialMmapSize int
}
BoltOptions controls the embedded B+tree metadata store. SyncInterval has the same durability boundary as LogOptions: commits are written immediately but fsync is coalesced until the interval expires or Sync is called.
type BucketReadTx ¶ added in v1.0.1
BucketReadTx enumerates all bucket names, including extension records which must survive exports even when not interpreted by the current namespace.
type Compactor ¶
type Compactor interface {
Compact(ctx context.Context) error
CompactAsync(ctx context.Context) <-chan error
}
Compactor is implemented by engines that can asynchronously reclaim old log records without changing the namespace API.
type Engine ¶
type Engine interface {
View(ctx context.Context, fn func(ReadTx) error) error
Update(ctx context.Context, fn func(Tx) error) error
Close() error
}
Engine is the extension point for metadata persistence. Implementations may be append-only local logs, embedded databases, or remote transactional stores. Values are binary records; the namespace layer owns their encoding.
type EngineStore ¶
type EngineStore struct {
Engine Engine
}
EngineStore persists namespace entries as independent binary records inside an Engine. It does not serialize the complete namespace as JSON or rewrite a monolithic manifest for every write.
type FileChunkUpdate ¶
FileChunkUpdate commits attributes and at most one chunk. Index -1 changes attributes/length only. Count bounds the logical manifest after truncation.
type ImageInfo ¶ added in v1.0.1
type ImageInfo struct {
Path string `json:"path"`
VolumeID string `json:"volume_id"`
Size int64 `json:"size"`
SHA256 string `json:"sha256"`
}
Images use a binary bbolt container as interchange, regardless of the live engine. All buckets (including extension records), format, ID and chunk refs are preserved. It is not a copy of a live Pebble directory or a JSON dump.
func Export ¶ added in v1.0.1
Export writes and validates a standalone image, then publishes it without overwriting an existing path. A core.FileSystem source normalizes staged raw refs; a bare Engine with such refs is rejected. Data objects stay in backend.
func Migrate ¶ added in v1.0.1
Migrate leaves the source untouched and creates a new target engine. Pending local-only chunks are rejected; callers must sync to backend before migrating. The returned Path names the new database; Size/SHA256 describe the interchange image used for conversion, rather than the engine's native files.
type LogEngine ¶
type LogEngine struct {
// contains filtered or unexported fields
}
LogEngine is an append-only metadata engine. Transactions append one checksummed binary batch to a sequential log and update an in-memory index. Recovery replays complete batches and truncates an incomplete tail left by a crash, so a partially written multi-key transaction is never published.
type LogOptions ¶
type MemoryEngine ¶
type MemoryEngine struct {
// contains filtered or unexported fields
}
MemoryEngine is a transactional in-memory Engine for tests and ephemeral mounts.
func NewMemoryEngine ¶
func NewMemoryEngine() *MemoryEngine
func (*MemoryEngine) Close ¶
func (e *MemoryEngine) Close() error
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace is the in-memory inode index backed by a transactional Engine. Lookups and directory listings do not hit the backend; mutations persist only changed records through a grouped engine update before publishing the new in-memory mapping.
func (*Namespace) ClearChunks ¶
func (n *Namespace) ClearChunks(ctx context.Context, inode uint64, first, count int) ([]chunk.Ref, error)
ClearChunks atomically removes chunk mappings without changing file size. It returns retired references only after the metadata transaction commits. Content-addressed backend objects may still be shared by other files.
func (*Namespace) GetChunk ¶
GetChunk returns inode attributes and one reference without copying the full file manifest. The returned Entry has no Chunks; negative indexes return attributes only. Hot raw-cache range reads should use this bounded lookup.
func (*Namespace) LookupAttr ¶ added in v1.0.1
LookupAttr resolves one dentry without copying the file's chunk manifest. Use Lookup when the caller also needs the file's content references.
func (*Namespace) Modify ¶
func (n *Namespace) Modify(ctx context.Context, inode uint64, change func(*Entry) error) (Entry, error)
Modify changes the latest inode atomically. Background chunk replacement must not overwrite a concurrent write, rename, chmod, or truncation.
func (*Namespace) ReadDirPage ¶ added in v1.0.1
func (n *Namespace) ReadDirPage(ctx context.Context, parent uint64, cursor string, limit int) ([]Entry, error)
ReadDirPage returns at most limit attributes ordered by name, strictly after cursor. Returned entries never contain chunk manifests. Use the last name as the next cursor; an empty page means EOF. Each page is consistent, but pages do not hold a long-lived database snapshot: concurrent changes may appear in later pages, and names inserted behind the cursor need a rewind to be seen.
func (*Namespace) RenameReplace ¶
func (n *Namespace) RenameReplace(ctx context.Context, inode, newParent uint64, newName string) (Entry, error)
RenameReplace atomically moves an entry, replacing an existing compatible target. It returns the removed entry, or an entry with Inode zero if absent. The caller retires removed references after the transaction is durable.
func (*Namespace) ReplaceChunk ¶
func (n *Namespace) ReplaceChunk(ctx context.Context, inode uint64, index int, expected, replacement chunk.Ref) (bool, error)
ReplaceChunk atomically replaces exactly one expected reference. It leaves attributes and other chunk slots untouched, including concurrent changes.
func (*Namespace) Store ¶
func (n *Namespace) Store() *EngineStore
func (*Namespace) UpdateFileChunk ¶
func (n *Namespace) UpdateFileChunk(ctx context.Context, inode uint64, update FileChunkUpdate) ([]chunk.Ref, error)
UpdateFileChunk avoids copying and diffing a growing file manifest for each chunk. Retired references are returned only after the transaction commits.
type Options ¶ added in v1.0.1
type Options struct {
Path string
Engine string
CacheBytes int64 // Pebble block cache, not total RSS; zero selects 128 MiB
SyncPolicy SyncPolicy
SyncInterval time.Duration
}
Options selects an on-disk engine. Auto recognizes an existing file as bbolt and a directory as Pebble; a missing path defaults to bbolt. Engine selection never converts existing data. Use Migrate or Import for conversion.
type PebbleEngine ¶ added in v1.0.1
type PebbleEngine struct {
// contains filtered or unexported fields
}
PebbleEngine implements the same bucket transaction contract as BoltEngine. Namespace still owns its current RAM index. This engine is separate from the standalone low-memory inode/dentry research Store in meta/pebble.
func OpenPebble ¶ added in v1.0.1
func OpenPebble(directory string, options PebbleOptions) (*PebbleEngine, error)
func (*PebbleEngine) Barrier ¶ added in v1.0.1
func (e *PebbleEngine) Barrier(ctx context.Context) error
Barrier needs no queue flush: every accepted Update is already committed.
func (*PebbleEngine) Close ¶ added in v1.0.1
func (e *PebbleEngine) Close() error
func (*PebbleEngine) Compact ¶ added in v1.0.1
func (e *PebbleEngine) Compact(ctx context.Context) error
func (*PebbleEngine) Name ¶ added in v1.0.1
func (*PebbleEngine) Name() string
func (*PebbleEngine) Snapshot ¶ added in v1.0.1
Snapshot uses the common binary interchange image, independent of the active engine. Existing backup normalization and staged-reference pinning apply.
type PebbleOptions ¶ added in v1.0.1
type PebbleOptions struct {
CacheBytes int64
SyncPolicy SyncPolicy
SyncInterval time.Duration
}
type RangeReadTx ¶ added in v1.0.1
type RangeReadTx interface {
Range(bucket, prefix, after []byte, fn func(key, value []byte) (bool, error)) error
}
RangeReadTx can seek directly past an exclusive key within a bucket prefix. Keys and values are borrowed only for the duration of fn. A false result stops iteration without treating a full page as a storage error.
type ReadTx ¶
type ReadTx interface {
Get(bucket, key []byte) ([]byte, error)
ForEach(bucket, prefix []byte, fn func(key, value []byte) error) error
}
ReadTx is a read-only transaction over named binary buckets.
type Snapshot ¶
func NewSnapshot ¶
func NewSnapshot() Snapshot
type Snapshotter ¶ added in v1.0.1
Snapshotter writes a consistent metadata image. Remote recovery images must contain backend references only; local-only raw references are rejected.
type Store ¶
type Store interface {
Load(ctx context.Context) (Snapshot, error)
Save(ctx context.Context, snapshot Snapshot) error
}
Store is the high-level metadata persistence contract used by the daemon.
type SyncPolicy ¶
type SyncPolicy uint8
const ( SyncAlways SyncPolicy = iota + 1 SyncInterval SyncNever )