use of org.apache.hadoop.hbase.client.CompactionState in project hbase by apache.
the class TestMobCompactor method waitUntilMobCompactionFinished.
private void waitUntilMobCompactionFinished(TableName tableName) throws IOException, InterruptedException {
long finished = EnvironmentEdgeManager.currentTime() + 60000;
CompactionState state = admin.getCompactionState(tableName, CompactType.MOB);
while (EnvironmentEdgeManager.currentTime() < finished) {
if (state == CompactionState.NONE) {
break;
}
state = admin.getCompactionState(tableName, CompactType.MOB);
Thread.sleep(10);
}
assertEquals(CompactionState.NONE, state);
}
use of org.apache.hadoop.hbase.client.CompactionState in project hbase by apache.
the class TestCompactionState method compaction.
/**
* Load data to a table, flush it to disk, trigger compaction,
* confirm the compaction state is right and wait till it is done.
*
* @param tableName
* @param flushes
* @param expectedState
* @param singleFamily otherwise, run compaction on all cfs
* @throws IOException
* @throws InterruptedException
*/
private void compaction(final String tableName, final int flushes, final CompactionState expectedState, boolean singleFamily) throws IOException, InterruptedException {
// Create a table with regions
TableName table = TableName.valueOf(tableName);
byte[] family = Bytes.toBytes("family");
byte[][] families = { family, Bytes.add(family, Bytes.toBytes("2")), Bytes.add(family, Bytes.toBytes("3")) };
Table ht = null;
try {
ht = TEST_UTIL.createTable(table, families);
loadData(ht, families, 3000, flushes);
HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
List<Region> regions = rs.getOnlineRegions(table);
int countBefore = countStoreFilesInFamilies(regions, families);
int countBeforeSingleFamily = countStoreFilesInFamily(regions, family);
// there should be some data files
assertTrue(countBefore > 0);
Admin admin = TEST_UTIL.getAdmin();
if (expectedState == CompactionState.MINOR) {
if (singleFamily) {
admin.compact(table, family);
} else {
admin.compact(table);
}
} else {
if (singleFamily) {
admin.majorCompact(table, family);
} else {
admin.majorCompact(table);
}
}
long curt = System.currentTimeMillis();
long waitTime = 5000;
long endt = curt + waitTime;
CompactionState state = admin.getCompactionState(table);
while (state == CompactionState.NONE && curt < endt) {
Thread.sleep(10);
state = admin.getCompactionState(table);
curt = System.currentTimeMillis();
}
// otherwise, the compaction should have already been done
if (expectedState != state) {
for (Region region : regions) {
state = CompactionState.valueOf(region.getCompactionState().toString());
assertEquals(CompactionState.NONE, state);
}
} else {
// Wait until the compaction is done
state = admin.getCompactionState(table);
while (state != CompactionState.NONE && curt < endt) {
Thread.sleep(10);
state = admin.getCompactionState(table);
}
// Now, compaction should be done.
assertEquals(CompactionState.NONE, state);
}
int countAfter = countStoreFilesInFamilies(regions, families);
int countAfterSingleFamily = countStoreFilesInFamily(regions, family);
assertTrue(countAfter < countBefore);
if (!singleFamily) {
if (expectedState == CompactionState.MAJOR)
assertTrue(families.length == countAfter);
else
assertTrue(families.length < countAfter);
} else {
int singleFamDiff = countBeforeSingleFamily - countAfterSingleFamily;
// assert only change was to single column family
assertTrue(singleFamDiff == (countBefore - countAfter));
if (expectedState == CompactionState.MAJOR) {
assertTrue(1 == countAfterSingleFamily);
} else {
assertTrue(1 < countAfterSingleFamily);
}
}
} finally {
if (ht != null) {
TEST_UTIL.deleteTable(table);
}
}
}
Aggregations