datastore

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 9, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const NamespaceBytes = 4

NamespaceBytes is the byte length of a namespace

Variables

View Source
var ErrInvalidNamespaceLength = errors.New("Namespace identifier does not have the right length")

ErrInvalidNamespaceLength indicates that a namespace identifier is used which does not have the correct length according to the NamespaceBytes

Functions

This section is empty.

Types

type DataStore

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

DataStore pulls arbitrary data, stored in transactions, from the blockchain, and saves it in a connected database

func New

func New(cs modules.ConsensusSet, db Database, persistDir string, bcInfo types.BlockchainInfo, chainCts types.ChainConstants) (*DataStore, error)

New creates a new DataStore from a consensus set and a Database. If the connection opts specify an unknown driver, initialization fails and an error is returned. Currently only `redis` is supported

func (*DataStore) Close

func (ds *DataStore) Close() error

Close closes the datastore, all namespace managers, and finally its connection to the database

type Database

type Database interface {
	// Ping tests the database connection
	Ping() error
	// StoreData stores the specified data, linked to a key and a field in that key
	// Multiple section of data must be storeable for the same key. The field is unique
	// for the key, but other keys might have the same fields for different data
	StoreData(string, string, []byte) error
	// DeleteData removes the data specified by the key and field.
	DeleteData(string, string) error
	// LoadFieldsForKey loads a mapping of all fields and the associated data for a given key
	LoadFieldsForKey(string) (map[string][]byte, error)
	// Subscribe continuously manages a channel for messages
	// Subscribe(SubEventCallback)
	Subscribe(chan<- *SubEvent)
	// Unsubscribe ends the subscription to the message channel and closes the
	// event channel provided by the subscribe function
	Unsubscribe() error
	// Close gracefully closes the database connection
	Close() error
}

Database is the common interface which must be implemented to be compatible with the datastore

type Namespace

type Namespace [NamespaceBytes]byte

Namespace is an identifier used to group data written on the blockchain when it is replicated to external storage

func (*Namespace) LoadString

func (ns *Namespace) LoadString(nsString string) error

LoadString tries to convert a string representation of a namespace into the corresponding bytes

func (*Namespace) String

func (ns *Namespace) String() string

String convets the Namespace to a string representation

type Redis

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

Redis wraps a redis connection

func NewRedis

func NewRedis(addr, password string, db int, persistDir string, bcInfo types.BlockchainInfo) (*Redis, error)

NewRedis creates a new redis struct which attempts to connect to the specified DB/instance The connection always used tcp

func (*Redis) Close

func (rd *Redis) Close() error

Close gracefully closes the database connection

func (*Redis) DeleteData

func (rd *Redis) DeleteData(key string, field string) error

DeleteData removes data from an HSET

func (*Redis) LoadFieldsForKey

func (rd *Redis) LoadFieldsForKey(key string) (map[string][]byte, error)

LoadFieldsForKey returns all field-value mappings in an HSET defined by key

func (*Redis) Ping

func (rd *Redis) Ping() error

Ping checks the connection to the database by sending a ping

func (*Redis) StoreData

func (rd *Redis) StoreData(key string, field string, data []byte) error

StoreData stores data in an HSET

func (*Redis) Subscribe

func (rd *Redis) Subscribe(seChan chan<- *SubEvent)

Subscribe starts a subscription to the replication channel. Once the subscribtion ends after a call to Unsubscribe, the channel is also closed

func (*Redis) Unsubscribe

func (rd *Redis) Unsubscribe() error

Unsubscribe stops the subsciption on the replication channel

type SubAction

type SubAction string

SubAction is the action which must be done for a subscription

const (
	// SubStart indicates that a new subscribtion must begin, with an optional
	// starttime indicating the earliest block which must be tracked
	SubStart SubAction = "start"
	// SubEnd indicates that a subscription ends immediatly
	SubEnd SubAction = "end"
)

The actions which can be passed through a channel

type SubEvent

type SubEvent struct {
	Action    SubAction
	Namespace Namespace
	Start     types.Timestamp // Optional starttime
}

SubEvent has some details regarding an event which has been received

Jump to

Keyboard shortcuts

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