causality

package
v0.0.0-...-be15534 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockStrategy

type BlockStrategy string

BlockStrategy is the strategy to handle the situation when the cache is full.

const (
	// BlockStrategyWaitAvailable means the cache will block until there is an available slot.
	BlockStrategyWaitAvailable BlockStrategy = "waitAvailable"
	// BlockStrategyWaitEmpty means the cache will block until all cached txns are consumed.
	BlockStrategyWaitEmpty = "waitAll"
)

type ConflictDetector

type ConflictDetector[Txn txnEvent] struct {
	// contains filtered or unexported fields
}

ConflictDetector implements a logic that dispatches transaction to different worker cache channels in a way that transactions modifying the same keys are never executed concurrently and have their original orders preserved. Transactions in different channels can be executed concurrently.

func NewConflictDetector

func NewConflictDetector[Txn txnEvent](
	numSlots uint64, opt TxnCacheOption,
) *ConflictDetector[Txn]

NewConflictDetector creates a new ConflictDetector.

func (*ConflictDetector[Txn]) Add

func (d *ConflictDetector[Txn]) Add(txn Txn)

Add pushes a transaction to the ConflictDetector.

NOTE: if multiple threads access this concurrently, Txn.GenSortedDedupKeysHash must be sorted by the slot index.

func (*ConflictDetector[Txn]) Close

func (d *ConflictDetector[Txn]) Close()

Close closes the ConflictDetector.

func (*ConflictDetector[Txn]) GetOutChByCacheID

func (d *ConflictDetector[Txn]) GetOutChByCacheID(id int64) <-chan TxnWithNotifier[Txn]

GetOutChByCacheID returns the output channel by cacheID. Note txns in single cache should be executed sequentially.

type TxnCacheOption

type TxnCacheOption struct {
	// Count controls the number of caches, txns in different caches could be executed concurrently.
	Count int
	// Size controls the max number of txns a cache can hold.
	Size int
	// BlockStrategy controls the strategy when the cache is full.
	BlockStrategy BlockStrategy
}

TxnCacheOption is the option for creating a cache for resolved txns.

type TxnWithNotifier

type TxnWithNotifier[Txn txnEvent] struct {
	TxnEvent Txn
	// The PostTxnExecuted will remove the txn related Node in the conflict detector's
	// dependency graph and resolve related dependencies for these transacitons
	// which depend on this executed txn.
	//
	// NOTE: the PostTxnExecuted() must be called after the txn executed.
	PostTxnExecuted func()
}

TxnWithNotifier is a wrapper of txnEvent with a PostTxnExecuted.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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