storage

package
v0.0.0-...-c447958 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("not found")
	ErrNotImplemented = errors.New("not implemented")
)
View Source
var ErrNotHashPointer = errors.New("not hash pointer")
View Source
var ErrReadOnly = errors.New("read-only store")
View Source
var Null = Pointer(nil)

Null is the hash pointer that can't be resolved.

Functions

This section is empty.

Types

type DeleteArgs

type DeleteArgs struct {
	Key Key
}

type DeleteReply

type DeleteReply struct{}

type DiskStore

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

func NewDiskStore

func NewDiskStore(dir string) *DiskStore

func (*DiskStore) Contains

func (s *DiskStore) Contains(k Key) (bool, error)

func (*DiskStore) Delete

func (s *DiskStore) Delete(k Key) error

func (*DiskStore) ForEach

func (s *DiskStore) ForEach(cb func(Key) error) error

func (*DiskStore) Get

func (s *DiskStore) Get(k Key) (Value, error)

func (*DiskStore) Put

func (s *DiskStore) Put(k Key, v Value) error

type Enumerable

type Enumerable interface {
	Store
	// TODO: "Contains" does not pertain to an Enumerable entity. Also, can we prevent embedding the Store?
	Contains(Key) (bool, error)
	ForEach(func(Key) error) error
}

type GetArgs

type GetArgs struct {
	Key Key
}

type GetReply

type GetReply struct {
	Value []byte
}

type InMemory

type InMemory struct {
	sync.Mutex
	// contains filtered or unexported fields
}

InMemory implements Store, meant to be used in unit tests in other packages.

func (*InMemory) Delete

func (s *InMemory) Delete(k Key) error

func (*InMemory) Get

func (s *InMemory) Get(k Key) (Value, error)

func (*InMemory) Put

func (s *InMemory) Put(k Key, v Value) error

type Key

type Key string

type Lister

type Lister interface {
	// TODO: This interface is strange; how can the error be known right away, but the
	// keys are progressively written to the channel? Isn't it possible to encounter an error
	// after List() returns, e.g., paginating results sets?
	List() (keys chan string, err error)
}

type NullStore

type NullStore struct{}

func (NullStore) Contains

func (NullStore) Contains(Key) (bool, error)

func (NullStore) Delete

func (NullStore) Delete(Key) error

func (NullStore) ForEach

func (NullStore) ForEach(func(Key) error) error

func (NullStore) Get

func (NullStore) Get(Key) (Value, error)

func (NullStore) Put

func (NullStore) Put(Key, Value) error

type Paired

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

Paired is a store implementation that is meant to provide the benefits of a fast local store and long term persistence and accessibility of cloud storage. Paired writes to the fast store and queues async writes to the slow store. It reads from the fast store if possible. If not, reads from the slow store and copies content to the fast store for next time. It deletes from the slow store first and then from the fast store.

func NewPaired

func NewPaired(fast, slow Store, logPath string) (p *Paired, err error)

NewPaired creates a write-back cache from fast to slow. If the log path is empty, the cache is read-only and puts will fail.

func (*Paired) Delete

func (p *Paired) Delete(k Key) error

Delete deletes an item from the slow store first, then from the fast store second. Note that if done in the other order, a concurrent Get could replenish the fast store from the slow store after the deletion, e.g., (1) delete from fast, (2) get from slow, (3) replenish fast, (4) delete from slow. Steps (1) and (4) belong to this method while (2) and (3) belong to Get.

func (*Paired) EnsureBackgroundPuts

func (p *Paired) EnsureBackgroundPuts()

func (*Paired) Get

func (p *Paired) Get(k Key) (v Value, err error)

func (*Paired) Notify

func (s *Paired) Notify()

func (*Paired) Put

func (p *Paired) Put(k Key, v Value) error

Put writes an item to the fast store and enqueues it to be written to the slow store asynchronously. Might block if the async write queue is full. Since this operation is used by the code creating a new revision, triggered by "echo snapshot > ctl", this in turn might block the fileserver entirely for the duration of the snapshot. This hasn't happened to me in practice. Could probably use the underlying filesystem as queue (e.g., hard or symbolic links) but that leads to assuming a disk store implementation and I don't want to.

type Pointer

type Pointer []byte

Pointer is the SHA-256 of some blob stored somewhere. In that sense, it points to that blob.

func NewPointer

func NewPointer(b []byte) Pointer

NewPointer is the inverse function to the Bytes method. This should be used in unpacking from storage. We don't own the passed slice so we'll make a copy.

func NewPointerFromHex

func NewPointerFromHex(hexDigits string) (Pointer, error)

NewPointerFromHex interprets a hex string as a hash pointer.

func PointerTo

func PointerTo(value []byte) Pointer

func RandomPointer

func RandomPointer() Pointer

RandomPointer returns a hash pointer that does not point to anything known. It is used to assign an initial key to a brand new child node.

func (Pointer) Bytes

func (p Pointer) Bytes() []byte

Bytes returns the hash pointer as a byte slice rather than a hex string, so it's as small as possible. This should be used in packing to storage. It should be treated as read-only, we own the byte slice.

func (Pointer) Equals

func (p Pointer) Equals(q Pointer) bool

func (Pointer) Hex

func (p Pointer) Hex() string

Hex returns the hex representation of the bytes making up the hash pointer (32 bytes, therefore 64 characters).

func (Pointer) IsNull

func (p Pointer) IsNull() bool

IsNull should be used instead of making explicit comparisons with Null.

func (Pointer) Key

func (p Pointer) Key() Key

func (Pointer) Len

func (p Pointer) Len() uint8

func (Pointer) String

func (p Pointer) String() string

func (Pointer) Value

func (p Pointer) Value() interface{}

type PutArgs

type PutArgs struct {
	Key   Key
	Value Value
}

type PutReply

type PutReply struct{}

type RemoteStore

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

RemoteStore implements Store by calling a remote endpoint serving a StoreService using net/rpc.

func NewRemoteStore

func NewRemoteStore(network, address string) (*RemoteStore, error)

func (*RemoteStore) Delete

func (s *RemoteStore) Delete(key Key) error

func (*RemoteStore) Get

func (s *RemoteStore) Get(key Key) (Value, error)

func (*RemoteStore) Put

func (s *RemoteStore) Put(key Key, value Value) error

type Store

type Store interface {
	Get(Key) (Value, error)
	Put(Key, Value) error
	Delete(Key) error
}

func NewStore

func NewStore(c *config.C) (Store, error)

type StoreService

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

StoreService wraps a Store implementation for use in a net/rpc client-server application.

func NewStoreService

func NewStoreService(delegate Store) *StoreService

func (*StoreService) Delete

func (s *StoreService) Delete(args DeleteArgs, reply *DeleteReply) error

func (*StoreService) Get

func (s *StoreService) Get(args GetArgs, reply *GetReply) error

func (*StoreService) Put

func (s *StoreService) Put(args PutArgs, reply *PutReply) error

type Value

type Value []byte

Jump to

Keyboard shortcuts

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