disk

package
v0.1.29 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// The capacity of the store in bytes. When breached, LRU eviction is used.
	CapacityBytes uint64 `yaml:"capacity_bytes"`
	// The root directory under which [Store]'s blobs and state are stored.
	RootDir string `yaml:"root_dir"`
	// Whether after crash/restart, the Store removes incomplete files from disk (usually to prevent leaks) OR
	// reboots any incomplete files from disk (allowing users to continue the blob download/upload, where it was left off before the crash).
	RebootIncompleteBlobs bool `yaml:"reboot_incomplete_blobs"`
	// If > 0, directory sharding is used to speed up performance, where ShardLength denotes
	// 1) the length of each directory shard's name and 2) the number of shards.
	// A value of 0 denotes no sharding.
	ShardLength int `yaml:"shard_length"`
}

Config configures Store.

type File

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

File represends an open file descriptor to a blob in Store.

func (*File) Cancel

func (f *File) Cancel() error

Cancel is supposed to remove any written content. In this implementation file is not actually removed, but rather closed, which is fine, as there won't be key collisions when creating new files.

func (*File) Close

func (f *File) Close() error

func (*File) Commit

func (f *File) Commit() error

Commit is supposed to flush all content for buffered writer.

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

func (*File) ReadAt

func (f *File) ReadAt(p []byte, off int64) (n int, err error)

func (*File) Seek

func (f *File) Seek(off int64, whence int) (int64, error)

func (*File) Size

func (f *File) Size() int64

Size returns the number of bytes the file contains.

func (*File) Write

func (f *File) Write(p []byte) (n int, err error)

func (*File) WriteAt

func (f *File) WriteAt(p []byte, off int64) (n int, err error)

type Store

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

Store is a key-value, persistent, thread-safe, LRU store for blobs and their metadata.Metadata.

  • Supports pagination of blobs during reading/writing, such that blobs don't need to be fully loaded into memory.

  • New blobs are considered 'incomplete', which unlists them from LRU eviction. The store can be scoped to work on only (in-)complete blobs.

  • All APIs are thread-safe. Parallel access to a single file is allowed but clients must ensure they don't intervene with one another.

  • Supports (un-)marking blobs as non-evictable (may be needed when that data must be written back to remote storage).

  • Crash-resistant - all state is restored upon restart (check [newStore] for details).

  • Supports directory sharding to speed up disk performance.

func NewStore

func NewStore(config *Config, stats tally.Scope) (*Store, error)

NewStore initializes a new *Store. If the store has been initialized in the same directory before, its state is recovered from disk with the following caveats:

  • `rebootIncompleteBlobs` configures whether incomplete blobs are evicted or rebooted on restart.

  • If the store's size is bigger than its capacity (e.g. configured capacity has been reduced or files have been leaked), it evicts blobs until size is within capacity.

func (*Store) BanEviction

func (s *Store) BanEviction(key string) error

BanEviction marks a blob as unevictable by LRU eviction. It is idempotent. Needed when e.g. blobs must be written back to GCS/S3 and eviction before that is unacceptable.

func (*Store) Clean

func (s *Store) Clean(targetUtilPercent int, respectEvictionBan bool) (newUtil int, err error)

Clean deletes blobs from the store until targetUtilPercent is hit. Intended for manual use for incident mitigation/benchmarking. Blobs are deleted in the following order:

  1. complete, non-eviction-banned blobs, in LRU order.
  2. incomplete, non-eviction-banned blobs, in a random order.
  3. If respectEvictionBan is true, Clean will not delete blobs banned from eviction. Else, it will delete them, in a random order.

func (*Store) Create

func (s *Store) Create(key string, sizeBytes uint64) (*File, error)

Create adds a new, incomplete blob to the store and reserves space for it. Incomplete entries cannot be automatically evicted. MarkComplete must be called once the blob is complete. The store uses `sizeBytes` for its eviction logic even if the blob's real size differs.

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete removes a blob and its metadata.Metadata from the store. Returns os.ErrNotExist on missing blob.

func (*Store) DeleteMetadata

func (s *Store) DeleteMetadata(key string, mdSuffix string) error

DeleteMetadata removes a blob's metadata. No error returned if the metadata is not present.

func (*Store) GetMetadata

func (s *Store) GetMetadata(key string, md metadata.Metadata) (ok bool, err error)

GetMetadata populates `md` if the metadata is present. Returns os.ErrNotExist if key is not in store.

func (*Store) Has

func (s *Store) Has(key string) (inStore bool, inScope bool)

Has checks if the blob is in the store.

func (*Store) List

func (s *Store) List() []string

List returns the keys of all blobs (except those out of scope).

func (*Store) ListMetadata

func (s *Store) ListMetadata(key string) ([]metadata.Metadata, error)

ListMetadata returns all metadata.Metadata of key.

func (*Store) MarkComplete

func (s *Store) MarkComplete(key string) error

MarkComplete marks a blob as fully written. It enlists the blob for LRU eviction (unless BanEviction has been called). Additionally, other store APIs may filter blobs based on completeness.

func (*Store) Open

func (s *Store) Open(key string) (*File, error)

Open returns an FD to a file in the store. os.ErrNotExist is returned on missing entry.

func (*Store) ScopeComplete

func (s *Store) ScopeComplete() *Store

ScopeComplete scopes Store's APIs such that they can only operate on complete blobs (except MarkComplete and Create). storelib.ErrOutOfScope is returned if the user tries to operate on an incomplete blob.

func (*Store) ScopeIncomplete

func (s *Store) ScopeIncomplete() *Store

ScopeIncomplete scopes Store's APIs such that they can only operate on incomplete blobs. storelib.ErrOutOfScope is returned if the user tries to operate on a complete blob.

func (*Store) Scoped

func (s *Store) Scoped(scope storelib.BlobScope) *Store

Scoped scopes Store's APIs, such that storelib.ErrOutOfScope is returned upon attempting to operate on blobs out of scope.

func (*Store) SetMetadata

func (s *Store) SetMetadata(key string, md metadata.Metadata) error

SetMetadata atomically sets the respective metadata for a blob.

func (*Store) Stat

func (s *Store) Stat(key string) (os.FileInfo, error)

Stat returns os.FileInfo about the blob. Returns os.ErrNotExist if the blob is not found.

func (*Store) UnbanEviction

func (s *Store) UnbanEviction(key string) error

UnbanEviction removes the effect of BanEviction for a blob. It is idempotent.

func (*Store) WriteAtMetadata

func (s *Store) WriteAtMetadata(key string, md metadata.Metadata, p []byte, off int64) error

WriteAtMetadata implements io.WriterAt for the metadata file on disk.

Jump to

Keyboard shortcuts

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