use of org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper in project hbase by apache.
the class TestDumpReplicationQueues method testDumpReplicationReturnsWalSorted.
/**
* Makes sure dumpQueues returns wals znodes ordered chronologically.
* @throws Exception if dumpqueues finds any error while handling list of znodes.
*/
@Test
public void testDumpReplicationReturnsWalSorted() throws Exception {
Configuration config = HBaseConfiguration.create();
ZKWatcher zkWatcherMock = mock(ZKWatcher.class);
ZNodePaths zNodePath = new ZNodePaths(config);
RecoverableZooKeeper recoverableZooKeeperMock = mock(RecoverableZooKeeper.class);
when(zkWatcherMock.getRecoverableZooKeeper()).thenReturn(recoverableZooKeeperMock);
when(zkWatcherMock.getZNodePaths()).thenReturn(zNodePath);
List<String> nodes = new ArrayList<>();
String server = "rs1,60030," + EnvironmentEdgeManager.currentTime();
nodes.add(server);
when(recoverableZooKeeperMock.getChildren("/hbase/rs", null)).thenReturn(nodes);
when(recoverableZooKeeperMock.getChildren("/hbase/replication/rs", null)).thenReturn(nodes);
List<String> queuesIds = new ArrayList<>();
queuesIds.add("1");
when(recoverableZooKeeperMock.getChildren("/hbase/replication/rs/" + server, null)).thenReturn(queuesIds);
List<String> wals = new ArrayList<>();
wals.add("rs1%2C60964%2C1549394085556.1549394101427");
wals.add("rs1%2C60964%2C1549394085556.1549394101426");
wals.add("rs1%2C60964%2C1549394085556.1549394101428");
when(recoverableZooKeeperMock.getChildren("/hbase/replication/rs/" + server + "/1", null)).thenReturn(wals);
DumpReplicationQueues dumpQueues = new DumpReplicationQueues();
Set<String> peerIds = new HashSet<>();
peerIds.add("1");
dumpQueues.setConf(config);
String dump = dumpQueues.dumpQueues(zkWatcherMock, peerIds, false);
String[] parsedDump = dump.split("Replication position for");
assertEquals("Parsed dump should have 4 parts.", 4, parsedDump.length);
assertTrue("First wal should be rs1%2C60964%2C1549394085556.1549394101426, but got: " + parsedDump[1], parsedDump[1].indexOf("rs1%2C60964%2C1549394085556.1549394101426") >= 0);
assertTrue("Second wal should be rs1%2C60964%2C1549394085556.1549394101427, but got: " + parsedDump[2], parsedDump[2].indexOf("rs1%2C60964%2C1549394085556.1549394101427") >= 0);
assertTrue("Third wal should be rs1%2C60964%2C1549394085556.1549394101428, but got: " + parsedDump[3], parsedDump[3].indexOf("rs1%2C60964%2C1549394085556.1549394101428") >= 0);
}
use of org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper in project hbase by apache.
the class RestartActiveNameNodeAction method perform.
@Override
public void perform() throws Exception {
getLogger().info("Performing action: Restart active namenode");
Configuration conf = CommonFSUtils.getRootDir(getConf()).getFileSystem(getConf()).getConf();
String nameServiceID = DFSUtil.getNamenodeNameServiceId(conf);
if (!HAUtil.isHAEnabled(conf, nameServiceID)) {
throw new Exception("HA for namenode is not enabled");
}
ZKWatcher zkw = null;
RecoverableZooKeeper rzk = null;
String activeNamenode = null;
String hadoopHAZkNode = conf.get(ZK_PARENT_ZNODE_KEY, ZK_PARENT_ZNODE_DEFAULT);
try {
zkw = new ZKWatcher(conf, "get-active-namenode", null);
rzk = zkw.getRecoverableZooKeeper();
String hadoopHAZkNodePath = ZNodePaths.joinZNode(hadoopHAZkNode, nameServiceID);
List<String> subChildern = ZKUtil.listChildrenNoWatch(zkw, hadoopHAZkNodePath);
for (String eachEntry : subChildern) {
if (eachEntry.contains(ACTIVE_NN_LOCK_NAME)) {
byte[] data = rzk.getData(ZNodePaths.joinZNode(hadoopHAZkNodePath, ACTIVE_NN_LOCK_NAME), false, null);
ActiveNodeInfo proto = ActiveNodeInfo.parseFrom(data);
activeNamenode = proto.getHostname();
}
}
} finally {
if (zkw != null) {
zkw.close();
}
}
if (activeNamenode == null) {
throw new Exception("No active Name node found in zookeeper under " + hadoopHAZkNode);
}
getLogger().info("Found active namenode host:" + activeNamenode);
ServerName activeNNHost = ServerName.valueOf(activeNamenode, -1, -1);
getLogger().info("Restarting Active NameNode :" + activeNamenode);
restartNameNode(activeNNHost, sleepTime);
}
use of org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper in project hbase by apache.
the class IntegrationTestZKAndFSPermissions method testZNodeACLs.
private void testZNodeACLs() throws IOException, KeeperException, InterruptedException {
ZKWatcher watcher = new ZKWatcher(conf, "IntegrationTestZnodeACLs", null);
RecoverableZooKeeper zk = RecoverableZooKeeper.connect(this.conf, watcher);
String baseZNode = watcher.getZNodePaths().baseZNode;
LOG.info("");
LOG.info("***********************************************************************************");
LOG.info("Checking ZK permissions, root znode: " + baseZNode);
LOG.info("***********************************************************************************");
LOG.info("");
checkZnodePermsRecursive(watcher, zk, baseZNode);
LOG.info("Checking ZK permissions: SUCCESS");
}
use of org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper in project hbase by apache.
the class TestNamespaceReplicationWithBulkLoadedData method testBulkLoadReplicationActiveActive.
@Test
@Override
public void testBulkLoadReplicationActiveActive() throws Exception {
Table peer1TestTable = UTIL1.getConnection().getTable(TestReplicationBase.tableName);
Table peer2TestTable = UTIL2.getConnection().getTable(TestReplicationBase.tableName);
Table peer3TestTable = UTIL3.getConnection().getTable(TestReplicationBase.tableName);
Table notPeerTable = UTIL4.getConnection().getTable(TestReplicationBase.tableName);
Table ns1Table = UTIL4.getConnection().getTable(NS1_TABLE);
Table ns2Table = UTIL4.getConnection().getTable(NS2_TABLE);
// case1: The ns1 tables will be replicate to cluster4
byte[] row = Bytes.toBytes("002_ns_peer");
byte[] value = Bytes.toBytes("v2");
bulkLoadOnCluster(ns1Table.getName(), row, value, UTIL1);
waitForReplication(ns1Table, 1, NB_RETRIES);
assertTableHasValue(ns1Table, row, value);
// case2: The ns2:t2_syncup will be replicate to cluster4
// If it's not fix HBASE-23098 the ns_peer1's hfile-refs(zk) will be backlog
row = Bytes.toBytes("003_ns_table_peer");
value = Bytes.toBytes("v2");
bulkLoadOnCluster(ns2Table.getName(), row, value, UTIL1);
waitForReplication(ns2Table, 1, NB_RETRIES);
assertTableHasValue(ns2Table, row, value);
// case3: The table test will be replicate to cluster1,cluster2,cluster3
// not replicate to cluster4, because we not set other peer for that tables.
row = Bytes.toBytes("001_nopeer");
value = Bytes.toBytes("v1");
assertBulkLoadConditions(tableName, row, value, UTIL1, peer1TestTable, peer2TestTable, peer3TestTable);
// 1 -> 4, table is empty
assertTableNoValue(notPeerTable, row, value);
// Verify hfile-refs for 1:ns_peer1, expect is empty
MiniZooKeeperCluster zkCluster = UTIL1.getZkCluster();
ZKWatcher watcher = new ZKWatcher(UTIL1.getConfiguration(), "TestZnodeHFiles-refs", null);
RecoverableZooKeeper zk = RecoverableZooKeeper.connect(UTIL1.getConfiguration(), watcher);
ZKReplicationQueueStorage replicationQueueStorage = new ZKReplicationQueueStorage(watcher, UTIL1.getConfiguration());
Set<String> hfiles = replicationQueueStorage.getAllHFileRefs();
assertTrue(hfiles.isEmpty());
}
Aggregations