dsstate

package
v0.0.0-...-8c384fb Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2023 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 14 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 BatchingState

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

BatchingState implements the IPFS Cluster "state" interface by wrapping a batching go-datastore. All writes are batched and only written disk when Commit() is called.

func NewBatching

func NewBatching(ctx context.Context, dstore ds.Batching, namespace string, handle codec.Handle) (*BatchingState, error)

NewBatching returns a new batching statate 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 the full state (marshaling/unmarshaling).

func (*BatchingState) Commit

func (bst *BatchingState) Commit(ctx context.Context) error

Commit persists the batched write operations.

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(ctx context.Context, 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 the full state (marshaling/unmarshaling).

func (*State) Add

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

Add adds a new Pin or replaces an existing one.

func (*State) Get

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

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

func (*State) Has

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

Has returns whether a Cid is stored.

func (*State) List

func (st *State) List(ctx context.Context, out chan<- api.Pin) error

List sends all the pins on the pinset on the given channel. Returns and closes channel when done.

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 api.Cid) error

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

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