diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java index 2c9b5a3..078b071 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java @@ -482,100 +482,174 @@ public interface Admin extends Abortable, Closeable { List getOnlineRegions(final ServerName sn) throws IOException; /** - * Flush a table or an individual region. Synchronous operation. + * Flush a table. Synchronous operation. * - * @param tableNameOrRegionName table or region to flush + * @param tableName table to flush * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ - void flush(final String tableNameOrRegionName) throws IOException, InterruptedException; + void flush(final TableName tableName) throws IOException, InterruptedException; /** - * Flush a table or an individual region. Synchronous operation. + * Flush an individual region. Synchronous operation. * - * @param tableNameOrRegionName table or region to flush + * @param regionName region to flush * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ + void flushRegion(final byte[] regionName) throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #flush(org.apache.hadoop.hbase.TableName)} or {@link #flushRegion + * (byte[])} instead. + */ + @Deprecated + void flush(final String tableNameOrRegionName) throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #flush(org.apache.hadoop.hbase.TableName)} or {@link #flushRegion + * (byte[])} instead. + */ + @Deprecated void flush(final byte[] tableNameOrRegionName) throws IOException, InterruptedException; /** - * Compact a table or an individual region. Asynchronous operation. + * Compact a table. Asynchronous operation. * - * @param tableNameOrRegionName table or region to compact + * @param tableName table to compact * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ - void compact(final String tableNameOrRegionName) throws IOException, InterruptedException; + void compact(final TableName tableName) throws IOException, InterruptedException; /** - * Compact a table or an individual region. Asynchronous operation. + * Compact an individual region. Asynchronous operation. * - * @param tableNameOrRegionName table or region to compact + * @param regionName region to compact * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ + void compactRegion(final byte[] regionName) throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #compact(org.apache.hadoop.hbase.TableName)} or {@link #compactRegion + * (byte[])} instead. + */ + @Deprecated + void compact(final String tableNameOrRegionName) throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #compact(org.apache.hadoop.hbase.TableName)} or {@link #compactRegion + * (byte[])} instead. + */ + @Deprecated void compact(final byte[] tableNameOrRegionName) throws IOException, InterruptedException; /** - * Compact a column family within a table or region. Asynchronous operation. + * Compact a column family within a table. Asynchronous operation. * - * @param tableOrRegionName table or region to compact - * @param columnFamily column family within a table or region + * @param tableName table to compact + * @param columnFamily column family within a table * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ - void compact(String tableOrRegionName, String columnFamily) - throws IOException, InterruptedException; + void compact(final TableName tableName, final byte[] columnFamily) + throws IOException, InterruptedException; /** - * Compact a column family within a table or region. Asynchronous operation. + * Compact a column family within a region. Asynchronous operation. * - * @param tableNameOrRegionName table or region to compact - * @param columnFamily column family within a table or region + * @param regionName region to compact + * @param columnFamily column family within a region * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ + void compactRegion(final byte[] regionName, final byte[] columnFamily) + throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #compact(org.apache.hadoop.hbase.TableName)} or {@link #compactRegion + * (byte[], byte[])} instead. + */ + @Deprecated + void compact(String tableOrRegionName, String columnFamily) + throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #compact(org.apache.hadoop.hbase.TableName)} or {@link #compactRegion + * (byte[], byte[])} instead. + */ + @Deprecated void compact(final byte[] tableNameOrRegionName, final byte[] columnFamily) throws IOException, InterruptedException; /** - * Major compact a table or an individual region. Asynchronous operation. + * Major compact a table. Asynchronous operation. * - * @param tableNameOrRegionName table or region to major compact + * @param tableName table to major compact * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ - void majorCompact(final String tableNameOrRegionName) throws IOException, InterruptedException; + void majorCompact(TableName tableName) throws IOException, InterruptedException; /** * Major compact a table or an individual region. Asynchronous operation. * - * @param tableNameOrRegionName table or region to major compact + * @param regionName region to major compact * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ + void majorCompactRegion(final byte[] regionName) throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #majorCompact(org.apache.hadoop.hbase.TableName)} or {@link + * #majorCompactRegion(byte[])} instead. + */ + @Deprecated + void majorCompact(final String tableNameOrRegionName) throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #majorCompact(org.apache.hadoop.hbase.TableName)} or {@link + * #majorCompactRegion(byte[])} instead. + */ + @Deprecated void majorCompact(final byte[] tableNameOrRegionName) throws IOException, InterruptedException; /** - * Major compact a column family within a table or region. Asynchronous operation. + * Major compact a column family within a table. Asynchronous operation. * - * @param tableNameOrRegionName table or region to major compact - * @param columnFamily column family within a table or region + * @param tableName table to major compact + * @param columnFamily column family within a table * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ - void majorCompact(final String tableNameOrRegionName, final String columnFamily) - throws IOException, InterruptedException; + void majorCompact(TableName tableName, final byte[] columnFamily) + throws IOException, InterruptedException; /** - * Major compact a column family within a table or region. Asynchronous operation. + * Major compact a column family within region. Asynchronous operation. * - * @param tableNameOrRegionName table or region to major compact - * @param columnFamily column family within a table or region + * @param regionName egion to major compact + * @param columnFamily column family within a region * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ + void majorCompactRegion(final byte[] regionName, final byte[] columnFamily) + throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #majorCompact(org.apache.hadoop.hbase.TableName, + * byte[])} or {@link #majorCompactRegion(byte[], byte[])} instead. + */ + @Deprecated + void majorCompact(final String tableNameOrRegionName, final String columnFamily) + throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #majorCompact(org.apache.hadoop.hbase.TableName, + * byte[])} or {@link #majorCompactRegion(byte[], byte[])} instead. + */ + @Deprecated void majorCompact(final byte[] tableNameOrRegionName, final byte[] columnFamily) throws IOException, InterruptedException; @@ -692,35 +766,72 @@ public interface Admin extends Abortable, Closeable { final boolean forcible) throws IOException; /** - * Split a table or an individual region. Asynchronous operation. + * Split a table. Asynchronous operation. * - * @param tableNameOrRegionName table or region to split + * @param tableName table to split * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ - void split(final String tableNameOrRegionName) throws IOException, InterruptedException; + void split(final TableName tableName) throws IOException, InterruptedException; /** - * Split a table or an individual region. Implicitly finds an optimal split point. Asynchronous - * operation. + * Split an individual region. Asynchronous operation. * - * @param tableNameOrRegionName table to region to split + * @param regionName region to split * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ + void splitRegion(final byte[] regionName) throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #split(org.apache.hadoop.hbase.TableName)} or {@link #splitRegion + * (byte[])} instead. + */ + @Deprecated + void split(final String tableNameOrRegionName) throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #split(org.apache.hadoop.hbase.TableName)} or {@link #splitRegion + * (byte[])} instead. + */ + @Deprecated void split(final byte[] tableNameOrRegionName) throws IOException, InterruptedException; - void split(final String tableNameOrRegionName, final String splitPoint) - throws IOException, InterruptedException; + /** + * Split a table. Asynchronous operation. + * + * @param tableName table to split + * @param splitPoint the explicit position to split on + * @throws IOException if a remote or network exception occurs + * @throws InterruptedException interrupt exception occurred + */ + void split(final TableName tableName, final byte[] splitPoint) + throws IOException, InterruptedException; /** - * Split a table or an individual region. Asynchronous operation. + * Split an individual region. Asynchronous operation. * - * @param tableNameOrRegionName table to region to split + * @param regionName region to split * @param splitPoint the explicit position to split on * @throws IOException if a remote or network exception occurs * @throws InterruptedException interrupt exception occurred */ + void splitRegion(final byte[] regionName, final byte[] splitPoint) + throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #split(org.apache.hadoop.hbase.TableName, + * byte[])} or {@link #splitRegion(byte[], byte[])} instead. + */ + @Deprecated + void split(final String tableNameOrRegionName, final String splitPoint) + throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #split(org.apache.hadoop.hbase.TableName, + * byte[])} or {@link #splitRegion(byte[], byte[])} instead. + */ + @Deprecated void split(final byte[] tableNameOrRegionName, final byte[] splitPoint) throws IOException, InterruptedException; @@ -880,26 +991,42 @@ public interface Admin extends Abortable, Closeable { String[] getMasterCoprocessors(); /** - * Get the current compaction state of a table or region. It could be in a major compaction, a - * minor compaction, both, or none. + * Get the current compaction state of a table. It could be in a major compaction, a minor + * compaction, both, or none. * - * @param tableNameOrRegionName table or region to major compact + * @param tableName table to examine * @return the current compaction state * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ - AdminProtos.GetRegionInfoResponse.CompactionState getCompactionState( - final String tableNameOrRegionName) throws IOException, InterruptedException; + AdminProtos.GetRegionInfoResponse.CompactionState getCompactionState(final TableName tableName) + throws IOException, InterruptedException; /** - * Get the current compaction state of a table or region. It could be in a major compaction, a - * minor compaction, both, or none. + * Get the current compaction state of region. It could be in a major compaction, a minor + * compaction, both, or none. * - * @param tableNameOrRegionName table or region to major compact + * @param regionName region to examine * @return the current compaction state * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ + AdminProtos.GetRegionInfoResponse.CompactionState getCompactionStateForRegion( + final byte[] regionName) throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #getCompactionState(org.apache.hadoop.hbase.TableName)} or {@link + * #getCompactionStateForRegion(byte[])} instead. + */ + @Deprecated + AdminProtos.GetRegionInfoResponse.CompactionState getCompactionState( + final String tableNameOrRegionName) throws IOException, InterruptedException; + + /** + * @deprecated Use {@link #getCompactionState(org.apache.hadoop.hbase.TableName)} or {@link + * #getCompactionStateForRegion(byte[])} instead. + */ + @Deprecated AdminProtos.GetRegionInfoResponse.CompactionState getCompactionState( final byte[] tableNameOrRegionName) throws IOException, InterruptedException; diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index fe8fb31..c3d3a5e 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -1466,47 +1466,56 @@ public class HBaseAdmin implements Admin { } /** - * Flush a table or an individual region. - * Synchronous operation. - * - * @param tableNameOrRegionName table or region to flush - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} + */ + @Override + public void flush(final TableName tableName) throws IOException, InterruptedException { + checkTableExists(tableName); + if (isTableDisabled(tableName)) { + LOG.info("Table is disabled: " + tableName.getNameAsString()); + return; + } + execProcedure("flush-table-proc", tableName.getNameAsString(), + new HashMap()); + } + + /** + * {@inheritDoc} + */ + @Override + public void flushRegion(final byte[] regionName) throws IOException, InterruptedException { + Pair regionServerPair = getRegion(regionName); + if (regionServerPair == null) { + throw new IllegalArgumentException("Unknown regionname: " + Bytes.toStringBinary(regionName)); + } + if (regionServerPair.getSecond() == null) { + throw new NoServerForRegionException(Bytes.toStringBinary(regionName)); + } + flush(regionServerPair.getSecond(), regionServerPair.getFirst()); + } + + /** + * {@inheritDoc} */ @Override + @Deprecated public void flush(final String tableNameOrRegionName) throws IOException, InterruptedException { flush(Bytes.toBytes(tableNameOrRegionName)); } /** - * Flush a table or an individual region. - * Synchronous operation. - * - * @param tableNameOrRegionName table or region to flush - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} */ @Override + @Deprecated public void flush(final byte[] tableNameOrRegionName) throws IOException, InterruptedException { - Pair regionServerPair - = getRegion(tableNameOrRegionName); - if (regionServerPair != null) { - if (regionServerPair.getSecond() == null) { - throw new NoServerForRegionException(Bytes.toStringBinary(tableNameOrRegionName)); - } else { - flush(regionServerPair.getSecond(), regionServerPair.getFirst()); - } - } else { - final TableName tableName = checkTableExists( - TableName.valueOf(tableNameOrRegionName)); - if (isTableDisabled(tableName)) { - LOG.info("Table is disabled: " + tableName.getNameAsString()); - return; - } - execProcedure("flush-table-proc", tableName.getNameAsString(), - new HashMap()); + try { + flushRegion(tableNameOrRegionName); + } catch (IllegalArgumentException e) { + // Unknown region. Try table. + flush(TableName.valueOf(tableNameOrRegionName)); } } @@ -1523,164 +1532,205 @@ public class HBaseAdmin implements Admin { } /** - * Compact a table or an individual region. - * Asynchronous operation. - * - * @param tableNameOrRegionName table or region to compact - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} */ @Override + public void compact(final TableName tableName) + throws IOException, InterruptedException { + compact(tableName, null, false); + } + + /** + * {@inheritDoc} + */ + @Override + public void compactRegion(final byte[] regionName) + throws IOException, InterruptedException { + compactRegion(regionName, null, false); + } + + /** + * {@inheritDoc} + */ + @Override + @Deprecated public void compact(final String tableNameOrRegionName) throws IOException, InterruptedException { compact(Bytes.toBytes(tableNameOrRegionName)); } /** - * Compact a table or an individual region. - * Asynchronous operation. - * - * @param tableNameOrRegionName table or region to compact - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} */ @Override + @Deprecated public void compact(final byte[] tableNameOrRegionName) throws IOException, InterruptedException { - compact(tableNameOrRegionName, null, false); + try { + compactRegion(tableNameOrRegionName, null, false); + } catch (IllegalArgumentException e) { + compact(TableName.valueOf(tableNameOrRegionName), null, false); + } } /** - * Compact a column family within a table or region. - * Asynchronous operation. - * - * @param tableOrRegionName table or region to compact - * @param columnFamily column family within a table or region - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} + */ + @Override + public void compact(final TableName tableName, final byte[] columnFamily) + throws IOException, InterruptedException { + compact(tableName, columnFamily, false); + } + + /** + * {@inheritDoc} + */ + @Override + public void compactRegion(final byte[] regionName, final byte[] columnFamily) + throws IOException, InterruptedException { + compactRegion(regionName, columnFamily, false); + } + + /** + * {@inheritDoc} */ @Override + @Deprecated public void compact(String tableOrRegionName, String columnFamily) throws IOException, InterruptedException { compact(Bytes.toBytes(tableOrRegionName), Bytes.toBytes(columnFamily)); } /** - * Compact a column family within a table or region. - * Asynchronous operation. - * - * @param tableNameOrRegionName table or region to compact - * @param columnFamily column family within a table or region - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} */ @Override + @Deprecated public void compact(final byte[] tableNameOrRegionName, final byte[] columnFamily) throws IOException, InterruptedException { - compact(tableNameOrRegionName, columnFamily, false); + try { + compactRegion(tableNameOrRegionName, columnFamily, false); + } catch (IllegalArgumentException e) { + // Bad region, try table + compact(TableName.valueOf(tableNameOrRegionName), columnFamily, false); + } } /** - * Major compact a table or an individual region. - * Asynchronous operation. - * - * @param tableNameOrRegionName table or region to major compact - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} + */ + @Override + public void majorCompact(final TableName tableName) + throws IOException, InterruptedException { + compact(tableName, null, true); + } + + /** + * {@inheritDoc} */ @Override + public void majorCompactRegion(final byte[] regionName) + throws IOException, InterruptedException { + compactRegion(regionName, null, true); + } + + /** + * {@inheritDoc} + */ + @Override + @Deprecated public void majorCompact(final String tableNameOrRegionName) throws IOException, InterruptedException { majorCompact(Bytes.toBytes(tableNameOrRegionName)); } /** - * Major compact a table or an individual region. - * Asynchronous operation. - * - * @param tableNameOrRegionName table or region to major compact - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} */ @Override + @Deprecated public void majorCompact(final byte[] tableNameOrRegionName) throws IOException, InterruptedException { - compact(tableNameOrRegionName, null, true); + try { + compactRegion(tableNameOrRegionName, null, true); + } catch (IllegalArgumentException e) { + // Invalid region, try table + compact(TableName.valueOf(tableNameOrRegionName), null, true); + } } /** - * Major compact a column family within a table or region. - * Asynchronous operation. - * - * @param tableNameOrRegionName table or region to major compact - * @param columnFamily column family within a table or region - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} */ @Override - public void majorCompact(final String tableNameOrRegionName, - final String columnFamily) throws IOException, InterruptedException { - majorCompact(Bytes.toBytes(tableNameOrRegionName), - Bytes.toBytes(columnFamily)); + public void majorCompact(final TableName tableName, final byte[] columnFamily) + throws IOException, InterruptedException { + compact(tableName, columnFamily, true); } /** - * Major compact a column family within a table or region. - * Asynchronous operation. - * - * @param tableNameOrRegionName table or region to major compact - * @param columnFamily column family within a table or region - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} + */ + @Override + public void majorCompactRegion(final byte[] regionName, final byte[] columnFamily) + throws IOException, InterruptedException { + compactRegion(regionName, columnFamily, true); + } + + /** + * {@inheritDoc} + */ + @Override + @Deprecated + public void majorCompact(final String tableNameOrRegionName, final String columnFamily) + throws IOException, InterruptedException { + majorCompact(Bytes.toBytes(tableNameOrRegionName), Bytes.toBytes(columnFamily)); + } + + /** + * {@inheritDoc} */ @Override - public void majorCompact(final byte[] tableNameOrRegionName, - final byte[] columnFamily) throws IOException, InterruptedException { - compact(tableNameOrRegionName, columnFamily, true); + @Deprecated + public void majorCompact(final byte[] tableNameOrRegionName, final byte[] columnFamily) + throws IOException, InterruptedException { + try { + compactRegion(tableNameOrRegionName, columnFamily, true); + } catch (IllegalArgumentException e) { + // Invalid region, try table + compact(TableName.valueOf(tableNameOrRegionName), columnFamily, true); + } } /** - * Compact a table or an individual region. + * Compact a table. * Asynchronous operation. * - * @param tableNameOrRegionName table or region to compact + * @param tableName table or region to compact * @param columnFamily column family within a table or region * @param major True if we are to do a major compaction. * @throws IOException if a remote or network exception occurs * @throws InterruptedException */ - private void compact(final byte[] tableNameOrRegionName, - final byte[] columnFamily,final boolean major) + private void compact(final TableName tableName, final byte[] columnFamily,final boolean major) throws IOException, InterruptedException { ZooKeeperWatcher zookeeper = null; try { - Pair regionServerPair - = getRegion(tableNameOrRegionName); - if (regionServerPair != null) { - if (regionServerPair.getSecond() == null) { - throw new NoServerForRegionException(Bytes.toStringBinary(tableNameOrRegionName)); - } else { - compact(regionServerPair.getSecond(), regionServerPair.getFirst(), major, columnFamily); - } - } else { - final TableName tableName = - checkTableExists(TableName.valueOf(tableNameOrRegionName)); - zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), - new ThrowableAbortable()); - List> pairs = - MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, - tableName); - for (Pair pair: pairs) { - if (pair.getFirst().isOffline()) continue; - if (pair.getSecond() == null) continue; - try { - compact(pair.getSecond(), pair.getFirst(), major, columnFamily); - } catch (NotServingRegionException e) { - if (LOG.isDebugEnabled()) { - LOG.debug("Trying to" + (major ? " major" : "") + " compact " + - pair.getFirst() + ": " + - StringUtils.stringifyException(e)); - } + checkTableExists(tableName); + zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), + new ThrowableAbortable()); + List> pairs = + MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, tableName); + for (Pair pair: pairs) { + if (pair.getFirst().isOffline()) continue; + if (pair.getSecond() == null) continue; + try { + compact(pair.getSecond(), pair.getFirst(), major, columnFamily); + } catch (NotServingRegionException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Trying to" + (major ? " major" : "") + " compact " + + pair.getFirst() + ": " + + StringUtils.stringifyException(e)); } } } @@ -1691,6 +1741,28 @@ public class HBaseAdmin implements Admin { } } + /** + * Compact an individual region. + * Asynchronous operation. + * + * @param regionName region to compact + * @param columnFamily column family within a table or region + * @param major True if we are to do a major compaction. + * @throws IOException if a remote or network exception occurs + * @throws InterruptedException + */ + private void compactRegion(final byte[] regionName, final byte[] columnFamily,final boolean major) + throws IOException, InterruptedException { + Pair regionServerPair = getRegion(regionName); + if (regionServerPair == null) { + throw new IllegalArgumentException("Invalid region: " + Bytes.toStringBinary(regionName)); + } + if (regionServerPair.getSecond() == null) { + throw new NoServerForRegionException(Bytes.toStringBinary(regionName)); + } + compact(regionServerPair.getSecond(), regionServerPair.getFirst(), major, columnFamily); + } + private void compact(final ServerName sn, final HRegionInfo hri, final boolean major, final byte [] family) throws IOException { @@ -1726,7 +1798,7 @@ public class HBaseAdmin implements Admin { try { MoveRegionRequest request = RequestConverter.buildMoveRegionRequest(encodedRegionName, destServerName); - stub.moveRegion(null,request); + stub.moveRegion(null, request); } catch (ServiceException se) { IOException ioe = ProtobufUtil.getRemoteException(se); if (ioe instanceof HBaseIOException) { @@ -1785,7 +1857,7 @@ public class HBaseAdmin implements Admin { public Void call(int callTimeout) throws ServiceException { UnassignRegionRequest request = RequestConverter.buildUnassignRegionRequest(toBeUnassigned, force); - master.unassignRegion(null,request); + master.unassignRegion(null, request); return null; } }); @@ -1858,7 +1930,7 @@ public class HBaseAdmin implements Admin { throws MasterNotRunningException, ZooKeeperConnectionException, ServiceException { MasterKeepAliveConnection stub = connection.getKeepAliveMasterService(); try { - return stub.balance(null,RequestConverter.buildBalanceRequest()).getBalancerRan(); + return stub.balance(null, RequestConverter.buildBalanceRequest()).getBalancerRan(); } finally { stub.close(); } @@ -1877,7 +1949,7 @@ public class HBaseAdmin implements Admin { MasterKeepAliveConnection stub = connection.getKeepAliveMasterService(); try { return stub.enableCatalogJanitor(null, - RequestConverter.buildEnableCatalogJanitorRequest(enable)).getPrevValue(); + RequestConverter.buildEnableCatalogJanitorRequest(enable)).getPrevValue(); } finally { stub.close(); } @@ -1894,7 +1966,7 @@ public class HBaseAdmin implements Admin { MasterKeepAliveConnection stub = connection.getKeepAliveMasterService(); try { return stub.runCatalogScan(null, - RequestConverter.buildCatalogScanRequest()).getScanResult(); + RequestConverter.buildCatalogScanRequest()).getScanResult(); } finally { stub.close(); } @@ -1910,7 +1982,7 @@ public class HBaseAdmin implements Admin { MasterKeepAliveConnection stub = connection.getKeepAliveMasterService(); try { return stub.isCatalogJanitorEnabled(null, - RequestConverter.buildIsCatalogJanitorEnabledRequest()).getValue(); + RequestConverter.buildIsCatalogJanitorEnabledRequest()).getValue(); } finally { stub.close(); } @@ -1953,85 +2025,112 @@ public class HBaseAdmin implements Admin { } /** - * Split a table or an individual region. - * Asynchronous operation. - * - * @param tableNameOrRegionName table or region to split - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} */ @Override + public void split(final TableName tableName) + throws IOException, InterruptedException { + split(tableName, null); + } + + /** + * {@inheritDoc} + */ + @Override + public void splitRegion(final byte[] regionName) + throws IOException, InterruptedException { + splitRegion(regionName, null); + } + + /** + * {@inheritDoc} + */ + @Override + @Deprecated public void split(final String tableNameOrRegionName) throws IOException, InterruptedException { split(Bytes.toBytes(tableNameOrRegionName)); } /** - * Split a table or an individual region. Implicitly finds an optimal split - * point. Asynchronous operation. - * - * @param tableNameOrRegionName table to region to split - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException + * {@inheritDoc} */ @Override + @Deprecated public void split(final byte[] tableNameOrRegionName) throws IOException, InterruptedException { split(tableNameOrRegionName, null); } + /** + * {@inheritDoc} + */ + @Override + public void split(final TableName tableName, final byte [] splitPoint) + throws IOException, InterruptedException { + ZooKeeperWatcher zookeeper = null; + try { + checkTableExists(tableName); + zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), + new ThrowableAbortable()); + List> pairs = + MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, tableName); + for (Pair pair: pairs) { + // May not be a server for a particular row + if (pair.getSecond() == null) continue; + HRegionInfo r = pair.getFirst(); + // check for parents + if (r.isSplitParent()) continue; + // if a split point given, only split that particular region + if (splitPoint != null && !r.containsRow(splitPoint)) continue; + // call out to region server to do split now + split(pair.getSecond(), pair.getFirst(), splitPoint); + } + } finally { + if (zookeeper != null) { + zookeeper.close(); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void splitRegion(final byte[] regionName, final byte [] splitPoint) + throws IOException, InterruptedException { + Pair regionServerPair = getRegion(regionName); + if (regionServerPair == null) { + throw new IllegalArgumentException("Invalid region: " + Bytes.toStringBinary(regionName)); + } + if (regionServerPair.getSecond() == null) { + throw new NoServerForRegionException(Bytes.toStringBinary(regionName)); + } + split(regionServerPair.getSecond(), regionServerPair.getFirst(), splitPoint); + } + + /** + * {@inheritDoc} + */ @Override + @Deprecated public void split(final String tableNameOrRegionName, final String splitPoint) throws IOException, InterruptedException { split(Bytes.toBytes(tableNameOrRegionName), Bytes.toBytes(splitPoint)); } /** - * Split a table or an individual region. - * Asynchronous operation. - * - * @param tableNameOrRegionName table to region to split - * @param splitPoint the explicit position to split on - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException interrupt exception occurred + * {@inheritDoc} */ @Override + @Deprecated public void split(final byte[] tableNameOrRegionName, final byte [] splitPoint) throws IOException, InterruptedException { - ZooKeeperWatcher zookeeper = null; try { - Pair regionServerPair - = getRegion(tableNameOrRegionName); - if (regionServerPair != null) { - if (regionServerPair.getSecond() == null) { - throw new NoServerForRegionException(Bytes.toStringBinary(tableNameOrRegionName)); - } else { - split(regionServerPair.getSecond(), regionServerPair.getFirst(), splitPoint); - } - } else { - final TableName tableName = - checkTableExists(TableName.valueOf(tableNameOrRegionName)); - zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), - new ThrowableAbortable()); - List> pairs = - MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, - tableName); - for (Pair pair: pairs) { - // May not be a server for a particular row - if (pair.getSecond() == null) continue; - HRegionInfo r = pair.getFirst(); - // check for parents - if (r.isSplitParent()) continue; - // if a split point given, only split that particular region - if (splitPoint != null && !r.containsRow(splitPoint)) continue; - // call out to region server to do split now - split(pair.getSecond(), pair.getFirst(), splitPoint); - } - } - } finally { - if (zookeeper != null) { - zookeeper.close(); - } + splitRegion(tableNameOrRegionName, splitPoint); + } catch (IllegalArgumentException e) { + // Bad region, try table + split(TableName.valueOf(tableNameOrRegionName), splitPoint); } } @@ -2083,24 +2182,24 @@ public class HBaseAdmin implements Admin { } /** - * @param tableNameOrRegionName Name of a table or name of a region. - * @return a pair of HRegionInfo and ServerName if tableNameOrRegionName is + * @param regionName Name of a region. + * @return a pair of HRegionInfo and ServerName if regionName is * a verified region name (we call {@link * MetaTableAccessor#getRegion(HConnection, byte[])} * else null. - * Throw an exception if tableNameOrRegionName is null. + * Throw IllegalArgumentException if regionName is null. * @throws IOException */ - Pair getRegion(final byte[] tableNameOrRegionName) throws IOException { - if (tableNameOrRegionName == null) { + Pair getRegion(final byte[] regionName) throws IOException { + if (regionName == null) { throw new IllegalArgumentException("Pass a table name or region name"); } Pair pair = - MetaTableAccessor.getRegion(connection, tableNameOrRegionName); + MetaTableAccessor.getRegion(connection, regionName); if (pair == null) { final AtomicReference> result = new AtomicReference>(null); - final String encodedName = Bytes.toString(tableNameOrRegionName); + final String encodedName = Bytes.toString(regionName); MetaScannerVisitor visitor = new MetaScannerVisitorBase() { @Override public boolean processRow(Result data) throws IOException { @@ -2187,7 +2286,7 @@ public class HBaseAdmin implements Admin { executeCallable(new MasterCallable(getConnection()) { @Override public Void call(int callTimeout) throws ServiceException { - master.stopMaster(null,StopMasterRequest.newBuilder().build()); + master.stopMaster(null, StopMasterRequest.newBuilder().build()); return null; } }); @@ -2226,7 +2325,7 @@ public class HBaseAdmin implements Admin { @Override public ClusterStatus call(int callTimeout) throws ServiceException { GetClusterStatusRequest req = RequestConverter.buildGetClusterStatusRequest(); - return ClusterStatus.convert(master.getClusterStatus(null,req).getClusterStatus()); + return ClusterStatus.convert(master.getClusterStatus(null, req).getClusterStatus()); } }); } @@ -2257,8 +2356,9 @@ public class HBaseAdmin implements Admin { public Void call(int callTimeout) throws Exception { master.createNamespace(null, CreateNamespaceRequest.newBuilder() - .setNamespaceDescriptor(ProtobufUtil - .toProtoNamespaceDescriptor(descriptor)).build()); + .setNamespaceDescriptor(ProtobufUtil + .toProtoNamespaceDescriptor(descriptor)).build() + ); return null; } }); @@ -2517,8 +2617,8 @@ public class HBaseAdmin implements Admin { * @throws IOException if a remote or network exception occurs * @throws FailedLogCloseException */ - @Override -public synchronized byte[][] rollHLogWriter(String serverName) + @Override + public synchronized byte[][] rollHLogWriter(String serverName) throws IOException, FailedLogCloseException { ServerName sn = ServerName.valueOf(serverName); AdminService.BlockingInterface admin = this.connection.getAdmin(sn); @@ -2548,96 +2648,60 @@ public synchronized byte[][] rollHLogWriter(String serverName) } /** - * Get the current compaction state of a table or region. - * It could be in a major compaction, a minor compaction, both, or none. - * - * @param tableNameOrRegionName table or region to major compact - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException - * @return the current compaction state - */ - @Override - public CompactionState getCompactionState(final String tableNameOrRegionName) - throws IOException, InterruptedException { - return getCompactionState(Bytes.toBytes(tableNameOrRegionName)); - } - - /** - * Get the current compaction state of a table or region. - * It could be in a major compaction, a minor compaction, both, or none. - * - * @param tableNameOrRegionName table or region to major compact - * @throws IOException if a remote or network exception occurs - * @throws InterruptedException - * @return the current compaction state + * {@inheritDoc} */ @Override - public CompactionState getCompactionState(final byte[] tableNameOrRegionName) - throws IOException, InterruptedException { + public CompactionState getCompactionState(final TableName tableName) + throws IOException, InterruptedException { CompactionState state = CompactionState.NONE; ZooKeeperWatcher zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), new ThrowableAbortable()); try { - Pair regionServerPair = getRegion(tableNameOrRegionName); - if (regionServerPair != null) { - if (regionServerPair.getSecond() == null) { - throw new NoServerForRegionException(Bytes.toStringBinary(tableNameOrRegionName)); - } else { - ServerName sn = regionServerPair.getSecond(); + checkTableExists(tableName); + List> pairs = + MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, tableName); + for (Pair pair: pairs) { + if (pair.getFirst().isOffline()) continue; + if (pair.getSecond() == null) continue; + try { + ServerName sn = pair.getSecond(); AdminService.BlockingInterface admin = this.connection.getAdmin(sn); GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest( - regionServerPair.getFirst().getRegionName(), true); + pair.getFirst().getRegionName(), true); GetRegionInfoResponse response = admin.getRegionInfo(null, request); - return response.getCompactionState(); - } - } else { - final TableName tableName = - checkTableExists(TableName.valueOf(tableNameOrRegionName)); - List> pairs = - MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, tableName); - for (Pair pair: pairs) { - if (pair.getFirst().isOffline()) continue; - if (pair.getSecond() == null) continue; - try { - ServerName sn = pair.getSecond(); - AdminService.BlockingInterface admin = this.connection.getAdmin(sn); - GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest( - pair.getFirst().getRegionName(), true); - GetRegionInfoResponse response = admin.getRegionInfo(null, request); - switch (response.getCompactionState()) { - case MAJOR_AND_MINOR: + switch (response.getCompactionState()) { + case MAJOR_AND_MINOR: + return CompactionState.MAJOR_AND_MINOR; + case MAJOR: + if (state == CompactionState.MINOR) { return CompactionState.MAJOR_AND_MINOR; - case MAJOR: - if (state == CompactionState.MINOR) { - return CompactionState.MAJOR_AND_MINOR; - } - state = CompactionState.MAJOR; - break; - case MINOR: - if (state == CompactionState.MAJOR) { - return CompactionState.MAJOR_AND_MINOR; - } - state = CompactionState.MINOR; - break; - case NONE: - default: // nothing, continue } - } catch (NotServingRegionException e) { - if (LOG.isDebugEnabled()) { - LOG.debug("Trying to get compaction state of " + - pair.getFirst() + ": " + - StringUtils.stringifyException(e)); + state = CompactionState.MAJOR; + break; + case MINOR: + if (state == CompactionState.MAJOR) { + return CompactionState.MAJOR_AND_MINOR; } - } catch (RemoteException e) { - if (e.getMessage().indexOf(NotServingRegionException.class.getName()) >= 0) { - if (LOG.isDebugEnabled()) { - LOG.debug("Trying to get compaction state of " + pair.getFirst() + ": " - + StringUtils.stringifyException(e)); - } - } else { - throw e; + state = CompactionState.MINOR; + break; + case NONE: + default: // nothing, continue + } + } catch (NotServingRegionException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Trying to get compaction state of " + + pair.getFirst() + ": " + + StringUtils.stringifyException(e)); + } + } catch (RemoteException e) { + if (e.getMessage().indexOf(NotServingRegionException.class.getName()) >= 0) { + if (LOG.isDebugEnabled()) { + LOG.debug("Trying to get compaction state of " + pair.getFirst() + ": " + + StringUtils.stringifyException(e)); } + } else { + throw e; } } } @@ -2650,6 +2714,56 @@ public synchronized byte[][] rollHLogWriter(String serverName) } /** + * {@inheritDoc} + */ + @Override + public CompactionState getCompactionStateForRegion(final byte[] regionName) + throws IOException, InterruptedException { + try { + Pair regionServerPair = getRegion(regionName); + if (regionServerPair == null) { + throw new IllegalArgumentException("Invalid region: " + Bytes.toStringBinary(regionName)); + } + if (regionServerPair.getSecond() == null) { + throw new NoServerForRegionException(Bytes.toStringBinary(regionName)); + } + ServerName sn = regionServerPair.getSecond(); + AdminService.BlockingInterface admin = this.connection.getAdmin(sn); + GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest( + regionServerPair.getFirst().getRegionName(), true); + GetRegionInfoResponse response = admin.getRegionInfo(null, request); + return response.getCompactionState(); + } catch (ServiceException se) { + throw ProtobufUtil.getRemoteException(se); + } + } + + /** + * {@inheritDoc} + */ + @Override + @Deprecated + public CompactionState getCompactionState(final String tableNameOrRegionName) + throws IOException, InterruptedException { + return getCompactionState(Bytes.toBytes(tableNameOrRegionName)); + } + + /** + * {@inheritDoc} + */ + @Override + @Deprecated + public CompactionState getCompactionState(final byte[] tableNameOrRegionName) + throws IOException, InterruptedException { + try { + return getCompactionStateForRegion(tableNameOrRegionName); + } catch (IllegalArgumentException e) { + // Invalid region, try table + return getCompactionState(TableName.valueOf(tableNameOrRegionName)); + } + } + + /** * Take a snapshot for the given table. If the table is enabled, a FLUSH-type snapshot will be * taken. If the table is disabled, an offline snapshot is taken. *

@@ -2726,7 +2840,7 @@ public synchronized byte[][] rollHLogWriter(String serverName) final byte[] tableName) throws IOException, SnapshotCreationException, IllegalArgumentException { snapshot(Bytes.toString(snapshotName), TableName.valueOf(tableName), - SnapshotDescription.Type.FLUSH); + SnapshotDescription.Type.FLUSH); } /** @@ -3398,7 +3512,8 @@ public synchronized byte[][] rollHLogWriter(String serverName) public Void call(int callTimeout) throws ServiceException { master.deleteSnapshot(null, DeleteSnapshotRequest.newBuilder(). - setSnapshot(SnapshotDescription.newBuilder().setName(snapshotName).build()).build()); + setSnapshot(SnapshotDescription.newBuilder().setName(snapshotName).build()).build() + ); return null; } });