fsstore

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package fsstore is a blob.Store that keeps blobs in a local directory.

Several Stores, in one process or in several, can share one directory. The directory must be on a local file system that renames atomically, supports hard links and keeps an open file readable after it is removed, such as ext4, XFS, APFS or ZFS. Network file systems such as NFS and SMB do not give these guarantees, and a directory on one must not be shared. Every process must run as the same user: the Store creates files that only their owner can read.

A staged upload is one data file that each chunk is written into at its offset, after its hash is checked. Complete does not read or copy the data: it appends a trailer that holds the manifest, syncs the file and renames it into place. Its cost does not depend on the blob's size, and a reader sees no blob or the whole blob, also after a crash. A staged upload survives a restart with the chunks it had. A crash can lose the chunks stored shortly before it; Staged then reports them missing.

The directory holds:

layout                                         the layout version
workspaces/<ws>/id                             the workspace id
workspaces/<ws>/blobs/<hex>.blob               a committed blob: bytes, then trailer
workspaces/<ws>/blobs/<hex>.unreferenced       its UnreferencedSince mark
workspaces/<ws>/staging/<hex>/upload.json      a staged upload and its upload id
workspaces/<ws>/staging/<hex>/<id>/data        the bytes of the chunks stored so far
workspaces/<ws>/staging/<hex>/<id>/<i>.chunk   empty marker: chunk i is in data
workspaces/<ws>/staging/<hex>/<id>/commit.json the trailer header Complete chose
trash/                                         removed state that is not yet deleted

<ws> is the hex SHA-256 of the workspace id and <hex> the hex digits of the digest, so names do not depend on how the file system compares case or Unicode. <id> is random per Begin. A trailer is the JSON header, its length as a big-endian uint32, then the 8 bytes "SPBLOB2\n". Temporary files start with ".tmp-".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Store)

Option configures Open.

func WithClock

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

WithClock makes the Store read the time from now instead of time.Now. It sets CommittedAt and StartedAt. A nil now keeps time.Now.

type Store

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

Store is a blob.Store over a local directory. It is safe for concurrent use by several goroutines, and by several Stores that share the directory.

func Open

func Open(dir string, opts ...Option) (*Store, error)

Open returns a Store over dir, and creates dir when it does not exist.

Open removes what an earlier process left behind when it stopped during a change: the contents of trash/, temporary files and abandoned staging state older than an hour, and the staged state of blobs that are committed. To find them it reads every directory in dir, so its cost grows with the number of blobs. It fails when dir holds a layout that this version does not know.

func (*Store) Abort

func (s *Store) Abort(_ context.Context, ws string, digest blob.Digest) error

func (*Store) Begin

func (s *Store) Begin(ctx context.Context, ws string, m blob.Manifest) error

Begin stages an upload of the blob m describes. It fails with an error wrapping blob.ErrInvalid when m's digest is malformed.

func (*Store) Close

func (s *Store) Close() error

Close does nothing. The Store stays usable.

func (*Store) Complete

func (s *Store) Complete(ctx context.Context, ws string, digest blob.Digest) error

Complete commits a staged upload that holds every chunk. It does not read the staged bytes: they were checked when PutChunk stored them.

func (*Store) Delete

func (s *Store) Delete(_ context.Context, ws string, digest blob.Digest) error

func (*Store) DeleteWorkspace

func (s *Store) DeleteWorkspace(_ context.Context, ws string) error

func (*Store) List

func (s *Store) List(_ context.Context, ws string) iter.Seq2[blob.Digest, error]

func (*Store) ListStaged

func (s *Store) ListStaged(_ context.Context, ws string) iter.Seq2[blob.Upload, error]

func (*Store) ListWorkspaces

func (s *Store) ListWorkspaces(context.Context) iter.Seq2[string, error]

ListWorkspaces yields the id of every workspace that has a committed blob or a staged upload. It reads the directories of every workspace.

func (*Store) Open

func (s *Store) Open(_ context.Context, ws string, digest blob.Digest) (io.ReadSeekCloser, error)

Open returns a reader over a committed blob's bytes. The reader stays readable after a Delete of the blob, until it is closed. A blob file that is damaged on disk gives an error that does not wrap blob.ErrNotFound.

func (*Store) PutChunk

func (s *Store) PutChunk(ctx context.Context, ws string, digest blob.Digest, index int, r io.Reader) error

PutChunk stores chunk index of a staged upload. It holds the chunk in memory, so each call that runs at the same time uses up to blob.ChunkSize bytes.

func (*Store) SetUnreferencedSince

func (s *Store) SetUnreferencedSince(_ context.Context, ws string, digest blob.Digest, t time.Time) error

func (*Store) Staged

func (s *Store) Staged(_ context.Context, ws string, digest blob.Digest) (blob.Upload, []int, error)

Staged returns a staged upload and the indexes of the chunks it holds.

func (*Store) Stat

func (s *Store) Stat(_ context.Context, ws string, digest blob.Digest) (blob.Info, error)

Stat returns a committed blob's Info. A blob file that is damaged on disk gives an error that does not wrap blob.ErrNotFound.

Jump to

Keyboard shortcuts

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