pebble

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Pebble 元数据原型

可运行的独立 inode/dentry 实现,Pebble 是唯一权威状态,不启动扫描全库,不保留全量 Go map。 这是实验包,尚未接入 CLI、FUSE、Afero 或 blk 的 chunk 存储流程。 完整架构、NVMe 百万文件基准、L1 对比及剩余限制见性能报告。

ctx := context.Background()
store, err := pebble.Open("/path/to/new-metadata", pebble.Options{
    CacheBytes: 64 << 20,
    MemTableBytes: 16 << 20,
})
if err != nil { return err }
defer store.Close()
entry, err := store.Create(ctx, 1, "file", pebble.Attr{
    Kind: meta.KindFile,
    Mode: 0644,
})
if err != nil { return err }
attr, err := store.Lookup(ctx, 1, "file")
_ = entry
_ = attr
return err

导入 github.com/lfhy/compactfs/fs/meta/pebble 与 github.com/lfhy/compactfs/fs/meta。 根 inode 固定为 1;Create 自动分配稳定编号,普通文件的名字属于 dentry,目录另存 Parent 用于环检查。 Lookup/GetAttr 返回独立属性值,ReadDir(parent,cursor,limit) 返回至多 4096 项属性及名称; 最后名称作为下一页的独占 cursor。每页短 snapshot,期间发生修改时不承诺跨页快照。

支持 Link、Unlink、Rmdir、原子替换 Rename、Sync、Flush 和 Metrics。默认每个成功修改同步 WAL; Options{NoSync:true} 必须显式选择,调用 Sync 才能承诺之前的异步 WAL 已持久化。 Close 等待正在进行的操作,并且可重复调用。该包没有活动文件句柄层,最后一次 Unlink 会直接删除 inode; 不能因此宣称已支持 POSIX open-unlink 的完整生命周期。

CacheBytes 是 block cache 预算,另有 MemTable、table reader、运行时和缓冲开销,并非 RSS 限额。 默认 MemTable 16 MiB,停止写入阈值 2,文件句柄软限制 256,每层 Bloom filter 10 bits/key。 未添加独立 L1;FreeCache/Ristretto 仅在只读实验工具里比较,不参与可变元数据读取。

CGO_ENABLED=0 GOWORK=off go test ./fs/meta/pebble
CGO_ENABLED=1 GOWORK=off go test -race -tags pebblegozstd ./fs/meta/pebble
# 百万 SST/WAL + SIGKILL 恢复回归(独立临时目录,不操作现有卷):
COMPACTFS_PEBBLE_CRASH_FILES=1000000 CGO_ENABLED=0 GOWORK=off \
  go test ./fs/meta/pebble -run '^TestWALCrashRecovery$' -v -count=1

当前原型不保存 chunk manifest、配额、卷标记,也不提供 backend 快照和 compact/rebuild 接口; 这些能力仍在现有 meta.Namespace/BoltEngine。接入三种导出前须补齐这些契约及用户选项, 不能将这里的数据库目录当成当前卷的 metadata.db。开发阶段不提供旧版本迁移。

Documentation

Overview

Package pebble provides an experimental, bounded-memory inode/dentry store. It does not yet replace compactfs's chunk-aware Namespace or volume backups.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed   = errors.New("metadata store is closed")
	ErrCorrupt  = errors.New("invalid pebble metadata record")
	ErrNotEmpty = errors.New("directory is not empty")
	ErrCycle    = errors.New("directory rename creates a cycle")
)

Functions

This section is empty.

Types

type Attr

type Attr struct {
	Inode, Parent, Size uint64
	Mode, UID, GID      uint32
	Nlink               uint32
	Kind                meta.Kind
	Atime, Mtime, Ctime int64 // Unix nanoseconds
}

Attr is independent of dentry names. Parent is meaningful only on directories.

type Entry

type Entry struct {
	Name string
	Attr Attr
}

type Options

type Options struct {
	CacheBytes    int64
	MemTableBytes uint64
	// NoSync acknowledges WAL writes before fsync. Call Sync before claiming
	// durability. The default synchronizes every successful mutation.
	NoSync bool
}

Options controls the two main memory consumers, not total process RSS.

type Store

type Store struct {
	// contains filtered or unexported fields
}

func Open

func Open(directory string, options Options) (*Store, error)

Open recovers the WAL without loading a namespace into Go maps.

func (*Store) Close

func (s *Store) Close() error

func (*Store) Create

func (s *Store) Create(ctx context.Context, parent uint64, name string, attr Attr) (Attr, error)

func (*Store) Flush

func (s *Store) Flush(ctx context.Context) error

Flush moves mutable tables to SST for a repeatable cold-block-cache reopen.

func (*Store) GetAttr

func (s *Store) GetAttr(ctx context.Context, inode uint64) (Attr, error)
func (s *Store) Link(ctx context.Context, inode, parent uint64, name string) error

func (*Store) Lookup

func (s *Store) Lookup(ctx context.Context, parent uint64, name string) (Attr, error)

func (*Store) Metrics

func (s *Store) Metrics() (*pdb.Metrics, error)

Metrics exposes block cache, WAL, MemTable and SST counters for experiments.

func (*Store) ReadDir

func (s *Store) ReadDir(ctx context.Context, parent uint64, cursor string, limit int) ([]Entry, error)

ReadDir returns attributes from one snapshot, ordered strictly after cursor. The last returned Name is the next cursor. Empty output means EOF. Concurrent mutations can be visible on subsequent pages; no snapshot outlives this call.

func (*Store) Rename

func (s *Store) Rename(ctx context.Context, oldParent uint64, oldName string, newParent uint64, newName string) error

Rename atomically replaces a compatible destination. Renaming either of two hard links to the same inode is a no-op. Directory parent/link-count changes and replacement retirement belong to the same indexed batch.

func (*Store) Rmdir

func (s *Store) Rmdir(ctx context.Context, parent uint64, name string) error

func (*Store) Sync

func (s *Store) Sync(ctx context.Context) error

Sync establishes a WAL durability boundary after all prior writes.

func (s *Store) Unlink(ctx context.Context, parent uint64, name string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL