Documentation
¶
Overview ¶
Package crdt provides a replicated go-datastore implementation using Merkle-CRDTs built with IPLD nodes. This Datastore is agnostic to how new MerkleDAG roots are broadcasted to the rest of replicas (Broadcaster component) and to how the IPLD nodes are made discoverable and retrievable to by other replicas (DAG-Syncer component).
Index ¶
- Variables
- type Broadcaster
- type DAGSyncer
- type Datastore
- func (store *Datastore) Batch() (ds.Batch, error)
- func (store *Datastore) Close() error
- func (store *Datastore) Delete(key ds.Key) error
- func (store *Datastore) Get(key ds.Key) (value []byte, err error)
- func (store *Datastore) GetSize(key ds.Key) (size int, err error)
- func (store *Datastore) Has(key ds.Key) (exists bool, err error)
- func (store *Datastore) IsThreadSafe()
- func (store *Datastore) PrintDAG() error
- func (store *Datastore) Put(key ds.Key, value []byte) error
- func (store *Datastore) Query(q query.Query) (query.Results, error)
- type Options
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoMoreBroadcast = errors.New("receiving blocks aborted since no new blocks will be broadcasted")
)
Common errors.
Functions ¶
This section is empty.
Types ¶
type Broadcaster ¶
type Broadcaster interface {
// Send payload to other replicas.
Broadcast([]byte) error
// Obtain the next payload received from the network.
Next() ([]byte, error)
}
A Broadcaster provides a way to send (notify) an opaque payload to all replicas and to retrieve payloads broadcasted.
type DAGSyncer ¶
type DAGSyncer interface {
ipld.DAGService
// Returns true if the block is locally available (therefore, it
// is considered processed).
IsKnownBlock(c cid.Cid) (bool, error)
}
A DAGSyncer is an abstraction to an IPLD-based p2p storage layer. A DAGSyncer is a DAGService with the ability to publish new ipld nodes to the network, and retrieving others from it.
type Datastore ¶
type Datastore struct {
// contains filtered or unexported fields
}
Datastore makes a go-datastore a distributed Key-Value store using Merkle-CRDTs and IPLD.
func New ¶
func New( store ds.Datastore, namespace ds.Key, dagSyncer DAGSyncer, bcast Broadcaster, opts *Options, ) *Datastore
New returns a Merkle-CRDT-based Datastore using the given one to persist all the necessary data under the given namespace. It needs a DAG-Syncer component for IPLD nodes and a Broadcaster component to distribute and receive information to and from the rest of replicas. Actual implementation of these must be provided by the user.
func (*Datastore) Batch ¶
Batch implements batching for writes by accumulating Put and Delete in the same CRDT-delta and only applying it and broadcasting it on Commit().
func (*Datastore) Get ¶
Get retrieves the object `value` named by `key`. Get will return ErrNotFound if the key is not mapped to a value.
func (*Datastore) GetSize ¶
GetSize returns the size of the `value` named by `key`. In some contexts, it may be much cheaper to only get the size of the value rather than retrieving the value itself.
func (*Datastore) Has ¶
Has returns whether the `key` is mapped to a `value`. In some contexts, it may be much cheaper only to check for existence of a value, rather than retrieving the value itself. (e.g. HTTP HEAD). The default implementation is found in `GetBackedHas`.
func (*Datastore) IsThreadSafe ¶
func (store *Datastore) IsThreadSafe()
IsThreadSafe declares that this datastore implementation is thread-safe.
func (*Datastore) PrintDAG ¶
PrintDAG pretty prints the current Merkle-DAG using the given printFunc
func (*Datastore) Query ¶
Query searches the datastore and returns a query result. This function may return before the query actually runs. To wait for the query:
result, _ := ds.Query(q)
// use the channel interface; result may come in at different times
for entry := range result.Next() { ... }
// or wait for the query to be completely done
entries, _ := result.Rest()
for entry := range entries { ... }
type Options ¶
type Options struct {
Logger logging.StandardLogger
RebroadcastInterval time.Duration
}
Options holds configurable values for Datastore.
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions initializes an Options object with sensible defaults.