use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class TestReplicationSourceManager method setupZkAndReplication.
protected static void setupZkAndReplication() throws Exception {
// The implementing class should set up the conf
assertNotNull(conf);
zkw = new ZKWatcher(conf, "test", null);
ZKUtil.createWithParents(zkw, "/hbase/replication");
ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1");
ZKUtil.setData(zkw, "/hbase/replication/peers/1", Bytes.toBytes(conf.get(HConstants.ZOOKEEPER_QUORUM) + ":" + conf.get(HConstants.ZOOKEEPER_CLIENT_PORT) + ":/1"));
ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1/peer-state");
ZKUtil.setData(zkw, "/hbase/replication/peers/1/peer-state", ZKReplicationPeerStorage.ENABLED_ZNODE_BYTES);
ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1/sync-rep-state");
ZKUtil.setData(zkw, "/hbase/replication/peers/1/sync-rep-state", ZKReplicationPeerStorage.NONE_STATE_ZNODE_BYTES);
ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1/new-sync-rep-state");
ZKUtil.setData(zkw, "/hbase/replication/peers/1/new-sync-rep-state", ZKReplicationPeerStorage.NONE_STATE_ZNODE_BYTES);
ZKUtil.createWithParents(zkw, "/hbase/replication/state");
ZKUtil.setData(zkw, "/hbase/replication/state", ZKReplicationPeerStorage.ENABLED_ZNODE_BYTES);
ZKClusterId.setClusterId(zkw, new ClusterId());
CommonFSUtils.setRootDir(utility.getConfiguration(), utility.getDataTestDir());
fs = FileSystem.get(conf);
oldLogDir = utility.getDataTestDir(HConstants.HREGION_OLDLOGDIR_NAME);
logDir = utility.getDataTestDir(HConstants.HREGION_LOGDIR_NAME);
remoteLogDir = utility.getDataTestDir(ReplicationUtils.REMOTE_WAL_DIR_NAME);
replication = new Replication();
replication.initialize(new DummyServer(), fs, logDir, oldLogDir, new WALFactory(conf, "test", null, false));
managerOfCluster = getManagerFromCluster();
if (managerOfCluster != null) {
// After replication procedure, we need to add peer by hand (other than by receiving
// notification from zk)
managerOfCluster.addPeer(slaveId);
}
manager = replication.getReplicationManager();
manager.addSource(slaveId);
if (managerOfCluster != null) {
waitPeer(slaveId, managerOfCluster, true);
}
waitPeer(slaveId, manager, true);
htd = TableDescriptorBuilder.newBuilder(test).setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(f1).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()).setColumnFamily(ColumnFamilyDescriptorBuilder.of(f2)).build();
scopes = new TreeMap<>(Bytes.BYTES_COMPARATOR);
for (byte[] fam : htd.getColumnFamilyNames()) {
scopes.put(fam, 0);
}
hri = RegionInfoBuilder.newBuilder(htd.getTableName()).setStartKey(r1).setEndKey(r2).build();
}
use of org.apache.hadoop.hbase.zookeeper.ZKWatcher 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.ZKWatcher in project hbase by apache.
the class TestZKProcedureControllers method testSimpleZKCohortMemberController.
/**
* Smaller test to just test the actuation on the cohort member
* @throws Exception on failure
*/
@Test
public void testSimpleZKCohortMemberController() throws Exception {
ZKWatcher watcher = UTIL.getZooKeeperWatcher();
final String operationName = "instanceTest";
final Subprocedure sub = Mockito.mock(Subprocedure.class);
Mockito.when(sub.getName()).thenReturn(operationName);
final byte[] data = new byte[] { 1, 2, 3 };
final CountDownLatch prepared = new CountDownLatch(1);
final CountDownLatch committed = new CountDownLatch(1);
final ForeignExceptionDispatcher monitor = spy(new ForeignExceptionDispatcher());
final ZKProcedureMemberRpcs controller = new ZKProcedureMemberRpcs(watcher, "testSimple");
// mock out cohort member callbacks
final ProcedureMember member = Mockito.mock(ProcedureMember.class);
Mockito.doReturn(sub).when(member).createSubprocedure(operationName, data);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
controller.sendMemberAcquired(sub);
prepared.countDown();
return null;
}
}).when(member).submitSubprocedure(sub);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
controller.sendMemberCompleted(sub, memberData);
committed.countDown();
return null;
}
}).when(member).receivedReachedGlobalBarrier(operationName);
// start running the listener
controller.start(COHORT_NODE_NAME, member);
// set a prepare node from a 'coordinator'
String prepare = ZKProcedureUtil.getAcquireBarrierNode(controller.getZkController(), operationName);
ZKUtil.createSetData(watcher, prepare, ProtobufUtil.prependPBMagic(data));
// wait for the operation to be prepared
prepared.await();
// create the commit node so we update the operation to enter the commit phase
String commit = ZKProcedureUtil.getReachedBarrierNode(controller.getZkController(), operationName);
LOG.debug("Found prepared, posting commit node:" + commit);
ZKUtil.createAndFailSilent(watcher, commit);
LOG.debug("Commit node:" + commit + ", exists:" + ZKUtil.checkExists(watcher, commit));
committed.await();
verify(monitor, never()).receive(Mockito.any());
// XXX: broken due to composition.
// verify(member, never()).getManager().controllerConnectionFailure(Mockito.anyString(),
// Mockito.any());
// cleanup after the test
ZKUtil.deleteNodeRecursively(watcher, controller.getZkController().getBaseZnode());
assertEquals("Didn't delete prepare node", -1, ZKUtil.checkExists(watcher, prepare));
assertEquals("Didn't delete commit node", -1, ZKUtil.checkExists(watcher, commit));
}
use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class TestSplitLogWorker method setup.
@Before
public void setup() throws Exception {
TEST_UTIL.startMiniZKCluster();
Configuration conf = TEST_UTIL.getConfiguration();
zkw = new ZKWatcher(TEST_UTIL.getConfiguration(), "split-log-worker-tests", null);
ds = new DummyServer(zkw, conf);
ZKUtil.deleteChildrenRecursively(zkw, zkw.getZNodePaths().baseZNode);
ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().baseZNode);
assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().baseZNode), not(is(-1)));
LOG.debug(zkw.getZNodePaths().baseZNode + " created");
ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().splitLogZNode);
assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().splitLogZNode), not(is(-1)));
LOG.debug(zkw.getZNodePaths().splitLogZNode + " created");
ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().rsZNode);
assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().rsZNode), not(is(-1)));
SplitLogCounters.resetCounters();
executorService = new ExecutorService("TestSplitLogWorker");
executorService.startExecutorService(executorService.new ExecutorConfig().setExecutorType(ExecutorType.RS_LOG_REPLAY_OPS).setCorePoolSize(10));
}
use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class TestRSStatusServlet method setupBasicMocks.
@Before
public void setupBasicMocks() throws IOException, ServiceException {
rs = Mockito.mock(HRegionServer.class);
rpcServices = Mockito.mock(RSRpcServices.class);
rpcServer = Mockito.mock(RpcServerInterface.class);
Mockito.doReturn(HBaseConfiguration.create()).when(rs).getConfiguration();
Mockito.doReturn(rpcServices).when(rs).getRSRpcServices();
Mockito.doReturn(rpcServer).when(rs).getRpcServer();
Mockito.doReturn(fakeResponse).when(rpcServices).getServerInfo(Mockito.any(), Mockito.any());
// Fake ZKW
ZKWatcher zkw = Mockito.mock(ZKWatcher.class);
Mockito.doReturn("fakequorum").when(zkw).getQuorum();
Mockito.doReturn(zkw).when(rs).getZooKeeper();
// Fake BlockCache
LOG.warn("The " + HConstants.HFILE_BLOCK_CACHE_SIZE_KEY + " is set to 0");
Mockito.doReturn(Optional.empty()).when(rs).getBlockCache();
// Fake MasterAddressTracker
MasterAddressTracker mat = Mockito.mock(MasterAddressTracker.class);
Mockito.doReturn(fakeMasterAddress).when(mat).getMasterAddress();
Mockito.doReturn(mat).when(rs).getMasterAddressTracker();
MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class);
Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper();
Mockito.doReturn(rms).when(rs).getMetrics();
MetricsHBaseServer ms = Mockito.mock(MetricsHBaseServer.class);
Mockito.doReturn(new MetricsHBaseServerWrapperStub()).when(ms).getHBaseServerWrapper();
Mockito.doReturn(ms).when(rpcServer).getMetrics();
Mockito.doReturn(ByteBuffAllocator.HEAP).when(rpcServer).getByteBuffAllocator();
}
Aggregations