Package org.apache.solr.cloud
Class ZkController
- java.lang.Object
- 
- org.apache.solr.cloud.ZkController
 
- 
- All Implemented Interfaces:
- Closeable,- AutoCloseable
 
 public class ZkController extends Object implements Closeable Handle ZooKeeper interactions.notes: loads everything on init, creates what's not there - further updates are prompted with Watches. TODO: exceptions during close on attempts to update cloud state 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classZkController.NotInClusterStateExceptionThrown during pre register process if the replica is not present in clusterstatestatic classZkController.ResourceModifiedInZkException
 - 
Field SummaryFields Modifier and Type Field Description static StringCOLLECTION_PARAM_PREFIXstatic StringCONFIGNAME_PROPprotected Overseeroverseerstatic byte[]TOUCHED_ZNODE_DATAorg.apache.solr.common.cloud.ZkStateReaderzkStateReader
 - 
Constructor SummaryConstructors Constructor Description ZkController(CoreContainer cc, String zkServerAddress, int zkClientConnectTimeout, CloudConfig cloudConfig, Supplier<List<CoreDescriptor>> descriptorsSupplier)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddOnReconnectListener(org.apache.solr.common.cloud.OnReconnect listener)Add a listener to be notified once there is a new session created after a ZooKeeper session expiration occurs; in most cases, listeners will be components that have watchers that need to be re-created.static booleancheckChrootPath(String zkHost, boolean create)Validates if the chroot exists in zk (or if it is successfully created).booleancheckIfCoreNodeNameAlreadyExists(CoreDescriptor dcore)voidcheckOverseerDesignate()booleanclaimAsyncId(String asyncId)When an operation needs to be performed in an asynchronous mode, the asyncId needs to be claimed by calling this method to make sure it's not duplicate (hasn't been claimed by other request).booleanclearAsyncId(String asyncId)Clears an asyncId previously claimed by callingclaimAsyncId(String)voidclearZkCollectionTerms()voidclose()Closes the underlying ZooKeeper client.static voidcreateClusterZkNodes(org.apache.solr.common.cloud.SolrZkClient zkClient)Create the zknodes necessary for a cluster to operateStringgetBaseUrl()intgetClientTimeout()org.apache.solr.common.cloud.ClusterStategetClusterState()org.apache.solr.common.cloud.OnReconnectgetConfigDirListener()CoreContainergetCoreContainer()StringgetCoreNodeName(CoreDescriptor descriptor)DistributedClusterStateUpdatergetDistributedClusterStateUpdater()StringgetHostName()intgetHostPort()intgetLeaderConflictResolveWait()org.apache.solr.common.cloud.ZkCoreNodePropsgetLeaderProps(String collection, String slice, int timeoutms)Get leader props directly from zk nodes.org.apache.solr.common.cloud.ZkCoreNodePropsgetLeaderProps(String collection, String slice, int timeoutms, boolean failImmediatelyOnExpiration)Get leader props directly from zk nodes.intgetLeaderVoteWait()StringgetNodeName()OverseergetOverseer()OverseerTaskQueuegetOverseerCollectionQueue()DistributedMapgetOverseerCompletedMap()OverseerTaskQueuegetOverseerConfigSetQueue()LeaderElectorgetOverseerElector()DistributedMapgetOverseerFailureMap()ZkDistributedQueuegetOverseerJobQueue()DistributedMapgetOverseerRunningMap()ZkShardTermsgetShardTerms(String collection, String shardId)org.apache.solr.client.solrj.cloud.SolrCloudManagergetSolrCloudManager()org.apache.solr.common.cloud.NodesSysPropsCachergetSysPropsCacher()org.apache.solr.common.cloud.SolrZkClientgetZkClient()StringgetZkServerAddress()org.apache.solr.common.cloud.ZkStateReadergetZkStateReader()voidgiveupLeadership(CoreDescriptor cd)Best effort to give up the leadership of a shard in a core after hitting a tragic exceptionbooleanisConnected()static voidlinkConfSet(org.apache.solr.common.cloud.SolrZkClient zkClient, String collection, String confSetName)booleanpathExists(String path)Returns true if the path existsstatic intpersistConfigResourceToZooKeeper(ZkSolrResourceLoader zkLoader, int znodeVersion, String resourceName, byte[] content, boolean createIfNotExists)Persists a config file to ZooKeeper using optimistic concurrency.voidpreClose()voidpreRegister(CoreDescriptor cd, boolean publishState)voidpublish(CoreDescriptor cd, org.apache.solr.common.cloud.Replica.State state)voidpublish(CoreDescriptor cd, org.apache.solr.common.cloud.Replica.State state, boolean updateLastState, boolean forcePublish)Publish core state to overseer.voidpublishAndWaitForDownStates()voidpublishAndWaitForDownStates(int timeoutSeconds)voidpublishNodeAsDown(String nodeName)Best effort to set DOWN state for all replicas on node.Stringregister(String coreName, CoreDescriptor desc, boolean skipRecovery)Register shard with ZooKeeper.Stringregister(String coreName, CoreDescriptor desc, boolean recoverReloadedCores, boolean afterExpiration, boolean skipRecovery)Register shard with ZooKeeper.voidregisterConfListenerForCore(String confDir, SolrCore core, Runnable listener)This will give a callback to the listener whenever a child is modified in the conf directory.voidrejoinOverseerElection(String electionNode, boolean joinAtHead)voidrejoinShardLeaderElection(org.apache.solr.common.params.SolrParams params)voidremoveEphemeralLiveNode()voidremoveOnReconnectListener(org.apache.solr.common.cloud.OnReconnect listener)Removed a previously registered OnReconnect listener, such as when a core is removed or reloaded.voidsetPreferredOverseer()voidstartReplicationFromLeader(String coreName, boolean switchTransactionLog)voidstopReplicationFromLeader(String coreName)voidthrowErrorIfReplicaReplaced(CoreDescriptor desc)static voidtouchConfDir(ZkSolrResourceLoader zkLoader)static StringtrimLeadingAndTrailingSlashes(String in)Utility method for trimming and leading and/or trailing slashes from its input.voidtryCancelAllElections()Attempts to cancel all leader elections.voidunregister(String coreName, CoreDescriptor cd)voidunregister(String coreName, CoreDescriptor cd, boolean removeCoreFromZk)
 
- 
- 
- 
Field Detail- 
COLLECTION_PARAM_PREFIXpublic static final String COLLECTION_PARAM_PREFIX - See Also:
- Constant Field Values
 
 - 
CONFIGNAME_PROPpublic static final String CONFIGNAME_PROP - See Also:
- Constant Field Values
 
 - 
TOUCHED_ZNODE_DATApublic static final byte[] TOUCHED_ZNODE_DATA 
 - 
zkStateReaderpublic final org.apache.solr.common.cloud.ZkStateReader zkStateReader 
 - 
overseerprotected volatile Overseer overseer 
 
- 
 - 
Constructor Detail- 
ZkControllerpublic ZkController(CoreContainer cc, String zkServerAddress, int zkClientConnectTimeout, CloudConfig cloudConfig, Supplier<List<CoreDescriptor>> descriptorsSupplier) throws InterruptedException, TimeoutException, IOException - Parameters:
- cc- Core container associated with this controller. cannot be null.
- zkServerAddress- where to connect to the zk server
- zkClientConnectTimeout- timeout in ms
- cloudConfig- configuration for this controller. TODO: possibly redundant with CoreContainer
- descriptorsSupplier- a supplier of the current core descriptors. used to know which cores to re-register on reconnect
- Throws:
- InterruptedException
- TimeoutException
- IOException
 
 
- 
 - 
Method Detail- 
getLeaderVoteWaitpublic int getLeaderVoteWait() 
 - 
getLeaderConflictResolveWaitpublic int getLeaderConflictResolveWait() 
 - 
getSysPropsCacherpublic org.apache.solr.common.cloud.NodesSysPropsCacher getSysPropsCacher() 
 - 
preClosepublic void preClose() 
 - 
closepublic void close() Closes the underlying ZooKeeper client.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
 
 - 
giveupLeadershippublic void giveupLeadership(CoreDescriptor cd) Best effort to give up the leadership of a shard in a core after hitting a tragic exception- Parameters:
- cd- The current core descriptor
 
 - 
getClusterStatepublic org.apache.solr.common.cloud.ClusterState getClusterState() - Returns:
- information about the cluster from ZooKeeper
 
 - 
getDistributedClusterStateUpdaterpublic DistributedClusterStateUpdater getDistributedClusterStateUpdater() 
 - 
getSolrCloudManagerpublic org.apache.solr.client.solrj.cloud.SolrCloudManager getSolrCloudManager() 
 - 
getHostNamepublic String getHostName() 
 - 
getHostPortpublic int getHostPort() 
 - 
getZkClientpublic org.apache.solr.common.cloud.SolrZkClient getZkClient() 
 - 
getZkServerAddresspublic String getZkServerAddress() - Returns:
- zookeeper server address
 
 - 
createClusterZkNodespublic static void createClusterZkNodes(org.apache.solr.common.cloud.SolrZkClient zkClient) throws org.apache.zookeeper.KeeperException, InterruptedException, IOExceptionCreate the zknodes necessary for a cluster to operate- Parameters:
- zkClient- a SolrZkClient
- Throws:
- org.apache.zookeeper.KeeperException- if there is a Zookeeper error
- InterruptedException- on interrupt
- IOException
 
 - 
publishAndWaitForDownStatespublic void publishAndWaitForDownStates() throws org.apache.zookeeper.KeeperException, InterruptedException- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
publishAndWaitForDownStatespublic void publishAndWaitForDownStates(int timeoutSeconds) throws org.apache.zookeeper.KeeperException, InterruptedException- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
checkChrootPathpublic static boolean checkChrootPath(String zkHost, boolean create) throws org.apache.zookeeper.KeeperException, InterruptedException Validates if the chroot exists in zk (or if it is successfully created). Optionally, if create is set to true this method will create the path in case it doesn't exist- Returns:
- true if the path exists or is created false if the path doesn't exist and 'create' = false
- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
isConnectedpublic boolean isConnected() 
 - 
removeEphemeralLiveNodepublic void removeEphemeralLiveNode() throws org.apache.zookeeper.KeeperException, InterruptedException- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
getNodeNamepublic String getNodeName() 
 - 
pathExistspublic boolean pathExists(String path) throws org.apache.zookeeper.KeeperException, InterruptedException Returns true if the path exists- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
registerpublic String register(String coreName, CoreDescriptor desc, boolean skipRecovery) throws Exception Register shard with ZooKeeper.- Returns:
- the shardId for the SolrCore
- Throws:
- Exception
 
 - 
registerpublic String register(String coreName, CoreDescriptor desc, boolean recoverReloadedCores, boolean afterExpiration, boolean skipRecovery) throws Exception Register shard with ZooKeeper.- Returns:
- the shardId for the SolrCore
- Throws:
- Exception
 
 - 
startReplicationFromLeaderpublic void startReplicationFromLeader(String coreName, boolean switchTransactionLog) 
 - 
stopReplicationFromLeaderpublic void stopReplicationFromLeader(String coreName) 
 - 
getLeaderPropspublic org.apache.solr.common.cloud.ZkCoreNodeProps getLeaderProps(String collection, String slice, int timeoutms) throws InterruptedException, org.apache.zookeeper.KeeperException.SessionExpiredException Get leader props directly from zk nodes.- Throws:
- org.apache.zookeeper.KeeperException.SessionExpiredException- on zk session expiration.
- InterruptedException
 
 - 
getLeaderPropspublic org.apache.solr.common.cloud.ZkCoreNodeProps getLeaderProps(String collection, String slice, int timeoutms, boolean failImmediatelyOnExpiration) throws InterruptedException, org.apache.zookeeper.KeeperException.SessionExpiredException Get leader props directly from zk nodes.- Returns:
- leader props
- Throws:
- org.apache.zookeeper.KeeperException.SessionExpiredException- on zk session expiration.
- InterruptedException
 
 - 
getBaseUrlpublic String getBaseUrl() 
 - 
publishpublic void publish(CoreDescriptor cd, org.apache.solr.common.cloud.Replica.State state) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
publishpublic void publish(CoreDescriptor cd, org.apache.solr.common.cloud.Replica.State state, boolean updateLastState, boolean forcePublish) throws org.apache.zookeeper.KeeperException, InterruptedException Publish core state to overseer.- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
getShardTermspublic ZkShardTerms getShardTerms(String collection, String shardId) 
 - 
clearZkCollectionTermspublic void clearZkCollectionTerms() 
 - 
unregisterpublic void unregister(String coreName, CoreDescriptor cd) throws Exception - Throws:
- Exception
 
 - 
unregisterpublic void unregister(String coreName, CoreDescriptor cd, boolean removeCoreFromZk) throws Exception - Throws:
- Exception
 
 - 
getZkStateReaderpublic org.apache.solr.common.cloud.ZkStateReader getZkStateReader() 
 - 
getCoreNodeNamepublic String getCoreNodeName(CoreDescriptor descriptor) 
 - 
preRegisterpublic void preRegister(CoreDescriptor cd, boolean publishState) 
 - 
tryCancelAllElectionspublic void tryCancelAllElections() Attempts to cancel all leader elections. This method should be called on node shutdown.
 - 
linkConfSetpublic static void linkConfSet(org.apache.solr.common.cloud.SolrZkClient zkClient, String collection, String confSetName) throws org.apache.zookeeper.KeeperException, InterruptedException- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
getOverseerJobQueuepublic ZkDistributedQueue getOverseerJobQueue() 
 - 
getOverseerCollectionQueuepublic OverseerTaskQueue getOverseerCollectionQueue() 
 - 
getOverseerConfigSetQueuepublic OverseerTaskQueue getOverseerConfigSetQueue() 
 - 
getOverseerRunningMappublic DistributedMap getOverseerRunningMap() 
 - 
getOverseerCompletedMappublic DistributedMap getOverseerCompletedMap() 
 - 
getOverseerFailureMappublic DistributedMap getOverseerFailureMap() 
 - 
claimAsyncIdpublic boolean claimAsyncId(String asyncId) throws org.apache.zookeeper.KeeperException When an operation needs to be performed in an asynchronous mode, the asyncId needs to be claimed by calling this method to make sure it's not duplicate (hasn't been claimed by other request). If this method returns true, the asyncId in the parameter has been reserved for the operation, meaning that no other thread/operation can claim it. If for whatever reason, the operation is not scheduled, the asuncId needs to be cleared usingclearAsyncId(String). If this method returns false, no reservation has been made, and this asyncId can't be used, since it's being used by another operation (currently or in the past)- Parameters:
- asyncId- A string representing the asyncId of an operation. Can't be null.
- Returns:
- True if the reservation succeeds. False if this ID is already in use.
- Throws:
- org.apache.zookeeper.KeeperException
 
 - 
clearAsyncIdpublic boolean clearAsyncId(String asyncId) throws org.apache.zookeeper.KeeperException Clears an asyncId previously claimed by callingclaimAsyncId(String)- Parameters:
- asyncId- A string representing the asyncId of an operation. Can't be null.
- Returns:
- True if the asyncId existed and was cleared. False if the asyncId didn't exist before.
- Throws:
- org.apache.zookeeper.KeeperException
 
 - 
getClientTimeoutpublic int getClientTimeout() 
 - 
getOverseerpublic Overseer getOverseer() 
 - 
getOverseerElectorpublic LeaderElector getOverseerElector() 
 - 
trimLeadingAndTrailingSlashespublic static String trimLeadingAndTrailingSlashes(String in) Utility method for trimming and leading and/or trailing slashes from its input. May return the empty string. May return null if and only if the input is null.
 - 
rejoinOverseerElectionpublic void rejoinOverseerElection(String electionNode, boolean joinAtHead) 
 - 
rejoinShardLeaderElectionpublic void rejoinShardLeaderElection(org.apache.solr.common.params.SolrParams params) 
 - 
checkOverseerDesignatepublic void checkOverseerDesignate() 
 - 
setPreferredOverseerpublic void setPreferredOverseer() throws org.apache.zookeeper.KeeperException, InterruptedException- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
getCoreContainerpublic CoreContainer getCoreContainer() 
 - 
throwErrorIfReplicaReplacedpublic void throwErrorIfReplicaReplaced(CoreDescriptor desc) 
 - 
addOnReconnectListenerpublic void addOnReconnectListener(org.apache.solr.common.cloud.OnReconnect listener) Add a listener to be notified once there is a new session created after a ZooKeeper session expiration occurs; in most cases, listeners will be components that have watchers that need to be re-created.
 - 
removeOnReconnectListenerpublic void removeOnReconnectListener(org.apache.solr.common.cloud.OnReconnect listener) Removed a previously registered OnReconnect listener, such as when a core is removed or reloaded.
 - 
persistConfigResourceToZooKeeperpublic static int persistConfigResourceToZooKeeper(ZkSolrResourceLoader zkLoader, int znodeVersion, String resourceName, byte[] content, boolean createIfNotExists) Persists a config file to ZooKeeper using optimistic concurrency.- Returns:
- true on success
 
 - 
touchConfDirpublic static void touchConfDir(ZkSolrResourceLoader zkLoader) 
 - 
registerConfListenerForCorepublic void registerConfListenerForCore(String confDir, SolrCore core, Runnable listener) This will give a callback to the listener whenever a child is modified in the conf directory. It is the responsibility of the listener to check if the individual item of interest has been modified. When the last core which was interested in this conf directory is gone the listeners will be removed automatically.
 - 
getConfigDirListenerpublic org.apache.solr.common.cloud.OnReconnect getConfigDirListener() 
 - 
checkIfCoreNodeNameAlreadyExistspublic boolean checkIfCoreNodeNameAlreadyExists(CoreDescriptor dcore) 
 - 
publishNodeAsDownpublic void publishNodeAsDown(String nodeName) Best effort to set DOWN state for all replicas on node.- Parameters:
- nodeName- to operate on
 
 
- 
 
-