Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- type Lock
- func (l *Lock) Acquire(ctx context.Context, id string) (lockID string, err error)
- func (l *Lock) Close(ctx context.Context)
- func (l *Lock) Init(ctx context.Context, lockClient Client, lockPurger Purger)
- func (l *Lock) Lock(ctx context.Context, resourceID string) (lockID string, err error)
- func (l *Lock) Unlock(ctx context.Context, lockID string)
- type Purger
Constants ¶
const PurgerPeriod = 5 * time.Minute
PurgerPeriod is the time period between expired lock purges
const TTL = 30
TTL is the 'time to live' for a lock in number of seconds
Variables ¶
var AcquireMaxRetries = 10
AcquireMaxRetries is the maximum number of locking retries by the Acquire lock, discounting the first attempt
var AcquirePeriod = 250 * time.Millisecond
AcquirePeriod is the time period between acquire lock retries
var ErrAcquireMaxRetries = errors.New("cannot acquire lock, maximum number of retries has been reached")
ErrAcquireMaxRetries is an error returned when acquire fails after retrying to lock a resource 'AcquireMaxRetries' times
var ErrMongoDbClosing = errors.New("mongo db is being closed")
ErrMongoDbClosing is an error returned because MongoDB is being closed
var ErrUnlockMaxRetries = errors.New("cannot unlock, maximum number of retries has been reached")
ErrUnlockMaxRetries is an error logged when unlock fails after retrying to unlock a resource 'UnlockMaxRetries' times
var GenerateTimeID = func() int { return time.Now().Nanosecond() }
GenerateTimeID returns the current timestamp in nanoseconds
var UnlockMaxRetries = 100
UnlockMaxRetries is the maximum number of unlocking retries by the Unlock lock, discounting the first attempt
var UnlockPeriod = 5 * time.Millisecond
UnlockPeriod is the time period between Unlock lock retries
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { XLock(ctx context.Context, resourceName, lockID string, ld lock.LockDetails) error Unlock(ctx context.Context, lockID string) ([]lock.LockStatus, error) }
Client defines the lock Client methods from mongo-lock
type Lock ¶
type Lock struct { Client Client CloserChannel chan struct{} Purger Purger WaitGroup *sync.WaitGroup Resource string }
Lock is a MongoDB lock for a resource
func New ¶
func New(ctx context.Context, mongoConnection *mongoDriver.MongoConnection, resource string) *Lock
New creates a new mongoDB lock for the provided session, db, collection and resource
func (*Lock) Acquire ¶
Acquire tries to lock the provided id. If the resource is already locked, this function will block until the existing lock is released, at which point we acquire the lock and return.
func (*Lock) Init ¶
Init initialises a lock with the provided client and purger, and starts the purger loop