Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( GlobalLockStore *LockStore // LeaseNotObtainedError returned when lease not obtained LeaseNotObtainedError error = errors.New("Lease Not Obtained") )
var ( // LeaseLostError returned when a lease is lost LeaseLostError error = errors.New("Lease Lost") )
Functions ¶
func SetupLockStoreGlobal ¶
SetupLockStoreGlobal initializes a global LockStore. Requires an instance of DynamoDB, a table name, and the name of the hash key for lock items.
Types ¶
type Lease ¶
type Lease struct { // LeaseID - HashKey value of the lease row LeaseID string // AttributeValues - Extra AttributeValues from the lease row AttributeValues map[string]*dynamodb.AttributeValue // Request - Lease Request that resulted in the Lease Request LeaseRequest // Until - Time the lease expires Until time.Time }
A Lease represents a lease for a given ID
type LeaseLogger ¶
type LeaseLogger interface { LogInfoMessage(message string, keyvals ...interface{}) LogErrorMessage(message string, keyvals ...interface{}) }
LeaseLogger is the interface for the internal logger.
type LeaseRequest ¶
type LeaseRequest interface { // LesseeID - A unique ID for the Lessee, so the lock is held for a single Lessee. LesseeID() string // LeaseDuration - How long to initially take out a lease for. LeaseDuration() time.Duration }
A LeaseRequest represents a request for a Lease.
type LockStore ¶
LockStore is the lockerStore implementation for DynamoDB.
func NewLockStore ¶
Returns a new LockStore. Requires an instance of DynamoDB, a table name, and the name of the hash key for lock items.
func (*LockStore) Lease ¶
Attempt to acquire, or renew, a lease on the given leaseID.
Returns a Lease if successfully acquired/renewed; if the lease is currently held by someone else, returns a LeaseNotObtainedError and nil Lease.
func (*LockStore) ListLeaseIDs ¶
List the IDs of all lease items stored in DynamoDB.
Returns a list of string PKs of Lease's; returns errors if failing to contact Dynamo.
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
A Locker provides methods to obtain and renew leases.
func NewLocker ¶
func NewLocker(store lockerStore) *Locker
Initialization of a Locker, requires a lockerStore.
func (*Locker) Heartbeat ¶
Heartbeat starts a loop that renews the lease periodically. Returns LeaseLostError if the lease is lost Returns other errors when failing to contact DDB.
func (*Locker) ObtainLease ¶
func (l *Locker) ObtainLease(request LeaseRequest) (*Lease, error)
ObtainLease scans over possible leaseable items and tries to acquire a lease on any of them. Returns nil with a LeaseNotObtainedError if it can't acquire a lease.
func (*Locker) WaitUntilLeaseObtained ¶
func (l *Locker) WaitUntilLeaseObtained(request LeaseRequest, waitPeriod time.Duration) *Lease
WaitUntilLeaseObtained scans over possible leaseable items and tries to acquire a lease on any of them. Returns as soon as it acquires a lease on one.
Keeps trying indefinitely until it acquires a lease, waiting waitPeriod between scans of the table.