transactions

package
v14.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDuplicateNodes indicates a transaction was registered with two
	// voters having the same name.
	ErrDuplicateNodes = errors.New("transactions cannot have duplicate nodes")
	// ErrMissingNodes indicates a transaction was registered with no voters.
	ErrMissingNodes = errors.New("transaction requires at least one node")
	// ErrInvalidThreshold indicates a transaction was registered with an
	// invalid threshold that may either allow for multiple different
	// quorums or none at all.
	ErrInvalidThreshold = errors.New("transaction has invalid threshold")

	// ErrTransactionFailed indicates the transaction didn't reach quorum.
	ErrTransactionFailed = errors.New("transaction did not reach quorum")
	// ErrTransactionCanceled indicates the transaction was canceled before
	// reaching quorum.
	ErrTransactionCanceled = errors.New("transaction has been canceled")
	// ErrTransactionStopped indicates the transaction was gracefully stopped.
	ErrTransactionStopped = errors.New("transaction has been stopped")
)
View Source
var ErrNotFound = errors.New("transaction not found")

nolint: revive,stylecheck // This is unintentionally missing documentation.

Functions

This section is empty.

Types

type CancelFunc

type CancelFunc func() error

CancelFunc is the transaction cancellation function returned by `RegisterTransaction`. Calling it will cause the transaction to be removed from the transaction manager.

type Manager

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

Manager handles reference transactions for Praefect. It is required in order for Praefect to handle transactions directly instead of having to reach out to reference transaction RPCs.

func NewManager

func NewManager(cfg config.Config) *Manager

NewManager creates a new transactions Manager.

func (*Manager) Collect

func (mgr *Manager) Collect(metrics chan<- prometheus.Metric)

nolint: revive,stylecheck // This is unintentionally missing documentation.

func (*Manager) Describe

func (mgr *Manager) Describe(descs chan<- *prometheus.Desc)

nolint: revive,stylecheck // This is unintentionally missing documentation.

func (*Manager) RegisterTransaction

func (mgr *Manager) RegisterTransaction(ctx context.Context, voters []Voter, threshold uint) (Transaction, CancelFunc, error)

RegisterTransaction registers a new reference transaction for a set of nodes taking part in the transaction. `threshold` is the threshold at which an election will succeed. It needs to be in the range `weight(voters)/2 < threshold <= weight(voters) to avoid indecidable votes.

func (*Manager) StopTransaction

func (mgr *Manager) StopTransaction(ctx context.Context, transactionID uint64) error

StopTransaction will gracefully stop a transaction.

func (*Manager) VoteTransaction

func (mgr *Manager) VoteTransaction(ctx context.Context, transactionID uint64, node string, vote voting.Vote) error

VoteTransaction is called by a client who's casting a vote on a reference transaction. It waits until quorum was reached on the given transaction.

type Transaction

type Transaction interface {
	// ID returns the ID of the transaction which uniquely identifies the transaction.
	ID() uint64
	// CountSubtransactions counts the number of subtransactions.
	CountSubtransactions() int
	// State returns the state of each voter part of the transaction.
	State() (map[string]VoteResult, error)
	// DidVote returns whether the given node has cast a vote.
	DidVote(string) bool
}

Transaction is an interface for transactions.

type VoteResult

type VoteResult int

VoteResult represents the outcome of a transaction for a single voter.

const (
	// VoteUndecided means that the voter either didn't yet show up or that
	// the vote couldn't yet be decided due to there being no majority yet.
	VoteUndecided VoteResult = iota
	// VoteCommitted means that the voter committed his vote.
	VoteCommitted
	// VoteFailed means that the voter has failed the vote because a
	// majority of nodes has elected a different result.
	VoteFailed
	// VoteCanceled means that the transaction was cancelled.
	VoteCanceled
	// VoteStopped means that the transaction was gracefully stopped.
	VoteStopped
)

type Voter

type Voter struct {
	// Name of the voter, usually Gitaly's storage name.
	Name string
	// Votes is the number of votes available to this voter in the voting
	// process. `0` means the outcome of the vote will not be influenced by
	// this voter.
	Votes uint
	// contains filtered or unexported fields
}

Voter is a participant in a given transaction that may cast a vote.

Jump to

Keyboard shortcuts

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