base

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2020 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultDataFileName = "data"

DefaultDataFileName is the name of the actual blob data file.

View Source
const DefaultDirPermission = 0775

DefaultDirPermission is the default permission for new directories.

View Source
const DefaultShardIDLength = 2

DefaultShardIDLength is the number of bytes of file digest to be used for shard ID. For every byte (2 HEX char), one more level of directories will be created.

Variables

View Source
var (
	ErrFilePersisted = errors.New("file is persisted")
)

FileEntry errors.

Functions

func IsFileStateError

func IsFileStateError(err error) bool

IsFileStateError returns true if the param is of FileStateError type.

Types

type Cleanup

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

Cleanup contains a list of function that are called to cleanup a fixture

func (*Cleanup) Add

func (c *Cleanup) Add(f ...func())

Add adds function to funcs list

func (*Cleanup) AppendFront

func (c *Cleanup) AppendFront(c1 *Cleanup)

AppendFront append funcs from another cleanup in front of the funcs list

func (*Cleanup) Recover

func (c *Cleanup) Recover()

Recover runs cleanup functions after test exit with exception

func (*Cleanup) Run

func (c *Cleanup) Run()

Run runs cleanup functions when a test finishes running

type FileEntry

type FileEntry interface {
	GetState() FileState
	GetName() string
	GetPath() string
	GetStat() (os.FileInfo, error)

	Create(targetState FileState, len int64) error
	Reload() error
	MoveFrom(targetState FileState, sourcePath string) error
	Move(targetState FileState) error
	LinkTo(targetPath string) error
	Delete() error

	GetReader() (FileReader, error)
	GetReadWriter() (FileReadWriter, error)

	AddMetadata(md metadata.Metadata) error

	GetMetadata(md metadata.Metadata) error
	SetMetadata(md metadata.Metadata) (bool, error)
	SetMetadataAt(md metadata.Metadata, b []byte, offset int64) (updated bool, err error)
	GetOrSetMetadata(md metadata.Metadata) error
	DeleteMetadata(md metadata.Metadata) error

	RangeMetadata(f func(md metadata.Metadata) error) error
}

FileEntry manages one file and its metadata. It doesn't guarantee thread-safety; That should be handled by FileMap.

type FileEntryFactory

type FileEntryFactory interface {
	// Create creates a file entry given a state directory and a name.
	// It calls GetRelativePath to generate the actual file path under given directory,
	Create(name string, state FileState) FileEntry

	// GetRelativePath returns the relative path for a file entry.
	// The path is relative to the state directory that file entry belongs to.
	// i.e. a file entry can have a relative path of 00/0e/filename under directory /var/cache/
	GetRelativePath(name string) string
}

FileEntryFactory initializes FileEntry obj.

func NewCASFileEntryFactory

func NewCASFileEntryFactory() FileEntryFactory

NewCASFileEntryFactory is the constructor for casFileEntryFactory.

func NewLocalFileEntryFactory

func NewLocalFileEntryFactory() FileEntryFactory

NewLocalFileEntryFactory is the constructor for localFileEntryFactory.

type FileMap

type FileMap interface {
	Contains(name string) bool
	TryStore(name string, entry FileEntry, f func(string, FileEntry) bool) bool
	LoadForWrite(name string, f func(string, FileEntry)) bool
	LoadForRead(name string, f func(string, FileEntry)) bool
	LoadForPeek(name string, f func(string, FileEntry)) bool
	Delete(name string, f func(string, FileEntry) bool) bool
}

FileMap is a thread-safe name -> FileEntry map.

func NewLATFileMap

func NewLATFileMap(clk clock.Clock) FileMap

NewLATFileMap creates a new file map that tracks last access time, but no auto-eviction.

func NewLRUFileMap

func NewLRUFileMap(size int, clk clock.Clock) FileMap

NewLRUFileMap creates a new LRU map given capacity.

type FileOp

type FileOp interface {
	AcceptState(state FileState) FileOp

	CreateFile(name string, createState FileState, len int64) error
	MoveFileFrom(name string, createState FileState, sourcePath string) error
	MoveFile(name string, goalState FileState) error
	LinkFileTo(name string, targetPath string) error
	DeleteFile(name string) error

	GetFilePath(name string) (string, error)
	GetFileStat(name string) (os.FileInfo, error)

	GetFileReader(name string) (FileReader, error)
	GetFileReadWriter(name string) (FileReadWriter, error)

	GetFileMetadata(name string, md metadata.Metadata) error
	SetFileMetadata(name string, md metadata.Metadata) (bool, error)
	SetFileMetadataAt(name string, md metadata.Metadata, b []byte, offset int64) (bool, error)
	GetOrSetFileMetadata(name string, md metadata.Metadata) error
	DeleteFileMetadata(name string, md metadata.Metadata) error
}

FileOp performs one file or metadata operation on FileStore, given a list of acceptable states.

func NewLocalFileOp

func NewLocalFileOp(s *localFileStore) FileOp

NewLocalFileOp inits a new FileOp obj.

type FileReadWriter

type FileReadWriter interface {
	FileReader
	io.Writer
	io.WriterAt
}

FileReadWriter provides read/write operation on a file.

type FileReader

type FileReader interface {
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Closer
}

FileReader provides read operation on a file.

type FileState

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

FileState decides what directory a file is in. A file can only be in one state at any given time.

func NewFileState

func NewFileState(directory string) FileState

NewFileState creates a new FileState for directory.

func (FileState) GetDirectory

func (s FileState) GetDirectory() string

GetDirectory returns the FileState's directory.

type FileStateError

type FileStateError struct {
	Op    string
	Name  string
	State FileState
	Msg   string
}

FileStateError represents errors related to file state. It's used when a file is not in the state it was supposed to be in.

func (*FileStateError) Error

func (e *FileStateError) Error() string

type FileStore

type FileStore interface {
	NewFileOp() FileOp
}

FileStore manages files and their metadata. Actual operations are done through FileOp.

func NewCASFileStore

func NewCASFileStore(clk clock.Clock) FileStore

NewCASFileStore initializes and returns a new Content-Addressable FileStore. It uses the first few bytes of file digest (which is also used as file name) as shard ID. For every byte, one more level of directories will be created.

func NewLRUFileStore

func NewLRUFileStore(size int, clk clock.Clock) FileStore

NewLRUFileStore initializes and returns a new LRU FileStore. When size exceeds limit, the least recently accessed entry will be removed.

func NewLocalFileStore

func NewLocalFileStore(clk clock.Clock) FileStore

NewLocalFileStore initializes and returns a new FileStore.

Jump to

Keyboard shortcuts

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