Class DefaultZooKeeperDistributedLockService
java.lang.Object
com.broadleafcommerce.search.index.solr.service.DefaultZooKeeperDistributedLockService
- All Implemented Interfaces:
com.broadleafcommerce.search.index.core.Distributable
,com.broadleafcommerce.search.index.core.LockService
,org.springframework.beans.factory.DisposableBean
public class DefaultZooKeeperDistributedLockService
extends Object
implements com.broadleafcommerce.search.index.core.LockService, org.springframework.beans.factory.DisposableBean
Service to provide access to a
Lock
backed by Apache ZooKeeper
- specifically, a ReentrantDistributedZookeeperLock
. These are meant to be shared locks,
across threads. While the lock instances are shared within a runtime environment or JVM, the
actual lock semantics are shared across runtime environments or JVMs, as long as all runtime
environments that make use of these locks reference the same ZooKeeper cluster.- Author:
- Kelly Tisdell (ktisdell)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultZooKeeperDistributedLockService
(org.apache.solr.common.cloud.SolrZkClient zooKeeper, com.broadleafcommerce.search.index.core.ProcessStateService processStateService) DefaultZooKeeperDistributedLockService
(org.apache.solr.common.cloud.SolrZkClient zooKeeper, List<org.apache.zookeeper.data.ACL> acls, com.broadleafcommerce.search.index.core.ProcessStateService processStateService) DefaultZooKeeperDistributedLockService
(org.apache.solr.common.cloud.SolrZkClient zooKeeper, org.springframework.context.ApplicationContext applicationContext, com.broadleafcommerce.search.index.core.ProcessStateService processStateService) DefaultZooKeeperDistributedLockService
(org.apache.solr.common.cloud.SolrZkClient zooKeeper, org.springframework.context.ApplicationContext applicationContext, List<org.apache.zookeeper.data.ACL> acls, com.broadleafcommerce.search.index.core.ProcessStateService processStateService) -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
This cleans up any sharedReentrantDistributedZookeeperLock
instances and stops their respective lock failure monitor threads.protected List<org.apache.zookeeper.data.ACL>
getAcls()
protected org.springframework.context.ApplicationContext
protected String
protected org.apache.solr.common.cloud.SolrZkClient
void
handleLockFailedEvent
(com.broadleafcommerce.search.provider.solr.util.zk.ZookeeperLockFailedEvent event) TheReentrantDistributedZookeeperLock
has a failure monitor.final boolean
ReentrantDistributedZookeeperLock
is always presumed to be a distributed lock, backed by a ZooKeeper cluster.boolean
obtainLockInstance
(String lockName) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.search.index.core.LockService
isLocked, lock, obtainLockInstance, unlock
-
Field Details
-
LOCAL_LOCK_REGISTRY
-
DEFAULT_LOCKS_FOLDER_NAME
- See Also:
-
-
Constructor Details
-
DefaultZooKeeperDistributedLockService
public DefaultZooKeeperDistributedLockService(org.apache.solr.common.cloud.SolrZkClient zooKeeper, com.broadleafcommerce.search.index.core.ProcessStateService processStateService) -
DefaultZooKeeperDistributedLockService
public DefaultZooKeeperDistributedLockService(org.apache.solr.common.cloud.SolrZkClient zooKeeper, org.springframework.context.ApplicationContext applicationContext, com.broadleafcommerce.search.index.core.ProcessStateService processStateService) -
DefaultZooKeeperDistributedLockService
public DefaultZooKeeperDistributedLockService(org.apache.solr.common.cloud.SolrZkClient zooKeeper, List<org.apache.zookeeper.data.ACL> acls, com.broadleafcommerce.search.index.core.ProcessStateService processStateService) -
DefaultZooKeeperDistributedLockService
public DefaultZooKeeperDistributedLockService(org.apache.solr.common.cloud.SolrZkClient zooKeeper, org.springframework.context.ApplicationContext applicationContext, List<org.apache.zookeeper.data.ACL> acls, com.broadleafcommerce.search.index.core.ProcessStateService processStateService)
-
-
Method Details
-
isLocked
- Specified by:
isLocked
in interfacecom.broadleafcommerce.search.index.core.LockService
-
obtainLockInstance
- Specified by:
obtainLockInstance
in interfacecom.broadleafcommerce.search.index.core.LockService
-
isDistributed
public final boolean isDistributed()ReentrantDistributedZookeeperLock
is always presumed to be a distributed lock, backed by a ZooKeeper cluster.- Specified by:
isDistributed
in interfacecom.broadleafcommerce.search.index.core.Distributable
- Returns:
-
handleLockFailedEvent
@EventListener public void handleLockFailedEvent(com.broadleafcommerce.search.provider.solr.util.zk.ZookeeperLockFailedEvent event) TheReentrantDistributedZookeeperLock
has a failure monitor. If a thread in this runtime environment has acquired a lock and it fails for some reason (usually due to ZooKeeper connectivity or state issues), then this event is raised. What it means is that a lock has been acquired, but can no longer be trusted. This is rare, but it's better to be safe than sorry. In this case, we callProcessStateService.failFast(IndexableType, String)
which will stop any reindex process that may be running without the knowledge that the lock failed. ThisReentrantDistributedZookeeperLock
instance will be force stopped and removed. Any future locks will be using a new lock instance. Note that the ability to actually acquire a lock, including with a new lock instance, will depend on the backing ZooKeeper cluster and the state of the shared ZooKeeper client and its connectivity.- Parameters:
event
-
-
getZookeeperClient
protected org.apache.solr.common.cloud.SolrZkClient getZookeeperClient() -
getLocksFolder
-
getApplicationContext
protected org.springframework.context.ApplicationContext getApplicationContext() -
getAcls
-
destroy
This cleans up any sharedReentrantDistributedZookeeperLock
instances and stops their respective lock failure monitor threads.- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
- Throws:
Exception
-