Documentation ¶
Index ¶
- func NewLocker(dynamodbClient *dynamodb.Client, ownerName string, options ...LockerOption) locker.Locker
- type LockerOption
- func WithDynamoDbTimeout(dynamoDbTimeout time.Duration) LockerOption
- func WithFencingEnabled(fencingEnabled bool) LockerOption
- func WithHeartbeat(heartbeat time.Duration) LockerOption
- func WithLease(lease time.Duration) LockerOption
- func WithLockIdPrefix(lockIdPrefix string) LockerOption
- func WithLogger(logger logger.Logger) LockerOption
- func WithMaxClockSkew(maxClockSkew time.Duration) LockerOption
- func WithTableName(tableName string) LockerOption
- func WithWarnAfter(warnAfter time.Duration) LockerOption
- func WithWarnDisabled() LockerOption
- type LockerParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLocker ¶
func NewLocker(dynamodbClient *dynamodb.Client, ownerName string, options ...LockerOption) locker.Locker
NewLocker creates a new Locker based on DynamoDB. ownerName: unique name identifying this Locker instance - this information will be written into the DynamoDB options: Additional, optional options.
Types ¶
type LockerOption ¶
type LockerOption func(params *LockerParams)
func WithDynamoDbTimeout ¶
func WithDynamoDbTimeout(dynamoDbTimeout time.Duration) LockerOption
Use this timeout for dynamoDb calls instead of the default. Locker will call dynamoDb both in methods directly triggered by the user, but also in goroutines (e.g. heartbeat). This timeout will be used for the remote calls.
func WithFencingEnabled ¶
func WithFencingEnabled(fencingEnabled bool) LockerOption
Use this fencing state instead of the default.
When fencing is enabled, each lock provides a fencing token, otherwise not. Maintaining fencing tokens has downsides:
- More requests to DynamoDB needed
- Locks are not actually deleted in DynamoDB but need to be kept there forever, in order to ensure that the fencing tokens fulfill the promises as given in Lock.FencingToken() (monotonically increasing).
func WithHeartbeat ¶
func WithHeartbeat(heartbeat time.Duration) LockerOption
Use the given heartbeat duration instead of the default defaultHeartbeat. See WithLease. Also, at heartbeat time, internal cleanup of Locker datastructures is executed, if it did not happen before.
func WithLease ¶
func WithLease(lease time.Duration) LockerOption
Use the given Lease time instead of the default defaultLease. The lease time is the duration after which a lock will timeout automatically and other owners can steal a lock (after an additional wait for the MaxClockSkew). The Locker runs a heartbeat loop which auto-refreshes all locks regularly, extending their lifetime to the leasetime as long as this locker is running and as long as we have a connection to DynamoDB. The lease time and heartbeat time should be chosen in a way that multiple heartbeats are sent during a normal lease time, which allows single heartbeats to fail e.g. due to temporary connection issues, but the lock not being lost immediately. Note that Locker will store a fixed internal leaseUntilTime for each lock, i.e. a timestamp that identifies when the lock will timeout if it is not refreshed with heartbeats. The guarantees that the Locks give, require that system clocks are synchronized well, see WithMaxClockSkew.
func WithLockIdPrefix ¶
func WithLockIdPrefix(lockIdPrefix string) LockerOption
Use this prefix to all lockIds that are used within TryLock. Since a single Locker should lock only items of the same type, this prefix can be used to re-use the same DynamoDB table for different Lockers locking different kinds of objects.
func WithLogger ¶
func WithLogger(logger logger.Logger) LockerOption
Use the given Logger instead of a default one
func WithMaxClockSkew ¶
func WithMaxClockSkew(maxClockSkew time.Duration) LockerOption
Use this maximum clock skew instead of the default defaultMaxClockSkew. Locker relies on well-synchronized system clocks, which in reality is very hard to achieve. To compensate, this parameter specifies an upper bound of the time difference of the system clocks of all participanting systems, i.e. all systems that execute a Locker with the same LockIdPrefix on the same dynamoDB table. The Locker will not steal an existing lock for leaseUntilTime+maxClockSkew.
func WithTableName ¶
func WithTableName(tableName string) LockerOption
Use the given DynamoDB table name instead of the default defaultTableName
func WithWarnAfter ¶
func WithWarnAfter(warnAfter time.Duration) LockerOption
Use the given warn time instead of the default defaultWarnAfter. A lock that has been acquired has a WarnChan that will receive a message after this amount of time has passed since acquiring the lock or the last successful heartbeat. This allows the program to stop working on resources that are locked by the distributed locks, since after the lock actually expired, there is no way to guarantee exclusive access to those resources anymore.
Example: leaseTime = 1 min, heartbeat = 15 sec, warnAfter = 50 sec After the lock is acquired, the heartbeats start extending the lifetime of the lock, each setting the internal leaseUntilTime of the lock to currentTime + lease duration. If all heartbeats succeed, there will be no warning issued. If heartbeats start failing, e.g. due to a network connection issue to DynamoDB, then 50 sec after the last update to the internal leaseUntilTime, the lock will send a message on the WarnChan.
See also WithWarnDisabled
func WithWarnDisabled ¶
func WithWarnDisabled() LockerOption
Disables warnChans fully. The corresponding methods will return nil.
See also WithWarnAfter.
type LockerParams ¶
type LockerParams struct {
// contains filtered or unexported fields
}