Class ZkDistributedCollectionLockFactory
- java.lang.Object
-
- org.apache.solr.cloud.ZkDistributedCollectionLockFactory
-
- All Implemented Interfaces:
DistributedCollectionLockFactory
public class ZkDistributedCollectionLockFactory extends Object implements DistributedCollectionLockFactory
A distributed lock implementation using Zookeeper "directory" nodes created within a collection znode hierarchy, for use with the distributed Collection API implementation. The locks are implemented using ephemeral nodes placed below the "directory" nodes.- See Also:
- Zookeeper lock recipe
-
-
Constructor Summary
Constructors Constructor Description ZkDistributedCollectionLockFactory(org.apache.solr.common.cloud.SolrZkClient zkClient, String rootPath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DistributedLock
createLock(boolean isWriteLock, org.apache.solr.common.params.CollectionParams.LockLevel level, String collName, String shardId, String replicaName)
Create a new lock of the specified type (read or write) entering the "competition" for actually getting the lock at the given level for the given path i.e.protected DistributedLock
doCreateLock(boolean isWriteLock, String lockPath)
protected StringBuilder
getPathPrefix()
-
-
-
Constructor Detail
-
ZkDistributedCollectionLockFactory
public ZkDistributedCollectionLockFactory(org.apache.solr.common.cloud.SolrZkClient zkClient, String rootPath)
-
-
Method Detail
-
createLock
public DistributedLock createLock(boolean isWriteLock, org.apache.solr.common.params.CollectionParams.LockLevel level, String collName, String shardId, String replicaName)
Description copied from interface:DistributedCollectionLockFactory
Create a new lock of the specified type (read or write) entering the "competition" for actually getting the lock at the given level for the given path i.e. a lock atcollName
or a lock atcollName/shardId
or a lock atcollName/shardId/replicaName
, depending on the passedlevel
.The paths are used to define which locks compete with each other (locks of equal paths compete).
Upon return from this call, the lock has not been acquired but the it had entered the lock acquiring "competition", and the caller can decide to wait until the lock is granted by calling
DistributedLock.waitUntilAcquired()
.
Separating the lock creation from lock acquisition allows a more deterministic release of the locks when/if they can't be acquired.Locks at different paths are independent of each other, multiple
DistributedLock
are therefore requested for a single operation and are packaged together and returned as anDistributedMultiLock
, seeCollectionApiLockFactory.createCollectionApiLock(org.apache.solr.common.params.CollectionParams.LockLevel, java.lang.String, java.lang.String, java.lang.String)
.- Specified by:
createLock
in interfaceDistributedCollectionLockFactory
- Parameters:
isWriteLock
-true
if requesting a write lock,false
for a read lock.level
- The requested locking level. Can be one of:CollectionParams.LockLevel.COLLECTION
CollectionParams.LockLevel.SHARD
CollectionParams.LockLevel.REPLICA
collName
- the collection name, can never benull
as is needed for all locks.shardId
- is ignored and can benull
iflevel
isCollectionParams.LockLevel.COLLECTION
replicaName
- is ignored and can benull
iflevel
isCollectionParams.LockLevel.COLLECTION
orCollectionParams.LockLevel.SHARD
- Returns:
- a lock instance that must be
DistributedLock.release()
'ed in afinally
, regardless of the lock having been acquired or not.
-
doCreateLock
protected DistributedLock doCreateLock(boolean isWriteLock, String lockPath)
-
getPathPrefix
protected StringBuilder getPathPrefix()
-
-