store

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCheckpointNotFound = fmt.Errorf("checkpoint is not found")

ErrCheckpointNotFound is reported when checkpoint is not found for a given key

View Source
var ErrCorruptCheckpoint = fmt.Errorf("checkpoint is corrupted")

ErrCorruptCheckpoint error is reported when checksum does not match

View Source
var (

	// ErrKeyNotFound is the error returned if key is not found in Store.
	ErrKeyNotFound = fmt.Errorf("key is not found")
)

Functions

func ValidateKey

func ValidateKey(key string) error

ValidateKey returns an error if the given key does not meet the requirement of the key format and length.

Types

type Checkpoint

type Checkpoint interface {
	MarshalCheckpoint() ([]byte, error)
	UnmarshalCheckpoint(blob []byte) error
	VerifyChecksum() error
}

Checkpoint provides the process checkpoint data

type CheckpointManager

type CheckpointManager interface {
	// CreateCheckpoint persists checkpoint in CheckpointStore. checkpointKey is the key for utilstore to locate checkpoint.
	// For file backed utilstore, checkpointKey is the file name to write the checkpoint data.
	CreateCheckpoint(checkpointKey string, checkpoint Checkpoint) error
	// GetCheckpoint retrieves checkpoint from CheckpointStore.
	GetCheckpoint(checkpointKey string, checkpoint Checkpoint) error
	// WARNING: RemoveCheckpoint will not return error if checkpoint does not exist.
	RemoveCheckpoint(checkpointKey string) error
	// ListCheckpoint returns the list of existing checkpoints.
	ListCheckpoints() ([]string, error)
}

CheckpointManager provides the interface to manage checkpoint

func NewCheckpointManager

func NewCheckpointManager(checkpointDir string) (CheckpointManager, error)

NewCheckpointManager returns a new instance of a checkpoint manager

type Checksum

type Checksum uint64

Checksum is the data to be stored as checkpoint

func NewChecksum

func NewChecksum(data interface{}) Checksum

NewChecksum returns the Checksum of checkpoint data

func (Checksum) Verify

func (cs Checksum) Verify(data interface{}) error

Verify verifies that passed checksum is same as calculated checksum

type DefaultFs

type DefaultFs struct{}

DefaultFs implements Filesystem using same-named functions from "os" and "io/ioutil"

func (DefaultFs) Chtimes

func (DefaultFs) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes via os.Chtimes

func (DefaultFs) Create

func (DefaultFs) Create(name string) (File, error)

Create via os.Create

func (DefaultFs) MkdirAll

func (DefaultFs) MkdirAll(path string, perm os.FileMode) error

MkdirAll via os.MkdirAll

func (DefaultFs) ReadDir

func (DefaultFs) ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir via ioutil.ReadDir

func (DefaultFs) ReadFile

func (DefaultFs) ReadFile(filename string) ([]byte, error)

ReadFile via ioutil.ReadFile

func (DefaultFs) Remove

func (DefaultFs) Remove(name string) error

Remove via os.RemoveAll

func (DefaultFs) RemoveAll

func (DefaultFs) RemoveAll(path string) error

RemoveAll via os.RemoveAll

func (DefaultFs) Rename

func (DefaultFs) Rename(oldpath, newpath string) error

Rename via os.Rename

func (DefaultFs) Stat

func (DefaultFs) Stat(name string) (os.FileInfo, error)

Stat via os.Stat

func (DefaultFs) TempDir

func (DefaultFs) TempDir(dir, prefix string) (string, error)

TempDir via ioutil.TempDir

func (DefaultFs) TempFile

func (DefaultFs) TempFile(dir, prefix string) (File, error)

TempFile via ioutil.TempFile

func (DefaultFs) Walk

func (DefaultFs) Walk(root string, walkFn filepath.WalkFunc) error

Walk via filepath.Walk

type File

type File interface {
	// for now, the only os.File methods used are those below, add more as necessary
	Name() string
	Write(b []byte) (n int, err error)
	Sync() error
	Close() error
}

File is an interface that we can use to mock various filesystem operations typically accessed through the File object from the "os" package

type FileStore

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

FileStore is an implementation of the Store interface which stores data in files.

func (*FileStore) Delete

func (f *FileStore) Delete(key string) error

Delete deletes the key file.

func (*FileStore) List

func (f *FileStore) List() ([]string, error)

List returns all keys in the store.

func (*FileStore) Read

func (f *FileStore) Read(key string) ([]byte, error)

Read reads the data from the file named key.

func (*FileStore) Write

func (f *FileStore) Write(key string, data []byte) error

Write writes the given data to a file named key.

type Filesystem

type Filesystem interface {
	// from "os"
	Stat(name string) (os.FileInfo, error)
	Create(name string) (File, error)
	Rename(oldpath, newpath string) error
	MkdirAll(path string, perm os.FileMode) error
	Chtimes(name string, atime time.Time, mtime time.Time) error
	RemoveAll(path string) error
	Remove(name string) error

	// from "io/ioutil"
	ReadFile(filename string) ([]byte, error)
	TempDir(dir, prefix string) (string, error)
	TempFile(dir, prefix string) (File, error)
	ReadDir(dirname string) ([]os.FileInfo, error)
	Walk(root string, walkFn filepath.WalkFunc) error
}

Filesystem is an interface that we can use to mock various filesystem operations

type Store

type Store interface {
	// key must contain one or more characters in [A-Za-z0-9]
	// Write writes data with key.
	Write(key string, data []byte) error
	// Read retrieves data with key
	// Read must return ErrKeyNotFound if key is not found.
	Read(key string) ([]byte, error)
	// Delete deletes data by key
	// Delete must not return error if key does not exist
	Delete(key string) error
	// List lists all existing keys.
	List() ([]string, error)
}

Store provides the interface for storing keyed data. Store must be thread-safe

func NewFileStore

func NewFileStore(path string, fs Filesystem) (Store, error)

NewFileStore returns an instance of FileStore.

Jump to

Keyboard shortcuts

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