Documentation ¶
Index ¶
- Variables
- func ValidateKey(key string) error
- type Checkpoint
- type CheckpointManager
- type Checksum
- type DefaultFs
- func (DefaultFs) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (DefaultFs) Create(name string) (File, error)
- func (DefaultFs) MkdirAll(path string, perm os.FileMode) error
- func (DefaultFs) ReadDir(dirname string) ([]os.FileInfo, error)
- func (DefaultFs) ReadFile(filename string) ([]byte, error)
- func (DefaultFs) Remove(name string) error
- func (DefaultFs) RemoveAll(path string) error
- func (DefaultFs) Rename(oldpath, newpath string) error
- func (DefaultFs) Stat(name string) (os.FileInfo, error)
- func (DefaultFs) TempDir(dir, prefix string) (string, error)
- func (DefaultFs) TempFile(dir, prefix string) (File, error)
- func (DefaultFs) Walk(root string, walkFn filepath.WalkFunc) error
- type File
- type FileStore
- type Filesystem
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrCheckpointNotFound = fmt.Errorf("checkpoint is not found")
ErrCheckpointNotFound is reported when checkpoint is not found for a given key
var ErrCorruptCheckpoint = fmt.Errorf("checkpoint is corrupted")
ErrCorruptCheckpoint error is reported when checksum does not match
var ( // ErrKeyNotFound is the error returned if key is not found in Store. ErrKeyNotFound = fmt.Errorf("key is not found") )
Functions ¶
func ValidateKey ¶
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
type DefaultFs ¶
type DefaultFs struct{}
DefaultFs implements Filesystem using same-named functions from "os" and "io/ioutil"
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.
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.