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
           
 
Constructor Summary
ZkController(CoreContainer cc, String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout, String localHost, String locaHostPort, String localHostContext, CurrentCoreDescriptorProvider registerOnReconnect)
           
 
Method Summary
static void bootstrapConf(org.apache.solr.common.cloud.SolrZkClient zkClient, Config cfg, String solrHome)
          If in SolrCloud mode, upload config sets for each SolrCore in solr.xml.
 void close()
          Closes the underlying ZooKeeper client.
 boolean configFileExists(String collection, String fileName)
           
 void createCollectionZkNode(CloudDescriptor cd)
           
 String getBaseUrl()
           
 org.apache.solr.common.cloud.CloudState getCloudState()
           
 byte[] getConfigFileData(String zkConfigName, String fileName)
           
 String getHostName()
           
 String getHostPort()
           
 String getNodeName()
           
 org.apache.solr.common.cloud.SolrZkClient getZkClient()
           
 String getZkServerAddress()
           
 org.apache.solr.common.cloud.ZkStateReader getZkStateReader()
           
 boolean isConnected()
           
static void main(String[] args)
          Bootstraps the current configs for all collections in solr.xml.
 boolean pathExists(String path)
           
 void preRegister(CoreDescriptor cd)
           
 void publish(CoreDescriptor cd, String state)
          Publish core state to overseer.
 String readConfigName(String collection)
           
 String register(String coreName, CoreDescriptor desc)
          Register shard with ZooKeeper.
 String register(String coreName, CoreDescriptor desc, boolean recoverReloadedCores)
          Register shard with ZooKeeper.
 void unregister(String coreName, CloudDescriptor cloudDesc)
           
 void uploadConfigDir(File dir, String configName)
           
static void uploadConfigDir(org.apache.solr.common.cloud.SolrZkClient zkClient, File dir, String configName)
           
 void uploadToZK(File dir, String zkPath)
           
static void uploadToZK(org.apache.solr.common.cloud.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

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
Constructor Detail

ZkController

public ZkController(CoreContainer cc,
                    String zkServerAddress,
                    int zkClientTimeout,
                    int zkClientConnectTimeout,
                    String localHost,
                    String locaHostPort,
                    String localHostContext,
                    CurrentCoreDescriptorProvider registerOnReconnect)
             throws InterruptedException,
                    TimeoutException,
                    IOException
Parameters:
cc - if null, recovery will not be enabled
zkServerAddress -
zkClientTimeout -
zkClientConnectTimeout -
localHost -
locaHostPort -
localHostContext -
registerOnReconnect -
Throws:
InterruptedException
TimeoutException
IOException
Method Detail

main

public static void main(String[] args)
                 throws Exception
Bootstraps the current configs for all collections in solr.xml. Takes two params - the zkhost to connect to and the solrhome location to find solr.xml. If you also pass a solrPort, it will be used to start an embedded zk useful for single machine, multi node tests.

Parameters:
args -
Throws:
Exception

close

public void close()
Closes the underlying ZooKeeper client.


configFileExists

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

getCloudState

public org.apache.solr.common.cloud.CloudState getCloudState()
Returns:
information about the cluster from ZooKeeper

getConfigFileData

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

getHostName

public String getHostName()

getHostPort

public String getHostPort()

getZkClient

public org.apache.solr.common.cloud.SolrZkClient getZkClient()

getZkServerAddress

public String getZkServerAddress()
Returns:
zookeeper server address

isConnected

public boolean isConnected()

getNodeName

public String getNodeName()

pathExists

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

readConfigName

public String readConfigName(String collection)
                      throws org.apache.zookeeper.KeeperException,
                             InterruptedException,
                             IOException
Parameters:
collection -
Returns:
config value
Throws:
org.apache.zookeeper.KeeperException
InterruptedException
IOException

register

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

Parameters:
coreName -
desc -
Returns:
the shardId for the SolrCore
Throws:
Exception

register

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

Parameters:
coreName -
desc -
recoverReloadedCores -
Returns:
the shardId for the SolrCore
Throws:
Exception

getBaseUrl

public String getBaseUrl()

publish

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

Parameters:
cd -
state -
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

unregister

public void unregister(String coreName,
                       CloudDescriptor cloudDesc)
                throws InterruptedException,
                       org.apache.zookeeper.KeeperException
Parameters:
coreName -
cloudDesc -
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

uploadToZK

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

uploadConfigDir

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

createCollectionZkNode

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

getZkStateReader

public org.apache.solr.common.cloud.ZkStateReader getZkStateReader()

uploadToZK

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

uploadConfigDir

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

preRegister

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

bootstrapConf

public static void bootstrapConf(org.apache.solr.common.cloud.SolrZkClient zkClient,
                                 Config cfg,
                                 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


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