transactionmanager

package
v0.0.0-...-a49da23 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTxManagerChannelBufferSize is the concurrent transactions before the tx manager begins backpressure
	DefaultTxManagerChannelBufferSize = 100
	// DefaultTxManagerTimeoutDurationSeconds is the amount of time before a transaction is marked as stale, 5 minutes by default
	DefaultTxManagerTimeoutDurationSeconds = 60 * 5
	// DefaultTxManagerEvictionDurationSeconds is the amount of time before a transaction is evicted and rolled back, 10 minutes by default
	DefaultTxManagerEvictionDurationSeconds = 60 * 10
	// DefaultTxManagerTickerIntervalSeconds is the ticker interval to mark transactions as stale / timeout.
	DefaultTxManagerTickerIntervalSeconds = 30
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AckAction

type AckAction struct {
	TransactionID, ActionID string
}

AckAction acknowledges an action for a given transaction.

type Action

type Action struct {
	ActionID               string
	CommittedTimestamp     time.Time
	Status                 ActionStatus
	StatusUpdatedTimestamp time.Time
}

Action represents a single operation in a checkmanager, which consists of one or more actions

type ActionNotFound

type ActionNotFound struct {
	TransactionID, ActionID string
}

ActionNotFound is triggered when trying to look up a non-existing action for a transaction in the transaction checkmanager

func (ActionNotFound) Error

func (a ActionNotFound) Error() string

Error returns a string representation of the ActionNotFound error and implements Error.

type ActionStatus

type ActionStatus int64

ActionStatus is an integer representing the state of the action

const (
	// Committed is used to represent a Committed action
	Committed ActionStatus = iota
	// Acknowledged is used to represent an Acknowledged action. ie successfully "completed" action
	Acknowledged
	// Rejected is used to represent an Rejected action. ie unsuccessfully "completed" action
	Rejected
)

func (ActionStatus) String

func (state ActionStatus) String() string

String returns a string representation of ActionStatus

type CommitAction

type CommitAction struct {
	TransactionID, ActionID string
}

CommitAction is used to commit an action for a certain transaction.

type CompleteTransaction

type CompleteTransaction struct {
	TransactionID string
	State         *TransactionState
}

CompleteTransaction completes a transaction. If all actions are acknowledges, the transaction is considered a success.

type DiscardTransaction

type DiscardTransaction struct {
	TransactionID, Reason string
}

DiscardTransaction rolls back a transaction and marks a transaction as a failure.

func (DiscardTransaction) Error

func (r DiscardTransaction) Error() string

Error returns a string representing the DiscardTransaction.

type EvictedTransaction

type EvictedTransaction struct {
	TransactionID string
}

EvictedTransaction is triggered once a stale transaction is evicted.

type IntakeTransaction

type IntakeTransaction struct {
	TransactionID        string
	CheckID              check.CheckID
	Status               TransactionStatus
	Actions              map[string]*Action // pointer to allow in-place mutation instead of setting the value again
	NotifyChannel        chan interface{}
	LastUpdatedTimestamp time.Time
	State                *TransactionState // the State of the TransactionState will be updated each time, no need for a pointer
}

IntakeTransaction represents an intake checkmanager which consists of one or more actions

type MockTransactionManager

type MockTransactionManager struct {
	TransactionActions chan interface{}
	// contains filtered or unexported fields
}

MockTransactionManager is a mock implementation of the transaction manager for tests

func NewMockTransactionManager

func NewMockTransactionManager() *MockTransactionManager

NewMockTransactionManager Create a mock verison of the transaction manager

func (*MockTransactionManager) AcknowledgeAction

func (ttm *MockTransactionManager) AcknowledgeAction(transactionID, actionID string)

AcknowledgeAction sends a AckAction to the TransactionActions channel to be used in assertions

func (*MockTransactionManager) CommitAction

func (ttm *MockTransactionManager) CommitAction(transactionID, actionID string)

CommitAction sends a CommitAction to the TransactionActions channel to be used in assertions

func (*MockTransactionManager) CompleteTransaction

func (ttm *MockTransactionManager) CompleteTransaction(transactionID string)

CompleteTransaction sends a CompleteTransaction to the TransactionActions channel to be used in assertions

func (*MockTransactionManager) DiscardTransaction

func (ttm *MockTransactionManager) DiscardTransaction(transactionID, reason string)

DiscardTransaction sends a DiscardTransaction to the TransactionActions channel to be used in assertions

func (*MockTransactionManager) GetActiveTransaction

func (ttm *MockTransactionManager) GetActiveTransaction(string) (*IntakeTransaction, error)

GetActiveTransaction returns nil, nil

func (*MockTransactionManager) GetCurrentTransaction

func (ttm *MockTransactionManager) GetCurrentTransaction() string

GetCurrentTransaction returns the current transaction

func (*MockTransactionManager) GetCurrentTransactionNotifyChannel

func (ttm *MockTransactionManager) GetCurrentTransactionNotifyChannel() chan interface{}

GetCurrentTransactionNotifyChannel returns the currentTransactionNotifyChannel

func (*MockTransactionManager) GetCurrentTransactionState

func (ttm *MockTransactionManager) GetCurrentTransactionState() *TransactionState

GetCurrentTransactionState returns the transactionState

func (*MockTransactionManager) NextAction

func (ttm *MockTransactionManager) NextAction() interface{}

NextAction returns the next action from the TransactionActions channel to be used in assertions

func (*MockTransactionManager) RejectAction

func (ttm *MockTransactionManager) RejectAction(transactionID, actionID, reason string)

RejectAction sends a RejectAction to the TransactionActions channel to be used in assertions

func (*MockTransactionManager) SetState

func (ttm *MockTransactionManager) SetState(_, key string, value string)

SetState sets the mock transactionState to the given key + value

func (*MockTransactionManager) Start

func (ttm *MockTransactionManager) Start()

Start is a noop

func (*MockTransactionManager) StartTransaction

func (ttm *MockTransactionManager) StartTransaction(_ check.CheckID, TransactionID string, NotifyChannel chan interface{})

StartTransaction sets the current transaction value and updates the notify channel

func (*MockTransactionManager) Stop

func (ttm *MockTransactionManager) Stop()

Stop resets the singleton init

func (*MockTransactionManager) TransactionCount

func (ttm *MockTransactionManager) TransactionCount() int

TransactionCount return 0

type RejectAction

type RejectAction struct {
	TransactionID, ActionID, Reason string
}

RejectAction rejects an action for a given transaction. This results in a failed transaction.

type SetTransactionState

type SetTransactionState struct {
	TransactionID, Key, State string
}

SetTransactionState is used to set transaction state for a given transactionID and Key.

type StartTransaction

type StartTransaction struct {
	CheckID       check.CheckID
	TransactionID string
	NotifyChannel chan interface{}
}

StartTransaction starts a transaction for a given checkID, with an optional OnComplete callback function.

type StopTransactionManager

type StopTransactionManager struct{}

StopTransactionManager triggers the shutdown of the transaction checkmanager.

type TransactionAPI

type TransactionAPI interface {
	GetActiveTransaction(transactionID string) (*IntakeTransaction, error)
	TransactionCount() int
	StartTransaction(CheckID check.CheckID, TransactionID string, NotifyChannel chan interface{})
	CompleteTransaction(transactionID string)
	DiscardTransaction(transactionID, reason string)
	CommitAction(transactionID, actionID string)
	AcknowledgeAction(transactionID, actionID string)
	SetState(transactionID, key string, state string)
	RejectAction(transactionID, actionID, reason string)
}

TransactionAPI contains the functions required for transactional behaviour

type TransactionCompleted

type TransactionCompleted struct {
	TransactionID string
}

TransactionCompleted is triggered when trying to look up a transaction that is already in a failed / succeeded state.

func (TransactionCompleted) Error

func (t TransactionCompleted) Error() string

Error returns a string representation of the TransactionCompleted error and implements Error.

type TransactionManager

type TransactionManager interface {
	Start()
	TransactionAPI
	Stop()
}

TransactionManager encapsulates all the functionality of the transaction manager to keep track of transactions

func NewTransactionManager

func NewTransactionManager(transactionChannelBufferSize int, tickerInterval, transactionTimeoutDuration,
	transactionEvictionDuration time.Duration) TransactionManager

NewTransactionManager returns an instance of a TransactionManager

type TransactionNotFound

type TransactionNotFound struct {
	TransactionID string
}

TransactionNotFound is triggered when trying to look up a non-existing transaction in the transaction checkmanager

func (TransactionNotFound) Error

func (t TransactionNotFound) Error() string

Error returns a string representation of the TransactionNotFound error and implements Error.

type TransactionState

type TransactionState struct {
	Key, State string
}

TransactionState keeps the state for a given key

type TransactionStatus

type TransactionStatus int64

TransactionStatus is an integer representing the state of the transaction

const (
	// InProgress is used to represent a InProgress transaction
	InProgress TransactionStatus = iota
	// Failed is used to represent a Failed transaction
	Failed
	// Succeeded is used to represent a Succeeded transaction
	Succeeded
	// Stale is used to represent a Stale transaction
	Stale
)

func (TransactionStatus) String

func (state TransactionStatus) String() string

String returns a string representation of TransactionStatus

Jump to

Keyboard shortcuts

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