processinglock

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoLock is returned when a lock can not be acquired due to normal causes.
	ErrNoLock = errors.New("advisory lock already taken or incompatible version")
)

Static errors

Functions

This section is empty.

Types

type Config

type Config struct {
	Type    Type
	Version int // Version must match the value in engine_processing_versions exactly or no lock will be obtained.
}

Config defines the parameters of the lock.

func (Config) String

func (cfg Config) String() string

String returns the string representation of Config.

type Conn

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

Conn allows using locked transactions over a single connection.

func (*Conn) BeginTx

func (c *Conn) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx will start a new transaction.

func (*Conn) Close

func (c *Conn) Close() error

Close returns the connection to the pool.

func (*Conn) Exec

func (c *Conn) Exec(ctx context.Context, stmt *sql.Stmt, args ...interface{}) (sql.Result, error)

Exec will call ExecContext on the statement wrapped in a locked transaction.

func (*Conn) ExecWithoutLock

func (c *Conn) ExecWithoutLock(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecWithoutLock will run a query directly on the connection (no Tx or locking).

type Lock

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

A Lock is used to start "locked" transactions.

func NewLock

func NewLock(ctx context.Context, db *sql.DB, cfg Config) (*Lock, error)

NewLock will return a new Lock for the given Config.

func (*Lock) BeginTx

func (l *Lock) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx will start a transaction with the appropriate lock in place (based on Config).

func (*Lock) Conn

func (l *Lock) Conn(ctx context.Context) (*Conn, error)

Conn returns a new connection from the DB pool.

Note: No version checking/locking is done until a transaction is started.

func (*Lock) Exec

func (l *Lock) Exec(ctx context.Context, stmt *sql.Stmt, args ...interface{}) (sql.Result, error)

Exec will run ExecContext on the statement, wrapped in a locked transaction.

type Type

type Type string

Type indicates the lock type. For TypeMessage, the RegionID is used.

const (
	TypeEscalation   Type = "escalation"
	TypeHeartbeat    Type = "heartbeat"
	TypeNPCycle      Type = "np_cycle"
	TypeRotation     Type = "rotation"
	TypeSchedule     Type = "schedule"
	TypeStatusUpdate Type = "status_update"
	TypeVerify       Type = "verify"
	TypeMessage      Type = "message"
	TypeCleanup      Type = "cleanup"
)

Recognized types

func (Type) LockID

func (t Type) LockID() int

LockID returns the int value used for the advisory lock for the Type.

func (*Type) Scan

func (t *Type) Scan(value interface{}) error

Scan will scan a DB enum value into Type.

func (Type) Value

func (t Type) Value() (driver.Value, error)

Value will return the DB enum value of the Type.

Jump to

Keyboard shortcuts

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