diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java index 9b13c16..6c72f42 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java @@ -1310,4 +1310,14 @@ public static boolean areAdjacent(HRegionInfo regionA, HRegionInfo regionB) { } return false; } + + /** + * Gets mob region name by the given table name. + * @param tableName The current table name. + * @return the mob region name. + */ + public static byte[] getMobRegionName(TableName tableName) { + return new HRegionInfo(tableName, Bytes.toBytes(".mob"), HConstants.EMPTY_END_ROW, false, 0) + .getRegionName(); + } } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java index f2fc958..632dec9 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java @@ -1496,58 +1496,6 @@ void deleteTableSnapshots(Pattern tableNamePattern, Pattern snapshotNamePattern) public int getMasterInfoPort() throws IOException; /** - * Compact the mob files in all mob-enabled column families. Asynchronous operation. - * - * @param tableName table to compact - * @throws IOException - * @throws InterruptedException - */ - void compactMobs(final TableName tableName) throws IOException, - InterruptedException; - - /** - * Compact the mob files in a mob-enabled column family. Asynchronous operation. - * - * @param tableName table to compact - * @param columnFamily column family within a table - * @throws IOException if not a mob column family or if a remote or network exception occurs - * @throws InterruptedException - */ - void compactMob(final TableName tableName, final byte[] columnFamily) throws IOException, - InterruptedException; - - /** - * Major compact the mob files in all mob-enabled column family. Asynchronous operation. - * - * @param tableName table to compact - * @throws IOException - * @throws InterruptedException - */ - void majorCompactMobs(final TableName tableName) throws IOException, - InterruptedException; - - /** - * Major compact the mob files in a mob-enabled column family. Asynchronous operation. - * - * @param tableName table to compact - * @param columnFamily column family within a table - * @throws IOException if not a mob column family or if a remote or network exception occurs - * @throws InterruptedException - */ - void majorCompactMob(final TableName tableName, final byte[] columnFamily) throws IOException, - InterruptedException; - - /** - * Get the current compaction state of a table. It could be in a compaction, or none. - * - * @param tableName table to examine - * @return the current compaction state - * @throws IOException if a remote or network exception occurs - */ - AdminProtos.GetRegionInfoResponse.CompactionState getMobCompactionState(final TableName tableName) - throws IOException; - - /** * Return the set of supported security capabilities. * @throws IOException * @throws UnsupportedOperationException diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 1df3ffa..d666660 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -1763,7 +1763,12 @@ public void compact(final TableName tableName) @Override public void compactRegion(final byte[] regionName) throws IOException { - compactRegion(regionName, null, false); + TableName tableName = HRegionInfo.getTable(regionName); + if (!isMobRegionName(tableName, regionName)) { + compactRegion(regionName, null, false); + } else { + compactMob(tableName, null, false); + } } /** @@ -1805,7 +1810,12 @@ public void compact(final TableName tableName, final byte[] columnFamily) @Override public void compactRegion(final byte[] regionName, final byte[] columnFamily) throws IOException { - compactRegion(regionName, columnFamily, false); + TableName tableName = HRegionInfo.getTable(regionName); + if (!isMobRegionName(tableName, regionName)) { + compactRegion(regionName, columnFamily, false); + } else { + compactMob(tableName, columnFamily, false); + } } /** @@ -1859,7 +1869,12 @@ public void majorCompact(final TableName tableName) @Override public void majorCompactRegion(final byte[] regionName) throws IOException { - compactRegion(regionName, null, true); + TableName tableName = HRegionInfo.getTable(regionName); + if (!isMobRegionName(tableName, regionName)) { + compactRegion(regionName, null, true); + } else { + compactMob(tableName, null, true); + } } /** @@ -1902,7 +1917,12 @@ public void majorCompact(final TableName tableName, final byte[] columnFamily) @Override public void majorCompactRegion(final byte[] regionName, final byte[] columnFamily) throws IOException { - compactRegion(regionName, columnFamily, true); + TableName tableName = HRegionInfo.getTable(regionName); + if (!isMobRegionName(tableName, regionName)) { + compactRegion(regionName, columnFamily, true); + } else { + compactMob(tableName, columnFamily, true); + } } /** @@ -3046,6 +3066,10 @@ public CompactionState getCompactionState(final TableName tableName) @Override public CompactionState getCompactionStateForRegion(final byte[] regionName) throws IOException { + TableName tableName = HRegionInfo.getTable(regionName); + if (isMobRegionName(tableName, regionName)) { + return getMobCompactionState(regionName); + } try { Pair regionServerPair = getRegion(regionName); if (regionServerPair == null) { @@ -4123,78 +4147,15 @@ public Long call(int callTimeout) throws ServiceException { } /** - * {@inheritDoc} - */ - @Override - public void compactMob(final TableName tableName, final byte[] columnFamily) - throws IOException, InterruptedException { - checkTableNameNotNull(tableName); - checkFamilyNameNotNull(columnFamily); - validateMobColumnFamily(tableName, columnFamily); - compactMob(tableName, columnFamily, false); - } - - /** - * {@inheritDoc} - */ - @Override - public void compactMobs(final TableName tableName) throws IOException, InterruptedException { - checkTableNameNotNull(tableName); - compactMob(tableName, null, false); - } - - /** - * {@inheritDoc} - */ - @Override - public void majorCompactMob(final TableName tableName, final byte[] columnFamily) - throws IOException, InterruptedException { - checkTableNameNotNull(tableName); - checkFamilyNameNotNull(columnFamily); - validateMobColumnFamily(tableName, columnFamily); - compactMob(tableName, columnFamily, true); - } - - /** - * {@inheritDoc} - */ - @Override - public void majorCompactMobs(final TableName tableName) throws IOException, InterruptedException { - checkTableNameNotNull(tableName); - compactMob(tableName, null, true); - } - - /** - * {@inheritDoc} - */ - @Override - public CompactionState getMobCompactionState(TableName tableName) throws IOException { - checkTableNameNotNull(tableName); - try { - ServerName master = getClusterStatus().getMaster(); - HRegionInfo info = new HRegionInfo(tableName, Bytes.toBytes(".mob"), - HConstants.EMPTY_END_ROW, false, 0); - GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest( - info.getRegionName(), true); - GetRegionInfoResponse response = this.connection.getAdmin(master) - .getRegionInfo(null, request); - return response.getCompactionState(); - } catch (ServiceException se) { - throw ProtobufUtil.getRemoteException(se); - } - } - - /** * Compacts the mob files in a mob-enabled column family. Asynchronous operation. * @param tableName The table to compact. * @param columnFamily The column family to compact. If it is null, all the mob-enabled * column families in this table will be compacted. * @param major Whether to select all the mob files in the compaction. * @throws IOException - * @throws InterruptedException */ private void compactMob(final TableName tableName, final byte[] columnFamily, boolean major) - throws IOException, InterruptedException { + throws IOException { // get the mob region info, this is a dummy region. HRegionInfo info = new HRegionInfo(tableName, Bytes.toBytes(".mob"), HConstants.EMPTY_END_ROW, false, 0); @@ -4202,28 +4163,6 @@ private void compactMob(final TableName tableName, final byte[] columnFamily, bo compact(master, info, major, columnFamily); } - private void checkTableNameNotNull(TableName tableName) { - if (tableName == null) { - throw new IllegalArgumentException("TableName cannot be null"); - } - } - - private void checkFamilyNameNotNull(byte[] columnFamily) { - if (columnFamily == null) { - throw new IllegalArgumentException("The column family name cannot be null"); - } - } - - private void validateMobColumnFamily(TableName tableName, byte[] columnFamily) - throws IOException { - HTableDescriptor htd = getTableDescriptor(tableName); - HColumnDescriptor family = htd.getFamily(columnFamily); - if (family == null || !family.isMobEnabled()) { - throw new IllegalArgumentException("Column family " + Bytes.toString(columnFamily) - + " is not a mob column family"); - } - } - /** * Future that waits on a procedure result. * Returned by the async version of the Admin calls, @@ -4644,4 +4583,32 @@ public boolean visit(Result rowResult) throws IOException { throw e; } } + + /** + * Checks whether the given region name is a mob regino name. + * @param tableName The current table name. + * @param regionName The current region name. + * @return true if the given region name is a mob region name. + */ + private boolean isMobRegionName(TableName tableName, byte[] regionName) { + return Bytes.equals(regionName, HRegionInfo.getMobRegionName(tableName)); + } + + /** + * Gets the mob compaction state. + * @param regionName The current region name. + * @return the compaction state. + * @throws IOException + */ + private CompactionState getMobCompactionState(byte[] regionName) throws IOException { + try { + ServerName master = getClusterStatus().getMaster(); + GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(regionName, true); + GetRegionInfoResponse response = this.connection.getAdmin(master) + .getRegionInfo(null, request); + return response.getCompactionState(); + } catch (ServiceException se) { + throw ProtobufUtil.getRemoteException(se); + } + } } diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactMobAction.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactMobAction.java index 87c6dee..ea4b483 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactMobAction.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/CompactMobAction.java @@ -20,6 +20,7 @@ import org.apache.commons.lang.math.RandomUtils; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; @@ -28,6 +29,7 @@ */ public class CompactMobAction extends Action { private final TableName tableName; + private final byte[] regionName; private final int majorRatio; private final long sleepTime; @@ -38,6 +40,7 @@ public CompactMobAction(TableName tableName, float majorRatio) { public CompactMobAction( int sleepTime, TableName tableName, float majorRatio) { this.tableName = tableName; + this.regionName = HRegionInfo.getMobRegionName(tableName); this.majorRatio = (int) (100 * majorRatio); this.sleepTime = sleepTime; } @@ -51,9 +54,9 @@ public void perform() throws Exception { LOG.info("Performing action: Compact mob of table " + tableName + ", major=" + major); try { if (major) { - admin.majorCompactMobs(tableName); + admin.majorCompactRegion(regionName); } else { - admin.compactMobs(tableName); + admin.compactRegion(regionName); } } catch (Exception ex) { LOG.warn("Mob Compaction failed, might be caused by other chaos: " + ex.getMessage()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/compactions/TestMobCompactor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/compactions/TestMobCompactor.java index fc03c77..30a37cd 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/compactions/TestMobCompactor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/compactions/TestMobCompactor.java @@ -46,6 +46,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.TableName; @@ -95,6 +96,7 @@ private Configuration conf = null; private String tableNameAsString; private TableName tableName; + private byte[] mobRegionName; private static Connection conn; private BufferedMutator bufMut; private Table hTable; @@ -143,6 +145,7 @@ public void setUp() throws Exception { long tid = System.currentTimeMillis(); tableNameAsString = "testMob" + tid; tableName = TableName.valueOf(tableNameAsString); + mobRegionName = HRegionInfo.getMobRegionName(tableName); hcd1 = new HColumnDescriptor(family1); hcd1.setMobEnabled(true); hcd1.setMobThreshold(5); @@ -570,7 +573,7 @@ public void testCompactionFromAdmin() throws Exception { int largeFilesCount = countLargeFiles(5000, family1); // do the mob compaction - admin.compactMob(tableName, hcd1.getName()); + admin.compactRegion(mobRegionName, hcd1.getName()); waitUntilMobCompactionFinished(tableName); assertEquals("After compaction: mob rows count", regionNum * (rowNumPerRegion - delRowNum), @@ -618,7 +621,7 @@ public void testMajorCompactionFromAdmin() throws Exception { countFiles(tableName, false, family2)); // do the major mob compaction, it will force all files to compaction - admin.majorCompactMob(tableName, hcd1.getName()); + admin.majorCompactRegion(mobRegionName, hcd1.getName()); waitUntilMobCompactionFinished(tableName); assertEquals("After compaction: mob rows count", regionNum*(rowNumPerRegion-delRowNum), @@ -657,7 +660,7 @@ public void testScannerOnBulkLoadRefHFiles() throws Exception { Cell cell = result.getColumnLatestCell(hcd1.getName(), Bytes.toBytes(qf1)); assertEquals("Before compaction: mob value of k0", newValue0, Bytes.toString(CellUtil.cloneValue(cell))); - admin.majorCompactMob(tableName, hcd1.getName()); + admin.majorCompactRegion(mobRegionName, hcd1.getName()); waitUntilMobCompactionFinished(tableName); // read the latest cell of key0, the cell seqId in bulk loaded file is not reset in the // scanner. The cell that has "new" value is still visible. @@ -705,7 +708,7 @@ public void testScannerAfterCompactions() throws Exception { loadData(admin, bufMut, tableName, new Put[] { put1 }); // now two mob files admin.majorCompact(tableName); waitUntilCompactionFinished(tableName); - admin.majorCompactMob(tableName, hcd1.getName()); + admin.majorCompactRegion(mobRegionName, hcd1.getName()); waitUntilMobCompactionFinished(tableName); // read the latest cell of key1. Get get = new Get(key1); @@ -731,12 +734,12 @@ private void waitUntilCompactionFinished(TableName tableName) throws IOException private void waitUntilMobCompactionFinished(TableName tableName) throws IOException, InterruptedException { long finished = EnvironmentEdgeManager.currentTime() + 60000; - CompactionState state = admin.getMobCompactionState(tableName); + CompactionState state = admin.getCompactionStateForRegion(mobRegionName); while (EnvironmentEdgeManager.currentTime() < finished) { if (state == CompactionState.NONE) { break; } - state = admin.getMobCompactionState(tableName); + state = admin.getCompactionStateForRegion(mobRegionName); Thread.sleep(10); } assertEquals(CompactionState.NONE, state);