Package org.graylog2.cluster.lock
Class MongoLockService
java.lang.Object
org.graylog2.cluster.lock.MongoLockService
- All Implemented Interfaces:
LockService
Lock service implementation using MongoDB to maintain locks.
Unless a lock is kept alive by periodically re-requesting the same lock, it will eventually expire.
Lock expiry is handled by MongoDB internally. We set lock expiry to 60 seconds, but in practice it may take up to ~2
minutes until a lock really expires.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMongoLockService
(NodeId nodeId, MongoConnection mongoConnection, Duration lockTTL) -
Method Summary
Modifier and TypeMethodDescriptionextendLock
(Lock lock) Extend the expiry time of an existing lock.Request a lock.Request a lock.Unlock an existing lock.Unlock an existing lock.
-
Field Details
-
COLLECTION_NAME
- See Also:
-
MIN_LOCK_TTL
-
-
Constructor Details
-
MongoLockService
@Inject public MongoLockService(NodeId nodeId, MongoConnection mongoConnection, @Named("lock_service_lock_ttl") Duration lockTTL)
-
-
Method Details
-
lock
Description copied from interface:LockService
Request a lock. If a lock already exists, the lock expiry time will be extended.- Specified by:
lock
in interfaceLockService
- Parameters:
resource
- Unique identifier for the resource that should be guarded by this lock.lockContext
- an identifier that will be appended to the callers' node id. This will create the lock owner string. A context can be used for resources that should only allow a single lock to be acquired, even from the same node. If the lockContext is null, only the nodeId will be used.- Returns:
- A
Lock
object, if a lock was obtained. An emptyOptional
, if no lock could be acquired.
-
lock
Description copied from interface:LockService
Request a lock. If a lock already exists, the lock expiry time will be extended.- Specified by:
lock
in interfaceLockService
- Parameters:
resource
- Unique identifier for the resource that should be guarded by this lock.- Returns:
- A
Lock
object, if a lock was obtained. An emptyOptional
, if no lock could be acquired.
-
extendLock
Description copied from interface:LockService
Extend the expiry time of an existing lock.- Specified by:
extendLock
in interfaceLockService
- Parameters:
lock
- the lock that should be extended.- Returns:
- A
Lock
object, if the lock could be extended. An emptyOptional
, if no lock extension could be acquired.
-
unlock
Description copied from interface:LockService
Unlock an existing lock.- Specified by:
unlock
in interfaceLockService
- Parameters:
resource
- Unique identifier for the resource that was guarded by this lock.lockContext
- the lockContext that was used to guard this lock.- Returns:
- A
Lock
object, if the lock could be unlocked. An emptyOptional
, if no lock was found.
-
unlock
Description copied from interface:LockService
Unlock an existing lock.- Specified by:
unlock
in interfaceLockService
- Parameters:
lock
- The lock to unlock.- Returns:
- A
Lock
object, if the lock could be unlocked. An emptyOptional
, if no lock was found.
-