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);
}
}
}
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());
}
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;
}
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);
}
}
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();
}
Aggregations