Documentation ¶
Overview ¶
Package worker defines miner node logic for database storage and sql-chain accounting integration.
Index ¶
- Constants
- Variables
- type BusService
- func (bs *BusService) GetCurrentDBMapping() (dbMap map[proto.DatabaseID]*types.SQLChainProfile)
- func (bs *BusService) RequestPermStat(dbID proto.DatabaseID, user proto.AccountAddress) (permStat *types.PermStat, ok bool)
- func (bs *BusService) RequestSQLProfile(dbID proto.DatabaseID) (p *types.SQLChainProfile, ok bool)
- func (bs *BusService) Start()
- func (bs *BusService) Stop()
- type DBConfig
- type DBKayakMuxService
- type DBMS
- func (dbms *DBMS) Ack(ack *types.Ack) (err error)
- func (dbms *DBMS) Create(instance *types.ServiceInstance, cleanup bool) (err error)
- func (dbms *DBMS) Drop(dbID proto.DatabaseID) (err error)
- func (dbms *DBMS) Init() (err error)
- func (dbms *DBMS) Query(req *types.Request) (res *types.Response, err error)
- func (dbms *DBMS) Shutdown() (err error)
- func (dbms *DBMS) Update(instance *types.ServiceInstance) (err error)
- func (dbms *DBMS) UpdatePermission(dbID proto.DatabaseID, user proto.AccountAddress, permStat *types.PermStat) (err error)
- type DBMSConfig
- type DBMSMeta
- type DBMSRPCService
- func (rpc *DBMSRPCService) Ack(ack *types.Ack, _ *types.AckResponse) (err error)
- func (rpc *DBMSRPCService) Deploy(req *types.UpdateService, _ *types.UpdateServiceResponse) (err error)
- func (rpc *DBMSRPCService) ObserverFetchBlock(req *ObserverFetchBlockReq, resp *ObserverFetchBlockResp) (err error)
- func (rpc *DBMSRPCService) Query(req *types.Request, res *types.Response) (err error)
- type Database
- func (db *Database) Ack(ack *types.Ack) (err error)
- func (db *Database) Check(rawReq interface{}) (err error)
- func (db *Database) Commit(rawReq interface{}, isLeader bool) (result interface{}, err error)
- func (db *Database) DecodePayload(data []byte) (request interface{}, err error)
- func (db *Database) Destroy() (err error)
- func (db *Database) EncodePayload(request interface{}) (data []byte, err error)
- func (db *Database) Query(request *types.Request) (response *types.Response, err error)
- func (db *Database) Shutdown() (err error)
- func (db *Database) UpdatePeers(peers *proto.Peers) (err error)
- type ObserverFetchBlockReq
- type ObserverFetchBlockResp
- type TrackerAndResponse
Constants ¶
const ( // StorageFileName defines storage file name of database instance. StorageFileName = "storage.db3" // KayakWalFileName defines log pool name of database instance. KayakWalFileName = "kayak.ldb" // SQLChainFileName defines sqlchain storage file name. SQLChainFileName = "chain.db" // MaxRecordedConnectionSequences defines the max connection slots to anti reply attack. MaxRecordedConnectionSequences = 1000 // PrepareThreshold defines the prepare complete threshold. PrepareThreshold = 1.0 // CommitThreshold defines the commit complete threshold. CommitThreshold = 0.0 // PrepareTimeout defines the prepare timeout config. PrepareTimeout = 10 * time.Second // CommitTimeout defines the commit timeout config. CommitTimeout = time.Minute // LogWaitTimeout defines the missing log wait timeout config. LogWaitTimeout = 10 * time.Second // SlowQuerySampleSize defines the maximum slow query log size (default: 1KB). SlowQuerySampleSize = 1 << 10 )
const ( // DBKayakRPCName defines rpc service name of database internal consensus. DBKayakRPCName = "DBC" // aka. database consensus // DBMetaFileName defines dbms meta file name. DBMetaFileName = "db.meta" // DefaultSlowQueryTime defines the default slow query log time DefaultSlowQueryTime = time.Second * 5 )
const ( // DBKayakApplyMethodName defines the database kayak apply rpc method name. DBKayakApplyMethodName = "Apply" // DBKayakFetchMethodName defines the database kayak fetch rpc method name. DBKayakFetchMethodName = "Fetch" )
Variables ¶
var ( // ErrInvalidRequest defines invalid request structure during request. ErrInvalidRequest = errors.New("invalid request supplied") // ErrInvalidRequestSeq defines invalid sequence no of request. ErrInvalidRequestSeq = errors.New("invalid request sequence applied") // ErrAlreadyExists defines error on re-creating existing database instance. ErrAlreadyExists = errors.New("database instance already exists") // ErrNotExists defines errors on manipulating a non-exists database instance. ErrNotExists = errors.New("database instance not exists") // ErrInvalidDBConfig defines errors on received invalid db config from block producer. ErrInvalidDBConfig = errors.New("invalid database configuration") // ErrSpaceLimitExceeded defines errors on disk space exceeding limit. ErrSpaceLimitExceeded = errors.New("space limit exceeded") // ErrUnknownMuxRequest indicates that the a multiplexing request endpoint is not found. ErrUnknownMuxRequest = errors.New("unknown multiplexing request") // ErrPermissionDeny indicates that the requester has no permission to send read or write query. ErrPermissionDeny = errors.New("permission deny") // ErrInvalidPermission indicates that the requester sends a unrecognized permission. ErrInvalidPermission = errors.New("invalid permission") // ErrInvalidTransactionType indicates that the transaction type is invalid. ErrInvalidTransactionType = errors.New("invalid transaction type") )
var ( // DefaultMaxReqTimeGap defines max time gap between request and server. DefaultMaxReqTimeGap = time.Minute )
Functions ¶
This section is empty.
Types ¶
type BusService ¶
BusService defines the man chain bus service type.
func NewBusService ¶
func NewBusService( ctx context.Context, addr proto.AccountAddress, checkInterval time.Duration) (_ *BusService, )
NewBusService creates a new chain bus instance.
func (*BusService) GetCurrentDBMapping ¶
func (bs *BusService) GetCurrentDBMapping() (dbMap map[proto.DatabaseID]*types.SQLChainProfile)
GetCurrentDBMapping returns current cached db mapping.
func (*BusService) RequestPermStat ¶
func (bs *BusService) RequestPermStat( dbID proto.DatabaseID, user proto.AccountAddress) (permStat *types.PermStat, ok bool, )
RequestPermStat fetches permission state from bus service.
func (*BusService) RequestSQLProfile ¶
func (bs *BusService) RequestSQLProfile(dbID proto.DatabaseID) (p *types.SQLChainProfile, ok bool)
RequestSQLProfile get specified database profile.
type DBConfig ¶
type DBConfig struct { DatabaseID proto.DatabaseID RootDir string DataDir string KayakMux *DBKayakMuxService ChainMux *sqlchain.MuxService MaxWriteTimeGap time.Duration EncryptionKey string SpaceLimit uint64 UpdateBlockCount uint64 LastBillingHeight int32 UseEventualConsistency bool ConsistencyLevel float64 IsolationLevel int SlowQueryTime time.Duration }
DBConfig defines the database config.
type DBKayakMuxService ¶
type DBKayakMuxService struct {
// contains filtered or unexported fields
}
DBKayakMuxService defines a mux service for sqlchain kayak.
func NewDBKayakMuxService ¶
func NewDBKayakMuxService(serviceName string, server *rpc.Server) (s *DBKayakMuxService, err error)
NewDBKayakMuxService returns a new kayak mux service.
func (*DBKayakMuxService) Apply ¶
func (s *DBKayakMuxService) Apply(req *kt.ApplyRequest, _ *interface{}) (err error)
Apply handles kayak apply call.
func (*DBKayakMuxService) Fetch ¶
func (s *DBKayakMuxService) Fetch(req *kt.FetchRequest, resp *kt.FetchResponse) (err error)
Fetch handles kayak fetch call.
type DBMS ¶
type DBMS struct {
// contains filtered or unexported fields
}
DBMS defines a database management instance.
func NewDBMS ¶
func NewDBMS(cfg *DBMSConfig) (dbms *DBMS, err error)
NewDBMS returns new database management instance.
func (*DBMS) Create ¶
func (dbms *DBMS) Create(instance *types.ServiceInstance, cleanup bool) (err error)
Create add new database to the miner dbms.
func (*DBMS) Drop ¶
func (dbms *DBMS) Drop(dbID proto.DatabaseID) (err error)
Drop remove database from the miner dbms.
func (*DBMS) Update ¶
func (dbms *DBMS) Update(instance *types.ServiceInstance) (err error)
Update apply the new peers config to dbms.
func (*DBMS) UpdatePermission ¶
func (dbms *DBMS) UpdatePermission(dbID proto.DatabaseID, user proto.AccountAddress, permStat *types.PermStat) (err error)
UpdatePermission exports the update permission interface for test.
type DBMSConfig ¶
type DBMSConfig struct { RootDir string Server *mux.Server DirectServer *rpc.Server // optional server to provide DBMS service MaxReqTimeGap time.Duration OnCreateDatabase func() }
DBMSConfig defines the local multi-database management system config.
type DBMSMeta ¶
type DBMSMeta struct {
DBS map[proto.DatabaseID]bool
}
DBMSMeta defines the meta structure.
type DBMSRPCService ¶
type DBMSRPCService struct {
// contains filtered or unexported fields
}
DBMSRPCService is the rpc endpoint of database management.
func NewDBMSRPCService ¶
func NewDBMSRPCService( serviceName string, server *mux.Server, direct *rpc.Server, dbms *DBMS, ) ( service *DBMSRPCService, )
NewDBMSRPCService returns new dbms rpc service endpoint.
func (*DBMSRPCService) Ack ¶
func (rpc *DBMSRPCService) Ack(ack *types.Ack, _ *types.AckResponse) (err error)
Ack rpc, called by client to confirm read request.
func (*DBMSRPCService) Deploy ¶
func (rpc *DBMSRPCService) Deploy(req *types.UpdateService, _ *types.UpdateServiceResponse) (err error)
Deploy rpc, called by BP to create/drop database and update peers.
func (*DBMSRPCService) ObserverFetchBlock ¶
func (rpc *DBMSRPCService) ObserverFetchBlock(req *ObserverFetchBlockReq, resp *ObserverFetchBlockResp) (err error)
ObserverFetchBlock handles observer fetch block logic.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database defines a single database instance in worker runtime.
func NewDatabase ¶
NewDatabase create a single database instance using config.
func (*Database) DecodePayload ¶
DecodePayload implements kayak.types.Handler.DecodePayload.
func (*Database) EncodePayload ¶
EncodePayload implements kayak.types.Handler.EncodePayload.
type ObserverFetchBlockReq ¶
type ObserverFetchBlockReq struct { proto.Envelope proto.DatabaseID Count int32 // sqlchain block serial number since genesis block (0) }
ObserverFetchBlockReq defines the request for observer to fetch block.
type ObserverFetchBlockResp ¶
type ObserverFetchBlockResp struct { Count int32 // sqlchain block serial number since genesis block (0) Block *types.Block }
ObserverFetchBlockResp defines the response for observer to fetch block.
type TrackerAndResponse ¶
type TrackerAndResponse struct { Tracker *x.QueryTracker Response *types.Response }
TrackerAndResponse defines a query tracker used by xenomint and an unsigned response.