replica

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store is a blob store that delegates reads and writes to two sets of nested stores. One set is synchronous: writes to all of these must succeed before a call to Put returns, and an error from any will cause Put to fail. The other set is asynchronous: a call to Put queues writes on these stores but does not wait for them to finish. However, if any asynchronous write encounters an error, the whole Store is put into an error state and further operations will fail.

func New

func New(ctx context.Context, sync []bs.Store, async []bs.Store, n int) *Store

New produces a new Store. The set of synchronous stores must be non-empty. The set of asynchronous stores may be empty. If there are any asynchronous stores, goroutines are launched for them, and canceling the given context object causes those to exit, placing the Store in an error state.

Normally, writes to asynchronous stores do not block calls to Put, but the queue for each nested store has a fixed length given by n, which must be 1 or greater. If any async store falls too far behind, Put will block until all requests can be queued.

func (*Store) Get

func (s *Store) Get(ctx context.Context, ref bs.Ref) (bs.Blob, error)

Get implements bs.Getter. It delegates the request to all of the synchronous stores in s. returning the result from the first one to respond without error and canceling the request to the others. If all synchronous stores respond with an error, one of those errors is returned.

func (*Store) ListRefs

func (s *Store) ListRefs(ctx context.Context, start bs.Ref, f func(bs.Ref) error) error

ListRefs implements bs.Getter. It delegates the request to all of the synchronous stores in s and synthesizes the result from the union of their refs.

func (*Store) Put

func (s *Store) Put(ctx context.Context, blob bs.Blob) (bs.Ref, bool, error)

Put implements bs.Store.Put. The blob is stored in all synchronous nested stores. An error from any of them causes Put to return an error.

Some nested stores may already have the blob and others may not, in which case the value of `added` (the boolean return value) is indeterminate. (It is determined by the first nested store to finish.)

A request to write the blob is queued for any asynchronous nested stores. Normally this does not block the call to Put, but if any async store falls too far behind, Put must wait for space to open in its request queue before proceeding. The size of this queue is given by the int passed to New.

Jump to

Keyboard shortcuts

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