Class SolrZkClient
- java.lang.Object
- 
- org.apache.solr.common.cloud.SolrZkClient
 
- 
- All Implemented Interfaces:
- Closeable,- AutoCloseable
 
 public class SolrZkClient extends Object implements Closeable All Solr ZooKeeper interactions should go through this class rather than ZooKeeper. This class handles synchronous connects and reconnections.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classSolrZkClient.Builderstatic classSolrZkClient.NodeDatastatic classSolrZkClient.ZkMetrics
 - 
Field SummaryFields Modifier and Type Field Description static StringZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAMEstatic StringZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAMEstatic StringZK_CREDENTIALS_INJECTOR_CLASS_NAME_VM_PARAM_NAME
 - 
Constructor SummaryConstructors Constructor Description SolrZkClient(SolrZkClient.Builder builder)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidatomicUpdate(String path, BiFunction<org.apache.zookeeper.data.Stat,byte[],byte[]> editor)voidatomicUpdate(String path, Function<byte[],byte[]> editor)static ThrowablecheckInterrupted(Throwable e)Check to see if a Throwable is an InterruptedException, and if it is, set the thread interrupt flagvoidclean(String path)voidclean(String path, Predicate<String> nodeFilter)voidclose()static booleancontainsChroot(String zkHost)Validates if zkHost contains a chroot.Stringcreate(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss)Returns path of created nodeStringcreate(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss, org.apache.zookeeper.data.Stat stat)Returns path of created nodeprotected ZkACLProvidercreateZkACLProvider()protected ZkCredentialsInjectorcreateZkCredentialsInjector()protected ZkCredentialsProvidercreateZkCredentialsToAddAutomatically()voiddelete(String path, int version, boolean retryOnConnLoss)voiddownConfig(String confName, Path confPath)voiddownloadFromZK(String zkPath, Path dir)Booleanexists(String path, boolean retryOnConnLoss)Returns true if path existsorg.apache.zookeeper.data.Statexists(String path, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)Return the stat of the node of the given path.List<org.apache.zookeeper.data.ACL>getACL(String path, org.apache.zookeeper.data.Stat stat, boolean retryOnConnLoss)List<String>getChildren(String path, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)Returns children of the node at the pathList<String>getChildren(String path, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat, boolean retryOnConnLoss)Returns children of the node at the pathStringgetConfig()Gets the raw config node /zookeeper/config as returned by server.ConnectionManagergetConnectionManager()byte[]getData(String path, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat, boolean retryOnConnLoss)Returns node's dataorg.apache.solr.common.MapWritergetMetrics()SolrZkClient.NodeDatagetNode(String path, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)ZkACLProvidergetZkACLProvider()ZkClientConnectionStrategygetZkClientConnectionStrategy()intgetZkClientTimeout()StringgetZkServerAddress()org.apache.zookeeper.ZooKeepergetZooKeeper()booleanisClosed()booleanisConnected()Returns true if client is connectedStringlistZnode(String path, Boolean recurse)voidmakePath(String path, boolean retryOnConnLoss)Creates the path in ZooKeeper, creating each node as necessary.voidmakePath(String path, boolean failOnExists, boolean retryOnConnLoss)voidmakePath(String path, byte[] data, boolean retryOnConnLoss)Creates the path in ZooKeeper, creating each node as necessary.voidmakePath(String path, byte[] data, boolean failOnExists, boolean retryOnConnLoss)voidmakePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss)Creates the path in ZooKeeper, creating each node as necessary.voidmakePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)Creates the path in ZooKeeper, creating each node as necessary.voidmakePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean failOnExists, boolean retryOnConnLoss)Creates the path in ZooKeeper, creating each node as necessary.voidmakePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean failOnExists, boolean retryOnConnLoss, int skipPathParts)Creates the path in ZooKeeper, creating each node as necessary.voidmakePath(String path, Path data, boolean retryOnConnLoss)voidmakePath(String path, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss)voidmakePath(String zkPath, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)voidmoveZnode(String src, String dst)List<org.apache.zookeeper.OpResult>multi(Iterable<org.apache.zookeeper.Op> ops, boolean retryOnConnLoss)voidprintLayout(String path, int indent, StringBuilder string)Fills string with printout of current ZooKeeper layout.voidprintLayoutToStream(PrintStream out)org.apache.zookeeper.data.StatsetACL(String path, List<org.apache.zookeeper.data.ACL> acls, boolean retryOnConnLoss)Set the ACL on a single node in ZooKeeper.org.apache.zookeeper.data.StatsetData(String path, byte[] data, boolean retryOnConnLoss)Write data to ZooKeeper.org.apache.zookeeper.data.StatsetData(String path, byte[] data, int version, boolean retryOnConnLoss)Returns node's stateorg.apache.zookeeper.data.StatsetData(String path, Path source, boolean retryOnConnLoss)Write file to ZooKeeper - default system encoding used.voidupConfig(Path confPath, String confName)voidupdateACLs(String root)Update all ACLs for a zk tree based on our configuredZkACLProvider.voiduploadToZK(Path rootPath, String zkPath, Pattern filenameExclusions)org.apache.zookeeper.WatcherwrapWatcher(org.apache.zookeeper.Watcher watcher)Wraps the watcher so that it doesn't fire off ZK's event queue.voidzkTransfer(String src, Boolean srcIsZk, String dst, Boolean dstIsZk, Boolean recurse)
 
- 
- 
- 
Field Detail- 
ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAMEpublic static final String ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME - See Also:
- Constant Field Values
 
 - 
ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAMEpublic static final String ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME - See Also:
- Constant Field Values
 
 - 
ZK_CREDENTIALS_INJECTOR_CLASS_NAME_VM_PARAM_NAMEpublic static final String ZK_CREDENTIALS_INJECTOR_CLASS_NAME_VM_PARAM_NAME - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
SolrZkClientpublic SolrZkClient(SolrZkClient.Builder builder) 
 
- 
 - 
Method Detail- 
getMetricspublic org.apache.solr.common.MapWriter getMetrics() 
 - 
getZkClientTimeoutpublic int getZkClientTimeout() 
 - 
getConnectionManagerpublic ConnectionManager getConnectionManager() 
 - 
getZkClientConnectionStrategypublic ZkClientConnectionStrategy getZkClientConnectionStrategy() 
 - 
createZkCredentialsToAddAutomaticallyprotected ZkCredentialsProvider createZkCredentialsToAddAutomatically() 
 - 
createZkACLProviderprotected ZkACLProvider createZkACLProvider() 
 - 
createZkCredentialsInjectorprotected ZkCredentialsInjector createZkCredentialsInjector() 
 - 
isConnectedpublic boolean isConnected() Returns true if client is connected
 - 
deletepublic void delete(String path, int version, boolean retryOnConnLoss) throws InterruptedException, org.apache.zookeeper.KeeperException - Throws:
- InterruptedException
- org.apache.zookeeper.KeeperException
 
 - 
wrapWatcherpublic org.apache.zookeeper.Watcher wrapWatcher(org.apache.zookeeper.Watcher watcher) Wraps the watcher so that it doesn't fire off ZK's event queue. In order to guarantee that a watch object will only be triggered once for a given notification, users need to wrap their watcher using this method before callingexists(String, org.apache.zookeeper.Watcher, boolean)orgetData(String, org.apache.zookeeper.Watcher, org.apache.zookeeper.data.Stat, boolean).
 - 
existspublic org.apache.zookeeper.data.Stat exists(String path, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Return the stat of the node of the given path. Return null if no such a node exists.If the watch is non-null and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that creates/delete the node or sets the data on the node. - Parameters:
- path- the node path
- watcher- explicit watcher
- Returns:
- the stat of the node of the given path; return null if no such a node exists.
- Throws:
- org.apache.zookeeper.KeeperException- If the server signals an error
- InterruptedException- If the server transaction is interrupted.
- IllegalArgumentException- if an invalid path is specified
 
 - 
existspublic Boolean exists(String path, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Returns true if path exists- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
getChildrenpublic List<String> getChildren(String path, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Returns children of the node at the path- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
getChildrenpublic List<String> getChildren(String path, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Returns children of the node at the path- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
getDatapublic byte[] getData(String path, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Returns node's data- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
getNodepublic SolrZkClient.NodeData getNode(String path, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
setDatapublic org.apache.zookeeper.data.Stat setData(String path, byte[] data, int version, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Returns node's state- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
atomicUpdatepublic void atomicUpdate(String path, Function<byte[],byte[]> editor) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
atomicUpdatepublic void atomicUpdate(String path, BiFunction<org.apache.zookeeper.data.Stat,byte[],byte[]> editor) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
createpublic String create(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Returns path of created node- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
createpublic String create(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss, org.apache.zookeeper.data.Stat stat) throws org.apache.zookeeper.KeeperException, InterruptedException Returns path of created node- Parameters:
- stat- Output argument that captures created node details
- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
makePathpublic void makePath(String path, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Creates the path in ZooKeeper, creating each node as necessary.e.g. If path=/solr/group/nodeand none of the nodes, solr, group, node exist, each will be created.- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
makePathpublic void makePath(String path, boolean failOnExists, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
makePathpublic void makePath(String path, byte[] data, boolean failOnExists, boolean retryOnConnLoss) throws IOException, org.apache.zookeeper.KeeperException, InterruptedException - Throws:
- IOException
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
makePathpublic void makePath(String path, Path data, boolean retryOnConnLoss) throws IOException, org.apache.zookeeper.KeeperException, InterruptedException - Throws:
- IOException
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
makePathpublic void makePath(String path, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
makePathpublic void makePath(String path, byte[] data, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Creates the path in ZooKeeper, creating each node as necessary.- Parameters:
- data- to set on the last zkNode
- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
makePathpublic void makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Creates the path in ZooKeeper, creating each node as necessary.e.g. If path=/solr/group/nodeand none of the nodes, solr, group, node exist, each will be created.- Parameters:
- data- to set on the last zkNode
- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
makePathpublic void makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Creates the path in ZooKeeper, creating each node as necessary.e.g. If path=/solr/group/nodeand none of the nodes, solr, group, node exist, each will be created.- Parameters:
- data- to set on the last zkNode
- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
makePathpublic void makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean failOnExists, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Creates the path in ZooKeeper, creating each node as necessary.e.g. If path=/solr/group/nodeand none of the nodes, solr, group, node exist, each will be created.- Parameters:
- data- to set on the last zkNode
- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
makePathpublic void makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean failOnExists, boolean retryOnConnLoss, int skipPathParts) throws org.apache.zookeeper.KeeperException, InterruptedException Creates the path in ZooKeeper, creating each node as necessary.e.g. If path=/solr/group/nodeand none of the nodes, solr, group, node exist, each will be created.skipPathParts will force the call to fail if the first skipPathParts do not exist already. Note: retryOnConnLoss is only respected for the final node - nodes before that are always retried on connection loss. Note: if failOnExists == false then we will always overwrite the existing data with the given data - Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
makePathpublic void makePath(String zkPath, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
setDatapublic org.apache.zookeeper.data.Stat setData(String path, byte[] data, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException Write data to ZooKeeper.- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
setDatapublic org.apache.zookeeper.data.Stat setData(String path, Path source, boolean retryOnConnLoss) throws IOException, org.apache.zookeeper.KeeperException, InterruptedException Write file to ZooKeeper - default system encoding used.- Parameters:
- path- path to upload file to e.g. /solr/conf/solrconfig.xml
- source- a filepath to read data from
- Throws:
- IOException
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
multipublic List<org.apache.zookeeper.OpResult> multi(Iterable<org.apache.zookeeper.Op> ops, boolean retryOnConnLoss) throws InterruptedException, org.apache.zookeeper.KeeperException - Throws:
- InterruptedException
- org.apache.zookeeper.KeeperException
 
 - 
printLayoutpublic void printLayout(String path, int indent, StringBuilder string) throws org.apache.zookeeper.KeeperException, InterruptedException Fills string with printout of current ZooKeeper layout.- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
printLayoutToStreampublic void printLayoutToStream(PrintStream out) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
closepublic void close() - Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
 
 - 
isClosedpublic boolean isClosed() 
 - 
getZooKeeperpublic org.apache.zookeeper.ZooKeeper getZooKeeper() 
 - 
containsChrootpublic static boolean containsChroot(String zkHost) Validates if zkHost contains a chroot. See http://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#ch_zkSessions
 - 
checkInterruptedpublic static Throwable checkInterrupted(Throwable e) Check to see if a Throwable is an InterruptedException, and if it is, set the thread interrupt flag- Parameters:
- e- the Throwable
- Returns:
- the Throwable
 
 - 
getZkServerAddresspublic String getZkServerAddress() - Returns:
- the address of the zookeeper cluster
 
 - 
getConfigpublic String getConfig() Gets the raw config node /zookeeper/config as returned by server. Response may look likeserver.1=localhost:2780:2783:participant;localhost:2791 server.2=localhost:2781:2784:participant;localhost:2792 server.3=localhost:2782:2785:participant;localhost:2793 version=400000003 - Returns:
- Multi line string representing the config. For standalone ZK this will return empty string
 
 - 
getZkACLProviderpublic ZkACLProvider getZkACLProvider() 
 - 
getACLpublic List<org.apache.zookeeper.data.ACL> getACL(String path, org.apache.zookeeper.data.Stat stat, boolean retryOnConnLoss) throws org.apache.zookeeper.KeeperException, InterruptedException - Returns:
- the ACLs on a single node in ZooKeeper.
- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
setACLpublic org.apache.zookeeper.data.Stat setACL(String path, List<org.apache.zookeeper.data.ACL> acls, boolean retryOnConnLoss) throws InterruptedException, org.apache.zookeeper.KeeperException Set the ACL on a single node in ZooKeeper. This will replace all existing ACL on that node.- Parameters:
- path- path to set ACL on e.g. /solr/conf/solrconfig.xml
- acls- a list of- ACLs to be applied
- retryOnConnLoss- true if the command should be retried on connection loss
- Returns:
- the stat of the node
- Throws:
- InterruptedException
- org.apache.zookeeper.KeeperException
 
 - 
updateACLspublic void updateACLs(String root) throws org.apache.zookeeper.KeeperException, InterruptedException Update all ACLs for a zk tree based on our configuredZkACLProvider.- Parameters:
- root- the root node to recursively update
- Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
cleanpublic void clean(String path) throws InterruptedException, org.apache.zookeeper.KeeperException - Throws:
- InterruptedException
- org.apache.zookeeper.KeeperException
 
 - 
cleanpublic void clean(String path, Predicate<String> nodeFilter) throws InterruptedException, org.apache.zookeeper.KeeperException - Throws:
- InterruptedException
- org.apache.zookeeper.KeeperException
 
 - 
upConfigpublic void upConfig(Path confPath, String confName) throws IOException - Throws:
- IOException
 
 - 
listZnodepublic String listZnode(String path, Boolean recurse) throws org.apache.zookeeper.KeeperException, InterruptedException, org.apache.solr.client.solrj.SolrServerException - Throws:
- org.apache.zookeeper.KeeperException
- InterruptedException
- org.apache.solr.client.solrj.SolrServerException
 
 - 
downConfigpublic void downConfig(String confName, Path confPath) throws IOException - Throws:
- IOException
 
 - 
zkTransferpublic void zkTransfer(String src, Boolean srcIsZk, String dst, Boolean dstIsZk, Boolean recurse) throws org.apache.solr.client.solrj.SolrServerException, org.apache.zookeeper.KeeperException, InterruptedException, IOException - Throws:
- org.apache.solr.client.solrj.SolrServerException
- org.apache.zookeeper.KeeperException
- InterruptedException
- IOException
 
 - 
moveZnodepublic void moveZnode(String src, String dst) throws org.apache.solr.client.solrj.SolrServerException, org.apache.zookeeper.KeeperException, InterruptedException - Throws:
- org.apache.solr.client.solrj.SolrServerException
- org.apache.zookeeper.KeeperException
- InterruptedException
 
 - 
uploadToZKpublic void uploadToZK(Path rootPath, String zkPath, Pattern filenameExclusions) throws IOException - Throws:
- IOException
 
 - 
downloadFromZKpublic void downloadFromZK(String zkPath, Path dir) throws IOException - Throws:
- IOException
 
 
- 
 
-