Index: src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java
===================================================================
--- src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java (revision 1461387)
+++ src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java (working copy)
@@ -22,6 +22,8 @@
import java.io.Closeable;
import java.io.IOException;
import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HConstants;
@@ -91,13 +93,20 @@
/**
* Add a new peer cluster to replicate to.
- * @param id a short that identifies the cluster
+ * @param id a short that identifies the cluster. A correct id may contain only 'a' through 'z'
+ * (in a case-insensitive manner), the digits '0' through '9', and the hyphen ('-'). It could not
+ * start with a hyphen, and must not end with a hyphen.
* @param clusterKey the concatenation of the slave cluster's
* hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent
* @throws IllegalStateException if there's already one slave since
* multi-slave isn't supported yet.
*/
public void addPeer(String id, String clusterKey) throws IOException {
+ Pattern pattern = Pattern.compile(HConstants.PEER_ID_FORMAT, Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(id);
+ if (!matcher.find()) {
+ throw new IOException("Invalid peer-id : " + id);
+ }
this.replicationZk.addPeer(id, clusterKey);
}
Index: src/main/java/org/apache/hadoop/hbase/HConstants.java
===================================================================
--- src/main/java/org/apache/hadoop/hbase/HConstants.java (revision 1461387)
+++ src/main/java/org/apache/hadoop/hbase/HConstants.java (working copy)
@@ -560,6 +560,11 @@
/*
* cluster replication constants.
*/
+ public final static String PEER_ID_FORMAT = "(^[0-9a-zA-Z]+$)|(^[0-9a-zA-Z][0-9a-zA-Z-]*[0-9a-zA-Z]$)";
+ /**
+ * Separator used in the peer-id for recovered queue.
+ */
+ public static final String REPLICATION_PEERID_SEPARATOR = "#";
public static final String
REPLICATION_ENABLE_KEY = "hbase.replication";
public static final String
Index: src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java
===================================================================
--- src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java (revision 1461387)
+++ src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java (working copy)
@@ -201,7 +201,7 @@
// The passed znode will be either the id of the peer cluster or
// the handling story of that queue in the form of id-servername-*
private void checkIfQueueRecovered(String peerClusterZnode) {
- String[] parts = peerClusterZnode.split("-");
+ String[] parts = peerClusterZnode.split(HConstants.REPLICATION_PEERID_SEPARATOR);
this.queueRecovered = parts.length != 1;
this.peerId = this.queueRecovered ?
parts[0] : peerClusterZnode;
Index: src/main/java/org/apache/hadoop/hbase/replication/ReplicationZookeeper.java
===================================================================
--- src/main/java/org/apache/hadoop/hbase/replication/ReplicationZookeeper.java (revision 1461387)
+++ src/main/java/org/apache/hadoop/hbase/replication/ReplicationZookeeper.java (working copy)
@@ -674,7 +674,7 @@
peerIdsToProcess = ZKUtil.listChildrenNoWatch(this.zookeeper, deadRSZnodePath);
if (peerIdsToProcess == null) return queues; // node already processed
for (String peerId : peerIdsToProcess) {
- String newPeerId = peerId + "-" + znode;
+ String newPeerId = peerId + HConstants.REPLICATION_PEERID_SEPARATOR + znode;
String newPeerZnode = ZKUtil.joinZNode(this.rsServerNameZnode, newPeerId);
// check the logs queue for the old peer cluster
String oldClusterZnode = ZKUtil.joinZNode(deadRSZnodePath, peerId);
@@ -738,7 +738,8 @@
// We add the name of the recovered RS to the new znode, we can even
// do that for queues that were recovered 10 times giving a znode like
// number-startcode-number-otherstartcode-number-anotherstartcode-etc
- String newCluster = cluster+"-"+znode;
+ String newCluster = cluster + HConstants.REPLICATION_PEERID_SEPARATOR
+ + znode;
String newClusterZnode = ZKUtil.joinZNode(rsServerNameZnode, newCluster);
String clusterPath = ZKUtil.joinZNode(nodePath, cluster);
List hlogs = ZKUtil.listChildrenNoWatch(this.zookeeper, clusterPath);