Documentation
¶
Overview ¶
Package db provides main consensus and data processing engines.
Index ¶
- Constants
- Variables
- type Catalog
- type DB
- func (db *DB) AddEndorsement(e *Endorsement) error
- func (db *DB) AddPolicy(p *Policy) error
- func (db *DB) Apply(s *Spore) error
- func (db *DB) CanEndorse(s *Spore) error
- func (db *DB) Check(policy string, o *Operation, value *operations.Value) error
- func (db *DB) Clean()
- func (db *DB) Endorse(s *Spore) error
- func (db *DB) Get(key string) ([]byte, *version.V, error)
- func (db *DB) HashSpore(s *Spore) []byte
- func (db *DB) Start(blocking bool)
- func (db *DB) Stop()
- func (db *DB) Submit(s *Spore) (err error)
- func (db *DB) VerifySporeSignature(s Spore) error
- type Endorsement
- type Endorser
- type OSpec
- func (*OSpec) Descriptor() ([]byte, []int)
- func (m *OSpec) GetAllowedOperations() []Operation_Op
- func (m *OSpec) GetKey() isOSpec_Key
- func (m *OSpec) GetMaxSize() uint64
- func (m *OSpec) GetName() string
- func (m *OSpec) GetRegex() string
- func (*OSpec) ProtoMessage()
- func (m *OSpec) Reset()
- func (m *OSpec) String() string
- func (*OSpec) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, ...)
- type OSpec_Name
- type OSpec_Regex
- type Operation
- func (o *Operation) CheckConflict(o2 *Operation) error
- func (*Operation) Descriptor() ([]byte, []int)
- func (o *Operation) Exec(v *operations.Value) error
- func (m *Operation) GetData() []byte
- func (m *Operation) GetKey() string
- func (m *Operation) GetMetadata() []byte
- func (m *Operation) GetOp() Operation_Op
- func (*Operation) ProtoMessage()
- func (m *Operation) Reset()
- func (m *Operation) String() string
- type Operation_Op
- type ParallelType
- type Policy
- func (*Policy) Descriptor() ([]byte, []int)
- func (m *Policy) GetComment() string
- func (m *Policy) GetEndorsers() []*Endorser
- func (m *Policy) GetGracePeriod() *google_protobuf1.Duration
- func (m *Policy) GetMaxOpSize() uint64
- func (m *Policy) GetMaxSize() uint64
- func (m *Policy) GetQuorum() uint64
- func (m *Policy) GetSpecs() []*OSpec
- func (m *Policy) GetTimeout() *google_protobuf1.Duration
- func (m *Policy) GetUuid() string
- func (*Policy) ProtoMessage()
- func (m *Policy) Reset()
- func (m *Policy) String() string
- type RecoverRequest
- type Spore
- func (s *Spore) CheckConflict(s2 *Spore) error
- func (*Spore) Descriptor() ([]byte, []int)
- func (m *Spore) GetDeadline() *google_protobuf.Timestamp
- func (m *Spore) GetEmitter() string
- func (m *Spore) GetOperations() []*Operation
- func (m *Spore) GetPolicy() string
- func (m *Spore) GetRequirements() map[string]*version.V
- func (m *Spore) GetSignature() []byte
- func (m *Spore) GetUuid() string
- func (*Spore) ProtoMessage()
- func (m *Spore) Reset()
- func (s *Spore) SetTimeout(t time.Duration)
- func (m *Spore) String() string
- type Store
Constants ¶
const ( ParallelTypeDEFAULT ParallelType = 0x01 ParallelTypeDISALLOWDIFFERENT = 0x02 ParallelTypeDISALLOWEQUAL = 0x04 )
Definition for ParallelType. Each flag may be combined using bitwise operators.
const InternalKeyPrefix = "__internal"
InternalKeyPrefix is used to discriminate internal keys.
Variables ¶
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
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.
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.
var Operation_Op_name = map[int32]string{
0: "SET",
1: "CONCAT",
10: "ADD",
11: "MUL",
20: "SADD",
21: "SREM",
}
var Operation_Op_value = map[string]int32{
"SET": 0,
"CONCAT": 1,
"ADD": 10,
"MUL": 11,
"SADD": 20,
"SREM": 21,
}
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 ¶
func (*Catalog) Descriptor ¶
func (*Catalog) ProtoMessage ¶
func (*Catalog) ProtoMessage()
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 (*DB) AddEndorsement ¶
func (db *DB) AddEndorsement(e *Endorsement) error
AddEndorsement registers the incoming endorsement.
func (*DB) CanEndorse ¶
CanEndorse checks wether a Spore can be endorsed or not regarding current database status. It is thread-safe.
func (*DB) Check ¶
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 ¶
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) HashSpore ¶
HashSpore process one spore's hash. It stores and caches the value for efficient computation.
func (*DB) Start ¶
Start starts the database, waiting for incoming spores to be processed. It can either work in blocking or non-blocking modes.
func (*DB) Submit ¶
Submit broadcasts the Spore to the Mycelium, then tries to endorse it with current state.
func (*DB) VerifySporeSignature ¶
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) GetComment ¶
func (*Endorser) ProtoMessage ¶
func (*Endorser) ProtoMessage()
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) GetAllowedOperations ¶
func (m *OSpec) GetAllowedOperations() []Operation_Op
func (*OSpec) GetMaxSize ¶
func (*OSpec) ProtoMessage ¶
func (*OSpec) ProtoMessage()
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 ¶
CheckConflict returns an error if two operations cannot be executed in parallel.
func (*Operation) Descriptor ¶
func (*Operation) Exec ¶
func (o *Operation) Exec(v *operations.Value) error
Exec returns the result of the given operation against stored data.
func (*Operation) GetMetadata ¶
func (*Operation) GetOp ¶
func (m *Operation) GetOp() Operation_Op
func (*Operation) ProtoMessage ¶
func (*Operation) ProtoMessage()
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) GetComment ¶
func (*Policy) GetEndorsers ¶
func (*Policy) GetGracePeriod ¶
func (m *Policy) GetGracePeriod() *google_protobuf1.Duration
func (*Policy) GetMaxOpSize ¶
func (*Policy) GetMaxSize ¶
func (*Policy) GetTimeout ¶
func (m *Policy) GetTimeout() *google_protobuf1.Duration
func (*Policy) ProtoMessage ¶
func (*Policy) ProtoMessage()
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 (*Spore) CheckConflict ¶
CheckConflict returns an error if two spores are conflicting.
func (*Spore) Descriptor ¶
func (*Spore) GetDeadline ¶
func (m *Spore) GetDeadline() *google_protobuf.Timestamp
func (*Spore) GetEmitter ¶
func (*Spore) GetOperations ¶
func (*Spore) GetSignature ¶
func (*Spore) ProtoMessage ¶
func (*Spore) ProtoMessage()
func (*Spore) SetTimeout ¶
SetTimeout updates the deadline of the spore according to current time.
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.
Source Files
¶
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. |