dsstate

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2019 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package dsstate implements the IPFS Cluster state interface using an underlying go-datastore.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHandle

func DefaultHandle() codec.Handle

DefaultHandle returns the codec handler of choice (Msgpack).

Types

type State

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

State implements the IPFS Cluster "state" interface by wrapping a go-datastore and choosing how api.Pin objects are stored in it. It also provides serialization methods for the whole state which are datastore-independent.

func New

func New(dstore ds.Datastore, namespace string, handle codec.Handle) (*State, error)

New returns a new state using the given datastore.

All keys are namespaced with the given string when written. Thus the same go-datastore can be sharded for different uses.

The Handle controls options for the serialization of items and the state itself.

func (*State) Add

func (st *State) Add(ctx context.Context, c *api.Pin) error

Add adds a new Pin or replaces an existing one.

func (*State) Get

func (st *State) Get(ctx context.Context, c cid.Cid) (*api.Pin, bool)

Get returns a Pin from the store and whether it was present. When not present, a default pin is returned.

func (*State) GetVersion

func (st *State) GetVersion() int

GetVersion returns the current state version.

func (*State) Has

func (st *State) Has(ctx context.Context, c cid.Cid) bool

Has returns whether a Cid is stored.

func (*State) List

func (st *State) List(ctx context.Context) []*api.Pin

List returns the unsorted list of all Pins that have been added to the datastore.

func (*State) Marshal

func (st *State) Marshal(w io.Writer) error

Marshal dumps the state to a writer. It does this by encoding every key/value in the store. The keys are stored without the namespace part to reduce the size of the snapshot.

func (*State) Migrate

func (st *State) Migrate(ctx context.Context, r io.Reader) error

Migrate migrates an older state version to the current one. This is a no-op for now.

func (*State) Rm

func (st *State) Rm(ctx context.Context, c cid.Cid) error

Rm removes an existing Pin. It is a no-op when the item does not exist.

func (*State) SetVersion

func (st *State) SetVersion(v int) error

SetVersion allows to manually modify the state version.

func (*State) Unmarshal

func (st *State) Unmarshal(r io.Reader) error

Unmarshal reads and parses a previous dump of the state. All the parsed key/values are added to the store. As of now, Unmarshal does not empty the existing store from any values before unmarshaling from the given reader.

Jump to

Keyboard shortcuts

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