transaction

package
v16.7.8 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTransactionAborted indicates a transaction was aborted, either
	// because it timed out or because the vote failed to reach quorum.
	ErrTransactionAborted = errors.New("transaction was aborted")
	// ErrTransactionStopped indicates a transaction was gracefully
	// stopped. This only happens in case the transaction was terminated
	// because of an external condition, e.g. access checks or hooks
	// rejected a change.
	ErrTransactionStopped = errors.New("transaction was stopped")
)

Functions

func CommitLockedFile

func CommitLockedFile(ctx context.Context, m Manager, writer *safe.LockingFileWriter) (returnedErr error)

CommitLockedFile will lock, vote and commit the LockingFileWriter in a race-free manner.

func RunOnContext

func RunOnContext(ctx context.Context, fn func(txinfo.Transaction) error) error

RunOnContext runs the given function if the context identifies a transaction.

func VoteOnContext

func VoteOnContext(ctx context.Context, m Manager, vote voting.Vote, phase voting.Phase) error

VoteOnContext casts the vote on a transaction identified by the context, if there is any.

Types

type Manager

type Manager interface {
	// Vote casts a vote on the given transaction which is hosted by the
	// given Praefect server.
	Vote(context.Context, txinfo.Transaction, voting.Vote, voting.Phase) error

	// Stop gracefully stops the given transaction which is hosted by the
	// given Praefect server.
	Stop(context.Context, txinfo.Transaction) error
}

Manager is an interface for handling voting on transactions.

type MockManager

type MockManager struct {
	VoteFn func(context.Context, txinfo.Transaction, voting.Vote, voting.Phase) error
	StopFn func(context.Context, txinfo.Transaction) error
}

MockManager is a mock Manager for use in tests.

func (*MockManager) Stop

Stop calls the MockManager's Stop function, if set. Otherwise, it returns an error.

func (*MockManager) Vote

func (m *MockManager) Vote(ctx context.Context, tx txinfo.Transaction, vote voting.Vote, phase voting.Phase) error

Vote calls the MockManager's Vote function, if set. Otherwise, it returns an error.

type PhasedVote

type PhasedVote struct {
	Vote  voting.Vote
	Phase voting.Phase
}

PhasedVote is used to keep track of votes and the phase they were cast in.

type PoolManager

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

PoolManager is an implementation of the Manager interface using a pool to connect to the transaction hosts.

func NewManager

func NewManager(cfg config.Cfg, logger log.Logger, backchannels *backchannel.Registry) *PoolManager

NewManager creates a new PoolManager to handle transactional voting.

func (*PoolManager) Collect

func (m *PoolManager) Collect(metrics chan<- prometheus.Metric)

Collect is used to collect Prometheus metrics.

func (*PoolManager) Describe

func (m *PoolManager) Describe(descs chan<- *prometheus.Desc)

Describe is used to describe Prometheus metrics.

func (*PoolManager) Stop

Stop connects to the given server and stops the transaction identified by tx.

func (*PoolManager) Vote

func (m *PoolManager) Vote(
	ctx context.Context,
	tx txinfo.Transaction,
	vote voting.Vote,
	phase voting.Phase,
) error

Vote connects to the given server and casts vote as a vote for the transaction identified by tx.

type TrackingManager

type TrackingManager struct {
	MockManager
	// contains filtered or unexported fields
}

TrackingManager is a transaction manager which tracks all votes. Voting functions never return an error.

func NewTrackingManager

func NewTrackingManager() *TrackingManager

NewTrackingManager creates a new TrackingManager which is ready for use.

func (*TrackingManager) Reset

func (m *TrackingManager) Reset()

Reset resets all votes which have been recorded up to this point.

func (*TrackingManager) Votes

func (m *TrackingManager) Votes() []PhasedVote

Votes returns a copy of all votes which have been cast.

Jump to

Keyboard shortcuts

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