org.apache.solr.cloud
Class ZkController

java.lang.Object
  extended by org.apache.solr.cloud.ZkController

public final class ZkController
extends Object

Handle ZooKeeper interactions. notes: loads everything on init, creates what's not there - further updates are prompted with Watches. TODO: exceptions during shutdown on attempts to update cloud state


Field Summary
static String COLLECTION_PARAM_PREFIX
           
static String CONFIGNAME_PROP
           
static String CONFIGS_ZKNODE
           
protected  Overseer overseer
           
 
Constructor Summary
ZkController(CoreContainer cc, String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout, String localHost, String locaHostPort, String localHostContext, int leaderVoteWait, boolean genericCoreNodeNames, int distribUpdateConnTimeout, int distribUpdateSoTimeout, CurrentCoreDescriptorProvider registerOnReconnect)
           
 
Method Summary
static void bootstrapConf(SolrZkClient zkClient, CoreContainer cc, String solrHome)
          If in SolrCloud mode, upload config sets for each SolrCore in solr.xml.
static boolean checkChrootPath(String zkHost, boolean create)
          Validates if the chroot exists in zk (or if it is successfully created).
 void close()
          Closes the underlying ZooKeeper client.
 boolean configFileExists(String collection, String fileName)
          Returns true if config file exists
 void createCollection(String collection)
           
 void createCollectionZkNode(CloudDescriptor cd)
           
static void downloadConfigDir(SolrZkClient zkClient, String configName, File dir)
           
static void downloadFromZK(SolrZkClient zkClient, String zkPath, File dir)
           
 String getBaseUrl()
           
 int getClientTimeout()
           
 ClusterState getClusterState()
           
 byte[] getConfigFileData(String zkConfigName, String fileName)
          Returns config file data (in bytes)
 String getCoreNodeName(CoreDescriptor descriptor)
           
 String getHostName()
           
 String getHostPort()
           
 ZkCoreNodeProps getLeaderProps(String collection, String slice, int timeoutms)
          Get leader props directly from zk nodes.
 ZkCoreNodeProps getLeaderProps(String collection, String slice, int timeoutms, boolean failImmediatelyOnExpiration)
          Get leader props directly from zk nodes.
 int getLeaderVoteWait()
           
 String getNodeName()
           
 DistributedQueue getOverseerCollectionQueue()
           
 DistributedQueue getOverseerJobQueue()
           
 UpdateShardHandler getUpdateShardHandler()
           
 SolrZkClient getZkClient()
           
 String getZkServerAddress()
           
 ZkStateReader getZkStateReader()
           
 boolean isConnected()
           
static void linkConfSet(SolrZkClient zkClient, String collection, String confSetName)
           
 boolean pathExists(String path)
          Returns true if the path exists
 void preRegister(CoreDescriptor cd)
           
 void publish(CoreDescriptor cd, String state)
           
 void publish(CoreDescriptor cd, String state, boolean updateLastState)
          Publish core state to overseer.
 void publishAndWaitForDownStates()
           
 String readConfigName(String collection)
          Returns config value
 String register(String coreName, CoreDescriptor desc)
          Register shard with ZooKeeper.
 String register(String coreName, CoreDescriptor desc, boolean recoverReloadedCores, boolean afterExpiration)
          Register shard with ZooKeeper.
static String trimLeadingAndTrailingSlashes(String in)
          Utility method for trimming and leading and/or trailing slashes from it's input.
 void unregister(String coreName, CoreDescriptor cd)
           
 void uploadConfigDir(File dir, String configName)
           
static void uploadConfigDir(SolrZkClient zkClient, File dir, String configName)
           
 void uploadToZK(File dir, String zkPath)
           
static void uploadToZK(SolrZkClient zkClient, File dir, String zkPath)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIGS_ZKNODE

public static final String CONFIGS_ZKNODE
See Also:
Constant Field Values

COLLECTION_PARAM_PREFIX

public static final String COLLECTION_PARAM_PREFIX
See Also:
Constant Field Values

CONFIGNAME_PROP

public static final String CONFIGNAME_PROP
See Also:
Constant Field Values

overseer

protected volatile Overseer overseer
Constructor Detail

ZkController

public ZkController(CoreContainer cc,
                    String zkServerAddress,
                    int zkClientTimeout,
                    int zkClientConnectTimeout,
                    String localHost,
                    String locaHostPort,
                    String localHostContext,
                    int leaderVoteWait,
                    boolean genericCoreNodeNames,
                    int distribUpdateConnTimeout,
                    int distribUpdateSoTimeout,
                    CurrentCoreDescriptorProvider registerOnReconnect)
             throws InterruptedException,
                    TimeoutException,
                    IOException
Throws:
InterruptedException
TimeoutException
IOException
Method Detail

getLeaderVoteWait

public int getLeaderVoteWait()

close

public void close()
Closes the underlying ZooKeeper client.


configFileExists

public boolean configFileExists(String collection,
                                String fileName)
                         throws org.apache.zookeeper.KeeperException,
                                InterruptedException
Returns true if config file exists

Throws:
org.apache.zookeeper.KeeperException
InterruptedException

getClusterState

public ClusterState getClusterState()
Returns:
information about the cluster from ZooKeeper

getConfigFileData

public byte[] getConfigFileData(String zkConfigName,
                                String fileName)
                         throws org.apache.zookeeper.KeeperException,
                                InterruptedException
Returns config file data (in bytes)

Throws:
org.apache.zookeeper.KeeperException
InterruptedException

getHostName

public String getHostName()

getHostPort

public String getHostPort()

getZkClient

public SolrZkClient getZkClient()

getZkServerAddress

public String getZkServerAddress()
Returns:
zookeeper server address

publishAndWaitForDownStates

public void publishAndWaitForDownStates()
                                 throws org.apache.zookeeper.KeeperException,
                                        InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

checkChrootPath

public 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

isConnected

public boolean isConnected()

getNodeName

public String getNodeName()

pathExists

public boolean pathExists(String path)
                   throws org.apache.zookeeper.KeeperException,
                          InterruptedException
Returns true if the path exists

Throws:
org.apache.zookeeper.KeeperException
InterruptedException

readConfigName

public String readConfigName(String collection)
                      throws org.apache.zookeeper.KeeperException,
                             InterruptedException
Returns config value

Throws:
org.apache.zookeeper.KeeperException
InterruptedException

register

public String register(String coreName,
                       CoreDescriptor desc)
                throws Exception
Register shard with ZooKeeper.

Returns:
the shardId for the SolrCore
Throws:
Exception

register

public String register(String coreName,
                       CoreDescriptor desc,
                       boolean recoverReloadedCores,
                       boolean afterExpiration)
                throws Exception
Register shard with ZooKeeper.

Returns:
the shardId for the SolrCore
Throws:
Exception

getLeaderProps

public ZkCoreNodeProps getLeaderProps(String collection,
                                      String slice,
                                      int timeoutms)
                               throws InterruptedException
Get leader props directly from zk nodes.

Throws:
InterruptedException

getLeaderProps

public ZkCoreNodeProps getLeaderProps(String collection,
                                      String slice,
                                      int timeoutms,
                                      boolean failImmediatelyOnExpiration)
                               throws InterruptedException
Get leader props directly from zk nodes.

Returns:
leader props
Throws:
InterruptedException

getBaseUrl

public String getBaseUrl()

publish

public void publish(CoreDescriptor cd,
                    String state)
             throws org.apache.zookeeper.KeeperException,
                    InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

publish

public void publish(CoreDescriptor cd,
                    String state,
                    boolean updateLastState)
             throws org.apache.zookeeper.KeeperException,
                    InterruptedException
Publish core state to overseer.

Throws:
org.apache.zookeeper.KeeperException
InterruptedException

unregister

public void unregister(String coreName,
                       CoreDescriptor cd)
                throws InterruptedException,
                       org.apache.zookeeper.KeeperException
Throws:
InterruptedException
org.apache.zookeeper.KeeperException

createCollection

public void createCollection(String collection)
                      throws org.apache.zookeeper.KeeperException,
                             InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

uploadToZK

public void uploadToZK(File dir,
                       String zkPath)
                throws IOException,
                       org.apache.zookeeper.KeeperException,
                       InterruptedException
Throws:
IOException
org.apache.zookeeper.KeeperException
InterruptedException

uploadConfigDir

public void uploadConfigDir(File dir,
                            String configName)
                     throws IOException,
                            org.apache.zookeeper.KeeperException,
                            InterruptedException
Throws:
IOException
org.apache.zookeeper.KeeperException
InterruptedException

createCollectionZkNode

public void createCollectionZkNode(CloudDescriptor cd)
                            throws org.apache.zookeeper.KeeperException,
                                   InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

getZkStateReader

public ZkStateReader getZkStateReader()

uploadToZK

public static void uploadToZK(SolrZkClient zkClient,
                              File dir,
                              String zkPath)
                       throws IOException,
                              org.apache.zookeeper.KeeperException,
                              InterruptedException
Throws:
IOException
org.apache.zookeeper.KeeperException
InterruptedException

downloadFromZK

public static void downloadFromZK(SolrZkClient zkClient,
                                  String zkPath,
                                  File dir)
                           throws IOException,
                                  org.apache.zookeeper.KeeperException,
                                  InterruptedException
Throws:
IOException
org.apache.zookeeper.KeeperException
InterruptedException

getCoreNodeName

public String getCoreNodeName(CoreDescriptor descriptor)

uploadConfigDir

public static void uploadConfigDir(SolrZkClient zkClient,
                                   File dir,
                                   String configName)
                            throws IOException,
                                   org.apache.zookeeper.KeeperException,
                                   InterruptedException
Throws:
IOException
org.apache.zookeeper.KeeperException
InterruptedException

downloadConfigDir

public static void downloadConfigDir(SolrZkClient zkClient,
                                     String configName,
                                     File dir)
                              throws IOException,
                                     org.apache.zookeeper.KeeperException,
                                     InterruptedException
Throws:
IOException
org.apache.zookeeper.KeeperException
InterruptedException

preRegister

public void preRegister(CoreDescriptor cd)

linkConfSet

public static void linkConfSet(SolrZkClient zkClient,
                               String collection,
                               String confSetName)
                        throws org.apache.zookeeper.KeeperException,
                               InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

bootstrapConf

public static void bootstrapConf(SolrZkClient zkClient,
                                 CoreContainer cc,
                                 String solrHome)
                          throws IOException,
                                 org.apache.zookeeper.KeeperException,
                                 InterruptedException
If in SolrCloud mode, upload config sets for each SolrCore in solr.xml.

Throws:
IOException
org.apache.zookeeper.KeeperException
InterruptedException

getOverseerJobQueue

public DistributedQueue getOverseerJobQueue()

getOverseerCollectionQueue

public DistributedQueue getOverseerCollectionQueue()

getClientTimeout

public int getClientTimeout()

getUpdateShardHandler

public UpdateShardHandler getUpdateShardHandler()

trimLeadingAndTrailingSlashes

public static String trimLeadingAndTrailingSlashes(String in)
Utility method for trimming and leading and/or trailing slashes from it's input. May return the empty string. May return null if and only if the input is null.



Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.