@Override public RpcScheduler create(Configuration conf, PriorityFunction priority, Abortable server) { int handlerCount = conf.getInt(HConstants.REGION_SERVER_HANDLER_COUNT, HConstants.DEFAULT_REGION_SERVER_HANDLER_COUNT); return new SimpleRpcScheduler( conf, handlerCount, conf.getInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, HConstants.DEFAULT_REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT), conf.getInt(HConstants.REGION_SERVER_REPLICATION_HANDLER_COUNT, HConstants.DEFAULT_REGION_SERVER_REPLICATION_HANDLER_COUNT), priority, server, HConstants.QOS_THRESHOLD); }
@BeforeClass public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniZKCluster(); Configuration conf = TEST_UTIL.getConfiguration(); conf.setBoolean("hbase.zookeeper.useMulti", true); Abortable abortable = new Abortable() { @Override public void abort(String why, Throwable e) { LOG.info(why, e); } @Override public boolean isAborted() { return false; } }; zkw = new ZooKeeperWatcher(conf, "TestZKMulti", abortable, true); }
@After public void tearDown() throws KeeperException, ZooKeeperConnectionException, IOException { // Make sure zk is clean before we run the next test. ZooKeeperWatcher zkw = new ZooKeeperWatcher(TESTUTIL.getConfiguration(), "@Before", new Abortable() { @Override public void abort(String why, Throwable e) { throw new RuntimeException(why, e); } @Override public boolean isAborted() { return false; } }); ZKUtil.deleteNodeRecursively(zkw, zkw.baseZNode); zkw.close(); }
@Ignore @Test public void testRpcScheduler() throws IOException, InterruptedException { PriorityFunction qosFunction = mock(PriorityFunction.class); Abortable abortable = new AbortServer(); RpcScheduler scheduler = new SimpleRpcScheduler(CONF, 2, 0, 0, qosFunction, abortable, 0); RpcServer rpcServer = new TestRpcServer(scheduler); RpcClientImpl client = new RpcClientImpl(CONF, HConstants.CLUSTER_ID_DEFAULT); try { rpcServer.start(); MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo"); EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build(); PayloadCarryingRpcController controller = new PayloadCarryingRpcController(CellUtil.createCellScanner(ImmutableList.of(CELL))); InetSocketAddress address = rpcServer.getListenerAddress(); if (address == null) { throw new IOException("Listener channel is closed"); } client.call(controller, md, param, md.getOutputType().toProto(), User.getCurrent(), address, new MetricsConnection.CallStats()); } catch (Throwable e) { assert(abortable.isAborted() == true); } finally { rpcServer.stop(); } }
private ZooKeeperWatcher createZooKeeperWatcher() throws IOException { // This Abortable doesn't 'abort'... it just logs. return new ZooKeeperWatcher(connection.getConfiguration(), "ReplicationAdmin", new Abortable() { @Override public void abort(String why, Throwable e) { LOG.error(why, e); // We used to call system.exit here but this script can be embedded by other programs that // want to do replication stuff... so inappropriate calling System.exit. Just log for now. } @Override public boolean isAborted() { return false; } }); }
/** * Instantiate a ZooKeeper connection and watcher. * @param conf * @param identifier string that is passed to RecoverableZookeeper to be used as identifier for * this instance. Use null for default. * @param abortable Can be null if there is on error there is no host to abort: e.g. client * context. * @param canCreateBaseZNode * @throws IOException * @throws ZooKeeperConnectionException */ public ZooKeeperWatcher(Configuration conf, String identifier, Abortable abortable, boolean canCreateBaseZNode) throws IOException, ZooKeeperConnectionException { this.conf = conf; // Capture a stack trace now. Will print it out later if problem so we can // distingush amongst the myriad ZKWs. try { throw new Exception("ZKW CONSTRUCTOR STACK TRACE FOR DEBUGGING"); } catch (Exception e) { this.constructorCaller = e; } this.quorum = ZKConfig.getZKQuorumServersString(conf); this.prefix = identifier; // Identifier will get the sessionid appended later below down when we // handle the syncconnect event. this.identifier = identifier + "0x0"; this.abortable = abortable; setNodeNames(conf); this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, this, identifier); if (canCreateBaseZNode) { createBaseZNodes(); } }
private void setZNodes(Abortable abortable) throws KeeperException { String replicationZNodeName = conf.get("zookeeper.znode.replication", "replication"); String peersZNodeName = conf.get("zookeeper.znode.replication.peers", "peers"); this.peerStateNodeName = conf.get( "zookeeper.znode.replication.peers.state", "peer-state"); this.replicationStateNodeName = conf.get("zookeeper.znode.replication.state", "state"); String rsZNodeName = conf.get("zookeeper.znode.replication.rs", "rs"); this.ourClusterKey = ZKUtil.getZooKeeperClusterKey(this.conf); this.replicationZNode = ZKUtil.joinZNode(this.zookeeper.baseZNode, replicationZNodeName); this.peersZNode = ZKUtil.joinZNode(replicationZNode, peersZNodeName); ZKUtil.createWithParents(this.zookeeper, this.peersZNode); this.rsZNode = ZKUtil.joinZNode(replicationZNode, rsZNodeName); ZKUtil.createWithParents(this.zookeeper, this.rsZNode); // Set a tracker on replicationStateNodeNode this.statusTracker = new ReplicationStatusTracker(this.zookeeper, abortable); statusTracker.start(); readReplicationStateZnode(); }
/** * Instantiate a ZooKeeper connection and watcher. * @param descriptor Descriptive string that is added to zookeeper sessionid * and used as identifier for this instance. * @throws IOException * @throws ZooKeeperConnectionException */ public ZooKeeperWatcher(Configuration conf, String descriptor, Abortable abortable, boolean canCreateBaseZNode) throws IOException, ZooKeeperConnectionException { this.conf = conf; // Capture a stack trace now. Will print it out later if problem so we can // distingush amongst the myriad ZKWs. try { throw new Exception("ZKW CONSTRUCTOR STACK TRACE FOR DEBUGGING"); } catch (Exception e) { this.constructorCaller = e; } this.quorum = ZKConfig.getZKQuorumServersString(conf); // Identifier will get the sessionid appended later below down when we // handle the syncconnect event. this.identifier = descriptor; this.abortable = abortable; setNodeNames(conf); this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, this, descriptor); if (canCreateBaseZNode) { createBaseZNodes(); } }
private ServerName getRootRegionServerName() throws IOException, InterruptedException { RootRegionTracker rootRegionTracker = new RootRegionTracker(this.connection.getZooKeeperWatcher(), new Abortable() { @Override public void abort(String why, Throwable e) { LOG.error(why, e); System.exit(1); } @Override public boolean isAborted(){ return false; } }); rootRegionTracker.start(); ServerName sn = null; try { sn = rootRegionTracker.getRootRegionLocation(); } finally { rootRegionTracker.stop(); } return sn; }
@Ignore @Test public void testRpcScheduler() throws IOException, InterruptedException { PriorityFunction qosFunction = mock(PriorityFunction.class); Abortable abortable = new AbortServer(); RpcScheduler scheduler = new SimpleRpcScheduler(CONF, 2, 0, 0, qosFunction, abortable, 0); RpcServer rpcServer = new TestRpcServer(scheduler); RpcClientImpl client = new RpcClientImpl(CONF, HConstants.CLUSTER_ID_DEFAULT); try { rpcServer.start(); MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo"); EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build(); client.call(null, md, param, CellUtil.createCellScanner(ImmutableList.of(CELL)), md .getOutputType().toProto(), User.getCurrent(), rpcServer.getListenerAddress(), 0); } catch (Throwable e) { assert(abortable.isAborted() == true); } finally { rpcServer.stop(); } }
private ZooKeeperWatcher createZooKeeperWatcher() throws IOException { return new ZooKeeperWatcher(connection.getConfiguration(), "Replication Admin", new Abortable() { @Override public void abort(String why, Throwable e) { LOG.error(why, e); System.exit(1); } @Override public boolean isAborted() { return false; } }); }
/** * Instantiate a ZooKeeper connection and watcher. * @param conf * @param identifier string that is passed to RecoverableZookeeper to be used as identifier for * this instance. Use null for default. * @param abortable Can be null if there is on error there is no host to abort: e.g. client * context. * @param canCreateBaseZNode * @throws IOException * @throws ZooKeeperConnectionException */ public ZooKeeperWatcher(Configuration conf, String identifier, Abortable abortable, boolean canCreateBaseZNode) throws IOException, ZooKeeperConnectionException { this.conf = conf; // Capture a stack trace now. Will print it out later if problem so we can // distingush amongst the myriad ZKWs. try { throw new Exception("ZKW CONSTRUCTOR STACK TRACE FOR DEBUGGING"); } catch (Exception e) { this.constructorCaller = e; } this.quorum = ZKConfig.getZKQuorumServersString(conf); // Identifier will get the sessionid appended later below down when we // handle the syncconnect event. this.identifier = identifier; this.abortable = abortable; setNodeNames(conf); this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, this, identifier); if (canCreateBaseZNode) { createBaseZNodes(); } }
@InterfaceAudience.Private public Context( final Configuration localConf, final Configuration conf, final FileSystem fs, final String peerId, final UUID clusterId, final ReplicationPeer replicationPeer, final MetricsSource metrics, final TableDescriptors tableDescriptors, final Abortable abortable) { this.localConf = localConf; this.conf = conf; this.fs = fs; this.clusterId = clusterId; this.peerId = peerId; this.replicationPeer = replicationPeer; this.metrics = metrics; this.tableDescriptors = tableDescriptors; this.abortable = abortable; }
public SplitOrMergeTracker(ZKWatcher watcher, Configuration conf, Abortable abortable) { try { if (ZKUtil.checkExists(watcher, watcher.znodePaths.switchZNode) < 0) { ZKUtil.createAndFailSilent(watcher, watcher.znodePaths.switchZNode); } } catch (KeeperException e) { throw new RuntimeException(e); } splitZnode = ZNodePaths.joinZNode(watcher.znodePaths.switchZNode, conf.get("zookeeper.znode.switch.split", "split")); mergeZnode = ZNodePaths.joinZNode(watcher.znodePaths.switchZNode, conf.get("zookeeper.znode.switch.merge", "merge")); splitStateTracker = new SwitchStateTracker(watcher, splitZnode, abortable); mergeStateTracker = new SwitchStateTracker(watcher, mergeZnode, abortable); }
@BeforeClass public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniZKCluster(); Configuration conf = TEST_UTIL.getConfiguration(); abortable = new Abortable() { @Override public void abort(String why, Throwable e) { LOG.info(why, e); } @Override public boolean isAborted() { return false; } }; zkw = new ZKWatcher(conf, "TableCFs", abortable, true); zkStorageUtil = new ZKStorageUtil(zkw, conf); }
/** * Test that abort is called when lockHeartbeat fails with IOException. */ @Test public void testHeartbeatException() throws Exception { final long workerSleepTime = 100; // in ms Abortable abortable = Mockito.mock(Abortable.class); EntityLock lock = admin.namespaceLock("namespace", "description", abortable); lock.setTestingSleepTime(workerSleepTime); when(master.requestLock(any(), any())) .thenReturn(LockResponse.newBuilder().setProcId(procId).build()); when(master.lockHeartbeat(any(), any())) .thenReturn(LOCKED_RESPONSE) .thenThrow(new ServiceException("Failed heartbeat!")); lock.requestLock(); lock.await(); assertTrue(waitLockTimeOut(lock, 100 * workerSleepTime)); while (lock.getWorker().isAlive()) { TimeUnit.MILLISECONDS.sleep(100); } verify(abortable, times(1)).abort(any(), isA(HBaseIOException.class)); assertFalse(lock.getWorker().isAlive()); }
@After public void tearDown() throws KeeperException, ZooKeeperConnectionException, IOException { // Make sure zk is clean before we run the next test. ZKWatcher zkw = new ZKWatcher(TESTUTIL.getConfiguration(), "@Before", new Abortable() { @Override public void abort(String why, Throwable e) { throw new RuntimeException(why, e); } @Override public boolean isAborted() { return false; } }); ZKUtil.deleteNodeRecursively(zkw, zkw.znodePaths.baseZNode); zkw.close(); }
@Ignore @Test public void testRpcScheduler() throws IOException, InterruptedException { PriorityFunction qosFunction = mock(PriorityFunction.class); Abortable abortable = new AbortServer(); CONF.set(RpcServerFactory.CUSTOM_RPC_SERVER_IMPL_CONF_KEY, rpcServerImpl); RpcScheduler scheduler = new SimpleRpcScheduler(CONF, 2, 0, 0, qosFunction, abortable, 0); RpcServer rpcServer = RpcServerFactory.createRpcServer(null, "testRpcServer", Lists.newArrayList(new BlockingServiceAndInterface((BlockingService) SERVICE, null)), new InetSocketAddress("localhost", 0), CONF, scheduler); try (BlockingRpcClient client = new BlockingRpcClient(CONF)) { rpcServer.start(); BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress()); stub.echo(null, EchoRequestProto.newBuilder().setMessage("hello").build()); } catch (Throwable e) { assert (abortable.isAborted() == true); } finally { rpcServer.stop(); } }
/** * Test that we can interrupt a node that is blocked on a wait. */ @Test public void testInterruptible() throws IOException, InterruptedException { Abortable abortable = new StubAbortable(); ZKWatcher zk = new ZKWatcher(TEST_UTIL.getConfiguration(), "testInterruptible", abortable); final TestTracker tracker = new TestTracker(zk, "/xyz", abortable); tracker.start(); Thread t = new Thread() { @Override public void run() { try { tracker.blockUntilAvailable(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted", e); } } }; t.start(); while (!t.isAlive()) { Threads.sleep(1); } tracker.stop(); t.join(); // If it wasn't interruptible, we'd never get to here. }
@BeforeClass public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniZKCluster(); Configuration conf = TEST_UTIL.getConfiguration(); Abortable abortable = new Abortable() { @Override public void abort(String why, Throwable e) { LOG.info(why, e); } @Override public boolean isAborted() { return false; } }; zkw = new ZKWatcher(conf, "TestZKMulti", abortable, true); }
FlushTableSubprocedurePool(String name, Configuration conf, Abortable abortable) { this.abortable = abortable; // configure the executor service long keepAlive = conf.getLong( RegionServerFlushTableProcedureManager.FLUSH_TIMEOUT_MILLIS_KEY, RegionServerFlushTableProcedureManager.FLUSH_TIMEOUT_MILLIS_DEFAULT); int threads = conf.getInt(CONCURENT_FLUSH_TASKS_KEY, DEFAULT_CONCURRENT_FLUSH_TASKS); this.name = name; executor = new ThreadPoolExecutor(1, threads, keepAlive, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new DaemonThreadFactory("rs(" + name + ")-flush-proc-pool")); taskPool = new ExecutorCompletionService<Void>(executor); }