Search in sources :

Example 96 with HMaster

use of org.apache.hadoop.hbase.master.HMaster 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
 * @param stateSource get the state by Admin or Master
 * @throws IOException
 * @throws InterruptedException
 */
private void compaction(final String tableName, final int flushes, final CompactionState expectedState, boolean singleFamily, StateSource stateSource) 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);
        HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
        List<HRegion> regions = rs.getRegions(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 = EnvironmentEdgeManager.currentTime();
        long waitTime = 5000;
        long endt = curt + waitTime;
        CompactionState state = getCompactionState(stateSource, master, admin, table);
        while (state == CompactionState.NONE && curt < endt) {
            Thread.sleep(10);
            state = getCompactionState(stateSource, master, admin, table);
            curt = EnvironmentEdgeManager.currentTime();
        }
        // 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 = getCompactionState(stateSource, master, admin, table);
            while (state != CompactionState.NONE && curt < endt) {
                Thread.sleep(10);
                state = getCompactionState(stateSource, master, admin, 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 : Table(org.apache.hadoop.hbase.client.Table) Admin(org.apache.hadoop.hbase.client.Admin) TableName(org.apache.hadoop.hbase.TableName) HMaster(org.apache.hadoop.hbase.master.HMaster) CompactionState(org.apache.hadoop.hbase.client.CompactionState)

Example 97 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestClusterId method testRewritingClusterIdToPB.

@Test
public void testRewritingClusterIdToPB() throws Exception {
    TEST_UTIL.startMiniZKCluster();
    TEST_UTIL.startMiniDFSCluster(1);
    TEST_UTIL.createRootDir();
    Path rootDir = CommonFSUtils.getRootDir(TEST_UTIL.getConfiguration());
    FileSystem fs = rootDir.getFileSystem(TEST_UTIL.getConfiguration());
    Path filePath = new Path(rootDir, HConstants.CLUSTER_ID_FILE_NAME);
    FSDataOutputStream s = null;
    try {
        s = fs.create(filePath);
        s.writeUTF(HBaseCommonTestingUtil.getRandomUUID().toString());
    } finally {
        if (s != null) {
            s.close();
        }
    }
    TEST_UTIL.startMiniHBaseCluster();
    HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
    assertEquals(1, master.getServerManager().getOnlineServersList().size());
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) HMaster(org.apache.hadoop.hbase.master.HMaster) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) Test(org.junit.Test)

Example 98 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestSplitTransactionOnCluster method abortAndWaitForMaster.

private HMaster abortAndWaitForMaster() throws IOException, InterruptedException {
    cluster.abortMaster(0);
    cluster.waitOnMaster(0);
    HMaster master = cluster.startMaster().getMaster();
    cluster.waitForActiveAndReadyMaster();
    // reset the connections
    Closeables.close(admin, true);
    TESTING_UTIL.invalidateConnection();
    admin = TESTING_UTIL.getAdmin();
    return master;
}
Also used : HMaster(org.apache.hadoop.hbase.master.HMaster)

Example 99 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestSplitTransactionOnCluster method testRITStateForRollback.

@Test
public void testRITStateForRollback() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final HMaster master = cluster.getMaster();
    try {
        // Create table then get the single region for our new table.
        Table t = createTableAndWait(tableName, Bytes.toBytes("cf"));
        final List<HRegion> regions = cluster.getRegions(tableName);
        final RegionInfo hri = getAndCheckSingleTableRegion(regions);
        insertData(tableName, admin, t);
        t.close();
        // Turn off balancer so it doesn't cut in and mess up our placements.
        this.admin.balancerSwitch(false, true);
        // Turn off the meta scanner so it don't remove parent on us.
        master.setCatalogJanitorEnabled(false);
        // find a splittable region
        final HRegion region = findSplittableRegion(regions);
        assertTrue("not able to find a splittable region", region != null);
        // install master co-processor to fail splits
        master.getMasterCoprocessorHost().load(FailingSplitMasterObserver.class, Coprocessor.PRIORITY_USER, master.getConfiguration());
        // split async
        this.admin.splitRegionAsync(region.getRegionInfo().getRegionName(), new byte[] { 42 });
        // we have to wait until the SPLITTING state is seen by the master
        FailingSplitMasterObserver observer = master.getMasterCoprocessorHost().findCoprocessor(FailingSplitMasterObserver.class);
        assertNotNull(observer);
        observer.latch.await();
        LOG.info("Waiting for region to come out of RIT");
        while (!cluster.getMaster().getAssignmentManager().getRegionStates().isRegionOnline(hri)) {
            Threads.sleep(100);
        }
        assertTrue(cluster.getMaster().getAssignmentManager().getRegionStates().isRegionOnline(hri));
    } finally {
        admin.balancerSwitch(true, false);
        master.setCatalogJanitorEnabled(true);
        abortAndWaitForMaster();
        TESTING_UTIL.deleteTable(tableName);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) HMaster(org.apache.hadoop.hbase.master.HMaster) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Test(org.junit.Test)

Example 100 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestRSGroupMajorCompactionTTL method setUp.

@Before
@Override
public void setUp() throws Exception {
    utility = new HBaseTestingUtil();
    Configuration conf = utility.getConfiguration();
    RSGroupUtil.enableRSGroup(conf);
    conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, NUM_SLAVES_BASE);
    conf.setInt("hbase.hfile.compaction.discharger.interval", 10);
    utility.startMiniCluster(NUM_SLAVES_BASE);
    SingleProcessHBaseCluster cluster = utility.getHBaseCluster();
    final HMaster master = cluster.getMaster();
    // wait for balancer to come online
    utility.waitFor(60000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() {
            return master.isInitialized() && ((RSGroupBasedLoadBalancer) master.getLoadBalancer()).isOnline();
        }
    });
    admin = utility.getAdmin();
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) Configuration(org.apache.hadoop.conf.Configuration) HMaster(org.apache.hadoop.hbase.master.HMaster) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Waiter(org.apache.hadoop.hbase.Waiter) Before(org.junit.Before)

Aggregations

HMaster (org.apache.hadoop.hbase.master.HMaster)132 Test (org.junit.Test)91 TableName (org.apache.hadoop.hbase.TableName)42 IOException (java.io.IOException)33 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)31 ServerName (org.apache.hadoop.hbase.ServerName)24 Admin (org.apache.hadoop.hbase.client.Admin)23 Table (org.apache.hadoop.hbase.client.Table)23 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)22 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)16 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)15 Configuration (org.apache.hadoop.conf.Configuration)13 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)12 BeforeClass (org.junit.BeforeClass)11 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)10 List (java.util.List)9 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)9 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)9 RegionStates (org.apache.hadoop.hbase.master.assignment.RegionStates)9 ClassRule (org.junit.ClassRule)9