db

package
v0.0.0-...-dab54ce Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2017 License: LGPL-3.0 Imports: 20 Imported by: 7

Documentation

Overview

Package db provides main consensus and data processing engines.

Index

Constants

View Source
const (
	ParallelTypeDEFAULT           ParallelType = 0x01
	ParallelTypeDISALLOWDIFFERENT              = 0x02
	ParallelTypeDISALLOWEQUAL                  = 0x04
)

Definition for ParallelType. Each flag may be combined using bitwise operators.

View Source
const InternalKeyPrefix = "__internal"

InternalKeyPrefix is used to discriminate internal keys.

Variables

View Source
var (
	ErrDeadlineExpired        = errors.New("unable to endorse a spore with expired deadline")
	ErrConflictingWithStaging = errors.New("unable to endorse a spore due to conflicting promise")
	ErrBehindRequirement      = errors.New("unable to endorse a spore due to unfulfillable requirement")

	ErrNoRelatedSpore        = errors.New("unable to find related spore")
	ErrDuplicatedEndorsement = errors.New("duplicated endorsement")
	ErrUnallowedEndorser     = errors.New("unallowed endorser")

	ErrGracePeriodExpired    = errors.New("unable to apply a spore with expired grace period")
	ErrDuplicatedApplication = errors.New("duplicated application")
)

Error messages

View Source
var (
	ErrUnknownPolicy       = errors.New("the requested policy is unknown")
	ErrOpTooLarge          = errors.New("the requested operation is too large for the policy")
	ErrOpNotAllowed        = errors.New("the requested operation is not allowed by the policy")
	ErrOpDisabledKey       = errors.New("the requested key is not modifiable according to the policy")
	ErrPolicyQuotaExceeded = errors.New("unable to endorse a spore due to policy quota reached")
	ErrOpSystemKey         = errors.New("the requested key has been reserved for internal use")
)

Error messages for policy.

View Source
var NonePolicy = &Policy{
	Uuid:    "none",
	Comment: "Allows everything on every key. Should only used for testing purposes.",
	Specs: []*OSpec{{
		Key: &OSpec_Regex{".*"},
	}},
}

NonePolicy is a basic policy used for testing and development.

View Source
var Operation_Op_name = map[int32]string{
	0:  "SET",
	1:  "CONCAT",
	10: "ADD",
	11: "MUL",
	20: "SADD",
	21: "SREM",
}
View Source
var Operation_Op_value = map[string]int32{
	"SET":    0,
	"CONCAT": 1,
	"ADD":    10,
	"MUL":    11,
	"SADD":   20,
	"SREM":   21,
}
View Source
var ParallelMatrix = map[Operation_Op]map[Operation_Op]ParallelType{
	Operation_SET: {Operation_SET: ParallelTypeDISALLOWDIFFERENT},
	Operation_ADD: {Operation_ADD: ParallelTypeDEFAULT},
	Operation_MUL: {Operation_MUL: ParallelTypeDEFAULT},
	Operation_SADD: {
		Operation_SADD: ParallelTypeDEFAULT,
		Operation_SREM: ParallelTypeDISALLOWEQUAL,
	},
	Operation_SREM: {
		Operation_SREM: ParallelTypeDEFAULT,
		Operation_SADD: ParallelTypeDISALLOWEQUAL,
	},
}

ParallelMatrix is used to know which operation can be run in parallel on a specific object.

Functions

This section is empty.

Types

type Catalog

type Catalog struct {
	Keys map[string]*version.V `` /* 128-byte string literal not displayed */
}

func (*Catalog) Descriptor

func (*Catalog) Descriptor() ([]byte, []int)

func (*Catalog) GetKeys

func (m *Catalog) GetKeys() map[string]*version.V

func (*Catalog) ProtoMessage

func (*Catalog) ProtoMessage()

func (*Catalog) Reset

func (m *Catalog) Reset()

func (*Catalog) String

func (m *Catalog) String() string

type DB

type DB struct {
	// Store is the underlying database storage engine.
	Store Store

	// Identity is the identity of the local node.
	// It should be unique.
	Identity string

	// KeyRing is the key management structure, used to
	// sign and verify endorsements and spores.
	KeyRing sec.KeyRing

	// Messages is the output port of the consensus algorithm.
	// It emits various messages, like new Spores or Endorsements.
	//
	// See gitlab.com/SporeDB/sporedb/myc/protocol
	Messages chan proto.Message
	// contains filtered or unexported fields
}

DB is the main structure for database management of a node.

func NewDB

func NewDB(s Store, identity string, keyring sec.KeyRing) *DB

NewDB instanciates a new database with clean initialization.

func (*DB) AddEndorsement

func (db *DB) AddEndorsement(e *Endorsement) error

AddEndorsement registers the incoming endorsement.

func (*DB) AddPolicy

func (db *DB) AddPolicy(p *Policy) error

AddPolicy registers a new policy for the database.

func (*DB) Apply

func (db *DB) Apply(s *Spore) error

Apply directly applies the Spore's operations to the database (atomic).

func (*DB) CanEndorse

func (db *DB) CanEndorse(s *Spore) error

CanEndorse checks wether a Spore can be endorsed or not regarding current database status. It is thread-safe.

func (*DB) Check

func (db *DB) Check(policy string, o *Operation, value *operations.Value) error

Check checks that a given operation is valid given its simulation and its database policy.

func (*DB) Clean

func (db *DB) Clean()

Clean is periodically called to free-up memory related to old transactions.

func (*DB) Endorse

func (db *DB) Endorse(s *Spore) error

Endorse tries to endorse a Spore, calling CanEndorse before any operation. It either adds the Spore to the staging list, pending list or discards it.

func (*DB) Get

func (db *DB) Get(key string) ([]byte, *version.V, error)

Get returns the currently stored data for the provided key.

func (*DB) HashSpore

func (db *DB) HashSpore(s *Spore) []byte

HashSpore process one spore's hash. It stores and caches the value for efficient computation.

func (*DB) Start

func (db *DB) Start(blocking bool)

Start starts the database, waiting for incoming spores to be processed. It can either work in blocking or non-blocking modes.

func (*DB) Stop

func (db *DB) Stop()

Stop asks the database to be gracefully stopped.

func (*DB) Submit

func (db *DB) Submit(s *Spore) (err error)

Submit broadcasts the Spore to the Mycelium, then tries to endorse it with current state.

func (*DB) VerifySporeSignature

func (db *DB) VerifySporeSignature(s Spore) error

VerifySporeSignature verifies emitter's signature of the given spore. It is passed by value because this function require's spore alteration.

type Endorsement

type Endorsement struct {
	Emitter   string `protobuf:"bytes,1,opt,name=emitter" json:"emitter,omitempty"`
	Uuid      string `protobuf:"bytes,2,opt,name=uuid" json:"uuid,omitempty"`
	Signature []byte `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"`
}

func (*Endorsement) Descriptor

func (*Endorsement) Descriptor() ([]byte, []int)

func (*Endorsement) GetEmitter

func (m *Endorsement) GetEmitter() string

func (*Endorsement) GetSignature

func (m *Endorsement) GetSignature() []byte

func (*Endorsement) GetUuid

func (m *Endorsement) GetUuid() string

func (*Endorsement) ProtoMessage

func (*Endorsement) ProtoMessage()

func (*Endorsement) Reset

func (m *Endorsement) Reset()

func (*Endorsement) String

func (m *Endorsement) String() string

type Endorser

type Endorser struct {
	Public  []byte `protobuf:"bytes,1,opt,name=public,proto3" json:"public,omitempty"`
	Comment string `protobuf:"bytes,2,opt,name=comment" json:"comment,omitempty"`
}

func (*Endorser) Descriptor

func (*Endorser) Descriptor() ([]byte, []int)

func (*Endorser) GetComment

func (m *Endorser) GetComment() string

func (*Endorser) GetPublic

func (m *Endorser) GetPublic() []byte

func (*Endorser) ProtoMessage

func (*Endorser) ProtoMessage()

func (*Endorser) Reset

func (m *Endorser) Reset()

func (*Endorser) String

func (m *Endorser) String() string

type OSpec

type OSpec struct {
	// Types that are valid to be assigned to Key:
	//	*OSpec_Name
	//	*OSpec_Regex
	Key               isOSpec_Key    `protobuf_oneof:"key"`
	MaxSize           uint64         `protobuf:"varint,4,opt,name=max_size,json=maxSize" json:"max_size,omitempty"`
	AllowedOperations []Operation_Op `` /* 134-byte string literal not displayed */
}

func (*OSpec) Descriptor

func (*OSpec) Descriptor() ([]byte, []int)

func (*OSpec) GetAllowedOperations

func (m *OSpec) GetAllowedOperations() []Operation_Op

func (*OSpec) GetKey

func (m *OSpec) GetKey() isOSpec_Key

func (*OSpec) GetMaxSize

func (m *OSpec) GetMaxSize() uint64

func (*OSpec) GetName

func (m *OSpec) GetName() string

func (*OSpec) GetRegex

func (m *OSpec) GetRegex() string

func (*OSpec) ProtoMessage

func (*OSpec) ProtoMessage()

func (*OSpec) Reset

func (m *OSpec) Reset()

func (*OSpec) String

func (m *OSpec) String() string

func (*OSpec) XXX_OneofFuncs

func (*OSpec) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})

XXX_OneofFuncs is for the internal use of the proto package.

type OSpec_Name

type OSpec_Name struct {
	Name string `protobuf:"bytes,1,opt,name=name,oneof"`
}

type OSpec_Regex

type OSpec_Regex struct {
	Regex string `protobuf:"bytes,2,opt,name=regex,oneof"`
}

type Operation

type Operation struct {
	Key      string       `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
	Op       Operation_Op `protobuf:"varint,2,opt,name=op,enum=db.Operation_Op" json:"op,omitempty"`
	Data     []byte       `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
	Metadata []byte       `protobuf:"bytes,4,opt,name=metadata,proto3" json:"metadata,omitempty"`
}

func (*Operation) CheckConflict

func (o *Operation) CheckConflict(o2 *Operation) error

CheckConflict returns an error if two operations cannot be executed in parallel.

func (*Operation) Descriptor

func (*Operation) Descriptor() ([]byte, []int)

func (*Operation) Exec

func (o *Operation) Exec(v *operations.Value) error

Exec returns the result of the given operation against stored data.

func (*Operation) GetData

func (m *Operation) GetData() []byte

func (*Operation) GetKey

func (m *Operation) GetKey() string

func (*Operation) GetMetadata

func (m *Operation) GetMetadata() []byte

func (*Operation) GetOp

func (m *Operation) GetOp() Operation_Op

func (*Operation) ProtoMessage

func (*Operation) ProtoMessage()

func (*Operation) Reset

func (m *Operation) Reset()

func (*Operation) String

func (m *Operation) String() string

type Operation_Op

type Operation_Op int32
const (
	// Operations on every values
	Operation_SET    Operation_Op = 0
	Operation_CONCAT Operation_Op = 1
	// Operations on numeric values
	Operation_ADD Operation_Op = 10
	Operation_MUL Operation_Op = 11
	// Operations on set values
	Operation_SADD Operation_Op = 20
	Operation_SREM Operation_Op = 21
)

func (Operation_Op) EnumDescriptor

func (Operation_Op) EnumDescriptor() ([]byte, []int)

func (Operation_Op) String

func (x Operation_Op) String() string

type ParallelType

type ParallelType int16

ParallelType specifies the various options available when specifiying a parallelizable operation.

type Policy

type Policy struct {
	Uuid        string                     `protobuf:"bytes,1,opt,name=uuid" json:"uuid,omitempty"`
	Comment     string                     `protobuf:"bytes,2,opt,name=comment" json:"comment,omitempty"`
	Endorsers   []*Endorser                `protobuf:"bytes,3,rep,name=endorsers" json:"endorsers,omitempty"`
	Quorum      uint64                     `protobuf:"varint,4,opt,name=quorum" json:"quorum,omitempty"`
	Timeout     *google_protobuf1.Duration `protobuf:"bytes,5,opt,name=timeout" json:"timeout,omitempty"`
	GracePeriod *google_protobuf1.Duration `protobuf:"bytes,6,opt,name=grace_period,json=gracePeriod" json:"grace_period,omitempty"`
	MaxSize     uint64                     `protobuf:"varint,7,opt,name=max_size,json=maxSize" json:"max_size,omitempty"`
	MaxOpSize   uint64                     `protobuf:"varint,8,opt,name=max_op_size,json=maxOpSize" json:"max_op_size,omitempty"`
	Specs       []*OSpec                   `protobuf:"bytes,9,rep,name=specs" json:"specs,omitempty"`
}

func (*Policy) Descriptor

func (*Policy) Descriptor() ([]byte, []int)

func (*Policy) GetComment

func (m *Policy) GetComment() string

func (*Policy) GetEndorsers

func (m *Policy) GetEndorsers() []*Endorser

func (*Policy) GetGracePeriod

func (m *Policy) GetGracePeriod() *google_protobuf1.Duration

func (*Policy) GetMaxOpSize

func (m *Policy) GetMaxOpSize() uint64

func (*Policy) GetMaxSize

func (m *Policy) GetMaxSize() uint64

func (*Policy) GetQuorum

func (m *Policy) GetQuorum() uint64

func (*Policy) GetSpecs

func (m *Policy) GetSpecs() []*OSpec

func (*Policy) GetTimeout

func (m *Policy) GetTimeout() *google_protobuf1.Duration

func (*Policy) GetUuid

func (m *Policy) GetUuid() string

func (*Policy) ProtoMessage

func (*Policy) ProtoMessage()

func (*Policy) Reset

func (m *Policy) Reset()

func (*Policy) String

func (m *Policy) String() string

type RecoverRequest

type RecoverRequest struct {
	Key string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
}

func (*RecoverRequest) Descriptor

func (*RecoverRequest) Descriptor() ([]byte, []int)

func (*RecoverRequest) GetKey

func (m *RecoverRequest) GetKey() string

func (*RecoverRequest) ProtoMessage

func (*RecoverRequest) ProtoMessage()

func (*RecoverRequest) Reset

func (m *RecoverRequest) Reset()

func (*RecoverRequest) String

func (m *RecoverRequest) String() string

type Spore

type Spore struct {
	Uuid         string                     `protobuf:"bytes,1,opt,name=uuid" json:"uuid,omitempty"`
	Policy       string                     `protobuf:"bytes,2,opt,name=policy" json:"policy,omitempty"`
	Emitter      string                     `protobuf:"bytes,3,opt,name=emitter" json:"emitter,omitempty"`
	Deadline     *google_protobuf.Timestamp `protobuf:"bytes,4,opt,name=deadline" json:"deadline,omitempty"`
	Requirements map[string]*version.V      `` /* 144-byte string literal not displayed */
	Operations   []*Operation               `protobuf:"bytes,6,rep,name=operations" json:"operations,omitempty"`
	// The signature of the spore is computed on the spore with an empty signature.
	// signature = signature by emitter ( hash ( marshal ( spore without signature ) ) )
	//
	// It is used to check spore's integrity.
	Signature []byte `protobuf:"bytes,10,opt,name=signature,proto3" json:"signature,omitempty"`
}

func NewSpore

func NewSpore() *Spore

NewSpore instanciates a new spore.

func (*Spore) CheckConflict

func (s *Spore) CheckConflict(s2 *Spore) error

CheckConflict returns an error if two spores are conflicting.

func (*Spore) Descriptor

func (*Spore) Descriptor() ([]byte, []int)

func (*Spore) GetDeadline

func (m *Spore) GetDeadline() *google_protobuf.Timestamp

func (*Spore) GetEmitter

func (m *Spore) GetEmitter() string

func (*Spore) GetOperations

func (m *Spore) GetOperations() []*Operation

func (*Spore) GetPolicy

func (m *Spore) GetPolicy() string

func (*Spore) GetRequirements

func (m *Spore) GetRequirements() map[string]*version.V

func (*Spore) GetSignature

func (m *Spore) GetSignature() []byte

func (*Spore) GetUuid

func (m *Spore) GetUuid() string

func (*Spore) ProtoMessage

func (*Spore) ProtoMessage()

func (*Spore) Reset

func (m *Spore) Reset()

func (*Spore) SetTimeout

func (s *Spore) SetTimeout(t time.Duration)

SetTimeout updates the deadline of the spore according to current time.

func (*Spore) String

func (m *Spore) String() string

type Store

type Store interface {
	sync.Locker
	io.Closer
	// Get returns the value and the version stored currently for the specified key.
	Get(key string) (value []byte, version *version.V, err error)
	// Set sets the value and the version that must be stored for the specified key.
	Set(key string, value []byte, version *version.V) error
	// SetBatch executes the given "Set" operations in a atomic way.
	SetBatch(keys []string, values [][]byte, versions []*version.V) error
	// List returns the map of keys with their values.
	List() (map[string]*version.V, error)
}

Store is the interface internal drivers must implement.

Directories

Path Synopsis
Package api is a generated protocol buffer package.
Package api is a generated protocol buffer package.
Package client provides SporeDB API client.
Package client provides SporeDB API client.
Package drivers holds required constructor for database drivers.
Package drivers holds required constructor for database drivers.
boltdb
Package boltdb provides the (default) BoldDB database driver.
Package boltdb provides the (default) BoldDB database driver.
rocksdb
Package rocksdb provides the native RocksDB database driver.
Package rocksdb provides the native RocksDB database driver.
Package encoding contains database types and (un)marshalling methods.
Package encoding contains database types and (un)marshalling methods.
Package operations contains database operations logic internals.
Package operations contains database operations logic internals.
Package server provides SporeDB API server.
Package server provides SporeDB API server.
Package version holds spores version management internal logic.
Package version holds spores version management internal logic.

Jump to

Keyboard shortcuts

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