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
    Modifier and Type
    Field
    Description
    protected static final String
     
    protected static final Map<String,com.broadleafcommerce.search.provider.solr.util.zk.ReentrantDistributedZookeeperLock>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultZooKeeperDistributedLockService(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 Type
    Method
    Description
    void
    This cleans up any shared ReentrantDistributedZookeeperLock instances and stops their respective lock failure monitor threads.
    protected List<org.apache.zookeeper.data.ACL>
     
    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)
    The ReentrantDistributedZookeeperLock has a failure monitor.
    final boolean
    ReentrantDistributedZookeeperLock is always presumed to be a distributed lock, backed by a ZooKeeper cluster.
    boolean
    isLocked(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

      protected static final Map<String,com.broadleafcommerce.search.provider.solr.util.zk.ReentrantDistributedZookeeperLock> LOCAL_LOCK_REGISTRY
    • DEFAULT_LOCKS_FOLDER_NAME

      protected static final String 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

      public boolean isLocked(@NonNull String lockName)
      Specified by:
      isLocked in interface com.broadleafcommerce.search.index.core.LockService
    • obtainLockInstance

      public Lock obtainLockInstance(@NonNull String lockName)
      Specified by:
      obtainLockInstance in interface com.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 interface com.broadleafcommerce.search.index.core.Distributable
      Returns:
    • handleLockFailedEvent

      @EventListener public void handleLockFailedEvent(com.broadleafcommerce.search.provider.solr.util.zk.ZookeeperLockFailedEvent event)
      The ReentrantDistributedZookeeperLock 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 call ProcessStateService.failFast(IndexableType, String) which will stop any reindex process that may be running without the knowledge that the lock failed. This ReentrantDistributedZookeeperLock 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

      protected String getLocksFolder()
    • getApplicationContext

      protected org.springframework.context.ApplicationContext getApplicationContext()
    • getAcls

      protected List<org.apache.zookeeper.data.ACL> getAcls()
    • destroy

      public void destroy() throws Exception
      This cleans up any shared ReentrantDistributedZookeeperLock instances and stops their respective lock failure monitor threads.
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Throws:
      Exception