esteban commented on a change in pull request #1446: HBASE-23723 Ensure MOB compaction works in optimized mode after snapshot clone URL: https://github.com/apache/hbase/pull/1446#discussion_r405745257
########## File path: hbase-server/src/test/java/org/apache/hadoop/hbase/mob/TestMobCompactionWithDefaults.java ########## @@ -152,49 +167,102 @@ private void loadData(int num) { public void tearDown() throws Exception { admin.disableTable(tableDescriptor.getTableName()); admin.deleteTable(tableDescriptor.getTableName()); - HTU.shutdownMiniCluster(); } - + @Test public void baseTestMobFileCompaction() throws InterruptedException, IOException { + LOG.info("MOB compaction " + description() + " started"); + loadAndFlushThreeTimes(rows, table, famStr); + mobCompact(tableDescriptor, familyDescriptor); + assertEquals("Should have 4 MOB files per region due to 3xflush + compaction.", numRegions * 4, + getNumberOfMobFiles(table, famStr)); + cleanupAndVerifyCounts(table, famStr, 3*rows); + LOG.info("MOB compaction " + description() + " finished OK"); + } + protected void loadAndFlushThreeTimes(int rows, TableName table, String family) + throws IOException { + final long start = getNumberOfMobFiles(table, family); // Load and flush data 3 times - loadData(rows); - loadData(rows); - loadData(rows); - long num = getNumberOfMobFiles(conf, table.getName(), new String(fam)); - assertEquals(numRegions * 3, num); - // Major MOB compact - mobCompact(admin, tableDescriptor, familyDescriptor); - // wait until compaction is complete - while (admin.getCompactionState(tableDescriptor.getTableName()) != CompactionState.NONE) { + loadData(table, rows); + loadData(table, rows); + loadData(table, rows); + assertEquals("Should have 3 more mob files per region from flushing.", start + numRegions * 3, + getNumberOfMobFiles(table, family)); + } + + protected String description() { + return "regular mode"; + } + + protected void enableCompactions() throws IOException { + final List<String> serverList = admin.getRegionServers().stream().map(sn -> sn.getServerName()) + .collect(Collectors.toList()); + admin.compactionSwitch(true, serverList); + } + + protected void disableCompactions() throws IOException { + final List<String> serverList = admin.getRegionServers().stream().map(sn -> sn.getServerName()) + .collect(Collectors.toList()); + admin.compactionSwitch(false, serverList); + } + + /** + * compact the given table and return once it is done. + * should presume compactions are disabled when called. + * should ensure compactions are disabled before returning. + */ + protected void mobCompact(TableDescriptor tableDescriptor, + ColumnFamilyDescriptor familyDescriptor) throws IOException, InterruptedException { + LOG.debug("Major compact MOB table " + tableDescriptor.getTableName()); + enableCompactions(); + mobCompactImpl(tableDescriptor, familyDescriptor); + waitUntilCompactionIsComplete(tableDescriptor.getTableName()); + disableCompactions(); + } + + /** + * Call the API for compaction specific to the test set. + * should not wait for compactions to finish. + * may assume compactions are enabled when called. + */ + protected void mobCompactImpl(TableDescriptor tableDescriptor, + ColumnFamilyDescriptor familyDescriptor) throws IOException, InterruptedException { + admin.majorCompact(tableDescriptor.getTableName(), familyDescriptor.getName()); + } + + protected void waitUntilCompactionIsComplete(TableName table) Review comment: Sounds good, we can rely on the test timeout for now. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services