Documentation ¶
Index ¶
- Variables
- func WithRefreshInterval(refreshInterval time.Duration) func(options *Options)
- func WithSortKey(sortKeyColumnName string) func(options *Options)
- func WithSortKeyValue(sortKeyValue types.AttributeValue) func(options *Options)
- func WithTimeout(timeout time.Duration) func(options *Options)
- type DynamodbClient
- type IdGenerator
- type Lock
- type Options
- type RepositoryLockHandler
Constants ¶
This section is empty.
Variables ¶
var ErrLockUpdate = errors.New("lock update error")
var ErrTimeout = errors.New("timeout")
var SkString = &types.AttributeValueMemberS{Value: "##LOCK##"}
Functions ¶
func WithRefreshInterval ¶
WithRefreshInterval Specifies a refresh interval that is used by the lock handler to poll if the lock is still active. Default value is 200ms
func WithSortKey ¶
WithSortKey Specifies the sort key column if exists.
func WithSortKeyValue ¶
func WithSortKeyValue(sortKeyValue types.AttributeValue) func(options *Options)
WithSortKeyValue Specifies the sort key value to use for a lock. This is required if the column hash a sort key that is not of they string. Note that the partition key + sort key must be unique within the table.
func WithTimeout ¶
WithTimeout Specifies a timeout value set in the distributed lock. Default value is 1 second.
Types ¶
type DynamodbClient ¶
type DynamodbClient interface { PutItem(ctx context.Context, params *dynamodb.PutItemInput, optFns ...func(options *dynamodb.Options)) (*dynamodb.PutItemOutput, error) GetItem(ctx context.Context, params *dynamodb.GetItemInput, optFns ...func(options *dynamodb.Options)) (*dynamodb.GetItemOutput, error) DeleteItem(ctx context.Context, params *dynamodb.DeleteItemInput, optFns ...func(options *dynamodb.Options)) (*dynamodb.DeleteItemOutput, error) }
type IdGenerator ¶
type IdGenerator interface {
ID() string
}
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
func (*Lock) TransactionCondition ¶
func (l *Lock) TransactionCondition() types.TransactWriteItem
TransactionCondition returns a TransactWriteItem to validate if the lock is still active
func (*Lock) TransactionWithRefresh ¶
func (l *Lock) TransactionWithRefresh() (types.TransactWriteItem, func(*dynamodb.TransactWriteItemsOutput, error) (*dynamodb.TransactWriteItemsOutput, error))
TransactionWithRefresh returns a TransactWriteItem to validate if the lock is still active and refresh the lock if successful Note the callback function returned as second argument should be called with the return types of the TransactWriteItems call
type Options ¶
type Options struct { // SortKeyName if table has a sort key this value represent the sort key value SortKeyName *string // SortKeyDefault value SortKeyValue types.AttributeValue // Timeout stored in distributed lock Timeout *time.Duration // RefreshInterval between two lock poll request RefreshInterval *time.Duration // IdGenerator a generator of unique IDs IdGenerator IdGenerator }
type RepositoryLockHandler ¶
type RepositoryLockHandler struct { Client DynamodbClient TableName string PartitionKeyName string SortKeyName *string SortKeyValue types.AttributeValue Timeout time.Duration RefreshInterval time.Duration IdGenerator IdGenerator }
RepositoryLockHandler will handle locks distributed locks within a single dynamodb table The RepositoryLockHandler can create locks on hash tables and hash+range tables
func New ¶
func New(client DynamodbClient, tableName string, partitionKeyName string, optFns ...func(options *Options)) *RepositoryLockHandler
New create a new initialized distributed lock.
func (*RepositoryLockHandler) Lock ¶
func (h *RepositoryLockHandler) Lock(ctx context.Context, partition types.AttributeValue) (*Lock, error)
Lock tries to lock a specified partition. The method will return a new lock once it is able to create a lock. If it was unable to create a new lock it will try after a RefreshInterval. Polling will stop if the context is Done.
func (*RepositoryLockHandler) TryLock ¶
func (h *RepositoryLockHandler) TryLock(ctx context.Context, partition types.AttributeValue) (*Lock, bool, error)
TryLock tries to lock a specified partition. If the handler was able to lock the partition a new lock will be returned. Additionally, the second return argument will be true If the handler was unable to lock the partition nil and false is returned as first arguments.