storage

package
v0.0.0-...-1c3f716 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	// Inserts a new lock with the given details iff none exists or the exisiting lock is older than stealLockUntil. In
	// the latter case the lock is stolen and details about the old lock are returned.
	// If the lock is taken by someone else and it is not being stolen, a dlock.LockTakenError is returned, but other
	// errors may be returned.
	InsertNewLock(ctx context.Context, lockId string, ownerName string, leaseUntil time.Time, stealLockUntil time.Time) (*StolenLockInfo, error)

	// Remove a lock iff its current leaseUntil and owner is as specified. If the lock is not removed or any other error
	// occurs, return an error.
	RemoveLock(ctx context.Context, lockId string, leaseUntil time.Time, ownerName string) error

	// Update the leaseUntil field of an existing lock iff its current leaseUntil is still oldUntil and the owner is as
	// specified. If the lock is not updated or any other error occurs, return an error.
	UpdateUntil(ctx context.Context, lockId string, oldUntil time.Time, newUntil time.Time, ownerName string) error
}

Database layer providing serializable compare-and-set operations as required by the Locker.

A lock has a unique identifying lockId and if it is locked a current ownerName and a timestamp until when it is leased by that owner. A lock can be stolen if the existing leaseTime is older than a specific time.

func NewDynamoDb

func NewDynamoDb(dynamoDbClient *dynamodb.Client, tableName string, timeout time.Duration) DB

Creates a new DB implemnentation using a DynamoDB backend. It uses the given dynamoDB table name and adds the given timeout to all calls to dynamoDB.

type DynamoDB

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

func (*DynamoDB) InsertNewLock

func (d *DynamoDB) InsertNewLock(ctx context.Context, lockId string, ownerName string, leaseUntil time.Time, stealLockUntil time.Time) (*StolenLockInfo, error)

func (*DynamoDB) RemoveLock

func (d *DynamoDB) RemoveLock(ctx context.Context, lockId string, leaseUntil time.Time, ownerName string) error

func (*DynamoDB) UpdateUntil

func (d *DynamoDB) UpdateUntil(ctx context.Context, lockId string, oldUntil time.Time, newUntil time.Time, ownerName string) error

type DynamoDBWithFencing

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

func (*DynamoDBWithFencing) InsertNewLock

func (d *DynamoDBWithFencing) InsertNewLock(ctx context.Context, lockId string, ownerName string, leaseUntil time.Time, stealLockUntil time.Time) (*StolenLockInfo, *big.Int, error)

func (*DynamoDBWithFencing) ReleaseLock

func (d *DynamoDBWithFencing) ReleaseLock(ctx context.Context, lockId string, leaseUntil time.Time, ownerName string) error

func (*DynamoDBWithFencing) UpdateUntil

func (d *DynamoDBWithFencing) UpdateUntil(ctx context.Context, lockId string, oldUntil time.Time, newUntil time.Time, ownerName string) error

type FencingDB

type FencingDB interface {
	// Inserts a new lock with the given details iff none exists or the exisiting lock is older than stealLockUntil. In
	// the latter case the lock is stolen and details about the old lock are returned. The lock fencing token is retruned
	// always.
	// If the lock is taken by someone else and it is not being stolen, a dlock.LockTakenError is returned, but other
	// errors may be returned.
	//
	// The big.Int result is the unique fencing token for the new lock.
	//
	// A fencing token is guaranteed to be of larger value than all previously acquired locks for the given lockId
	// (monotonically increasing). It can be used for fencing support in downstream systems as described at
	// https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html#making-the-lock-safe-with-fencing.
	// The actual token will never be negative.
	InsertNewLock(ctx context.Context, lockId string, ownerName string, leaseUntil time.Time, stealLockUntil time.Time) (*StolenLockInfo, *big.Int, error)

	// Release a lock iff its current leaseUntil and owner is as specified. If the lock is not released or any other error
	// occurs, return an error.
	ReleaseLock(ctx context.Context, lockId string, leaseUntil time.Time, ownerName string) error

	// Update the leaseUntil field of an existing lock iff its current leaseUntil is still oldUntil and the owner is as
	// specified. If the lock is not updated or any other error occurs, return an error.
	UpdateUntil(ctx context.Context, lockId string, oldUntil time.Time, newUntil time.Time, ownerName string) error
}

Database layer providing serializable compare-and-set operations as required by the Locker with Fencing support.

A lock has a unique identifying lockId and if it is locked a current ownerName and a timestamp until when it is leased by that owner. A lock can be stolen if the existing leaseTime is older than a specific time.

func NewDynamoDbWithFencing

func NewDynamoDbWithFencing(dynamoDbClient *dynamodb.Client, tableName string, timeout time.Duration) FencingDB

Creates a new DB implemnentation using a DynamoDB backend. It uses the given dynamoDB table name and adds the given timeout to all calls to dynamoDB.

type StolenLockInfo

type StolenLockInfo struct {
	// The owner who previously owned the lock
	OwnerName string
	// The time until that owner owned the lock previously
	LockedUntil time.Time
}

Jump to

Keyboard shortcuts

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