Documentation
¶
Overview ¶
Package etx uses logging to make extended transactions from a sequence of operations.
For example it allows a web server request to be split between an immediate operation and asynchronous completion, with a guarantee that the second part will be completed even if the server is restarted between the two parts. It also allows responsibility for continuing the extended transaction to be passed between resource managers.
Index ¶
- func String(tx TxId) string
- func Timestamp(tx TxId) time.Time
- type App
- type Op
- type RM
- type Redo
- type RedoStore
- type TM
- func (tm *TM) AddNext(tx TxId, rm RM, opType int, op Op) error
- func (tm *TM) AddTimed(tx TxId, rm RM, opType int, op Op, after time.Duration) error
- func (tm *TM) Begin() TxId
- func (tm *TM) Do(tx TxId) error
- func (tm *TM) End(txId TxId) error
- func (tm *TM) Forget(tx TxId, rm RM, opType int) error
- func (tm *TM) Recover(mgrs ...RM) error
- type TxId
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type App ¶
type App interface {
// Log optionally records an error
Log(error)
}
App is the interface to functions provided by the parent application.
type Op ¶
type Op interface {
}
Op is the interface to an RM operation. Operations must either be database transactions or idempotent.
type RM ¶
type RM interface {
Name() string // manager name, for the redo log
ForOperation(opType int) Op // return operation struct to receive unmarshalled data
Operation(tx TxId, opType int, op Op) // operation for execution, to be executed in current goroutine
}
RM is the interface for a resource manager, which implements operations.
type Redo ¶
type Redo struct {
Id int64 // operation ID
Tx int64 // transaction ID
Manager string // resource manager name
RedoType int // transaction manager's type
Delay int // timed delay, in seconds
OpType int // operation type
Operation []byte // operation arguments, in JSON
}
Redo struct holds the stored data for a V2 transaction operation.
type RedoStore ¶
type RedoStore interface {
All() []*Redo // all redo log entries in ID order
DeleteId(id int64) error // delete redo
ForManager(rm string, before int64) []*Redo // aged log entries for RM
GetIf(id int64) (*Redo, error) // get entry if it still exists
Insert(t *Redo) error // add entry
Update(t *Redo) error // update entry
}
RedoStore is the interface for storage of V2 extended transactions, implemented by the parent application. The store must implement database transactions so that tx.Redo records are stored either: (1) with the associated RM database transaction, or (2) before the associated RM idempotent operation.
type TM ¶
type TM struct {
// contains filtered or unexported fields
}
TM holds transaction manager state, and dependencies of this package on the parent application. It has no non-volatile state of its own.
func (*TM) AddNext ¶
AddNext adds an operation to the extended transaction, to be executed after the previous one. Database changes may have been requested, but must not be commmitted yet.
func (*TM) AddTimed ¶
AddTimed adds an operation to the extended transaction, to be executed after the specified delay. The delay time has a resolution of one minute, and a maximum of 90 days.
func (*TM) Do ¶
Do executes the operations specified by AddNext(). It is called to start the first operation and after the completion of each asyncronous operation. It must be called after database changes have been committed.
func (*TM) End ¶
End terminates and forgets an operation. It must be called by each RM.Operation, synchronously or asynchronously, in the context of a RedoStore transaction.