vault

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DeadlockDetected   = dbdriver.DeadlockDetected
	UniqueKeyViolation = dbdriver.UniqueKeyViolation
)
View Source
var DoubleDBCases = []struct {
	Name string
	Fn   func(*testing.T, VersionedPersistence, VersionedPersistence, artifactsProvider)
}{
	{"Run", TTestRun},
}
View Source
var RemoveNils func(items []VersionedRead) []VersionedRead
View Source
var SingleDBCases = []struct {
	Name string
	Fn   func(*testing.T, VersionedPersistence, artifactsProvider)
}{
	{"Merge", TTestMerge},
	{"Inspector", TTestInspector},
	{"InterceptorErr", TTestInterceptorErr},
	{"InterceptorConcurrency", TTestInterceptorConcurrency},
	{"QueryExecutor", TTestQueryExecutor},
	{"ShardLikeCommit", TTestShardLikeCommit},
	{"VaultErr", TTestVaultErr},
	{"ParallelVaults", TTestParallelVaults},
	{"Deadlock", TTestDeadlock},
}

Functions

func BlockTxIndexToBytes

func BlockTxIndexToBytes(Block driver2.BlockNum, TxNum driver2.TxNum) []byte

func Equal

func Equal(a, c driver2.RawVersion) bool

func TTestDeadlock

func TTestDeadlock(t *testing.T, ddb VersionedPersistence, vp artifactsProvider)

func TTestInspector

func TTestInspector(t *testing.T, ddb VersionedPersistence, vp artifactsProvider)

func TTestInterceptorConcurrency

func TTestInterceptorConcurrency(t *testing.T, ddb VersionedPersistence, vp artifactsProvider)

func TTestInterceptorErr

func TTestInterceptorErr(t *testing.T, ddb VersionedPersistence, vp artifactsProvider)

func TTestMerge

func TTestMerge(t *testing.T, ddb VersionedPersistence, vp artifactsProvider)

func TTestParallelVaults

func TTestParallelVaults(t *testing.T, ddb VersionedPersistence, vp artifactsProvider)

func TTestQueryExecutor

func TTestQueryExecutor(t *testing.T, ddb VersionedPersistence, vp artifactsProvider)

func TTestRun

func TTestRun(t *testing.T, db1, db2 VersionedPersistence, vp artifactsProvider)

func TTestShardLikeCommit

func TTestShardLikeCommit(t *testing.T, ddb VersionedPersistence, vp artifactsProvider)

func TTestVaultErr

func TTestVaultErr(t *testing.T, ddb VersionedPersistence, vp artifactsProvider)

Types

type BlockTxIndexVersionBuilder

type BlockTxIndexVersionBuilder struct{}

func (*BlockTxIndexVersionBuilder) VersionedMetaValues

func (*BlockTxIndexVersionBuilder) VersionedValues

func (b *BlockTxIndexVersionBuilder) VersionedValues(rws *ReadWriteSet, ns driver2.Namespace, writes NamespaceWrites, block driver2.BlockNum, indexInBloc driver2.TxNum) (map[driver2.PKey]VersionedValue, error)

type BlockTxIndexVersionComparator

type BlockTxIndexVersionComparator struct{}

func (*BlockTxIndexVersionComparator) Equal

type BlockTxIndexVersionMarshaller

type BlockTxIndexVersionMarshaller struct{}

func (BlockTxIndexVersionMarshaller) FromBytes

func (BlockTxIndexVersionMarshaller) ToBytes

type Inspector

type Inspector struct {
	Rws ReadWriteSet
}

func (*Inspector) AddReadAt

func (i *Inspector) AddReadAt(ns driver.Namespace, key string, version Version) error

func (*Inspector) AppendRWSet

func (i *Inspector) AppendRWSet(driver.RawValue, ...driver.Namespace) error

func (*Inspector) Bytes

func (i *Inspector) Bytes() ([]byte, error)

func (*Inspector) Clear

func (i *Inspector) Clear(driver.Namespace) error

func (*Inspector) DeleteState

func (i *Inspector) DeleteState(driver.Namespace, driver.PKey) error

func (*Inspector) Done

func (i *Inspector) Done()

func (*Inspector) Equals

func (i *Inspector) Equals(other interface{}, nss ...driver.Namespace) error

func (*Inspector) GetDirectState

func (i *Inspector) GetDirectState(driver.Namespace, driver.PKey) ([]byte, error)

func (*Inspector) GetReadAt

func (i *Inspector) GetReadAt(ns driver.Namespace, pos int) (driver.PKey, driver.RawValue, error)

func (*Inspector) GetReadKeyAt

func (i *Inspector) GetReadKeyAt(ns driver.Namespace, pos int) (driver.PKey, error)

func (*Inspector) GetState

func (i *Inspector) GetState(namespace driver.Namespace, key driver.PKey, _ ...driver.GetStateOpt) (driver.RawValue, error)

func (*Inspector) GetStateMetadata

func (i *Inspector) GetStateMetadata(namespace driver.Namespace, key driver.PKey, _ ...driver.GetStateOpt) (driver.Metadata, error)

func (*Inspector) GetWriteAt

func (i *Inspector) GetWriteAt(ns driver.Namespace, pos int) (driver.PKey, driver.RawValue, error)

func (*Inspector) IsClosed

func (i *Inspector) IsClosed() bool

func (*Inspector) IsValid

func (i *Inspector) IsValid() error

func (*Inspector) Namespaces

func (i *Inspector) Namespaces() []driver.Namespace

func (*Inspector) NumReads

func (i *Inspector) NumReads(ns driver.Namespace) int

func (*Inspector) NumWrites

func (i *Inspector) NumWrites(ns driver.Namespace) int

func (*Inspector) SetState

func (*Inspector) SetStateMetadata

func (i *Inspector) SetStateMetadata(driver.Namespace, driver.PKey, driver.Metadata) error

func (*Inspector) SetStateMetadatas

func (i *Inspector) SetStateMetadatas(ns driver.Namespace, kvs map[driver.PKey]driver.VersionedMetadataValue) map[driver.PKey]error

type Interceptor

type Interceptor[V driver.ValidationCode] struct {
	Logger            Logger
	QE                VersionedQueryExecutor
	TxIDStore         TXIDStoreReader[V]
	Rws               ReadWriteSet
	Marshaller        Marshaller
	VersionComparator VersionComparator
	Closed            bool
	TxID              string

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewInterceptor

func NewInterceptor[V driver.ValidationCode](
	logger Logger,
	rwSet ReadWriteSet,
	qe VersionedQueryExecutor,
	txIDStore TXIDStoreReader[V],
	txID driver.TxID,
	vcProvider driver.ValidationCodeProvider[V],
	marshaller Marshaller,
	versionComparator VersionComparator,
) *Interceptor[V]

func (*Interceptor[V]) AddReadAt

func (i *Interceptor[V]) AddReadAt(ns driver.Namespace, key string, version Version) error

func (*Interceptor[V]) AppendRWSet

func (i *Interceptor[V]) AppendRWSet(raw []byte, nss ...string) error

func (*Interceptor[V]) Bytes

func (i *Interceptor[V]) Bytes() ([]byte, error)

func (*Interceptor[V]) Clear

func (i *Interceptor[V]) Clear(ns string) error

func (*Interceptor[V]) DeleteState

func (i *Interceptor[V]) DeleteState(namespace string, key string) error

func (*Interceptor[V]) Done

func (i *Interceptor[V]) Done()

func (*Interceptor[V]) Equals

func (i *Interceptor[V]) Equals(other interface{}, nss ...string) error

func (*Interceptor[V]) GetDirectState

func (i *Interceptor[V]) GetDirectState(namespace driver.Namespace, key string) ([]byte, error)

func (*Interceptor[V]) GetReadAt

func (i *Interceptor[V]) GetReadAt(ns string, pos int) (string, []byte, error)

func (*Interceptor[V]) GetReadKeyAt

func (i *Interceptor[V]) GetReadKeyAt(ns string, pos int) (string, error)

func (*Interceptor[V]) GetState

func (i *Interceptor[V]) GetState(namespace driver.Namespace, key driver.PKey, opts ...driver.GetStateOpt) ([]byte, error)

func (*Interceptor[V]) GetStateMetadata

func (i *Interceptor[V]) GetStateMetadata(namespace, key string, opts ...driver.GetStateOpt) (map[string][]byte, error)

func (*Interceptor[V]) GetWriteAt

func (i *Interceptor[V]) GetWriteAt(ns string, pos int) (string, []byte, error)

func (*Interceptor[V]) IsClosed

func (i *Interceptor[V]) IsClosed() bool

func (*Interceptor[V]) IsValid

func (i *Interceptor[V]) IsValid() error

func (*Interceptor[V]) Namespaces

func (i *Interceptor[V]) Namespaces() []string

func (*Interceptor[V]) NumReads

func (i *Interceptor[V]) NumReads(ns string) int

func (*Interceptor[V]) NumWrites

func (i *Interceptor[V]) NumWrites(ns string) int

func (*Interceptor[V]) RWs

func (i *Interceptor[V]) RWs() *ReadWriteSet

func (*Interceptor[V]) Reopen

func (i *Interceptor[V]) Reopen(qe VersionedQueryExecutor) error

func (*Interceptor[V]) SetState

func (i *Interceptor[V]) SetState(namespace string, key string, value []byte) error

func (*Interceptor[V]) SetStateMetadata

func (i *Interceptor[V]) SetStateMetadata(namespace string, key string, value map[string][]byte) error

func (*Interceptor[V]) SetStateMetadatas

func (i *Interceptor[V]) SetStateMetadatas(ns driver.Namespace, kvs map[driver.PKey]driver.Metadata) map[driver.PKey]error

type KeyedMetaWrites

type KeyedMetaWrites map[string]MetaWrites

func (KeyedMetaWrites) Equals

type Logger

type Logger interface {
	Debugf(template string, args ...interface{})
	Infof(template string, args ...interface{})
	Errorf(template string, args ...interface{})
}

type Marshaller

type Marshaller interface {
	Marshal(txID string, rws *ReadWriteSet) ([]byte, error)
	Append(destination *ReadWriteSet, raw []byte, nss ...string) error
}

type MetaWriteSet

type MetaWriteSet struct {
	MetaWrites NamespaceKeyedMetaWrites
}

func (*MetaWriteSet) Add

func (w *MetaWriteSet) Add(ns, key string, meta map[string][]byte) error

func (*MetaWriteSet) Clear

func (w *MetaWriteSet) Clear(ns string)

func (*MetaWriteSet) Get

func (w *MetaWriteSet) Get(ns, key string) map[string][]byte

func (*MetaWriteSet) In

func (w *MetaWriteSet) In(ns, key string) bool

type MetaWrites

type MetaWrites = driver.Metadata

type Metrics

type Metrics struct {
	CommitDuration        metrics.Histogram
	BatchedCommitDuration metrics.Histogram

	Vault trace.Tracer
}

func NewMetrics

func NewMetrics(m metrics.Provider, p trace.TracerProvider) *Metrics

type NamespaceKeyedMetaWrites

type NamespaceKeyedMetaWrites map[driver.Namespace]KeyedMetaWrites

func (NamespaceKeyedMetaWrites) Equals

type NamespaceReads

type NamespaceReads map[string]Version

func (NamespaceReads) Equals

func (r NamespaceReads) Equals(o NamespaceReads) error

type NamespaceWrites

type NamespaceWrites map[driver.PKey]driver.RawValue

func (NamespaceWrites) Equals

func (NamespaceWrites) Keys

func (r NamespaceWrites) Keys() []string

type NewInterceptorFunc

type NewInterceptorFunc[V driver.ValidationCode] func(logger Logger, rwSet ReadWriteSet, qe VersionedQueryExecutor, txidStore TXIDStoreReader[V], txid driver.TxID) TxInterceptor

type Populator

type Populator interface {
	Populate(rwsetBytes []byte, namespaces ...driver.Namespace) (ReadWriteSet, error)
}

type QueryExecutor

type QueryExecutor = dbdriver.QueryExecutor

type ReadSet

type ReadSet struct {
	Reads        Reads
	OrderedReads map[string][]string
}

func (*ReadSet) Add

func (r *ReadSet) Add(ns driver.Namespace, key string, version Version)

func (*ReadSet) Clear

func (r *ReadSet) Clear(ns driver.Namespace)

func (*ReadSet) Get

func (r *ReadSet) Get(ns driver.Namespace, key string) (Version, bool)

func (*ReadSet) GetAt

func (r *ReadSet) GetAt(ns driver.Namespace, i int) (string, bool)

type ReadWriteSet

type ReadWriteSet struct {
	ReadSet
	WriteSet
	MetaWriteSet
}

func EmptyRWSet

func EmptyRWSet() ReadWriteSet

type Reads

func (Reads) Equals

func (r Reads) Equals(o Reads, nss ...driver.Namespace) error

type TXIDStore

type TXIDStore[V driver.ValidationCode] interface {
	TXIDStoreReader[V]
	Set(txID driver.TxID, code V, message string) error
	SetMultiple(txs []driver.ByNum[V]) error
	Invalidate(txID driver.TxID)
}

type TXIDStoreReader

type TXIDStoreReader[V driver.ValidationCode] interface {
	Iterator(pos interface{}) (collections.Iterator[*driver.ByNum[V]], error)
	Get(txID driver.TxID) (V, string, error)
}

type TxInterceptor

type TxInterceptor interface {
	driver.RWSet
	RWs() *ReadWriteSet
	Reopen(qe VersionedQueryExecutor) error
}

type VCProvider

type VCProvider struct{}

func (*VCProvider) Busy

func (p *VCProvider) Busy() ValidationCode

func (*VCProvider) FromInt32

func (p *VCProvider) FromInt32(code int32) ValidationCode

func (*VCProvider) Invalid

func (p *VCProvider) Invalid() ValidationCode

func (*VCProvider) NotFound

func (p *VCProvider) NotFound() ValidationCode

func (*VCProvider) ToInt32

func (p *VCProvider) ToInt32(code ValidationCode) int32

func (*VCProvider) Unknown

func (p *VCProvider) Unknown() ValidationCode

func (*VCProvider) Valid

func (p *VCProvider) Valid() ValidationCode

type ValidationCode

type ValidationCode = int

type Vault

type Vault[V driver.ValidationCode] struct {
	Interceptors map[driver.TxID]TxInterceptor
	// contains filtered or unexported fields
}

Vault models a key-value Store that can be modified by committing rwsets

func New

func New[V driver.ValidationCode](
	logger Logger,
	store VersionedPersistence,
	txIDStore TXIDStore[V],
	vcProvider driver.ValidationCodeProvider[V],
	newInterceptor NewInterceptorFunc[V],
	populator Populator,
	metricsProvider metrics.Provider,
	tracerProvider trace.TracerProvider,
	versionBuilder VersionBuilder,
) *Vault[V]

New returns a new instance of Vault

func (*Vault[V]) Close

func (db *Vault[V]) Close() error

func (*Vault[V]) CommitTX

func (db *Vault[V]) CommitTX(ctx context.Context, txID driver.TxID, block driver.BlockNum, indexInBloc driver.TxNum) error

func (*Vault[V]) DiscardTx

func (db *Vault[V]) DiscardTx(txID driver.TxID, message string) error

func (*Vault[V]) GetExistingRWSet

func (db *Vault[V]) GetExistingRWSet(txID driver.TxID) (driver.RWSet, error)

func (*Vault[V]) GetRWSet

func (db *Vault[V]) GetRWSet(txID driver.TxID, rwsetBytes []byte) (driver.RWSet, error)

func (*Vault[V]) InspectRWSet

func (db *Vault[V]) InspectRWSet(rwsetBytes []byte, namespaces ...driver.Namespace) (driver.RWSet, error)

func (*Vault[V]) Match

func (db *Vault[V]) Match(txID driver.TxID, rwsRaw []byte) error

func (*Vault[V]) NewInspector

func (db *Vault[V]) NewInspector(txID driver.TxID) (TxInterceptor, error)

func (*Vault[V]) NewQueryExecutor

func (db *Vault[V]) NewQueryExecutor() (QueryExecutor, error)

func (*Vault[V]) NewRWSet

func (db *Vault[V]) NewRWSet(txID driver.TxID) (driver.RWSet, error)

func (*Vault[V]) RWSExists

func (db *Vault[V]) RWSExists(txID driver.TxID) bool

func (*Vault[V]) SetBusy

func (db *Vault[V]) SetBusy(txID driver.TxID) error

func (*Vault[V]) SetDiscarded

func (db *Vault[V]) SetDiscarded(txID driver.TxID, message string) error

func (*Vault[V]) SetStatus

func (db *Vault[V]) SetStatus(txID driver.TxID, code V) error

func (*Vault[V]) Status

func (db *Vault[V]) Status(txID driver.TxID) (V, string, error)

func (*Vault[V]) Statuses

func (db *Vault[V]) Statuses(txIDs ...driver.TxID) ([]driver.TxValidationStatus[V], error)

func (*Vault[V]) UnmapInterceptor

func (db *Vault[V]) UnmapInterceptor(txID driver.TxID) (TxInterceptor, error)

type Version

type Version = driver.RawVersion

type VersionBuilder

type VersionBuilder interface {
	VersionedValues(rws *ReadWriteSet, ns driver.Namespace, writes NamespaceWrites, block driver.BlockNum, indexInBloc driver.TxNum) (map[driver.PKey]VersionedValue, error)
	VersionedMetaValues(rws *ReadWriteSet, ns driver.Namespace, writes KeyedMetaWrites, block driver.BlockNum, indexInBloc driver.TxNum) (map[driver.PKey]driver.VersionedMetadataValue, error)
}

type VersionComparator

type VersionComparator interface {
	Equal(v1, v2 driver.RawVersion) bool
}

type VersionedMetadataValue

type VersionedMetadataValue = dbdriver.VersionedMetadataValue

type VersionedPersistence

type VersionedPersistence = dbdriver.VersionedPersistence

type VersionedQueryExecutor

type VersionedQueryExecutor interface {
	GetStateMetadata(namespace, key string) (driver.Metadata, driver.RawVersion, error)
	GetState(namespace, key string) (VersionedValue, error)
	Done()
}

type VersionedRead

type VersionedRead = dbdriver.VersionedRead

type VersionedResultsIterator

type VersionedResultsIterator = dbdriver.VersionedResultsIterator

type VersionedValue

type VersionedValue = dbdriver.VersionedValue

type WriteSet

type WriteSet struct {
	Writes        Writes
	OrderedWrites map[string][]string
}

func (*WriteSet) Add

func (w *WriteSet) Add(ns, key string, value []byte) error

func (*WriteSet) Clear

func (w *WriteSet) Clear(ns string)

func (*WriteSet) Get

func (w *WriteSet) Get(ns, key string) []byte

func (*WriteSet) GetAt

func (w *WriteSet) GetAt(ns string, i int) (key string, in bool)

func (*WriteSet) In

func (w *WriteSet) In(ns, key string) bool

type Writes

type Writes map[driver.Namespace]NamespaceWrites

func (Writes) Equals

func (r Writes) Equals(o Writes, nss ...string) error

Directories

Path Synopsis
mocks
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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