keyvalue

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseFileRecord

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

BaseFileRecord is a FileRecord with a convenient constructor for easier Store implementations.

func NewBaseFileRecord

func NewBaseFileRecord(
	initialSize int64,
	modTime time.Time,
	mode hackpadfs.FileMode,
	sys interface{},
	getData func() (blob.Blob, error),
	getDirNames func() ([]string, error),
) *BaseFileRecord

NewBaseFileRecord returns a new BaseFileRecord for the given file's metadata and getters. getData and getDirNames may be set to nil if not applicable to this file's type.

Initial size is the currently known byte size of the record. This value is used for optimized Stat() calls. Sys may be set to nil, it's returned as the result of FileInfo.Sys(). 'getData' must return the contents of the file or an error if retrieval fails, but may be nil if this is a directory. 'getDirNames' must return this directory's child names, but may be nil if this is a regular file.

func (*BaseFileRecord) Data

func (b *BaseFileRecord) Data() (blob.Blob, error)

Data implements keyvalue.FileRecord

func (*BaseFileRecord) ModTime

func (b *BaseFileRecord) ModTime() time.Time

ModTime implements keyvalue.FileRecord

func (*BaseFileRecord) Mode

func (b *BaseFileRecord) Mode() hackpadfs.FileMode

Mode implements keyvalue.FileRecord

func (*BaseFileRecord) ReadDirNames

func (b *BaseFileRecord) ReadDirNames() ([]string, error)

ReadDirNames implements keyvalue.FileRecord

func (*BaseFileRecord) Size

func (b *BaseFileRecord) Size() int64

Size implements keyvalue.FileRecord

func (*BaseFileRecord) Sys

func (b *BaseFileRecord) Sys() interface{}

Sys implements keyvalue.FileRecord

type FS

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

FS wraps a Store as a file system.

func NewFS

func NewFS(store Store) (*FS, error)

NewFS returns a new FS wrapping the given 'store'.

func (*FS) Chmod

func (fs *FS) Chmod(name string, mode hackpadfs.FileMode) error

Chmod implements hackpadfs.ChmodFS

func (*FS) Chtimes

func (fs *FS) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes implements hackpadfs.ChtimesFS

func (*FS) Mkdir

func (fs *FS) Mkdir(name string, perm hackpadfs.FileMode) error

Mkdir implements hackpadfs.MkdirFS

func (*FS) MkdirAll

func (fs *FS) MkdirAll(path string, perm hackpadfs.FileMode) error

MkdirAll implements hackpadfs.MkdirAllFS

func (*FS) Open

func (fs *FS) Open(name string) (hackpadfs.File, error)

Open implements hackpadfs.FS

func (*FS) OpenFile

func (fs *FS) OpenFile(name string, flag int, perm hackpadfs.FileMode) (afFile hackpadfs.File, retErr error)

OpenFile implements hackpadfs.OpenFileFS

func (*FS) Remove

func (fs *FS) Remove(name string) error

Remove implements hackpadfs.RemoveFS

func (*FS) Rename

func (fs *FS) Rename(oldname, newname string) error

Rename implements hackpadfs.RenameFS

func (*FS) Stat

func (fs *FS) Stat(name string) (hackpadfs.FileInfo, error)

Stat implements hackpadfs.StatFS

type FileRecord

type FileRecord interface {
	// Data returns the Blob representing a copy of this file's contents. Returns an error if file is a directory.
	Data() (blob.Blob, error)
	// ReadDir returns this file's directory entries. Returns an error if not a directory or failed during retrieval.
	ReadDirNames() ([]string, error)
	// Size returns the number of bytes in this file's contents.
	// May return the size at initial fetch time, rather than at call time.
	Size() int64
	// Mode returns this file's FileMode.
	Mode() hackpadfs.FileMode
	// ModTime returns this file's last modified time.
	ModTime() time.Time
	// Sys returns the underlying data source (can return nil)
	Sys() interface{}
}

FileRecord represents a file inside a Store. A FileRecord's receivers may only be called once and their return values cached by the wrapping FS. Therefore, each receiver must return consistent values unless otherwise specified.

NOTE: Does not require retrieving the file's name. The name can be stored separately to simplify your store.

type OpHandler

type OpHandler interface {
	Handle(txn Transaction, result OpResult) error
}

OpHandler processes 'result' during the commit process of 'txn'. If the transaction should not proceed, the handler should call txn.Abort().

type OpHandlerFunc

type OpHandlerFunc func(txn Transaction, result OpResult) error

OpHandlerFunc is a convenient func wrapper for implementing OpHandler

func (OpHandlerFunc) Handle

func (o OpHandlerFunc) Handle(txn Transaction, result OpResult) error

Handle implements OpHandler

type OpID

type OpID int64

OpID is a unique ID within the transaction that generated it. It's used to correlate which Get/Set operation produced which result.

type OpResult

type OpResult struct {
	Op     OpID
	Record FileRecord
	Err    error
}

OpResult is returned from Transaction.Commit(), representing an operation's result with any data or error it produced.

type Store

type Store interface {
	// Get retrieves a file record for the given 'path'.
	// Returns an error if the path was not found or could not be retrieved.
	// If the path was not found, the error must satisfy errors.Is(err, hackpadfs.ErrNotExist).
	Get(ctx context.Context, path string) (FileRecord, error)
	// Set assigns 'src' to the given 'path'. Returns an error if the data could not be set.
	Set(ctx context.Context, path string, src FileRecord) error
}

Store holds arbitrary file data at the given 'path' location. Can be wrapped as a file system with keyvalue.NewFS().

type Transaction

type Transaction interface {
	Get(path string) OpID
	GetHandler(path string, handler OpHandler) OpID
	Set(path string, src FileRecord, contents blob.Blob) OpID
	SetHandler(path string, src FileRecord, contents blob.Blob, handler OpHandler) OpID
	Commit(ctx context.Context) ([]OpResult, error)
	Abort() error
}

Transaction behaves like a Store but only returns results after running Commit(). GetHandler and SetHandler can be used to interrupt transaction processing and handle the response, permitting an opportunity to Abort() or perform more operations.

func TransactionOrSerial

func TransactionOrSerial(store Store, options TransactionOptions) (Transaction, error)

TransactionOrSerial attempts to produce a Transaction from 'store'. If unsupported, returns an unsafe transaction instead, which runs each action serially without transactional safety.

This is used in FS to attempt transactions whenever possible. Since some Stores don't need transactions, they aren't required to implement TransactionStore.

type TransactionMode

type TransactionMode int

TransactionMode is the kind of transaction mode, i.e. read-only or read-write

const (
	TransactionReadOnly TransactionMode = iota
	TransactionReadWrite
)

Transaction modes

type TransactionOptions

type TransactionOptions struct {
	Mode TransactionMode
}

TransactionOptions contain options used to construct a Transaction from a Store

type TransactionStore

type TransactionStore interface {
	Store
	Transaction(options TransactionOptions) (Transaction, error)
}

TransactionStore is a Store that can create a Transaction.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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