HBASE-11394 Replication can have data loss if peer id contains hyphen "-"
This commit is contained in:
parent
3f2e599a99
commit
65ae2e5126
|
@ -110,6 +110,11 @@ public class ReplicationPeersZKImpl extends ReplicationStateZKBase implements Re
|
||||||
throw new IllegalArgumentException("Cannot add a peer with id=" + id
|
throw new IllegalArgumentException("Cannot add a peer with id=" + id
|
||||||
+ " because that id already exists.");
|
+ " because that id already exists.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(id.contains("-")){
|
||||||
|
throw new IllegalArgumentException("Found invalid peer name:" + id);
|
||||||
|
}
|
||||||
|
|
||||||
ZKUtil.createWithParents(this.zookeeper, this.peersZNode);
|
ZKUtil.createWithParents(this.zookeeper, this.peersZNode);
|
||||||
List<ZKUtilOp> listOfOps = new ArrayList<ZKUtil.ZKUtilOp>();
|
List<ZKUtilOp> listOfOps = new ArrayList<ZKUtil.ZKUtilOp>();
|
||||||
ZKUtilOp op1 = ZKUtilOp.createAndFailSilent(ZKUtil.joinZNode(this.peersZNode, id),
|
ZKUtilOp op1 = ZKUtilOp.createAndFailSilent(ZKUtil.joinZNode(this.peersZNode, id),
|
||||||
|
|
|
@ -1316,7 +1316,11 @@ public class ZKUtil {
|
||||||
deleteNodeRecursively(zkw, joinZNode(node, child));
|
deleteNodeRecursively(zkw, joinZNode(node, child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Zookeeper Watches are one time triggers; When children of parent nodes are deleted recursively.
|
||||||
|
//Must set another watch, get notified of delete node
|
||||||
|
if (zkw.getRecoverableZooKeeper().exists(node, zkw) != null){
|
||||||
zkw.getRecoverableZooKeeper().delete(node, -1);
|
zkw.getRecoverableZooKeeper().delete(node, -1);
|
||||||
|
}
|
||||||
} catch(InterruptedException ie) {
|
} catch(InterruptedException ie) {
|
||||||
zkw.interruptedException(ie);
|
zkw.interruptedException(ie);
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ public class TestReplicationTrackerZKImpl {
|
||||||
assertEquals("hostname2.example.org:1234", rsRemovedData);
|
assertEquals("hostname2.example.org:1234", rsRemovedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore ("Flakey") @Test(timeout = 30000)
|
@Test(timeout = 30000)
|
||||||
public void testPeerRemovedEvent() throws Exception {
|
public void testPeerRemovedEvent() throws Exception {
|
||||||
rp.addPeer("5", new ReplicationPeerConfig().setClusterKey(utility.getClusterKey()), null);
|
rp.addPeer("5", new ReplicationPeerConfig().setClusterKey(utility.getClusterKey()), null);
|
||||||
rt.registerListener(new DummyReplicationListener());
|
rt.registerListener(new DummyReplicationListener());
|
||||||
|
@ -155,7 +155,7 @@ public class TestReplicationTrackerZKImpl {
|
||||||
assertEquals("5", peerRemovedData);
|
assertEquals("5", peerRemovedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore ("Flakey") @Test(timeout = 30000)
|
@Test(timeout = 30000)
|
||||||
public void testPeerListChangedEvent() throws Exception {
|
public void testPeerListChangedEvent() throws Exception {
|
||||||
// add a peer
|
// add a peer
|
||||||
rp.addPeer("5", new ReplicationPeerConfig().setClusterKey(utility.getClusterKey()), null);
|
rp.addPeer("5", new ReplicationPeerConfig().setClusterKey(utility.getClusterKey()), null);
|
||||||
|
@ -172,7 +172,32 @@ public class TestReplicationTrackerZKImpl {
|
||||||
assertTrue(plChangedData.contains("5"));
|
assertTrue(plChangedData.contains("5"));
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
ZKUtil.deleteNode(zkw, "/hbase/replication/peers/5");
|
//ZKUtil.deleteNode(zkw, "/hbase/replication/peers/5");
|
||||||
|
rp.removePeer("5");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 30000)
|
||||||
|
public void testPeerNameControl() throws Exception {
|
||||||
|
int exists = 0;
|
||||||
|
int hyphen = 0;
|
||||||
|
rp.addPeer("6", new ReplicationPeerConfig().setClusterKey(utility.getClusterKey()), null);
|
||||||
|
|
||||||
|
try{
|
||||||
|
rp.addPeer("6", new ReplicationPeerConfig().setClusterKey(utility.getClusterKey()), null);
|
||||||
|
}catch(IllegalArgumentException e){
|
||||||
|
exists++;
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
rp.addPeer("6-ec2", new ReplicationPeerConfig().setClusterKey(utility.getClusterKey()), null);
|
||||||
|
}catch(IllegalArgumentException e){
|
||||||
|
hyphen++;
|
||||||
|
}
|
||||||
|
assertEquals(1, exists);
|
||||||
|
assertEquals(1, hyphen);
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
rp.removePeer("6");
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DummyReplicationListener implements ReplicationListener {
|
private class DummyReplicationListener implements ReplicationListener {
|
||||||
|
|
Loading…
Reference in New Issue