Package org.apache.solr.common.cloud
Class ZkMaintenanceUtils
- java.lang.Object
-
- org.apache.solr.common.cloud.ZkMaintenanceUtils
-
public class ZkMaintenanceUtils extends Object
Class to hold ZK upload/download/move common code. With the advent of the upconfig/downconfig/cp/ls/mv commands in bin/solr it made sense to keep the individual transfer methods in a central place, so here it is.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classZkMaintenanceUtils.VISIT_ORDERstatic interfaceZkMaintenanceUtils.ZkVisitor
-
Field Summary
Fields Modifier and Type Field Description static StringCONFIGS_ZKNODEZkNode where named configs are storedstatic Set<String>DEFAULT_FORBIDDEN_FILE_TYPESstatic StringFORBIDDEN_FILE_TYPES_ENVstatic StringFORBIDDEN_FILE_TYPES_PROPstatic PatternUPLOAD_FILENAME_EXCLUDE_PATTERNfiles matching this pattern will not be uploaded to ZkNode /configsstatic StringUPLOAD_FILENAME_EXCLUDE_REGEX
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclean(SolrZkClient zkClient, String path)static voidclean(SolrZkClient zkClient, String path, Predicate<String> filter)Delete a path and all of its sub nodesstatic StringcreateZkNodeName(String zkRoot, Path root, Path file)static voiddownloadFromZK(SolrZkClient zkClient, String zkPath, Path file)static voidensureExists(String path, byte[] data, SolrZkClient zkClient)Create a persistent znode with the given data if it does not already existstatic voidensureExists(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, SolrZkClient zkClient)Create a znode with the given mode and data if it does not already existstatic voidensureExists(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, SolrZkClient zkClient, int skipPathParts)Create a node if it does not existstatic voidensureExists(String path, SolrZkClient zkClient)Create a persistent znode with no data if it does not already existstatic StringgetZkParent(String path)static booleanisFileForbiddenInConfigSets(String filePath)static StringlistZnode(SolrZkClient zkClient, String path, Boolean recurse)Lists a ZNode child and (optionally) the znodes of all the children.static voidmoveZnode(SolrZkClient zkClient, String src, String dst)static voidtraverseZkTree(SolrZkClient zkClient, String path, ZkMaintenanceUtils.VISIT_ORDER visitOrder, ZkMaintenanceUtils.ZkVisitor visitor)Recursively visit a zk tree rooted at path and apply the given visitor to each path.static voiduploadToZK(SolrZkClient zkClient, Path fromPath, String zkPath, Pattern filenameExclusions)static voidzkTransfer(SolrZkClient zkClient, String src, Boolean srcIsZk, String dst, Boolean dstIsZk, Boolean recurse)Copy between local file system and Zookeeper, or from one Zookeeper node to another, optionally copying recursively.
-
-
-
Field Detail
-
CONFIGS_ZKNODE
public static final String CONFIGS_ZKNODE
ZkNode where named configs are stored- See Also:
- Constant Field Values
-
UPLOAD_FILENAME_EXCLUDE_REGEX
public static final String UPLOAD_FILENAME_EXCLUDE_REGEX
- See Also:
- Constant Field Values
-
UPLOAD_FILENAME_EXCLUDE_PATTERN
public static final Pattern UPLOAD_FILENAME_EXCLUDE_PATTERN
files matching this pattern will not be uploaded to ZkNode /configs
-
FORBIDDEN_FILE_TYPES_PROP
public static final String FORBIDDEN_FILE_TYPES_PROP
- See Also:
- Constant Field Values
-
FORBIDDEN_FILE_TYPES_ENV
public static final String FORBIDDEN_FILE_TYPES_ENV
- See Also:
- Constant Field Values
-
-
Method Detail
-
listZnode
public static String listZnode(SolrZkClient zkClient, String path, Boolean recurse) throws org.apache.zookeeper.KeeperException, InterruptedException, org.apache.solr.client.solrj.SolrServerException
Lists a ZNode child and (optionally) the znodes of all the children. No data is dumped.- Parameters:
path- The node to remove on Zookeeperrecurse- Whether to remove children.- Returns:
- an indented list of the znodes suitable for display
- Throws:
org.apache.zookeeper.KeeperException- Could not perform the Zookeeper operation.InterruptedException- Thread interruptedorg.apache.solr.client.solrj.SolrServerException- zookeeper node has children and recurse not specified.
-
zkTransfer
public static void zkTransfer(SolrZkClient zkClient, String src, Boolean srcIsZk, String dst, Boolean dstIsZk, Boolean recurse) throws org.apache.solr.client.solrj.SolrServerException, org.apache.zookeeper.KeeperException, InterruptedException, IOException
Copy between local file system and Zookeeper, or from one Zookeeper node to another, optionally copying recursively.- Parameters:
src- Source to copy from. Both src and dst may be Znodes. However, both may NOT be localdst- The place to copy the files too. Both src and dst may be Znodes. However both may NOT be localrecurse- if the source is a directory, reccursively copy the contents iff this is true.- Throws:
org.apache.solr.client.solrj.SolrServerException- Explanatory exception due to bad params, failed operation, etc.org.apache.zookeeper.KeeperException- Could not perform the Zookeeper operation.InterruptedException- Thread interruptedIOException
-
moveZnode
public static void moveZnode(SolrZkClient zkClient, String src, String dst) throws org.apache.solr.client.solrj.SolrServerException, org.apache.zookeeper.KeeperException, InterruptedException
- Throws:
org.apache.solr.client.solrj.SolrServerExceptionorg.apache.zookeeper.KeeperExceptionInterruptedException
-
clean
public static void clean(SolrZkClient zkClient, String path) throws InterruptedException, org.apache.zookeeper.KeeperException
- Throws:
InterruptedExceptionorg.apache.zookeeper.KeeperException
-
clean
public static void clean(SolrZkClient zkClient, String path, Predicate<String> filter) throws InterruptedException, org.apache.zookeeper.KeeperException
Delete a path and all of its sub nodes- Parameters:
filter- for node to be deleted- Throws:
InterruptedExceptionorg.apache.zookeeper.KeeperException
-
uploadToZK
public static void uploadToZK(SolrZkClient zkClient, Path fromPath, String zkPath, Pattern filenameExclusions) throws IOException
- Throws:
IOException
-
downloadFromZK
public static void downloadFromZK(SolrZkClient zkClient, String zkPath, Path file) throws IOException
- Throws:
IOException
-
traverseZkTree
public static void traverseZkTree(SolrZkClient zkClient, String path, ZkMaintenanceUtils.VISIT_ORDER visitOrder, ZkMaintenanceUtils.ZkVisitor visitor) throws InterruptedException, org.apache.zookeeper.KeeperException
Recursively visit a zk tree rooted at path and apply the given visitor to each path. Exists as a separate method because some of the logic can get nuanced.- Parameters:
path- the path to start fromvisitOrder- whether to call the visitor at the at the ending or beginning of the run.visitor- the operation to perform on each path- Throws:
InterruptedExceptionorg.apache.zookeeper.KeeperException
-
isFileForbiddenInConfigSets
public static boolean isFileForbiddenInConfigSets(String filePath)
-
ensureExists
public static void ensureExists(String path, SolrZkClient zkClient) throws org.apache.zookeeper.KeeperException, InterruptedException
Create a persistent znode with no data if it does not already exist- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException- See Also:
ensureExists(String, byte[], CreateMode, SolrZkClient, int)
-
ensureExists
public static void ensureExists(String path, byte[] data, SolrZkClient zkClient) throws org.apache.zookeeper.KeeperException, InterruptedException
Create a persistent znode with the given data if it does not already exist- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException- See Also:
ensureExists(String, byte[], CreateMode, SolrZkClient, int)
-
ensureExists
public static void ensureExists(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, SolrZkClient zkClient) throws org.apache.zookeeper.KeeperException, InterruptedException
Create a znode with the given mode and data if it does not already exist- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException- See Also:
ensureExists(String, byte[], CreateMode, SolrZkClient, int)
-
ensureExists
public static void ensureExists(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, SolrZkClient zkClient, int skipPathParts) throws org.apache.zookeeper.KeeperException, InterruptedException
Create a node if it does not exist- Parameters:
path- the path at which to create the znodedata- the optional data to set on the znodecreateMode- the mode with which to create the znodezkClient- the client to use to check and createskipPathParts- how many path elements to skip- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
-