database

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Overview

Copyright 2021 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	SetKeyPrefix byte = iota
	SortedSetKeyPrefix
	SQLPrefix
)
View Source
const (
	PlainValuePrefix = iota
	ReferenceValuePrefix
)
View Source
const MaxKeyResolutionLimit = 1
View Source
const MaxKeyScanLimit = 1000

Variables

View Source
var (
	ErrIndexKeyMismatch      = status.New(codes.InvalidArgument, "mismatch between provided index and key").Err()
	ErrNoReferenceProvided   = status.New(codes.InvalidArgument, "provided argument is not a reference").Err()
	ErrReferenceKeyMissing   = status.New(codes.InvalidArgument, "reference key not provided").Err()
	ErrZAddIndexMissing      = status.New(codes.InvalidArgument, "zAdd index not provided").Err()
	ErrReferenceIndexMissing = status.New(codes.InvalidArgument, "reference index not provided").Err()
	ErrDatabaseNotExists     = status.New(codes.NotFound, "database does not exist").Err()
)
View Source
var ErrFinalKeyCannotBeConvertedIntoReference = errors.New("final key cannot be converted into a reference")
View Source
var ErrIllegalArguments = store.ErrIllegalArguments
View Source
var ErrIllegalState = store.ErrIllegalState
View Source
var ErrIsReplica = errors.New("database is read-only because it's a replica")
View Source
var ErrMaxKeyResolutionLimitReached = errors.New("max key resolution limit reached. It may be due to cyclic references")
View Source
var ErrMaxKeyScanLimitExceeded = errors.New("max key scan limit exceeded")
View Source
var ErrNotReplica = errors.New("database is NOT a replica")
View Source
var ErrReferencedKeyCannotBeAReference = errors.New("referenced key cannot be a reference")
View Source
var ErrSQLNotReady = errors.New("SQL catalog not yet replicated")

Functions

func EncodeKV

func EncodeKV(key []byte, value []byte) *store.KV

func EncodeKey

func EncodeKey(key []byte) []byte

func EncodeReference

func EncodeReference(key, referencedKey []byte, atTx uint64) *store.KV

func EncodeZAdd

func EncodeZAdd(set []byte, score float64, key []byte, atTx uint64) *store.KV

func TrimPrefix added in v0.9.1

func TrimPrefix(prefixed []byte) []byte

func WrapReferenceValueAt

func WrapReferenceValueAt(key []byte, atTx uint64) []byte

func WrapWithPrefix

func WrapWithPrefix(b []byte, prefix byte) []byte

WrapWithPrefix ...

func WrapZAddReferenceAt

func WrapZAddReferenceAt(set []byte, score float64, key []byte, atTx uint64) []byte

Types

type DB

type DB interface {
	CurrentState() (*schema.ImmutableState, error)
	WaitForTx(txID uint64, cancellation <-chan struct{}) error
	WaitForIndexingUpto(txID uint64, cancellation <-chan struct{}) error
	Set(req *schema.SetRequest) (*schema.TxMetadata, error)
	Get(req *schema.KeyRequest) (*schema.Entry, error)
	VerifiableSet(req *schema.VerifiableSetRequest) (*schema.VerifiableTx, error)
	VerifiableGet(req *schema.VerifiableGetRequest) (*schema.VerifiableEntry, error)
	GetAll(req *schema.KeyListRequest) (*schema.Entries, error)
	ExecAll(operations *schema.ExecAllRequest) (*schema.TxMetadata, error)
	Size() (uint64, error)
	Count(prefix *schema.KeyPrefix) (*schema.EntryCount, error)
	CountAll() (*schema.EntryCount, error)
	TxByID(req *schema.TxRequest) (*schema.Tx, error)
	ExportTxByID(req *schema.TxRequest) ([]byte, error)
	ReplicateTx(exportedTx []byte) (*schema.TxMetadata, error)
	VerifiableTxByID(req *schema.VerifiableTxRequest) (*schema.VerifiableTx, error)
	TxScan(req *schema.TxScanRequest) (*schema.TxList, error)
	History(req *schema.HistoryRequest) (*schema.Entries, error)
	SetReference(req *schema.ReferenceRequest) (*schema.TxMetadata, error)
	VerifiableSetReference(req *schema.VerifiableReferenceRequest) (*schema.VerifiableTx, error)
	ZAdd(req *schema.ZAddRequest) (*schema.TxMetadata, error)
	ZScan(req *schema.ZScanRequest) (*schema.ZEntries, error)
	VerifiableZAdd(req *schema.VerifiableZAddRequest) (*schema.VerifiableTx, error)
	Scan(req *schema.ScanRequest) (*schema.Entries, error)
	Close() error
	GetOptions() *DbOptions
	UpdateReplicationOptions(replicationOpts *ReplicationOptions)
	IsReplica() bool
	CompactIndex() error
	VerifiableSQLGet(req *schema.VerifiableSQLGetRequest) (*schema.VerifiableSQLEntry, error)
	SQLExec(req *schema.SQLExecRequest) (*schema.SQLExecResult, error)
	SQLExecPrepared(stmts []sql.SQLStmt, namedParams []*schema.NamedParam, waitForIndexing bool) (*schema.SQLExecResult, error)
	InferParameters(sql string) (map[string]sql.SQLValueType, error)
	InferParametersPrepared(stmt sql.SQLStmt) (map[string]sql.SQLValueType, error)
	UseSnapshot(req *schema.UseSnapshotRequest) error
	SQLQuery(req *schema.SQLQueryRequest) (*schema.SQLQueryResult, error)
	SQLQueryPrepared(stmt *sql.SelectStmt, namedParams []*schema.NamedParam, renewSnapshot bool) (*schema.SQLQueryResult, error)
	SQLQueryRowReader(stmt *sql.SelectStmt, renewSnapshot bool) (sql.RowReader, error)
	ListTables() (*schema.SQLQueryResult, error)
	DescribeTable(table string) (*schema.SQLQueryResult, error)
	GetName() string
}

func NewDb

func NewDb(op *DbOptions, systemDB DB, log logger.Logger) (DB, error)

NewDb Creates a new Database along with it's directories and files

func OpenDb

func OpenDb(op *DbOptions, systemDB DB, log logger.Logger) (DB, error)

OpenDb Opens an existing Database from disk

type DatabaseList added in v1.0.0

type DatabaseList interface {
	Append(database DB)
	GetByIndex(index int64) DB
	GetByName(string) (DB, error)
	GetId(dbname string) int64
	Length() int
}

DatabaseList interface

func NewDatabaseList added in v1.0.0

func NewDatabaseList() DatabaseList

NewDatabaseList constructs a new database list

type DbOptions

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

DbOptions database instance options

func DefaultOption

func DefaultOption() *DbOptions

DefaultOption Initialise Db Optionts to default values

func (*DbOptions) GetCorruptionChecker

func (o *DbOptions) GetCorruptionChecker() bool

GetCorruptionChecker returns if corruption checker should start for this database instance

func (*DbOptions) GetDbName

func (o *DbOptions) GetDbName() string

GetDbName Returns Database name which is also db instance directory

func (*DbOptions) GetDbRootPath

func (o *DbOptions) GetDbRootPath() string

GetDbRootPath returns the directory in which this database resides

func (*DbOptions) GetReplicationOptions added in v1.0.5

func (o *DbOptions) GetReplicationOptions() *ReplicationOptions

GetReplicationOptions returns replication options

func (*DbOptions) GetStoreOptions

func (o *DbOptions) GetStoreOptions() *store.Options

GetStoreOptions returns backing store options

func (*DbOptions) WithCorruptionChecker

func (o *DbOptions) WithCorruptionChecker(cc bool) *DbOptions

WithCorruptionChecker sets if corruption checker should start for this database instance

func (*DbOptions) WithDbName

func (o *DbOptions) WithDbName(dbName string) *DbOptions

WithDbName sets dbName, which is also db instance directory

func (*DbOptions) WithDbRootPath

func (o *DbOptions) WithDbRootPath(Path string) *DbOptions

WithDbRootPath sets the directory in which this database will reside

func (*DbOptions) WithReplicationOptions added in v1.0.5

func (o *DbOptions) WithReplicationOptions(replicationOpts *ReplicationOptions) *DbOptions

WithReplicationOptions sets replication options

func (*DbOptions) WithStoreOptions

func (o *DbOptions) WithStoreOptions(storeOpts *store.Options) *DbOptions

WithStoreOptions sets backing store options

type ReplicationOptions added in v1.0.5

type ReplicationOptions struct {
	Replica     bool
	SrcDatabase string
	SrcAddress  string
	SrcPort     int
	FollowerUsr string
	FollowerPwd string
}

func (*ReplicationOptions) AsReplica added in v1.0.5

func (o *ReplicationOptions) AsReplica(replica bool) *ReplicationOptions

AsReplica sets if the database is a replica

func (*ReplicationOptions) WithFollowerPwd added in v1.0.5

func (o *ReplicationOptions) WithFollowerPwd(followerPwd string) *ReplicationOptions

WithFollowerPwd sets follower password

func (*ReplicationOptions) WithFollowerUsr added in v1.0.5

func (o *ReplicationOptions) WithFollowerUsr(followerUsr string) *ReplicationOptions

WithFollowerUsr sets follower username

func (*ReplicationOptions) WithSrcAddress added in v1.0.5

func (o *ReplicationOptions) WithSrcAddress(srcAddress string) *ReplicationOptions

WithSrcAddress sets the source database address

func (*ReplicationOptions) WithSrcDatabase added in v1.0.5

func (o *ReplicationOptions) WithSrcDatabase(srcDatabase string) *ReplicationOptions

WithSrcDatabase sets the source database name

func (*ReplicationOptions) WithSrcPort added in v1.0.5

func (o *ReplicationOptions) WithSrcPort(srcPort int) *ReplicationOptions

WithSrcPort sets the source database port

Jump to

Keyboard shortcuts

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