Documentation ¶
Overview ¶
Copyright 2023 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
- Variables
- func EncodeEntrySpec(key []byte, md *store.KVMetadata, value []byte) *store.EntrySpec
- func EncodeKey(key []byte) []byte
- func EncodeReference(key []byte, md *store.KVMetadata, referencedKey []byte, atTx uint64) *store.EntrySpec
- func EncodeZAdd(set []byte, score float64, key []byte, atTx uint64) *store.EntrySpec
- func PreconditionFromProto(c *schema.Precondition) (store.Precondition, error)
- func TrimPrefix(prefixed []byte) []byte
- func WrapReferenceValueAt(key []byte, atTx uint64) []byte
- func WrapWithPrefix(b []byte, prefix byte) []byte
- func WrapZAddReferenceAt(set []byte, score float64, key []byte, atTx uint64) []byte
- type DB
- type DatabaseList
- type DocumentDatabase
- type Options
- func (o *Options) AsReplica(replica bool) *Options
- func (o *Options) GetCorruptionChecker() bool
- func (o *Options) GetDBRootPath() string
- func (o *Options) GetStoreOptions() *store.Options
- func (o *Options) GetTxPoolSize() int
- func (o *Options) WithCorruptionChecker(cc bool) *Options
- func (o *Options) WithDBRootPath(Path string) *Options
- func (o *Options) WithReadTxPoolSize(txPoolSize int) *Options
- func (o *Options) WithRetentionPeriod(c time.Duration) *Options
- func (o *Options) WithStoreOptions(storeOpts *store.Options) *Options
- func (o *Options) WithSyncAcks(syncAcks int) *Options
- func (o *Options) WithSyncReplication(syncReplication bool) *Options
- func (o *Options) WithTruncationFrequency(c time.Duration) *Options
- type Truncator
Constants ¶
const ( DefaultDbRootPath = "./data" DefaultReadTxPoolSize = 128 DefaultTruncationFrequency = 24 * time.Hour )
const ( SetKeyPrefix byte = iota SortedSetKeyPrefix SQLPrefix DocumentPrefix )
const ( PlainValuePrefix = iota ReferenceValuePrefix )
const MaxKeyResolutionLimit = 1
const MaxKeyScanLimit = 1000
Variables ¶
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() ErrDatabaseAlreadyExists = errors.New("database already exists") ErrDatabaseNotExists = errors.New("database does not exist") ErrCannotDeleteAnOpenDatabase = errors.New("cannot delete an open database") ErrTxReadPoolExhausted = errors.New("read tx pool exhausted") )
var ( ErrTruncatorAlreadyRunning = errors.New("truncator already running") ErrRetentionPeriodNotReached = errors.New("retention period has not been reached") )
var ErrFinalKeyCannotBeConvertedIntoReference = errors.New("final key cannot be converted into a reference")
var ErrIllegalArguments = store.ErrIllegalArguments
var ErrIllegalState = store.ErrIllegalState
var ErrInvalidRevision = errors.New("invalid key revision number")
var ErrIsReplica = errors.New("database is read-only because it's a replica")
var ErrKeyResolutionLimitReached = errors.New("key resolution limit reached. It may be due to cyclic references")
var ErrNoWaitOperationMustBeSelfContained = fmt.Errorf("no wait operation must be self-contained: %w", store.ErrIllegalArguments)
var ErrNotReplica = errors.New("database is NOT a replica")
var ErrReferencedKeyCannotBeAReference = errors.New("referenced key cannot be a reference")
var ErrReplicaDivergedFromPrimary = errors.New("replica diverged from primary")
var ErrResultSizeLimitExceeded = errors.New("result size limit exceeded")
var ErrResultSizeLimitReached = errors.New("result size limit reached")
Functions ¶
func EncodeEntrySpec ¶ added in v1.2.0
func EncodeReference ¶
func EncodeZAdd ¶
func PreconditionFromProto ¶ added in v1.2.3
func PreconditionFromProto(c *schema.Precondition) (store.Precondition, error)
func TrimPrefix ¶ added in v0.9.1
func WrapReferenceValueAt ¶
Types ¶
type DB ¶
type DB interface { GetName() string // Setttings GetOptions() *Options Path() string AsReplica(asReplica, syncReplication bool, syncAcks int) IsReplica() bool IsSyncReplicationEnabled() bool SetSyncReplication(enabled bool) MaxResultSize() int UseTimeFunc(timeFunc store.TimeFunc) error // State Health() (waitingCount int, lastReleaseAt time.Time) CurrentState() (*schema.ImmutableState, error) Size() (uint64, error) // Key-Value Set(ctx context.Context, req *schema.SetRequest) (*schema.TxHeader, error) VerifiableSet(ctx context.Context, req *schema.VerifiableSetRequest) (*schema.VerifiableTx, error) Get(ctx context.Context, req *schema.KeyRequest) (*schema.Entry, error) VerifiableGet(ctx context.Context, req *schema.VerifiableGetRequest) (*schema.VerifiableEntry, error) GetAll(ctx context.Context, req *schema.KeyListRequest) (*schema.Entries, error) Delete(ctx context.Context, req *schema.DeleteKeysRequest) (*schema.TxHeader, error) SetReference(ctx context.Context, req *schema.ReferenceRequest) (*schema.TxHeader, error) VerifiableSetReference(ctx context.Context, req *schema.VerifiableReferenceRequest) (*schema.VerifiableTx, error) Scan(ctx context.Context, req *schema.ScanRequest) (*schema.Entries, error) History(ctx context.Context, req *schema.HistoryRequest) (*schema.Entries, error) ExecAll(ctx context.Context, operations *schema.ExecAllRequest) (*schema.TxHeader, error) Count(ctx context.Context, prefix *schema.KeyPrefix) (*schema.EntryCount, error) CountAll(ctx context.Context) (*schema.EntryCount, error) ZAdd(ctx context.Context, req *schema.ZAddRequest) (*schema.TxHeader, error) VerifiableZAdd(ctx context.Context, req *schema.VerifiableZAddRequest) (*schema.VerifiableTx, error) ZScan(ctx context.Context, req *schema.ZScanRequest) (*schema.ZEntries, error) // SQL-related NewSQLTx(ctx context.Context, opts *sql.TxOptions) (*sql.SQLTx, error) SQLExec(ctx context.Context, tx *sql.SQLTx, req *schema.SQLExecRequest) (ntx *sql.SQLTx, ctxs []*sql.SQLTx, err error) SQLExecPrepared(ctx context.Context, tx *sql.SQLTx, stmts []sql.SQLStmt, params map[string]interface{}) (ntx *sql.SQLTx, ctxs []*sql.SQLTx, err error) InferParameters(ctx context.Context, tx *sql.SQLTx, sql string) (map[string]sql.SQLValueType, error) InferParametersPrepared(ctx context.Context, tx *sql.SQLTx, stmt sql.SQLStmt) (map[string]sql.SQLValueType, error) SQLQuery(ctx context.Context, tx *sql.SQLTx, req *schema.SQLQueryRequest) (*schema.SQLQueryResult, error) SQLQueryPrepared(ctx context.Context, tx *sql.SQLTx, stmt sql.DataSource, namedParams []*schema.NamedParam) (*schema.SQLQueryResult, error) SQLQueryRowReader(ctx context.Context, tx *sql.SQLTx, stmt sql.DataSource, params map[string]interface{}) (sql.RowReader, error) VerifiableSQLGet(ctx context.Context, req *schema.VerifiableSQLGetRequest) (*schema.VerifiableSQLEntry, error) ListTables(ctx context.Context, tx *sql.SQLTx) (*schema.SQLQueryResult, error) DescribeTable(ctx context.Context, tx *sql.SQLTx, table string) (*schema.SQLQueryResult, error) // Transactional layer WaitForTx(ctx context.Context, txID uint64, allowPrecommitted bool) error WaitForIndexingUpto(ctx context.Context, txID uint64) error TxByID(ctx context.Context, req *schema.TxRequest) (*schema.Tx, error) ExportTxByID(ctx context.Context, req *schema.ExportTxRequest) (txbs []byte, mayCommitUpToTxID uint64, mayCommitUpToAlh [sha256.Size]byte, err error) ReplicateTx(ctx context.Context, exportedTx []byte, skipIntegrityCheck bool, waitForIndexing bool) (*schema.TxHeader, error) AllowCommitUpto(txID uint64, alh [sha256.Size]byte) error DiscardPrecommittedTxsSince(txID uint64) error VerifiableTxByID(ctx context.Context, req *schema.VerifiableTxRequest) (*schema.VerifiableTx, error) TxScan(ctx context.Context, req *schema.TxScanRequest) (*schema.TxList, error) // Maintenance FlushIndex(req *schema.FlushIndexRequest) error CompactIndex() error IsClosed() bool Close() error DocumentDatabase }
type DatabaseList ¶ added in v1.0.0
type DatabaseList interface { Put(database DB) Delete(string) (DB, error) GetByIndex(index int) (DB, error) GetByName(string) (DB, error) GetId(dbname string) int Length() int }
DatabaseList interface
func NewDatabaseList ¶ added in v1.0.0
func NewDatabaseList() DatabaseList
NewDatabaseList constructs a new database list
type DocumentDatabase ¶ added in v1.5.0
type DocumentDatabase interface { // GetCollection returns the collection schema GetCollection(ctx context.Context, req *protomodel.GetCollectionRequest) (*protomodel.GetCollectionResponse, error) // GetCollections returns the list of collection schemas GetCollections(ctx context.Context, req *protomodel.GetCollectionsRequest) (*protomodel.GetCollectionsResponse, error) // CreateCollection creates a new collection CreateCollection(ctx context.Context, req *protomodel.CreateCollectionRequest) (*protomodel.CreateCollectionResponse, error) // UpdateCollection updates an existing collection UpdateCollection(ctx context.Context, req *protomodel.UpdateCollectionRequest) (*protomodel.UpdateCollectionResponse, error) // DeleteCollection deletes a collection DeleteCollection(ctx context.Context, req *protomodel.DeleteCollectionRequest) (*protomodel.DeleteCollectionResponse, error) // CreateIndex creates an index for a collection CreateIndex(ctx context.Context, req *protomodel.CreateIndexRequest) (*protomodel.CreateIndexResponse, error) // DeleteIndex deletes an index from a collection DeleteIndex(ctx context.Context, req *protomodel.DeleteIndexRequest) (*protomodel.DeleteIndexResponse, error) // InsertDocuments creates new documents InsertDocuments(ctx context.Context, req *protomodel.InsertDocumentsRequest) (*protomodel.InsertDocumentsResponse, error) // ReplaceDocuments replaces documents matching the query ReplaceDocuments(ctx context.Context, req *protomodel.ReplaceDocumentsRequest) (*protomodel.ReplaceDocumentsResponse, error) // AuditDocument returns the document audit history AuditDocument(ctx context.Context, req *protomodel.AuditDocumentRequest) (*protomodel.AuditDocumentResponse, error) // SearchDocuments returns the documents matching the query SearchDocuments(ctx context.Context, query *protomodel.Query, offset int64) (document.DocumentReader, error) // CountDocuments returns the number of documents matching the query CountDocuments(ctx context.Context, req *protomodel.CountDocumentsRequest) (*protomodel.CountDocumentsResponse, error) // DeleteDocuments deletes documents maching the query DeleteDocuments(ctx context.Context, req *protomodel.DeleteDocumentsRequest) (*protomodel.DeleteDocumentsResponse, error) // ProofDocument returns the proofs for a document ProofDocument(ctx context.Context, req *protomodel.ProofDocumentRequest) (*protomodel.ProofDocumentResponse, error) }
DocumentDatabase is the interface for document database
type Options ¶ added in v1.1.0
type Options struct { // TruncationFrequency determines how frequently to truncate data from the database. TruncationFrequency time.Duration // RetentionPeriod determines how long to store data in the database. RetentionPeriod time.Duration // contains filtered or unexported fields }
Options database instance options
func DefaultOption ¶
func DefaultOption() *Options
DefaultOption Initialise Db Optionts to default values
func (*Options) GetCorruptionChecker ¶ added in v1.1.0
GetCorruptionChecker returns if corruption checker should start for this database instance
func (*Options) GetDBRootPath ¶ added in v1.1.0
GetDbRootPath returns the directory in which this database resides
func (*Options) GetStoreOptions ¶ added in v1.1.0
GetStoreOptions returns backing store options
func (*Options) GetTxPoolSize ¶ added in v1.3.2
func (*Options) WithCorruptionChecker ¶ added in v1.1.0
WithCorruptionChecker sets if corruption checker should start for this database instance
func (*Options) WithDBRootPath ¶ added in v1.1.0
WithDbRootPath sets the directory in which this database will reside
func (*Options) WithReadTxPoolSize ¶ added in v1.3.2
func (*Options) WithRetentionPeriod ¶ added in v1.5.0
func (*Options) WithStoreOptions ¶ added in v1.1.0
WithStoreOptions sets backing store options
func (*Options) WithSyncAcks ¶ added in v1.4.0
func (*Options) WithSyncReplication ¶ added in v1.4.0
type Truncator ¶ added in v1.5.0
type Truncator interface { // Plan returns the latest transaction upto which the log can be truncated. // When resulting transaction before specified time does not exists // * No transaction header is returned. // * Returns nil TxHeader, and an error. Plan(ctx context.Context, truncationUntil time.Time) (*store.TxHeader, error) // TruncateUptoTx runs truncation against the relevant appendable logs. Must // be called after result of Plan(). TruncateUptoTx(ctx context.Context, txID uint64) error }
Truncator provides truncation against an underlying storage of appendable data.