/** * Load the list of disabled tables in ZK into local set. * @throws ZooKeeperConnectionException * @throws IOException */ private void loadDisabledTables() throws ZooKeeperConnectionException, IOException { HConnectionManager.execute(new HConnectable<Void>(getConf()) { @Override public Void connect(HConnection connection) throws IOException { ZooKeeperWatcher zkw = createZooKeeperWatcher(); try { for (TableName tableName : ZKTableStateClientSideReader.getDisabledOrDisablingTables(zkw)) { disabledTables.add(tableName); } } catch (KeeperException ke) { throw new IOException(ke); } catch (InterruptedException e) { throw new InterruptedIOException(); } finally { zkw.close(); } return null; } }); }
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); } }
/** * Get a Mocked {@link HConnection} that goes with the passed <code>conf</code> * configuration instance. Minimally the mock will return * <code>conf</conf> when {@link ClusterConnection#getConfiguration()} is invoked. * Be sure to shutdown the connection when done by calling * {@link HConnectionManager#deleteConnection(Configuration)} else it * will stick around; this is probably not what you want. * @param conf configuration * @return HConnection object for <code>conf</code> * @throws ZooKeeperConnectionException */ public static ClusterConnection getMockedConnection(final Configuration conf) throws ZooKeeperConnectionException { HConnectionKey connectionKey = new HConnectionKey(conf); synchronized (ConnectionManager.CONNECTION_INSTANCES) { HConnectionImplementation connection = ConnectionManager.CONNECTION_INSTANCES.get(connectionKey); if (connection == null) { connection = Mockito.mock(HConnectionImplementation.class); Mockito.when(connection.getConfiguration()).thenReturn(conf); Mockito.when(connection.getRpcControllerFactory()).thenReturn( Mockito.mock(RpcControllerFactory.class)); // we need a real retrying caller RpcRetryingCallerFactory callerFactory = new RpcRetryingCallerFactory(conf); Mockito.when(connection.getRpcRetryingCallerFactory()).thenReturn(callerFactory); ConnectionManager.CONNECTION_INSTANCES.put(connectionKey, connection); } return connection; } }
@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(); }
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; } }); }
/** * 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 createBaseZNodes() throws ZooKeeperConnectionException { try { // Create all the necessary "directories" of znodes ZKUtil.createWithParents(this, baseZNode); if (conf.getBoolean("hbase.assignment.usezk", true)) { ZKUtil.createAndFailSilent(this, assignmentZNode); } ZKUtil.createAndFailSilent(this, rsZNode); ZKUtil.createAndFailSilent(this, drainingZNode); ZKUtil.createAndFailSilent(this, tableZNode); ZKUtil.createAndFailSilent(this, splitLogZNode); ZKUtil.createAndFailSilent(this, backupMasterAddressesZNode); ZKUtil.createAndFailSilent(this, tableLockZNode); ZKUtil.createAndFailSilent(this, recoveringRegionsZNode); } catch (KeeperException e) { throw new ZooKeeperConnectionException( prefix("Unexpected KeeperException creating base node"), e); } }
@Test public void testIsClientReadable() throws ZooKeeperConnectionException, IOException { ZooKeeperWatcher watcher = new ZooKeeperWatcher(HBaseConfiguration.create(), "testIsClientReadable", null, false); assertTrue(watcher.isClientReadable(watcher.baseZNode)); assertTrue(watcher.isClientReadable(watcher.getZNodeForReplica(0))); assertTrue(watcher.isClientReadable(watcher.getMasterAddressZNode())); assertTrue(watcher.isClientReadable(watcher.clusterIdZNode)); assertTrue(watcher.isClientReadable(watcher.tableZNode)); assertTrue(watcher.isClientReadable(ZKUtil.joinZNode(watcher.tableZNode, "foo"))); assertTrue(watcher.isClientReadable(watcher.rsZNode)); assertFalse(watcher.isClientReadable(watcher.tableLockZNode)); assertFalse(watcher.isClientReadable(watcher.balancerZNode)); assertFalse(watcher.isClientReadable(watcher.getRegionNormalizerZNode())); assertFalse(watcher.isClientReadable(watcher.clusterStateZNode)); assertFalse(watcher.isClientReadable(watcher.drainingZNode)); assertFalse(watcher.isClientReadable(watcher.recoveringRegionsZNode)); assertFalse(watcher.isClientReadable(watcher.splitLogZNode)); assertFalse(watcher.isClientReadable(watcher.backupMasterAddressesZNode)); watcher.close(); }
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); }
/** * Get the connection that goes with the passed <code>conf</code> * configuration instance. * If no current connection exists, method creates a new connection for the * passed <code>conf</code> instance. * @param conf configuration * @return HConnection object for <code>conf</code> * @throws ZooKeeperConnectionException */ public static HConnection getConnection(Configuration conf) throws ZooKeeperConnectionException { HConnectionKey connectionKey = new HConnectionKey(conf); synchronized (HBASE_INSTANCES) { HConnectionImplementation connection = HBASE_INSTANCES.get(connectionKey); if (connection == null) { connection = new HConnectionImplementation(conf, true, null); HBASE_INSTANCES.put(connectionKey, connection); } else if (connection.isClosed()) { HConnectionManager.deleteConnection(connectionKey, true); connection = new HConnectionImplementation(conf, true, null); HBASE_INSTANCES.put(connectionKey, connection); } connection.incCount(); return connection; } }
/** * Get the ZooKeeper instance for this TableServers instance. * * If ZK has not been initialized yet, this will connect to ZK. * @returns zookeeper reference * @throws ZooKeeperConnectionException if there's a problem connecting to zk */ @Deprecated public synchronized ZooKeeperWatcher getZooKeeperWatcher() throws ZooKeeperConnectionException { if(zooKeeper == null) { try { if (this.closed) { throw new IOException(toString() + " closed"); } this.zooKeeper = new ZooKeeperWatcher(conf, "hconnection", this); } catch(ZooKeeperConnectionException zce) { throw zce; } catch (IOException e) { throw new ZooKeeperConnectionException("An error is preventing" + " HBase from connecting to ZooKeeper", e); } } return zooKeeper; }
public static void createNewConfigurations() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, InterruptedException, ZooKeeperConnectionException { HConnection last = null; for (int i = 0; i <= (HConnectionManager.MAX_CACHED_HBASE_INSTANCES * 2); i++) { // set random key to differentiate the connection from previous ones Configuration configuration = HBaseConfiguration.create(); configuration.set("somekey", String.valueOf(_randy.nextInt())); System.out.println("Hash Code: " + configuration.hashCode()); HConnection connection = HConnectionManager.getConnection(configuration); if (last != null) { if (last == connection) { System.out.println("!! Got same connection for once !!"); } } // change the configuration once, and the cached connection is lost forever: // the hashtable holding the cache won't be able to find its own keys // to remove them, so the LRU strategy does not work. configuration.set("someotherkey", String.valueOf(_randy.nextInt())); last = connection; LOG.info("Cache Size: " + getHConnectionManagerCacheSize()); Thread.sleep(100); } Assert.assertEquals(1, getHConnectionManagerCacheSize()); }
public synchronized void close() throws ZooKeeperConnectionException { if (this.closed) { throw new ZooKeeperConnectionException("HzDataSource was already closed"); } // this.closed = true; GenericObjectPool<HConnection> oldpool = this.objectPool; this.objectPool = null; this.instance = null; try { if (oldpool != null) oldpool.close(); } catch (Exception ex) { throw new ZooKeeperConnectionException("Cannot close pool", ex); } }
/** * Load the list of disabled tables in ZK into local set. * @throws ZooKeeperConnectionException * @throws IOException */ private void loadDisabledTables() throws ZooKeeperConnectionException, IOException { HConnectionManager.execute(new HConnectable<Void>(getConf()) { @Override public Void connect(HConnection connection) throws IOException { ZooKeeperWatcher zkw = createZooKeeperWatcher(); try { for (TableName tableName : ZKTableReadOnly.getDisabledOrDisablingTables(zkw)) { disabledTables.add(tableName); } } catch (KeeperException ke) { throw new IOException(ke); } finally { zkw.close(); } return null; } }); }
/** * 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(); } }
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); } }
public HFileArchiveManager(HConnection connection, Configuration conf) throws ZooKeeperConnectionException, IOException { this.zooKeeper = new ZooKeeperWatcher(conf, "hfileArchiveManager-on-" + connection.toString(), connection); this.archiveZnode = ZKTableArchiveClient.getArchiveZNode(this.zooKeeper.getConfiguration(), this.zooKeeper); }
/** * 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)); }
/** * @param sn Name of this mock regionserver * @throws IOException * @throws org.apache.hadoop.hbase.ZooKeeperConnectionException */ MockRegionServer(final Configuration conf, final ServerName sn) throws ZooKeeperConnectionException, IOException { this.sn = sn; this.conf = conf; this.zkw = new ZooKeeperWatcher(conf, sn.toString(), this, true); }
/** * @param htu Testing utility to use * @param zkw If true, create a zkw. * @throws ZooKeeperConnectionException * @throws IOException */ public MockServer(final HBaseTestingUtility htu, final boolean zkw) throws ZooKeeperConnectionException, IOException { this.htu = htu; this.zk = zkw? new ZooKeeperWatcher(htu.getConfiguration(), NAME.toString(), this, true): null; }
/** * 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(); } }
@Test public void testCreateACL() throws ZooKeeperConnectionException, IOException { Configuration conf = HBaseConfiguration.create(); conf.set(Superusers.SUPERUSER_CONF_KEY, "user1,@group1,user2,@group2,user3"); String node = "/hbase/testCreateACL"; ZooKeeperWatcher watcher = new ZooKeeperWatcher(conf, node, null, false); List<ACL> aclList = ZKUtil.createACL(watcher, node, true); Assert.assertEquals(aclList.size(), 4); // 3+1, since ACL will be set for the creator by default Assert.assertTrue(!aclList.contains(new ACL(Perms.ALL, new Id("auth", "@group1"))) && !aclList.contains(new ACL(Perms.ALL, new Id("auth", "@group2")))); Assert.assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("auth", "user1"))) && aclList.contains(new ACL(Perms.ALL, new Id("auth", "user2"))) && aclList.contains(new ACL(Perms.ALL, new Id("auth", "user3")))); }
public void createTable(String tableName, String[] columnFamilies) throws Exception, ZooKeeperConnectionException{ HBaseAdmin ad = new HBaseAdmin(conf); if(ad.tableExists(tableName)){ System.out.println("table:"+tableName+" is existed already!"); System.exit(0); }else{ HTableDescriptor htd = new HTableDescriptor(tableName); for (String family : columnFamilies) { htd.addFamily(new HColumnDescriptor(family)); } ad.createTable(htd); System.out.println("create table:"+tableName+" successfully!!"); } }
public void deleteTable(String tableName) throws Exception, ZooKeeperConnectionException{ HBaseAdmin ad = new HBaseAdmin(conf); if(ad.tableExists(tableName)){ ad.disableTableAsync(tableName); ad.deleteTable(tableName); System.out.println("delete table:"+tableName+" successfully!!"); }else{ System.out.println("the table:"+tableName+" was deleted unsuccessfully!!"); System.exit(0); } }
/** * 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"); } } }
private static void validateAuthentication() throws ZooKeeperConnectionException { try { // Is there something better? admin.isMasterRunning(); } catch (MasterNotRunningException e) { System.out.println("Maybe you are connecting to the secured cluster without kerberos config.\n"); } }
/** * 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.getHostAndPort()); 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(); } }
/** * Check to see if HBase is running. Throw an exception if not. * @param conf system configuration * @throws MasterNotRunningException if the master is not running * @throws ZooKeeperConnectionException if unable to connect to zookeeper */ public static void checkHBaseAvailable(Configuration conf) throws MasterNotRunningException, ZooKeeperConnectionException { Configuration copyOfConf = HBaseConfiguration.create(conf); copyOfConf.setInt("hbase.client.retries.number", 1); HBaseAdmin admin = new HBaseAdmin(copyOfConf); try { admin.close(); } catch (IOException ioe) { admin.LOG.info("Failed to close connection", ioe); } }
/** * Constructor. * See {@link #HBaseAdmin(HConnection connection)} * * @param c Configuration object. Copied internally. */ 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(HConnectionManager.getConnection(new Configuration(c))); this.cleanupConnectionOnClose = true; }
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); }
ServerManager(final Server master, final MasterServices services, final boolean connect) throws ZooKeeperConnectionException { this.master = master; this.services = services; Configuration c = master.getConfiguration(); maxSkew = c.getLong("hbase.master.maxclockskew", 30000); warningSkew = c.getLong("hbase.master.warningclockskew", 10000); this.deadservers = new DeadServer(); this.connection = connect ? HConnectionManager.getConnection(c) : null; }