filesystem

package
v0.0.0-...-a499ac4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RootInode uint64 = 1

	DefaultChunkSize = 4 * bytesPerMiB
)

Variables

View Source
var (
	ErrStoreRequired       = errors.New("filesystem: store is required")
	ErrDispatcherRequired  = errors.New("filesystem: dispatcher is required")
	ErrNotFound            = errors.New("filesystem: no such file or directory")
	ErrExists              = errors.New("filesystem: file exists")
	ErrNotDir              = errors.New("filesystem: not a directory")
	ErrIsDir               = errors.New("filesystem: is a directory")
	ErrNotEmpty            = errors.New("filesystem: directory not empty")
	ErrCrossDevice         = errors.New("filesystem: cross-domain rename")
	ErrInvalid             = errors.New("filesystem: invalid argument")
	ErrUnsupported         = errors.New("filesystem: operation not supported")
	ErrStaleHome           = errors.New("filesystem: stale or migrating file home")
	ErrMoveJobNotFound     = errors.New("filesystem: move job not found")
	ErrMoveFenceLost       = errors.New("filesystem: move job lost its epoch fence")
	ErrPlacementRequired   = errors.New("filesystem: placement resolver is required")
	ErrInodeCollisionLimit = errors.New("filesystem: inode allocation collision limit reached")
)

Functions

This section is empty.

Types

type CreateOptions

type CreateOptions struct {
	Mode     uint32
	UID      uint32
	GID      uint32
	ClientID []byte
}

type CreateResult

type CreateResult struct {
	Inode uint64
	FH    uint64
	Stat  Stat
}

type DirEntry

type DirEntry struct {
	Inode uint64   `json:"inode"`
	Type  FileType `json:"type"`
}

type Dirent

type Dirent struct {
	Name  []byte
	Inode uint64
	Type  FileType
}

type Dispatcher

type Dispatcher interface {
	Dispatch(context.Context, *kv.OperationGroup[kv.OP]) (*kv.CoordinateResponse, error)
}

type FSUsage

type FSUsage struct {
	Files uint64 `json:"files"`
	Bytes uint64 `json:"bytes"`
}

type FileType

type FileType string
const (
	TypeFile      FileType = "file"
	TypeDirectory FileType = "directory"
)

type Home

type Home struct {
	HomeSlot       uint64    `json:"home_slot"`
	TargetHomeSlot uint64    `json:"target_home_slot,omitempty"`
	State          HomeState `json:"state"`
	Epoch          uint64    `json:"epoch"`
}

type HomeState

type HomeState string
const (
	HomeStateActive    HomeState = "active"
	HomeStateMigrating HomeState = "migrating"
)

type InodeMeta

type InodeMeta struct {
	Inode      uint64   `json:"inode"`
	Parent     uint64   `json:"parent"`
	Type       FileType `json:"type"`
	Mode       uint32   `json:"mode"`
	UID        uint32   `json:"uid"`
	GID        uint32   `json:"gid"`
	Size       uint64   `json:"size"`
	AtimeNsec  int64    `json:"atime_nsec"`
	MtimeNsec  int64    `json:"mtime_nsec"`
	CtimeNsec  int64    `json:"ctime_nsec"`
	ChunkSize  uint64   `json:"chunk_size"`
	HomeSlot   uint64   `json:"home_slot"`
	Epoch      uint64   `json:"epoch"`
	Nlink      uint32   `json:"nlink"`
	Generation uint64   `json:"generation"`
	Orphaned   bool     `json:"orphaned,omitempty"`
}

func (InodeMeta) Stat

func (m InodeMeta) Stat() Stat

type IntentKind

type IntentKind string
const (
	IntentKindCreate IntentKind = "create"
	IntentKindDelete IntentKind = "delete"
	IntentKindMove   IntentKind = "move"
)

type IntentState

type IntentState struct {
	ID        []byte     `json:"id"`
	Kind      IntentKind `json:"kind"`
	Phase     string     `json:"phase"`
	Inode     uint64     `json:"inode,omitempty"`
	Parent    uint64     `json:"parent,omitempty"`
	Name      []byte     `json:"name,omitempty"`
	JobID     []byte     `json:"job_id,omitempty"`
	CreatedAt int64      `json:"created_at_nsec"`
	UpdatedAt int64      `json:"updated_at_nsec"`
}

type LeaseReapStats

type LeaseReapStats struct {
	ExpiredRefs        uint64
	OrphanedInodesGCed uint64
}

type MoveJob

type MoveJob struct {
	ID             []byte    `json:"id"`
	Inode          uint64    `json:"inode"`
	SourceHome     uint64    `json:"source_home"`
	TargetHome     uint64    `json:"target_home"`
	TargetGroup    uint64    `json:"target_group"`
	MigrationEpoch uint64    `json:"migration_epoch"`
	SwitchEpoch    uint64    `json:"switch_epoch,omitempty"`
	Phase          MovePhase `json:"phase"`
	Cursor         []byte    `json:"cursor,omitempty"`
	CopiedChunks   uint64    `json:"copied_chunks,omitempty"`
	CleanedChunks  uint64    `json:"cleaned_chunks,omitempty"`
	CreatedAt      int64     `json:"created_at_nsec"`
	UpdatedAt      int64     `json:"updated_at_nsec"`
}

type MovePhase

type MovePhase string
const (
	MovePhaseTargetCleanup MovePhase = "target_cleanup"
	MovePhaseCopy          MovePhase = "copy"
	MovePhaseSwitch        MovePhase = "switch"
	MovePhaseSourceCleanup MovePhase = "source_cleanup"
	MovePhaseCompleted     MovePhase = "completed"
)

type OpenHandleLease

type OpenHandleLease struct {
	Inode       uint64 `json:"inode"`
	ClientID    []byte `json:"client_id"`
	FH          uint64 `json:"fh"`
	CreatedNsec int64  `json:"created_nsec"`
	ExpiresNsec int64  `json:"expires_nsec,omitempty"`
}

type OperationalObserver

type OperationalObserver interface {
	ObserveChunkRead(time.Duration)
	ObserveChunkWrite(time.Duration)
	ObserveHomeEpochConflict()
	ObserveInodeIDCollisionRetry()
	ObserveMoveJob(jobID []byte, active bool)
	ObservePlacementStats(PlacementStats)
}

type Option

type Option func(*Service)

func WithCapacity

func WithCapacity(capacity uint64) Option

func WithChunkSize

func WithChunkSize(size uint64) Option

func WithClock

func WithClock(now func() time.Time) Option

func WithHomeSlotAllocator

func WithHomeSlotAllocator(homeSlot func(uint64) uint64) Option

func WithIDAllocator

func WithIDAllocator(alloc func() (uint64, error)) Option

func WithMaxFiles

func WithMaxFiles(maxFiles uint64) Option

func WithOpenHandleLeaseTTL

func WithOpenHandleLeaseTTL(ttl time.Duration) Option

func WithOperationalObserver

func WithOperationalObserver(observer OperationalObserver) Option

type PlacementStats

type PlacementStats struct {
	FilesByGroup     map[uint64]uint64
	MultiShardFiles  uint64
	MultiShardInodes []uint64
	MoveInflight     uint64
	OpenHandleLeases uint64
	OrphanedInodes   uint64
}

type ReaddirResult

type ReaddirResult struct {
	Entries    []Dirent
	NextCookie string
}

type RecoveryStats

type RecoveryStats struct {
	MoveJobsResumed uint64
	MoveJobsCleared uint64
	IntentsCleared  uint64
}

type Service

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

func NewService

func NewService(st store.MVCCStore, dispatch Dispatcher, opts ...Option) (*Service, error)

func (*Service) Create

func (s *Service) Create(ctx context.Context, parent uint64, name []byte, opts CreateOptions) (CreateResult, error)

func (*Service) Flush

func (s *Service) Flush(context.Context, uint64, uint64) error

func (*Service) Fsync

func (s *Service) Fsync(ctx context.Context, inode uint64, _ uint64, _ bool) error

func (*Service) GetAttr

func (s *Service) GetAttr(ctx context.Context, inode uint64) (Stat, error)

func (*Service) GetFileHome

func (s *Service) GetFileHome(ctx context.Context, inode uint64) (Home, error)

GetFileHome returns the durable placement state for an inode.

func (*Service) InitializeRoot

func (s *Service) InitializeRoot(ctx context.Context, mode uint32, uid uint32, gid uint32) error

func (*Service) ListFilePlacementStats

func (s *Service) ListFilePlacementStats(ctx context.Context) (PlacementStats, error)

ListFilePlacementStats computes operator-facing placement state at one fenced snapshot and publishes it to the configured observer.

func (*Service) Mkdir

func (s *Service) Mkdir(ctx context.Context, parent uint64, name []byte, opts CreateOptions) (CreateResult, error)

func (*Service) MoveFile

func (s *Service) MoveFile(ctx context.Context, inode uint64, targetGroup uint64) (MoveJob, error)

MoveFile synchronously executes a resumable whole-file migration. The job is durable before any chunk copy starts, so RecoverIntents can resume it after a process or leader restart.

func (*Service) Open

func (s *Service) Open(ctx context.Context, inode uint64, clientID []byte) (uint64, error)

func (*Service) Read

func (s *Service) Read(ctx context.Context, inode uint64, _ uint64, offset uint64, size uint64) ([]byte, error)

func (*Service) Readdir

func (s *Service) Readdir(ctx context.Context, inode uint64, cookie string, limit int) (ReaddirResult, error)

func (*Service) ReapExpiredOpenHandleLeases

func (s *Service) ReapExpiredOpenHandleLeases(ctx context.Context, limit int) (LeaseReapStats, error)

func (*Service) RecoverIntents

func (s *Service) RecoverIntents(ctx context.Context, limit int) (RecoveryStats, error)

RecoverIntents resumes durable move jobs and aborts prepared namespace intents. Create/delete publish their intent before the atomic namespace txn and delete it inside that txn, so a surviving marker proves the namespace mutation did not commit and is safe to clear.

func (*Service) RefreshOpenHandleLease

func (s *Service) RefreshOpenHandleLease(ctx context.Context, inode uint64, fh uint64, clientID []byte) error

func (*Service) Release

func (s *Service) Release(ctx context.Context, inode uint64, fh uint64, clientID []byte) error

func (*Service) Rename

func (s *Service) Rename(ctx context.Context, oldParent uint64, oldName []byte, newParent uint64, newName []byte) error

func (*Service) Resolve

func (s *Service) Resolve(ctx context.Context, parent uint64, name []byte) (uint64, error)

func (*Service) ResumeMoveFile

func (s *Service) ResumeMoveFile(ctx context.Context, jobID []byte) (MoveJob, error)

ResumeMoveFile advances a durable migration state machine until completion.

func (*Service) Rmdir

func (s *Service) Rmdir(ctx context.Context, parent uint64, name []byte) error

func (*Service) SetAttr

func (s *Service) SetAttr(ctx context.Context, inode uint64, mask SetAttrMask, attrs SetAttr) (Stat, error)

func (*Service) StatFS

func (s *Service) StatFS(ctx context.Context, _ uint64) (StatFS, error)

func (*Service) Truncate

func (s *Service) Truncate(ctx context.Context, inode uint64, size uint64) error
func (s *Service) Unlink(ctx context.Context, parent uint64, name []byte) error

func (*Service) Write

func (s *Service) Write(ctx context.Context, inode uint64, _ uint64, offset uint64, data []byte) (int, error)

type SetAttr

type SetAttr struct {
	Mode      uint32
	UID       uint32
	GID       uint32
	Size      uint64
	AtimeNsec int64
	MtimeNsec int64
}

type SetAttrMask

type SetAttrMask struct {
	Mode  bool
	UID   bool
	GID   bool
	Size  bool
	Atime bool
	Mtime bool
}

type Stat

type Stat struct {
	Inode      uint64
	Generation uint64
	Type       FileType
	Mode       uint32
	UID        uint32
	GID        uint32
	Size       uint64
	Nlink      uint32
	AtimeNsec  int64
	MtimeNsec  int64
	CtimeNsec  int64
}

type StatFS

type StatFS struct {
	ChunkSize uint64
	Files     uint64
	FreeFiles uint64
	Capacity  uint64
	Free      uint64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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