sstxn

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: BSD-2-Clause Imports: 4 Imported by: 2

Documentation

Overview

The sstxn package implements the txn/Runner interface for server-side transactions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWriteConflict

func IsWriteConflict(err error) bool

IsWriteConflict checks if the supplied error is a Mongo WriteConflict error. This usually indicates we had 2 transactions trying to write to the same document, but is also possible when the server side needs the transaction to be retried due to replica consistency issues.

Types

type Logger

type Logger interface {
	Tracef(message string, args ...interface{})
	Debugf(message string, args ...interface{})
	Infof(message string, args ...interface{})
	Warningf(message string, args ...interface{})
	Errorf(message string, args ...interface{})
	Criticalf(message string, args ...interface{})
}

Logger defines the types of logging that we will be doing

type Runner

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

A Runner applies operations as part of a transaction onto any number of collections within a database. See the Run method for details.

func NewRunner

func NewRunner(db *mgo.Database, logger Logger) *Runner

NewRunner returns a new transaction runner that uses tc to hold its transactions.

Multiple transaction collections may exist in a single database, but all collections that are touched by operations in a given transaction collection must be handled exclusively by it.

A second collection with the same name of tc but suffixed by ".stash" will be used for implementing the transactional behavior of insert and remove operations.

func (*Runner) ChangeLog

func (r *Runner) ChangeLog(logc *mgo.Collection)

ChangeLog enables logging of changes to the given collection every time a transaction that modifies content is done being applied.

Saved documents are in the format:

{"_id": <txn id>, <collection>: {"d": [<doc id>, ...], "r": [<doc revno>, ...]}}

The document revision is the value of the txn-revno field after the change has been applied. Negative values indicate the document was not present in the collection. Revisions will not change when updates or removes are applied to missing documents or inserts are attempted when the document isn't present.

func (*Runner) ResumeAll

func (r *Runner) ResumeAll() error

ResumeAll is a no-op on server-side transactions because there is nothing to resume.

func (*Runner) Run

func (r *Runner) Run(ops []txn.Op, id bson.ObjectId, info interface{}) (err error)

Run creates a new transaction with ops and runs it immediately. The id parameter specifies the transaction id, and may be written down ahead of time to later verify the success of the change and resume it, when the procedure is interrupted for any reason. If empty, a random id will be generated. The info parameter, is ignored, and only preserved for api compatibility with client-side transaction Runner.Run()

Operations across documents are not atomically applied, but are guaranteed to be eventually all applied in the order provided or all aborted, as long as the affected documents are only modified through transactions. If documents are simultaneously modified by transactions and out of transactions the behavior is undefined.

If Run returns no errors, all operations were applied successfully. If it returns ErrAborted, one or more operations can't be applied and the transaction was entirely aborted with no changes performed.

Any number of transactions may be run concurrently, with one runner or many.

func (*Runner) SetPostAssertHook

func (r *Runner) SetPostAssertHook(hook func())

SetPostAssertHook will call func() after we have done Assertions, but before we actually make any database changes.

func (*Runner) SetStartHook

func (r *Runner) SetStartHook(hook func())

SetStartHook will call func() as soon as StartTransaction is called. This can be used to play games before the Assert check.

Jump to

Keyboard shortcuts

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