Search in sources :

Example 1 with CompactionState

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);
}
Also used : CompactionState(org.apache.hadoop.hbase.client.CompactionState)

Example 2 with CompactionState

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);
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) CompactionState(org.apache.hadoop.hbase.client.CompactionState) Admin(org.apache.hadoop.hbase.client.Admin)

Aggregations

CompactionState (org.apache.hadoop.hbase.client.CompactionState)2 TableName (org.apache.hadoop.hbase.TableName)1 Admin (org.apache.hadoop.hbase.client.Admin)1 Table (org.apache.hadoop.hbase.client.Table)1