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 ¶
- type Option
- type Store
- func (s *Store) Abort(_ context.Context, ws string, digest blob.Digest) error
- func (s *Store) Begin(ctx context.Context, ws string, m blob.Manifest) error
- func (s *Store) Close() error
- func (s *Store) Complete(ctx context.Context, ws string, digest blob.Digest) error
- func (s *Store) Delete(_ context.Context, ws string, digest blob.Digest) error
- func (s *Store) DeleteWorkspace(_ context.Context, ws string) error
- func (s *Store) List(_ context.Context, ws string) iter.Seq2[blob.Digest, error]
- func (s *Store) ListStaged(_ context.Context, ws string) iter.Seq2[blob.Upload, error]
- func (s *Store) ListWorkspaces(context.Context) iter.Seq2[string, error]
- func (s *Store) Open(_ context.Context, ws string, digest blob.Digest) (io.ReadSeekCloser, error)
- func (s *Store) PutChunk(ctx context.Context, ws string, digest blob.Digest, index int, r io.Reader) error
- func (s *Store) SetUnreferencedSince(_ context.Context, ws string, digest blob.Digest, t time.Time) error
- func (s *Store) Staged(_ context.Context, ws string, digest blob.Digest) (blob.Upload, []int, error)
- func (s *Store) Stat(_ context.Context, ws string, digest blob.Digest) (blob.Info, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 ¶
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) Begin ¶
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) Complete ¶
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) ListStaged ¶
func (*Store) ListWorkspaces ¶
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 ¶
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.