private void moveRegionAndWait(HRegionInfo destRegion, ServerName destServer) throws InterruptedException, MasterNotRunningException, ZooKeeperConnectionException, IOException { HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); TEST_UTIL.getHBaseAdmin().move( destRegion.getEncodedNameAsBytes(), Bytes.toBytes(destServer.getServerName())); while (true) { ServerName serverName = master.getAssignmentManager() .getRegionStates().getRegionServerOfRegion(destRegion); if (serverName != null && serverName.equals(destServer)) { TEST_UTIL.assertRegionOnServer( destRegion, serverName, 200); break; } Thread.sleep(10); } }
private void moveRegionAndWait(Region destRegion, HRegionServer destServer) throws InterruptedException, MasterNotRunningException, ZooKeeperConnectionException, IOException { HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); TEST_UTIL.getHBaseAdmin().move( destRegion.getRegionInfo().getEncodedNameAsBytes(), Bytes.toBytes(destServer.getServerName().getServerName())); while (true) { ServerName serverName = master.getAssignmentManager() .getRegionStates().getRegionServerOfRegion(destRegion.getRegionInfo()); if (serverName != null && serverName.equals(destServer.getServerName())) { TEST_UTIL.assertRegionOnServer( destRegion.getRegionInfo(), serverName, 200); break; } Thread.sleep(10); } }
/** * @param regionName * Region name to assign. * @throws MasterNotRunningException * @throws ZooKeeperConnectionException * @throws IOException */ @Override public void assign(final byte[] regionName) throws MasterNotRunningException, ZooKeeperConnectionException, IOException { final byte[] toBeAssigned = getRegionName(regionName); executeCallable(new MasterCallable<Void>(getConnection()) { @Override public Void call(int callTimeout) throws ServiceException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setCallTimeout(callTimeout); // Hard to know the table name, at least check if meta if (isMetaRegion(regionName)) { controller.setPriority(TableName.META_TABLE_NAME); } AssignRegionRequest request = RequestConverter.buildAssignRegionRequest(toBeAssigned); master.assignRegion(controller,request); return null; } }); }
/** * Unassign a region from current hosting regionserver. Region will then be * assigned to a regionserver chosen at random. Region could be reassigned * back to the same server. Use {@link #move(byte[], byte[])} if you want * to control the region movement. * @param regionName Region to unassign. Will clear any existing RegionPlan * if one found. * @param force If true, force unassign (Will remove region from * regions-in-transition too if present. If results in double assignment * use hbck -fix to resolve. To be used by experts). * @throws MasterNotRunningException * @throws ZooKeeperConnectionException * @throws IOException */ @Override public void unassign(final byte [] regionName, final boolean force) throws MasterNotRunningException, ZooKeeperConnectionException, IOException { final byte[] toBeUnassigned = getRegionName(regionName); executeCallable(new MasterCallable<Void>(getConnection()) { @Override public Void call(int callTimeout) throws ServiceException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setCallTimeout(callTimeout); // Hard to know the table name, at least check if meta if (isMetaRegion(regionName)) { controller.setPriority(TableName.META_TABLE_NAME); } UnassignRegionRequest request = RequestConverter.buildUnassignRegionRequest(toBeUnassigned, force); master.unassignRegion(controller, request); return null; } }); }
private void checkIfBaseNodeAvailable(ZooKeeperWatcher zkw) throws MasterNotRunningException { String errorMsg; try { if (ZKUtil.checkExists(zkw, zkw.baseZNode) == -1) { errorMsg = "The node " + zkw.baseZNode+" is not in ZooKeeper. " + "It should have been written by the master. " + "Check the value configured in 'zookeeper.znode.parent'. " + "There could be a mismatch with the one configured in the master."; LOG.error(errorMsg); throw new MasterNotRunningException(errorMsg); } } catch (KeeperException e) { errorMsg = "Can't get connection to ZooKeeper: " + e.getMessage(); LOG.error(errorMsg); throw new MasterNotRunningException(errorMsg, e); } }
public HBaseAdminMultiCluster(Configuration c) throws MasterNotRunningException, ZooKeeperConnectionException, IOException { super(HBaseMultiClusterConfigUtil.splitMultiConfigFile(c).get( HBaseMultiClusterConfigUtil.PRIMARY_NAME)); Map<String, Configuration> configs = HBaseMultiClusterConfigUtil .splitMultiConfigFile(c); for (Entry<String, Configuration> entry : configs.entrySet()) { if (!entry.getKey().equals(HBaseMultiClusterConfigUtil.PRIMARY_NAME)) { HBaseAdmin admin = new HBaseAdmin(entry.getValue()); LOG.info("creating HBaseAdmin for : " + entry.getKey()); failoverAdminMap.put(entry.getKey(), admin); LOG.info(" - successfully creating HBaseAdmin for : " + entry.getKey()); } } LOG.info("Successful loaded all HBaseAdmins"); }
/** * Turn the load balancer on or off. * @param on If true, enable balancer. If false, disable balancer. * @param synchronous If true, it waits until current balance() call, if outstanding, to return. * @return Previous balancer value */ public boolean setBalancerRunning(final boolean on, final boolean synchronous) throws MasterNotRunningException, ZooKeeperConnectionException { if (synchronous && synchronousBalanceSwitchSupported) { try { return getMaster().synchronousBalanceSwitch(on); } catch (UndeclaredThrowableException ute) { String error = ute.getCause().getMessage(); if (error != null && error.matches("(?s).+NoSuchMethodException:.+synchronousBalanceSwitch.+")) { LOG.info("HMaster doesn't support synchronousBalanceSwitch"); synchronousBalanceSwitchSupported = false; } else { throw ute; } } } return balanceSwitch(on); }
public void createTable(HTableDescriptor hTableDescriptor, byte [][] splitKeys) throws IOException { if (!isMasterRunning()) { throw new MasterNotRunningException(); } HRegionInfo [] newRegions = getHRegionInfos(hTableDescriptor, splitKeys); checkInitialized(); if (cpHost != null) { cpHost.preCreateTable(hTableDescriptor, newRegions); } this.executorService.submit(new CreateTableHandler(this, this.fileSystemManager, this.serverManager, hTableDescriptor, conf, newRegions, catalogTracker, assignmentManager)); if (cpHost != null) { cpHost.postCreateTable(hTableDescriptor, newRegions); } }
@SuppressWarnings("deprecation") public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException, ParseException { String tableName = args[0]; String fileLocation = args[1]; Configuration conf = HBaseConfiguration.create(); HTable table = new HTable(conf, tableName); try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileLocation), "UTF8"))) { String line; while ((line = br.readLine()) != null) { Put put = get_put(line); put.add(Bytes.toBytes("raw"), Bytes.toBytes("line"), Bytes.toBytes(line)); table.put(put); } } table.flushCommits(); table.close(); }
@Override public void createTable(HTableDescriptor hTableDescriptor, byte[][] splitKeys) throws IOException { if (isStopped()) { throw new MasterNotRunningException(); } String namespace = hTableDescriptor.getTableName().getNamespaceAsString(); ensureNamespaceExists(namespace); HRegionInfo[] newRegions = getHRegionInfos(hTableDescriptor, splitKeys); checkInitialized(); sanityCheckTableDescriptor(hTableDescriptor); if (cpHost != null) { cpHost.preCreateTable(hTableDescriptor, newRegions); } LOG.info(getClientIdAuditPrefix() + " create " + hTableDescriptor); this.service.submit(new CreateTableHandler(this, this.fileSystemManager, hTableDescriptor, conf, newRegions, this).prepare()); if (cpHost != null) { cpHost.postCreateTable(hTableDescriptor, newRegions); } }
private void moveRegionAndWait(HRegion destRegion, HRegionServer destServer) throws InterruptedException, MasterNotRunningException, ZooKeeperConnectionException, IOException { HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); TEST_UTIL.getHBaseAdmin().move( destRegion.getRegionInfo().getEncodedNameAsBytes(), Bytes.toBytes(destServer.getServerName().getServerName())); while (true) { ServerName serverName = master.getAssignmentManager() .getRegionStates().getRegionServerOfRegion(destRegion.getRegionInfo()); if (serverName != null && serverName.equals(destServer.getServerName())) { TEST_UTIL.assertRegionOnServer( destRegion.getRegionInfo(), serverName, 200); break; } Thread.sleep(10); } }
private void checkIfBaseNodeAvailable(ZooKeeperWatcher zkw) throws MasterNotRunningException { String errorMsg; try { if (ZKUtil.checkExists(zkw, zkw.baseZNode) == -1) { errorMsg = "The node " + zkw.baseZNode + " is not in ZooKeeper. " + "It should have been written by the master. " + "Check the value configured in 'zookeeper.znode.parent'. " + "There could be a mismatch with the one configured in the master."; LOG.error(errorMsg); throw new MasterNotRunningException(errorMsg); } } catch (KeeperException e) { errorMsg = "Can't get connection to ZooKeeper: " + e.getMessage(); LOG.error(errorMsg); throw new MasterNotRunningException(errorMsg, e); } }
@Override public void createTable(HTableDescriptor hTableDescriptor, byte [][] splitKeys) throws IOException { if (!isMasterRunning()) { throw new MasterNotRunningException(); } String namespace = hTableDescriptor.getTableName().getNamespaceAsString(); getNamespaceDescriptor(namespace); // ensure namespace exists HRegionInfo[] newRegions = getHRegionInfos(hTableDescriptor, splitKeys); checkInitialized(); checkCompression(hTableDescriptor); if (cpHost != null) { cpHost.preCreateTable(hTableDescriptor, newRegions); } LOG.info(getClientIdAuditPrefix() + " create " + hTableDescriptor); this.executorService.submit(new CreateTableHandler(this, this.fileSystemManager, hTableDescriptor, conf, newRegions, this).prepare()); if (cpHost != null) { cpHost.postCreateTable(hTableDescriptor, newRegions); } }
/** * Move the region <code>r</code> to <code>dest</code>. * @param encodedRegionName The encoded region name; i.e. the hash that makes * up the region name suffix: e.g. if regionname is * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>, * then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>. * @param destServerName The servername of the destination regionserver. If * passed the empty byte array we'll assign to a random server. A server name * is made of host, port and startcode. Here is an example: * <code> host187.example.com,60020,1289493121758</code> * @throws UnknownRegionException Thrown if we can't find a region named * <code>encodedRegionName</code> * @throws ZooKeeperConnectionException * @throws MasterNotRunningException */ public void move(final byte [] encodedRegionName, final byte [] destServerName) throws HBaseIOException, MasterNotRunningException, ZooKeeperConnectionException { MasterKeepAliveConnection stub = connection.getKeepAliveMasterService(); try { MoveRegionRequest request = RequestConverter.buildMoveRegionRequest(encodedRegionName, destServerName); stub.moveRegion(null,request); } catch (ServiceException se) { IOException ioe = ProtobufUtil.getRemoteException(se); if (ioe instanceof HBaseIOException) { throw (HBaseIOException)ioe; } LOG.error("Unexpected exception: " + se + " from calling HMaster.moveRegion"); } catch (DeserializationException de) { LOG.error("Could not parse destination server name: " + de); } finally { stub.close(); } }
/** * Turn the load balancer on or off. * @param on If true, enable balancer. If false, disable balancer. * @param synchronous If true, it waits until current balance() call, if outstanding, to return. * @return Previous balancer value */ public boolean setBalancerRunning(final boolean on, final boolean synchronous) throws MasterNotRunningException, ZooKeeperConnectionException { MasterKeepAliveConnection stub = connection.getKeepAliveMasterService(); try { SetBalancerRunningRequest req = RequestConverter.buildSetBalancerRunningRequest(on, synchronous); return stub.setBalancerRunning(null, req).getPrevBalanceValue(); } catch (ServiceException se) { IOException ioe = ProtobufUtil.getRemoteException(se); if (ioe instanceof MasterNotRunningException) { throw (MasterNotRunningException)ioe; } if (ioe instanceof ZooKeeperConnectionException) { throw (ZooKeeperConnectionException)ioe; } // Throwing MasterNotRunningException even though not really valid in order to not // break interface by adding additional exception type. throw new MasterNotRunningException("Unexpected exception when calling balanceSwitch",se); } finally { stub.close(); } }
@Override public long createTable( final HTableDescriptor hTableDescriptor, final byte [][] splitKeys, final long nonceGroup, final long nonce) throws IOException { if (isStopped()) { throw new MasterNotRunningException(); } String namespace = hTableDescriptor.getTableName().getNamespaceAsString(); ensureNamespaceExists(namespace); HRegionInfo[] newRegions = ModifyRegionUtils.createHRegionInfos(hTableDescriptor, splitKeys); checkInitialized(); sanityCheckTableDescriptor(hTableDescriptor); if (cpHost != null) { cpHost.preCreateTable(hTableDescriptor, newRegions); } LOG.info(getClientIdAuditPrefix() + " create " + hTableDescriptor); // TODO: We can handle/merge duplicate requests, and differentiate the case of // TableExistsException by saying if the schema is the same or not. ProcedurePrepareLatch latch = ProcedurePrepareLatch.createLatch(); long procId = this.procedureExecutor.submitProcedure( new CreateTableProcedure( procedureExecutor.getEnvironment(), hTableDescriptor, newRegions, latch), nonceGroup, nonce); latch.await(); if (cpHost != null) { cpHost.postCreateTable(hTableDescriptor, newRegions); } return procId; }
/** * Constructor * * @param conf * Configuration object * @throws MasterNotRunningException * if the master is not running * @throws ZooKeeperConnectionException * if unable to connect to ZooKeeper */ public HBaseFsck(Configuration conf, ExecutorService exec) throws MasterNotRunningException, ZooKeeperConnectionException, IOException, ClassNotFoundException { super(conf); errors = getErrorReporter(getConf()); this.executor = exec; lockFileRetryCounterFactory = new RetryCounterFactory( getConf().getInt("hbase.hbck.lockfile.attempts", DEFAULT_MAX_LOCK_FILE_ATTEMPTS), getConf().getInt( "hbase.hbck.lockfile.attempt.sleep.interval", DEFAULT_LOCK_FILE_ATTEMPT_SLEEP_INTERVAL), getConf().getInt( "hbase.hbck.lockfile.attempt.maxsleeptime", DEFAULT_LOCK_FILE_ATTEMPT_MAX_SLEEP_TIME)); }
/** * return the index of the active master in the cluster * * @throws org.apache.hadoop.hbase.MasterNotRunningException * if no active master found */ private int getActiveMasterIndex(MiniHBaseCluster cluster) throws MasterNotRunningException { // get all the master threads List<JVMClusterUtil.MasterThread> masterThreads = cluster.getMasterThreads(); for (int i = 0; i < masterThreads.size(); i++) { if (masterThreads.get(i).getMaster().isActiveMaster()) { return i; } } throw new MasterNotRunningException(); }
/** * Ensure single table region is not on same server as the single hbase:meta table * region. * @param admin * @param hri * @return Index of the server hosting the single table region * @throws UnknownRegionException * @throws MasterNotRunningException * @throws org.apache.hadoop.hbase.ZooKeeperConnectionException * @throws InterruptedException */ private int ensureTableRegionNotOnSameServerAsMeta(final Admin admin, final HRegionInfo hri) throws IOException, MasterNotRunningException, ZooKeeperConnectionException, InterruptedException { // Now make sure that the table region is not on same server as that hosting // hbase:meta We don't want hbase:meta replay polluting our test when we later crash // the table region serving server. int metaServerIndex = cluster.getServerWithMeta(); assertTrue(metaServerIndex != -1); HRegionServer metaRegionServer = cluster.getRegionServer(metaServerIndex); int tableRegionIndex = cluster.getServerWith(hri.getRegionName()); assertTrue(tableRegionIndex != -1); HRegionServer tableRegionServer = cluster.getRegionServer(tableRegionIndex); if (metaRegionServer.getServerName().equals(tableRegionServer.getServerName())) { HRegionServer hrs = getOtherRegionServer(cluster, metaRegionServer); assertNotNull(hrs); assertNotNull(hri); LOG.info("Moving " + hri.getRegionNameAsString() + " from " + metaRegionServer.getServerName() + " to " + hrs.getServerName() + "; metaServerIndex=" + metaServerIndex); admin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(hrs.getServerName().toString())); } // Wait till table region is up on the server that is NOT carrying hbase:meta. for (int i = 0; i < 20; i++) { tableRegionIndex = cluster.getServerWith(hri.getRegionName()); if (tableRegionIndex != -1 && tableRegionIndex != metaServerIndex) break; LOG.debug("Waiting on region move off the hbase:meta server; current index " + tableRegionIndex + " and metaServerIndex=" + metaServerIndex); Thread.sleep(1000); } assertTrue("Region not moved off hbase:meta server", tableRegionIndex != -1 && tableRegionIndex != metaServerIndex); // Verify for sure table region is not on same server as hbase:meta tableRegionIndex = cluster.getServerWith(hri.getRegionName()); assertTrue(tableRegionIndex != -1); assertNotSame(metaServerIndex, tableRegionIndex); return tableRegionIndex; }
/** * @deprecated Use {@link #isAccessControllerRunning(Connection)} instead. */ @Deprecated public static boolean isAccessControllerRunning(Configuration conf) throws MasterNotRunningException, ZooKeeperConnectionException, IOException { try (Connection connection = ConnectionFactory.createConnection(conf)) { return isAccessControllerRunning(connection); } }
/** * Constructor. * See {@link #HBaseAdmin(Connection connection)} * * @param c Configuration object. Copied internally. * @deprecated Constructing HBaseAdmin objects manually has been deprecated. * Use {@link Connection#getAdmin()} to obtain an instance of {@link Admin} instead. */ @Deprecated public HBaseAdmin(Configuration c) throws MasterNotRunningException, ZooKeeperConnectionException, IOException { // Will not leak connections, as the new implementation of the constructor // does not throw exceptions anymore. this(ConnectionManager.getConnectionInternal(new Configuration(c))); this.cleanupConnectionOnClose = true; }
/** * @return true if the master is running, throws an exception otherwise * @throws MasterNotRunningException - if the master is not running * @throws ZooKeeperConnectionException */ @Deprecated @Override public boolean isMasterRunning() throws MasterNotRunningException, ZooKeeperConnectionException { // When getting the master connection, we check it's running, // so if there is no exception, it means we've been able to get a // connection on a running master MasterKeepAliveConnection m = getKeepAliveMasterService(); m.close(); return true; }
/** * Create a stub. Try once only. It is not typed because there is no common type to * protobuf services nor their interfaces. Let the caller do appropriate casting. * @return A stub for master services. * @throws IOException * @throws KeeperException * @throws ServiceException */ private Object makeStubNoRetries() throws IOException, KeeperException, ServiceException { ZooKeeperKeepAliveConnection zkw; try { zkw = getKeepAliveZooKeeperWatcher(); } catch (IOException e) { ExceptionUtil.rethrowIfInterrupt(e); throw new ZooKeeperConnectionException("Can't connect to ZooKeeper", e); } try { checkIfBaseNodeAvailable(zkw); ServerName sn = MasterAddressTracker.getMasterAddress(zkw); if (sn == null) { String msg = "ZooKeeper available but no active master location found"; LOG.info(msg); throw new MasterNotRunningException(msg); } if (isDeadServer(sn)) { throw new MasterNotRunningException(sn + " is dead."); } // Use the security info interface name as our stub key String key = getStubKey(getServiceName(), sn.getHostname(), sn.getPort(), hostnamesCanChange); connectionLock.putIfAbsent(key, key); Object stub = null; synchronized (connectionLock.get(key)) { stub = stubs.get(key); if (stub == null) { BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sn, user, rpcTimeout); stub = makeStub(channel); isMasterRunning(); stubs.put(key, stub); } } return stub; } finally { zkw.close(); } }
/** * Constructor * @param c Configuration object * @throws MasterNotRunningException if the master is not running * @throws ZooKeeperConnectionException if unable to connect to zookeeper */ public HBaseAdmin(Configuration c) throws MasterNotRunningException, ZooKeeperConnectionException { this.conf = HBaseConfiguration.create(c); this.connection = HConnectionManager.getConnection(this.conf); this.pause = this.conf.getLong("hbase.client.pause", 1000); this.numRetries = this.conf.getInt("hbase.client.retries.number", 10); this.retryLongerMultiplier = this.conf.getInt("hbase.client.retries.longer.multiplier", 10); this.cleanupConnectionOnClose = true; int tries = 0; while (true) { try { this.connection.getMaster(); return; } catch (MasterNotRunningException mnre) { HConnectionManager.deleteStaleConnection(this.connection); this.connection = HConnectionManager.getConnection(this.conf); } tries++; if (tries >= numRetries) { // we should delete connection between client and zookeeper HConnectionManager.deleteStaleConnection(this.connection); throw new MasterNotRunningException("Retried " + numRetries + " times"); } try { Thread.sleep(getPauseTime(tries)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // we should delete connection between client and zookeeper HConnectionManager.deleteStaleConnection(this.connection); throw new MasterNotRunningException("Interrupted after " + tries + " tries"); } } }
/** * Constructor for externally managed HConnections. This constructor fails fast if the HMaster is * not running. The HConnection can be re-used again in another attempt. This constructor fails * fast. * @param connection The HConnection instance to use * @throws MasterNotRunningException if the master is not running * @throws ZooKeeperConnectionException if unable to connect to zookeeper */ public HBaseAdmin(HConnection connection) throws MasterNotRunningException, ZooKeeperConnectionException { this.conf = connection.getConfiguration(); this.connection = connection; this.cleanupConnectionOnClose = false; this.pause = this.conf.getLong("hbase.client.pause", 1000); this.numRetries = this.conf.getInt("hbase.client.retries.number", 10); this.retryLongerMultiplier = this.conf.getInt("hbase.client.retries.longer.multiplier", 10); this.connection.getMaster(); }
private void checkIfBaseNodeAvailable() throws MasterNotRunningException { if (false == masterAddressTracker.checkIfBaseNodeAvailable()) { String errorMsg = "Check the value configured in 'zookeeper.znode.parent'. " + "There could be a mismatch with the one configured in the master."; LOG.error(errorMsg); throw new MasterNotRunningException(errorMsg); } }
public boolean isMasterRunning() throws MasterNotRunningException, ZooKeeperConnectionException { if (this.master == null) { getMaster(); } boolean isRunning = master.isMasterRunning(); if(isRunning) { return true; } throw new MasterNotRunningException(); }
/** * Constructor * * @param conf Configuration object * @throws MasterNotRunningException if the master is not running * @throws ZooKeeperConnectionException if unable to connect to ZooKeeper */ public HBaseFsck(Configuration conf) throws MasterNotRunningException, ZooKeeperConnectionException, IOException, ClassNotFoundException { super(conf); errors = getErrorReporter(conf); initialPoolNumThreads(); }
private void moveRegionAndWait(HRegion destRegion, HRegionServer destServer) throws InterruptedException, MasterNotRunningException, ZooKeeperConnectionException, IOException { HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); TEST_UTIL.getHBaseAdmin().move( destRegion.getRegionInfo().getEncodedNameAsBytes(), Bytes.toBytes(destServer.getServerName().getServerName())); while (true) { ServerName serverName = master.getAssignmentManager() .getRegionServerOfRegion(destRegion.getRegionInfo()); if (serverName != null && serverName.equals(destServer.getServerName())) break; Thread.sleep(10); } }
public PoolableHConnection(HConnection hConnection, ObjectPool<HConnection> pool) throws MasterNotRunningException, ZooKeeperConnectionException { this.hConnection = hConnection; this.pool = pool; // this.delegate = new HBaseAdmin(this.hConnection); this.maxThreads = getConfiguration().getInt("hbase.htable.threads.max", 100); if (this.maxThreads == 0) { this.maxThreads = 1; } // this.keepAliveTime = getConfiguration().getLong("hbase.htable.threads.keepalivetime", 60L); }
public LCCPutData(String resourcePath) throws MasterNotRunningException, ZooKeeperConnectionException { conf = HBaseConfiguration.create(); if (resourcePath != null) { conf.addResource(resourcePath); } admin = new HBaseAdmin(conf); }
/** * Constructor * * @param conf Configuration object * @throws MasterNotRunningException if the master is not running * @throws ZooKeeperConnectionException if unable to connect to ZooKeeper */ public HBaseFsck(Configuration conf) throws MasterNotRunningException, ZooKeeperConnectionException, IOException, ClassNotFoundException { super(conf); // make a copy, just to be sure we're not overriding someone else's config setConf(HBaseConfiguration.create(getConf())); // disable blockcache for tool invocation, see HBASE-10500 getConf().setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0); errors = getErrorReporter(conf); int numThreads = conf.getInt("hbasefsck.numthreads", MAX_NUM_THREADS); executor = new ScheduledThreadPoolExecutor(numThreads, Threads.newDaemonThreadFactory("hbasefsck")); }
/** * Verify that PleaseHoldException gets retried. * HBASE-8764 * @throws IOException * @throws ZooKeeperConnectionException * @throws MasterNotRunningException * @throws ServiceException */ @Test public void testMasterMonitorCallableRetries() throws MasterNotRunningException, ZooKeeperConnectionException, IOException, ServiceException { Configuration configuration = HBaseConfiguration.create(); // Set the pause and retry count way down. configuration.setLong(HConstants.HBASE_CLIENT_PAUSE, 1); final int count = 10; configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, count); // Get mocked connection. Getting the connection will register it so when HBaseAdmin is // constructed with same configuration, it will find this mocked connection. ClusterConnection connection = HConnectionTestingUtility.getMockedConnection(configuration); // Mock so we get back the master interface. Make it so when createTable is called, we throw // the PleaseHoldException. MasterKeepAliveConnection masterAdmin = Mockito.mock(MasterKeepAliveConnection.class); Mockito.when(masterAdmin.createTable((RpcController)Mockito.any(), (CreateTableRequest)Mockito.any())). thenThrow(new ServiceException("Test fail").initCause(new PleaseHoldException("test"))); Mockito.when(connection.getKeepAliveMasterService()).thenReturn(masterAdmin); Admin admin = new HBaseAdmin(connection); try { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("testMasterMonitorCollableRetries")); // Pass any old htable descriptor; not important try { admin.createTable(htd, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE); fail(); } catch (RetriesExhaustedException e) { Log.info("Expected fail", e); } // Assert we were called 'count' times. Mockito.verify(masterAdmin, Mockito.atLeast(count)).createTable((RpcController)Mockito.any(), (CreateTableRequest)Mockito.any()); } finally { admin.close(); if (connection != null) connection.close(); } }
private void testMasterOperationIsRetried(MethodCaller caller) throws Exception { Configuration configuration = HBaseConfiguration.create(); // Set the pause and retry count way down. configuration.setLong(HConstants.HBASE_CLIENT_PAUSE, 1); final int count = 10; configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, count); ClusterConnection connection = mock(ClusterConnection.class); when(connection.getConfiguration()).thenReturn(configuration); MasterKeepAliveConnection masterAdmin = Mockito.mock(MasterKeepAliveConnection.class, new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { if (invocation.getMethod().getName().equals("close")) { return null; } throw new MasterNotRunningException(); // all methods will throw an exception } }); Mockito.when(connection.getKeepAliveMasterService()).thenReturn(masterAdmin); Admin admin = null; try { admin = new HBaseAdmin(connection); try { caller.call(admin); // invoke the HBaseAdmin method fail(); } catch (RetriesExhaustedException e) { Log.info("Expected fail", e); } // Assert we were called 'count' times. caller.verify(masterAdmin, count); } finally { if (admin != null) {admin.close();} } }
public static boolean isAccessControllerRunning(Configuration conf) throws MasterNotRunningException, ZooKeeperConnectionException, IOException { // TODO: Make it so caller passes in a Connection rather than have us do this expensive // setup each time. This class only used in test and shell at moment though. try (Connection connection = ConnectionFactory.createConnection(conf)) { try (Admin admin = connection.getAdmin()) { return admin.isTableAvailable(ACL_TABLE_NAME); } } }
/** * @param regionName * Region name to assign. * @throws MasterNotRunningException * @throws ZooKeeperConnectionException * @throws IOException */ @Override public void assign(final byte[] regionName) throws MasterNotRunningException, ZooKeeperConnectionException, IOException { final byte[] toBeAssigned = getRegionName(regionName); executeCallable(new MasterCallable<Void>(getConnection()) { @Override public Void call(int callTimeout) throws ServiceException { AssignRegionRequest request = RequestConverter.buildAssignRegionRequest(toBeAssigned); master.assignRegion(null,request); return null; } }); }