core

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 36 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.

Documentation

Index

Constants

View Source
const (
	UploadPartBytes     int64 = 8 << 20
	MaxUploadBytes      int64 = 10 << 30
	MaxSplitUploadBytes int64 = 1 << 30
	UploadSessionTTL          = 24 * time.Hour
)

Variables

View Source
var (
	ErrUnknownStorage     = errors.New("unknown storage backend")
	ErrStorageUnavailable = errors.New("storage backend is not configured")
)
View Source
var (
	ErrTrashInvalid  = errors.New("invalid trash request")
	ErrTrashConflict = errors.New("destination already exists")
)
View Source
var (
	ErrUploadNotFound        = errors.New("upload not found")
	ErrUploadExpired         = errors.New("upload expired")
	ErrUploadNotOpen         = errors.New("upload is not open")
	ErrUploadIncomplete      = errors.New("upload is incomplete")
	ErrUploadInvalid         = errors.New("invalid upload request")
	ErrUploadRange           = errors.New("invalid upload part range")
	ErrUploadTooLarge        = errors.New("upload exceeds size limit")
	ErrUploadExists          = errors.New("file already exists")
	ErrUploadPathIsDirectory = errors.New("path is a directory")
)
View Source
var ErrDirectoryNotEmpty = errors.New("directory not empty")
View Source
var ErrNotAFile = errors.New("path is not a file")
View Source
var ErrReplicaCommitPending = errors.New("write committed on primary, replica commit pending")
View Source
var ErrReplicationDisabled = errors.New("replication is disabled")
View Source
var ErrVerifyMismatch = errors.New("stored file does not match the uploaded bytes")

Functions

func WithinPrefixBoundary

func WithinPrefixBoundary(path, prefix string) bool

Types

type CacheEntry

type CacheEntry struct {
	Metadata  *metadata.Metadata
	ExpiresAt time.Time
}

func (*CacheEntry) IsExpired

func (e *CacheEntry) IsExpired() bool

type CacheGeneration

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

type CacheStats

type CacheStats struct {
	Enabled        bool
	TTL            time.Duration
	Entries        int
	MaxEntries     int
	Hits           uint64
	Misses         uint64
	Evictions      uint64
	ExpiredCleaned uint64
	LastCleanupAt  time.Time
}

type DeletePlan

type DeletePlan struct {
	Files           int      `json:"files"`
	Directories     int      `json:"directories"`
	Bytes           int64    `json:"bytes"`
	ErasureFiles    int      `json:"erasure_files"`
	RemoteInstances []string `json:"remote_instances"`
}

type Engine

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

Engine represents the core CallFS engine that orchestrates operations

func NewEngine

func NewEngine(
	metadataStore metadata.Store,
	localFSBackend backends.Storage,
	s3Backend backends.Storage,
	internalProxyBackend backends.Storage,
	internalProxyAdapter *internalproxy.InternalProxyAdapter,
	lockManager locks.Manager,
	currentInstanceID string,
	peerEndpoints map[string]string,
	replicationEnabled bool,
	replicaBackend string,
	requireReplicaAck bool,
	logger *zap.Logger,
) *Engine

NewEngine creates a new core engine instance

func (*Engine) AddPeerEndpoint

func (e *Engine) AddPeerEndpoint(instanceID, endpoint string) error

func (*Engine) Close

func (e *Engine) Close()

Close shuts down the engine and releases background resources.

func (*Engine) CountDirectoryChildren

func (e *Engine) CountDirectoryChildren(ctx context.Context, path string) (int, error)

CountDirectoryChildren returns the number of direct children of a directory whose metadata the caller has already resolved.

func (*Engine) CreateDirectory

func (e *Engine) CreateDirectory(ctx context.Context, path string, md *metadata.Metadata) error

CreateDirectory creates a new directory

func (*Engine) CreateErasureFile

func (e *Engine) CreateErasureFile(ctx context.Context, path string, r io.Reader, opts *erasure.StoreOptions, build func(*erasure.ErasureFileInfo) *metadata.Metadata) (*metadata.Metadata, error)

func (*Engine) DeleteDirectoryRecursive

func (e *Engine) DeleteDirectoryRecursive(ctx context.Context, path string) (int, int, error)

func (*Engine) DeleteFile

func (e *Engine) DeleteFile(ctx context.Context, path string) error

func (*Engine) DeleteFileOnInstance

func (e *Engine) DeleteFileOnInstance(ctx context.Context, instanceID, path string) error

DeleteFileOnInstance deletes a file on a specific instance using the internal proxy

func (*Engine) DeleteMetadataOnly

func (e *Engine) DeleteMetadataOnly(ctx context.Context, path string) error

func (*Engine) DeletePrefixWithin

func (e *Engine) DeletePrefixWithin(ctx context.Context, prefix string, boundary bool) (int, error)

func (*Engine) DeleteTreeOnInstance

func (e *Engine) DeleteTreeOnInstance(ctx context.Context, instanceID, path string) error

func (*Engine) EnsureRootDirectory

func (e *Engine) EnsureRootDirectory(ctx context.Context) error

func (*Engine) GetCurrentInstanceID

func (e *Engine) GetCurrentInstanceID() string

GetCurrentInstanceID returns the current instance ID

func (*Engine) GetErasureManager

func (e *Engine) GetErasureManager() *erasure.Manager

GetErasureManager returns the erasure manager (may be nil)

func (*Engine) GetFile

func (e *Engine) GetFile(ctx context.Context, path string) (io.ReadCloser, error)

func (*Engine) GetMetadata

func (e *Engine) GetMetadata(ctx context.Context, path string) (*metadata.Metadata, error)

func (*Engine) GetMetadataUncached

func (e *Engine) GetMetadataUncached(ctx context.Context, path string) (*metadata.Metadata, error)

func (*Engine) GetMetadataWithSource

func (e *Engine) GetMetadataWithSource(ctx context.Context, path string) (*metadata.Metadata, bool, error)

func (*Engine) GetPeerEndpoint

func (e *Engine) GetPeerEndpoint(instanceID string) string

GetPeerEndpoint returns the endpoint URL for a given instance ID

func (*Engine) ListDirectory

func (e *Engine) ListDirectory(ctx context.Context, path string) ([]*metadata.Metadata, error)

ListDirectory lists directory contents

func (*Engine) ListDirectoryRecursive

func (e *Engine) ListDirectoryRecursive(ctx context.Context, path string, maxDepth int) ([]*metadata.Metadata, error)

ListDirectoryRecursive lists directory contents recursively

func (*Engine) ListDirectoryRecursiveLimited

func (e *Engine) ListDirectoryRecursiveLimited(ctx context.Context, path string, maxDepth, limit int) ([]*metadata.Metadata, error)

ListDirectoryRecursiveLimited lists directory contents recursively, returning at most limit entries (0 means unlimited)

func (*Engine) ListObjects

func (e *Engine) ListObjects(ctx context.Context, prefix, startAfter string, limit int) ([]*metadata.Metadata, bool, error)

func (*Engine) MetadataCache

func (e *Engine) MetadataCache() *MetadataCache

func (*Engine) Move

func (e *Engine) Move(ctx context.Context, srcPath, dstPath string, opts MoveOptions) error

Move relocates a file or directory to dstPath, optionally changing its backend and/or owning instance.

func (*Engine) OpenFile

func (e *Engine) OpenFile(ctx context.Context, md *metadata.Metadata, path string) (io.ReadCloser, error)

func (*Engine) OpenFileRange

func (e *Engine) OpenFileRange(ctx context.Context, md *metadata.Metadata, path string, offset, length int64) (io.ReadCloser, error)

func (*Engine) PlanDelete

func (e *Engine) PlanDelete(ctx context.Context, path string) (DeletePlan, error)

func (*Engine) ProbeStorage

func (e *Engine) ProbeStorage(ctx context.Context, name string) (StorageProbe, error)

func (*Engine) PutFile

func (e *Engine) PutFile(ctx context.Context, path string, reader io.Reader, size int64, md *metadata.Metadata, ifMatch string, ifNoneMatch bool) (*metadata.Metadata, bool, error)

func (*Engine) RecoverOverwrites

func (e *Engine) RecoverOverwrites(ctx context.Context) error

func (*Engine) RemovePeerEndpoint

func (e *Engine) RemovePeerEndpoint(instanceID string)

func (*Engine) Rename

func (e *Engine) Rename(ctx context.Context, srcPath, newName string) error

Rename changes only the name of a file or directory, leaving it in the same folder, backend, and instance. newName must be a single path segment.

func (*Engine) ReplicatePath

func (e *Engine) ReplicatePath(ctx context.Context, path string) error

func (*Engine) SearchDirectoryRecursiveLimited

func (e *Engine) SearchDirectoryRecursiveLimited(ctx context.Context, path string, maxDepth, limit int, match func(*metadata.Metadata) bool) ([]*metadata.Metadata, int, error)

func (*Engine) SetErasureManager

func (e *Engine) SetErasureManager(em *erasure.Manager)

SetErasureManager sets the erasure manager on the engine

func (*Engine) SetMetadataCacheSize

func (e *Engine) SetMetadataCacheSize(size int)

func (*Engine) SetMetadataCacheTTL

func (e *Engine) SetMetadataCacheTTL(ttl time.Duration)

func (*Engine) SetReplicationFailureRecorder

func (e *Engine) SetReplicationFailureRecorder(record func(path, message string))

func (*Engine) SetReplicationOutcomeRecorder

func (e *Engine) SetReplicationOutcomeRecorder(record func(outcome string))

func (*Engine) SetStrict

func (e *Engine) SetStrict(strict bool)

func (*Engine) SetTrueOverwrite

func (e *Engine) SetTrueOverwrite(enabled bool, tmpSaveMaxSize int64)

func (*Engine) UpdateFileOnInstance

func (e *Engine) UpdateFileOnInstance(ctx context.Context, instanceID, path string, reader io.Reader, size int64, ifMatch string, ifNoneMatch bool) (string, error)

UpdateFileOnInstance updates a file on a specific instance using the internal proxy

func (*Engine) UpdateMetadataOnly

func (e *Engine) UpdateMetadataOnly(ctx context.Context, md *metadata.Metadata) error

func (*Engine) UseTaskQueue

func (e *Engine) UseTaskQueue(queue cluster.Queue)

func (*Engine) WalkPrefix

func (e *Engine) WalkPrefix(ctx context.Context, prefix string, boundary bool, visit func(page []*metadata.Metadata) (bool, error)) error

type ErrInvalidRename

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

ErrInvalidRename indicates a malformed rename/move request (bad name, moving a path into its own subtree, etc.). Mapped to 400 by the handler.

func (*ErrInvalidRename) Error

func (e *ErrInvalidRename) Error() string

type ErrProxyFailed

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

func (*ErrProxyFailed) Error

func (e *ErrProxyFailed) Error() string

func (*ErrProxyFailed) Unwrap

func (e *ErrProxyFailed) Unwrap() error

type ErrUnsupportedMove

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

ErrUnsupportedMove indicates a relocation the current release does not perform (e.g. erasure re-tiering or cross-backend/instance directory moves). Mapped to 400.

func (*ErrUnsupportedMove) Error

func (e *ErrUnsupportedMove) Error() string

type MetadataCache

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

func NewMetadataCache

func NewMetadataCache(ttl time.Duration, maxSize int) *MetadataCache

func (*MetadataCache) Clear

func (c *MetadataCache) Clear() int

func (*MetadataCache) Close

func (c *MetadataCache) Close()

func (*MetadataCache) Generation

func (c *MetadataCache) Generation(path string) CacheGeneration

func (*MetadataCache) Get

func (c *MetadataCache) Get(path string) (*metadata.Metadata, bool)

func (*MetadataCache) Invalidate

func (c *MetadataCache) Invalidate(path string)

func (*MetadataCache) InvalidatePrefix

func (c *MetadataCache) InvalidatePrefix(prefix string) int

func (*MetadataCache) IsAbsent

func (c *MetadataCache) IsAbsent(path string) bool

func (*MetadataCache) SetAbsent

func (c *MetadataCache) SetAbsent(path string)

func (*MetadataCache) SetBypass

func (c *MetadataCache) SetBypass(bypass bool)

func (*MetadataCache) SetIfGeneration

func (c *MetadataCache) SetIfGeneration(path string, md *metadata.Metadata, gen CacheGeneration)

func (*MetadataCache) SetMaxSize

func (c *MetadataCache) SetMaxSize(size int)

func (*MetadataCache) SetTTL

func (c *MetadataCache) SetTTL(ttl time.Duration)

func (*MetadataCache) Stats

func (c *MetadataCache) Stats() CacheStats

type MoveOptions

type MoveOptions struct {
	Backend       string // target backend type ("localfs", "s3", "erasure"); "" keeps source's
	Instance      string // target instance ID; "" keeps source's
	Overwrite     bool   // replace an existing destination instead of failing
	CreateParents bool   // create missing destination parent directories
	// contains filtered or unexported fields
}

MoveOptions controls a move operation. Empty Backend/Instance mean "keep the source's"; a different value triggers a physical relocation of the bytes.

type PrefixDeleteError

type PrefixDeleteError struct {
	Deleted    int
	FailedPath string
	Err        error
}

func (*PrefixDeleteError) Error

func (e *PrefixDeleteError) Error() string

func (*PrefixDeleteError) Unwrap

func (e *PrefixDeleteError) Unwrap() error

type StorageProbe

type StorageProbe struct {
	OK       bool
	WriteMS  int64
	ReadMS   int64
	DeleteMS int64
	Error    string
}

type Trash

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

func NewTrash

func NewTrash(engine *Engine, authorizer auth.Authorizer, admins *auth.AdminSet, runner *jobs.Runner, retention time.Duration, logger *zap.Logger) *Trash

func (*Trash) Cleanup

func (t *Trash) Cleanup(ctx context.Context, retention time.Duration) (int, error)

func (*Trash) Delete

func (t *Trash) Delete(ctx context.Context, userID, id string) error

func (*Trash) Empty

func (t *Trash) Empty(ctx context.Context, userID, deletedBy string) (jobs.Job, error)

func (*Trash) IsAdmin

func (t *Trash) IsAdmin(userID string) bool

func (*Trash) List

func (t *Trash) List(ctx context.Context, userID, deletedBy, cursor string, limit int) (TrashPage, error)

func (*Trash) Logger

func (t *Trash) Logger() *zap.Logger

func (*Trash) MoveToTrash

func (t *Trash) MoveToTrash(ctx context.Context, userID, filePath string) (TrashItem, error)

func (*Trash) Restore

func (t *Trash) Restore(ctx context.Context, userID, id, to, onConflict string) (string, error)

type TrashItem

type TrashItem struct {
	ID           string    `json:"id"`
	OriginalPath string    `json:"original_path"`
	Name         string    `json:"name"`
	Type         string    `json:"type"`
	Size         int64     `json:"size"`
	DeletedBy    string    `json:"deleted_by"`
	DeletedAt    time.Time `json:"deleted_at"`
	ExpiresAt    time.Time `json:"expires_at"`
}

type TrashPage

type TrashPage struct {
	Items      []TrashItem
	NextCursor string
	TotalBytes int64
}

type UploadEngine

type UploadEngine interface {
	GetMetadata(ctx context.Context, path string) (*metadata.Metadata, error)
	PutFile(ctx context.Context, path string, reader io.Reader, size int64, md *metadata.Metadata, ifMatch string, ifNoneMatch bool) (*metadata.Metadata, bool, error)
	CreateErasureFile(ctx context.Context, path string, r io.Reader, opts *erasure.StoreOptions, build func(*erasure.ErasureFileInfo) *metadata.Metadata) (*metadata.Metadata, error)
}

type UploadOffsetError

type UploadOffsetError struct {
	Offset int64
}

func (*UploadOffsetError) Error

func (e *UploadOffsetError) Error() string

type UploadPart

type UploadPart struct {
	Start int64
	End   int64
	Total int64
}

type UploadRequest

type UploadRequest struct {
	Path      string
	Size      int64
	Overwrite bool
	IfMatch   string
	Mode      string
	Storage   string
	Erasure   *erasure.StoreOptions
	NoErasure bool
}

type UploadResult

type UploadResult struct {
	Path    string
	ETag    string
	Created bool
}

type UploadSession

type UploadSession struct {
	ID        string                `json:"id"`
	UserID    string                `json:"user_id"`
	Path      string                `json:"path"`
	Size      int64                 `json:"size"`
	Offset    int64                 `json:"offset"`
	Overwrite bool                  `json:"overwrite"`
	IfMatch   string                `json:"if_match"`
	Mode      string                `json:"mode"`
	Storage   string                `json:"storage"`
	Erasure   *erasure.StoreOptions `json:"erasure"`
	State     UploadState           `json:"state"`
	ExpiresAt time.Time             `json:"expires_at"`
}

type UploadState

type UploadState string
const (
	UploadOpen       UploadState = "open"
	UploadCompleting UploadState = "completing"
	UploadDone       UploadState = "done"
	UploadFailed     UploadState = "failed"
	UploadExpired    UploadState = "expired"
)

type Uploads

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

func NewUploads

func NewUploads(engine UploadEngine, authorizer auth.Authorizer, localRoot, defaultBackend string, logger *zap.Logger) (*Uploads, error)

func (*Uploads) Abort

func (u *Uploads) Abort(userID, id string) error

func (*Uploads) Cleanup

func (u *Uploads) Cleanup(now time.Time) (int, error)

func (*Uploads) Complete

func (u *Uploads) Complete(ctx context.Context, userID, id string) (UploadResult, error)

func (*Uploads) Create

func (u *Uploads) Create(ctx context.Context, userID string, req UploadRequest) (UploadSession, error)

func (*Uploads) Logger

func (u *Uploads) Logger() *zap.Logger

func (*Uploads) PutPart

func (u *Uploads) PutPart(userID, id string, part UploadPart, body io.Reader) (UploadSession, error)

func (*Uploads) Status

func (u *Uploads) Status(userID, id string) (UploadSession, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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