/** * 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 = connection.getZooKeeperWatcher(); try { for (Entry<TableState, Set<String>> e : ZKTableReadOnly.getDisabledOrDisablingTables(zkw) .entrySet()) { for (String tableName : e.getValue()) { disabledTables.add(Bytes.toBytes(tableName)); } } } catch (KeeperException ke) { throw new IOException(ke); } return null; } }); }
/** * Go to zookeeper and see if state of table is {@link TableState#ENABLED}. * @param zkw * @param tableName * @return True if table is enabled. * @throws KeeperException */ public static boolean isEnabledTable(final ZooKeeperWatcher zkw, final String tableName) throws KeeperException { TableState state = getTableState(zkw, tableName); // If a table is ENABLED then we are removing table state znode in 0.92 // but in 0.94 we keep it in ENABLED state. return state == null || state == TableState.ENABLED; }
/** * Gets a list of all the tables set as disabled in zookeeper. * @return Set of disabled tables, empty Set if none * @throws KeeperException */ public static Set<String> getDisabledTables(ZooKeeperWatcher zkw) throws KeeperException { Set<String> disabledTables = new HashSet<String>(); List<String> children = ZKUtil.listChildrenNoWatch(zkw, zkw.clientTableZNode); for (String child: children) { TableState state = getTableState(zkw, child); if (state == TableState.DISABLED) disabledTables.add(child); } return disabledTables; }
/** * Gets a list of all the tables set as disabled in zookeeper. * @return Set of disabled tables, empty Set if none * @throws KeeperException */ public static Set<String> getDisabledOrDisablingTables(ZooKeeperWatcher zkw) throws KeeperException { Set<String> disabledTables = new HashSet<String>(); List<String> children = ZKUtil.listChildrenNoWatch(zkw, zkw.clientTableZNode); for (String child: children) { TableState state = getTableState(zkw, child); if (state == TableState.DISABLED || state == TableState.DISABLING) disabledTables.add(child); } return disabledTables; }
/** * @deprecated Only for 0.92/0.94 compatibility. Use getTableState(zkw, child) instead. */ static TableState getTableState(final ZooKeeperWatcher zkw, final String parent, final String child) throws KeeperException { String znode = ZKUtil.joinZNode(parent, child); byte [] data = ZKUtil.getData(zkw, znode); if (data == null || data.length <= 0) { return null; } String str = Bytes.toString(data); try { return TableState.valueOf(str); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(str); } }
private void runTest9294CompatibilityTest(String tableName, Configuration conf) throws Exception { ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, tableName, abortable, true); ZKTable zkt = new ZKTable(zkw); zkt.setEnabledTable(tableName); // check that current/0.94 format table has proper ENABLED format assertTrue( ZKTableReadOnly.getTableState(zkw, zkw.masterTableZNode, tableName) == TableState.ENABLED); // check that 0.92 format table is null, as expected by 0.92.0/0.92.1 clients assertTrue(ZKTableReadOnly.getTableState(zkw, zkw.masterTableZNode92, tableName) == null); }
/** * To test closed region handler to remove rit and delete corresponding znode if region in pending * close or closing while processing shutdown of a region server.(HBASE-5927). * @throws KeeperException * @throws IOException */ @Test public void testSSHWhenDisableTableInProgress() throws KeeperException, IOException { testCaseWithPartiallyDisabledState(TableState.DISABLING, false); testCaseWithPartiallyDisabledState(TableState.DISABLED, false); }
private void setTablesInZK() throws IOException { if (tablesToBeSetInZK != null && !tablesToBeSetInZK.isEmpty()) { for (Pair<String, TableState> p : tablesToBeSetInZK) { setStateInZK(p.getFirst(), p.getSecond()); } } }
private void setStateInZK(String tableName, TableState state) throws IOException { if (state == TableState.ENABLED) { admin.setEnableTable(tableName); } if (state == TableState.DISABLED) { admin.setDisableTable(tableName); } }
static boolean isTableState(final TableState expectedState, final TableState currentState) { return currentState != null && currentState.equals(expectedState); }
/** * Read the TableState from ZooKeeper * @throws KeeperException */ static TableState getTableState(final ZooKeeperWatcher zkw, final String child) throws KeeperException { return getTableState(zkw, zkw.clientTableZNode, child); }