Documentation ¶
Index ¶
- Constants
- func FatalErr(err error) bool
- func GenId() gopter.Gen
- func GenSagaState() gopter.Gen
- func GenSagaStateAndTaskId() gopter.Gen
- func NewInternalLogError(msg string) error
- func NewInvalidRequestError(msg string) error
- func NewInvalidSagaMessageError(msg string) error
- func NewInvalidSagaStateError(msg string) error
- type InternalLogError
- type InvalidRequestError
- type InvalidSagaMessageError
- type InvalidSagaStateError
- type MockSagaLog
- func (_m *MockSagaLog) EXPECT() *_MockSagaLogRecorder
- func (_m *MockSagaLog) GetActiveSagas() ([]string, error)
- func (_m *MockSagaLog) GetMessages(sagaId string) ([]SagaMessage, error)
- func (_m *MockSagaLog) LogMessage(message SagaMessage) error
- func (_m *MockSagaLog) StartSaga(sagaId string, job []byte) error
- type Saga
- func (s *Saga) AbortSaga() error
- func (s *Saga) EndCompensatingTask(taskId string, results []byte) error
- func (s *Saga) EndSaga() error
- func (s *Saga) EndTask(taskId string, results []byte) error
- func (s *Saga) GetEndCompTaskData(taskId string) []byte
- func (s *Saga) GetEndTaskData(taskId string) []byte
- func (s *Saga) GetStartCompTaskData(taskId string) []byte
- func (s *Saga) GetStartTaskData(taskId string) []byte
- func (s *Saga) GetTaskIds() []string
- func (s *Saga) IsCompTaskCompleted(taskId string) bool
- func (s *Saga) IsCompTaskStarted(taskId string) bool
- func (s *Saga) IsSagaAborted() bool
- func (s *Saga) IsSagaCompleted() bool
- func (s *Saga) IsTaskCompleted(taskId string) bool
- func (s *Saga) IsTaskStarted(taskId string) bool
- func (s *Saga) Job() []byte
- func (s *Saga) SagaId() string
- func (s *Saga) StartCompensatingTask(taskId string, data []byte) error
- func (s *Saga) StartTask(taskId string, data []byte) error
- type SagaCoordinator
- type SagaLog
- type SagaMessage
- func MakeAbortSagaMessage(sagaId string) SagaMessage
- func MakeEndCompTaskMessage(sagaId string, taskId string, results []byte) SagaMessage
- func MakeEndSagaMessage(sagaId string) SagaMessage
- func MakeEndTaskMessage(sagaId string, taskId string, results []byte) SagaMessage
- func MakeStartCompTaskMessage(sagaId string, taskId string, data []byte) SagaMessage
- func MakeStartSagaMessage(sagaId string, job []byte) SagaMessage
- func MakeStartTaskMessage(sagaId string, taskId string, data []byte) SagaMessage
- type SagaMessageType
- type SagaRecoveryType
- type SagaState
- type StateTaskPair
Constants ¶
const ( TaskStarted flag = 1 << iota TaskCompleted CompTaskStarted CompTaskCompleted )
Variables ¶
This section is empty.
Functions ¶
func FatalErr ¶
Checks the error returned by updating saga state. Returns true if the error is a FatalErr. Returns false if the error is transient and a retry might succeed
func GenSagaStateAndTaskId ¶
Generator for a SagaState and TaskId, returns a StateTaskPair SagaState is always valid. TaskId may or may not be part of the saga
func NewInternalLogError ¶
func NewInvalidRequestError ¶
Types ¶
type InternalLogError ¶
type InternalLogError struct {
// contains filtered or unexported fields
}
InternalLogError should be returned by the SagaLog when the request failed, but may succeed on retry this is equivalent to an HTTP 500
func (InternalLogError) Error ¶
func (e InternalLogError) Error() string
type InvalidRequestError ¶
type InvalidRequestError struct {
// contains filtered or unexported fields
}
InvalidRequestError should be returned by the SagaLog when the request is invalid and the same request will fail on restart, equivalent to an HTTP 400
func (InvalidRequestError) Error ¶
func (e InvalidRequestError) Error() string
type InvalidSagaMessageError ¶
type InvalidSagaMessageError struct {
// contains filtered or unexported fields
}
InvalidSagaMessageError signifies that the SagaMessage was not valid
func (InvalidSagaMessageError) Error ¶
func (e InvalidSagaMessageError) Error() string
type InvalidSagaStateError ¶
type InvalidSagaStateError struct {
// contains filtered or unexported fields
}
InvalidSagaStateError signifies that an illegal SagaState would occur from the requested action.
func (InvalidSagaStateError) Error ¶
func (e InvalidSagaStateError) Error() string
type MockSagaLog ¶
type MockSagaLog struct {
// contains filtered or unexported fields
}
Mock of SagaLog interface
func NewMockSagaLog ¶
func NewMockSagaLog(ctrl *gomock.Controller) *MockSagaLog
func (*MockSagaLog) EXPECT ¶
func (_m *MockSagaLog) EXPECT() *_MockSagaLogRecorder
func (*MockSagaLog) GetActiveSagas ¶
func (_m *MockSagaLog) GetActiveSagas() ([]string, error)
func (*MockSagaLog) GetMessages ¶
func (_m *MockSagaLog) GetMessages(sagaId string) ([]SagaMessage, error)
func (*MockSagaLog) LogMessage ¶
func (_m *MockSagaLog) LogMessage(message SagaMessage) error
type Saga ¶
type Saga struct {
// contains filtered or unexported fields
}
Concurrent Object Representing a Saga, to allow for the concurrent execution of tasks Methods update the state of the saga.
func (*Saga) AbortSaga ¶
Log an AbortSaga message. This indicates that the Saga has failed and all execution should be stopped and compensating transactions should be applied.
Returns an error if it fails
func (*Saga) EndCompensatingTask ¶
Log an End Compensating Task Message to the log when a Compensating Task has been successfully completed. Returns an error if it fails.
EndCompTask is idempotent with respect to sagaId & taskId. If the data passed changes the last written EndCompTask message will win
Returns an error if it fails
func (*Saga) EndSaga ¶
Log an End Saga Message to the log, returns updated SagaState Returns the resulting SagaState or an error if it fails
Once EndSaga is succesfully called, trying to log additional messages will result in a panic.
func (*Saga) EndTask ¶
Log an EndTask Message to the log. Indicates that this task has been successfully completed. Returns an error if it fails.
EndTask is idempotent with respect to sagaId & taskId. If the data passed changes the last written EndTask message will win
Returns an error if it fails
func (*Saga) GetEndCompTaskData ¶
func (*Saga) GetEndTaskData ¶
func (*Saga) GetStartCompTaskData ¶
func (*Saga) GetStartTaskData ¶
func (*Saga) GetTaskIds ¶
func (*Saga) IsCompTaskCompleted ¶
func (*Saga) IsCompTaskStarted ¶
func (*Saga) IsSagaAborted ¶
func (*Saga) IsSagaCompleted ¶
func (*Saga) IsTaskCompleted ¶
func (*Saga) IsTaskStarted ¶
func (*Saga) StartCompensatingTask ¶
Log a Start Compensating Task Message to the log. Should only be logged after a Saga has been avoided and in Rollback Recovery Mode. Should not be used in ForwardRecovery Mode returns an error if it fails
StartCompTask is idempotent with respect to sagaId & taskId. If the data passed changes the last written StartCompTask message will win
Returns an error if it fails
type SagaCoordinator ¶
type SagaCoordinator struct {
// contains filtered or unexported fields
}
SagaCoordinator organizes a set of Sagas.
func MakeSagaCoordinator ¶
func MakeSagaCoordinator(log SagaLog) SagaCoordinator
Make a Saga which uses the specied SagaLog interface for durable storage
func (SagaCoordinator) GetActiveSagas ¶
func (s SagaCoordinator) GetActiveSagas() ([]string, error)
Should be called at SEC Startup Time. Returns a Slice of In Progress SagaIds
func (SagaCoordinator) MakeSaga ¶
func (s SagaCoordinator) MakeSaga(sagaId string, job []byte) (*Saga, error)
Make a Saga add it to the SagaCoordinator, if a Saga Already exists with the same id, it will overwrite the already existing one.
func (SagaCoordinator) RecoverSagaState ¶
func (sc SagaCoordinator) RecoverSagaState(sagaId string, recoveryType SagaRecoveryType) (*Saga, error)
Recovers SagaState by reading all logged messages from the log. Utilizes the specified recoveryType to determine if Saga needs to be Aborted or can proceed safely.
Returns the current SagaState
type SagaLog ¶
type SagaLog interface { // // Log a Start Saga Message message to the log. // Returns an error if it fails. // StartSaga(sagaId string, job []byte) error // // Update the State of the Saga by Logging a message. // Returns an error if it fails. // LogMessage(message SagaMessage) error // // Returns all of the messages logged so far for the // specified saga. // GetMessages(sagaId string) ([]SagaMessage, error) // // Returns a list of all in progress sagaIds. // This MUST include all not completed sagaIds. // It may also included completed sagas // Returns an error if it fails. // GetActiveSagas() ([]string, error) }
SagaLog Interface, Implemented
type SagaMessage ¶
type SagaMessage struct {
// contains filtered or unexported fields
}
Data Structure representation of a entry in the SagaLog. Different SagaMessageTypes utilize different fields. Factory Methods are supplied for creation of Saga Messages and should be used instead of directly creatinga sagaMessage struct
func MakeAbortSagaMessage ¶
func MakeAbortSagaMessage(sagaId string) SagaMessage
AbortSaga SagaMessageType
- sagaId - id of the Saga
func MakeEndCompTaskMessage ¶
func MakeEndCompTaskMessage(sagaId string, taskId string, results []byte) SagaMessage
EndCompTask SagaMessageType
- sagaId - id of the Saga
- taskId - id of the completed compensating task. Should be the same as the original taskId
- data - any results from compensating task completion
func MakeEndSagaMessage ¶
func MakeEndSagaMessage(sagaId string) SagaMessage
EndSaga SagaMessageType
- sagaId - id of the Saga
func MakeEndTaskMessage ¶
func MakeEndTaskMessage(sagaId string, taskId string, results []byte) SagaMessage
EndTask SagaMessageType
- sagaId - id of the Saga
- taskId - id of the completed Task
- data - any results from task completion
func MakeStartCompTaskMessage ¶
func MakeStartCompTaskMessage(sagaId string, taskId string, data []byte) SagaMessage
StartCompTask SagaMessageType
- sagaId - id of the Saga
- taskId - id of the started compensating task. Should be the same as the original taskId
- data - data that is persisted to the log, useful for diagnostic information
func MakeStartSagaMessage ¶
func MakeStartSagaMessage(sagaId string, job []byte) SagaMessage
StartSaga SagaMessageType
- sagaId - id of the Saga
- data - data needed to execute the saga
func MakeStartTaskMessage ¶
func MakeStartTaskMessage(sagaId string, taskId string, data []byte) SagaMessage
StartTask SagaMessageType
- sagaId - id of the Saga
- taskId - id of the started Task
- data - data that is persisted to the log, useful for diagnostic information
func (SagaMessage) GetData ¶
func (sm SagaMessage) GetData() []byte
func (SagaMessage) GetMessageType ¶
func (sm SagaMessage) GetMessageType() SagaMessageType
func (SagaMessage) GetSagaId ¶
func (sm SagaMessage) GetSagaId() string
func (SagaMessage) GetTaskId ¶
func (sm SagaMessage) GetTaskId() string
type SagaMessageType ¶
type SagaMessageType int
const ( StartSaga SagaMessageType = iota EndSaga AbortSaga StartTask EndTask StartCompTask EndCompTask )
func (SagaMessageType) String ¶
func (s SagaMessageType) String() string
type SagaRecoveryType ¶
type SagaRecoveryType int
const ( RollbackRecovery SagaRecoveryType = iota ForwardRecovery )
Saga Recovery Types define how to interpret SagaState in RecoveryMode.
ForwardRecovery: all tasks in the saga must be executed at least once.
tasks MUST BE idempotent
RollbackRecovery: if Saga is Aborted or in unsafe state, compensating
tasks for all started tasks need to be executed. compensating tasks MUST BE idempotent.
type SagaState ¶
type SagaState struct {
// contains filtered or unexported fields
}
Data Structure representation of the current state of the Saga.
type StateTaskPair ¶
type StateTaskPair struct {
// contains filtered or unexported fields
}
func (StateTaskPair) String ¶
func (p StateTaskPair) String() string