Java Code Examples for org.apache.hadoop.hbase.MiniHBaseCluster#getMaster()
The following examples show how to use
org.apache.hadoop.hbase.MiniHBaseCluster#getMaster() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexLoadBalancerIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test(timeout = 180000) public void testRandomAssignmentDuringIndexTableEnable() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); master.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", false); TableName tableName = TableName.valueOf("testRandomAssignmentDuringIndexTableEnable"); TableName indexTableName = TableName.valueOf("testRandomAssignmentDuringIndexTableEnable_index"); createUserAndIndexTable(tableName, indexTableName); admin.disableTable(tableName); admin.disableTable(indexTableName); admin.enableTable(tableName); admin.enableTable(indexTableName); boolean isRegionColocated = checkForColocation(master, tableName.getNameAsString(), indexTableName .getNameAsString()); assertTrue("User regions and index regions should colocate.", isRegionColocated); }
Example 2
Source File: IndexLoadBalancerIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test(timeout = 180000) public void testRoundRobinAssignmentAfterRegionServerDown() throws Exception { ZooKeeperWatcher zkw = UTIL.getZooKeeperWatcher(UTIL); MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); TableName tableName = TableName.valueOf("testRoundRobinAssignmentAfterRegionServerDown"); TableName indexTableName = TableName.valueOf("testRoundRobinAssignmentAfterRegionServerDown_index"); createUserAndIndexTable(tableName, indexTableName); HRegionServer regionServer = cluster.getRegionServer(1); regionServer.abort("Aborting to test random assignment after region server down"); while (master.getServerManager().areDeadServersInProgress()) { Thread.sleep(1000); } ZKAssign.blockUntilNoRIT(zkw); while (master.getAssignmentManager().getRegionStates().isRegionsInTransition()) { Threads.sleep(1000); } boolean isRegionColocated = checkForColocation(master, tableName.getNameAsString(), indexTableName .getNameAsString()); assertTrue("User regions and index regions should colocate.", isRegionColocated); }
Example 3
Source File: TestMasterObserver.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testTableDescriptorsEnumeration() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); cp.resetStates(); GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null); master.getMasterRpcServices().getTableDescriptors(null, req); assertTrue("Coprocessor should be called on table descriptors request", cp.wasGetTableDescriptorsCalled()); }
Example 4
Source File: TestRSGroupMajorCompactionTTL.java From hbase with Apache License 2.0 | 6 votes |
@Before @Override public void setUp() throws Exception { utility = new HBaseTestingUtility(); 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); MiniHBaseCluster 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(); }
Example 5
Source File: TestMasterObserver.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testGetLocksOperation() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); cp.resetStates(); master.getLocks(); assertTrue( "Coprocessor should be called on get locks request", cp.wasGetLocksCalled()); }
Example 6
Source File: IndexLoadBalancerIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test(timeout = 180000) public void testRoundRobinAssignmentDuringIndexTableCreation() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); TableName tableName = TableName.valueOf("testRoundRobinAssignmentDuringIndexTableCreation"); TableName indexTableName = TableName.valueOf("testRoundRobinAssignmentDuringIndexTableCreation_index"); createUserAndIndexTable(tableName, indexTableName); boolean isRegionColocated = checkForColocation(master, tableName.getNameAsString(), indexTableName .getNameAsString()); assertTrue("User regions and index regions should colocate.", isRegionColocated); }
Example 7
Source File: IndexLoadBalancerIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test(timeout = 180000) public void testBalanceByTable() throws Exception { ZooKeeperWatcher zkw = UTIL.getZooKeeperWatcher(UTIL); MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); master.getConfiguration().setBoolean("hbase.master.loadbalance.bytable", true); TableName tableName = TableName.valueOf("testBalanceByTable"); TableName indexTableName = TableName.valueOf("testBalanceByTable_index"); createUserAndIndexTable(tableName, indexTableName); HTableDescriptor htd1 = new HTableDescriptor(TableName.valueOf("testBalanceByTable1")); htd1.addFamily(new HColumnDescriptor("fam1")); char c = 'A'; byte[][] split1 = new byte[12][]; for (int i = 0; i < 12; i++) { byte[] b = { (byte) c }; split1[i] = b; c++; } admin.disableTable(tableName); admin.enableTable(tableName); admin.setBalancerRunning(true, false); boolean isRegionColocated = checkForColocation(master, tableName.getNameAsString(), indexTableName .getNameAsString()); assertTrue("User regions and index regions should colocate.", isRegionColocated); admin.balancer(); Thread.sleep(10000); ZKAssign.blockUntilNoRIT(zkw); while (master.getAssignmentManager().getRegionStates().isRegionsInTransition()) { Threads.sleep(1000); } isRegionColocated = checkForColocation(master, tableName.getNameAsString(), indexTableName .getNameAsString()); assertTrue("User regions and index regions should colocate.", isRegionColocated); }
Example 8
Source File: MasterProcedureTestingUtility.java From hbase with Apache License 2.0 | 5 votes |
public static void waitBackupMaster(final HBaseTestingUtility testUtil, final HMaster oldMaster) throws Exception { MiniHBaseCluster cluster = testUtil.getMiniHBaseCluster(); HMaster newMaster = cluster.getMaster(); while (newMaster == null || newMaster == oldMaster) { Thread.sleep(250); newMaster = cluster.getMaster(); } while (!(newMaster.isActiveMaster() && newMaster.isInitialized())) { Thread.sleep(250); } }
Example 9
Source File: TestAdmin2.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMoveToPreviouslyAssignedRS() throws IOException, InterruptedException { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); final TableName tableName = TableName.valueOf(name.getMethodName()); Admin localAdmin = createTable(tableName); List<RegionInfo> tableRegions = localAdmin.getRegions(tableName); RegionInfo hri = tableRegions.get(0); AssignmentManager am = master.getAssignmentManager(); ServerName server = am.getRegionStates().getRegionServerOfRegion(hri); localAdmin.move(hri.getEncodedNameAsBytes(), server); assertEquals("Current region server and region server before move should be same.", server, am.getRegionStates().getRegionServerOfRegion(hri)); }
Example 10
Source File: TestRegionPlacement.java From hbase with Apache License 2.0 | 5 votes |
/** * Verify the number of region movement is expected */ private void verifyRegionMovementNum(int expected) throws InterruptedException, IOException { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster m = cluster.getMaster(); int lastRegionOpenedCount = m.getAssignmentManager().getNumRegionsOpened(); // get the assignments start to execute m.balance(); int retry = 10; long sleep = 3000; int attempt = 0; int currentRegionOpened, regionMovement; do { currentRegionOpened = m.getAssignmentManager().getNumRegionsOpened(); regionMovement= currentRegionOpened - lastRegionOpenedCount; LOG.debug("There are " + regionMovement + "/" + expected + " regions moved after " + attempt + " attempts"); Thread.sleep((++attempt) * sleep); } while (regionMovement != expected && attempt <= retry); // update the lastRegionOpenedCount lastRegionOpenedCount = currentRegionOpened; assertEquals("There are only " + regionMovement + " instead of " + expected + " region movement for " + attempt + " attempts", expected, regionMovement); }
Example 11
Source File: TestMaster.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testMoveRegionWhenNotInitialized() { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster m = cluster.getMaster(); try { m.setInitialized(false); // fake it, set back later RegionInfo meta = RegionInfoBuilder.FIRST_META_REGIONINFO; m.move(meta.getEncodedNameAsBytes(), null); fail("Region should not be moved since master is not initialized"); } catch (IOException ioe) { assertTrue(ioe instanceof PleaseHoldException); } finally { m.setInitialized(true); } }
Example 12
Source File: TestRegionMergeTransactionOnCluster.java From hbase with Apache License 2.0 | 5 votes |
@BeforeClass public static void beforeAllTests() throws Exception { // Start a cluster StartMiniClusterOption option = StartMiniClusterOption.builder() .masterClass(MyMaster.class).numRegionServers(NB_SERVERS).numDataNodes(NB_SERVERS).build(); TEST_UTIL.startMiniCluster(option); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); MASTER = cluster.getMaster(); MASTER.balanceSwitch(false); ADMIN = TEST_UTIL.getConnection().getAdmin(); }
Example 13
Source File: TestMasterFailoverBalancerPersistence.java From hbase with Apache License 2.0 | 5 votes |
/** * Kill the master and wait for a new active master to show up * * @param cluster * @return the new active master * @throws InterruptedException * @throws java.io.IOException */ private HMaster killActiveAndWaitForNewActive(MiniHBaseCluster cluster) throws InterruptedException, IOException { int activeIndex = getActiveMasterIndex(cluster); HMaster active = cluster.getMaster(); cluster.stopMaster(activeIndex); cluster.waitOnMaster(activeIndex); assertTrue(cluster.waitForActiveAndReadyMaster()); // double check this is actually a new master HMaster newActive = cluster.getMaster(); assertFalse(active == newActive); return newActive; }
Example 14
Source File: TestMasterFailover.java From hbase with Apache License 2.0 | 4 votes |
/** * Test meta in transition when master failover. * This test used to manipulate region state up in zk. That is not allowed any more in hbase2 * so I removed that messing. That makes this test anemic. */ @Test public void testMetaInTransitionWhenMasterFailover() throws Exception { // Start the cluster HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); TEST_UTIL.startMiniCluster(); try { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); LOG.info("Cluster started"); HMaster activeMaster = cluster.getMaster(); ServerName metaServerName = cluster.getServerHoldingMeta(); HRegionServer hrs = cluster.getRegionServer(metaServerName); // Now kill master, meta should remain on rs, where we placed it before. LOG.info("Aborting master"); activeMaster.abort("test-kill"); cluster.waitForMasterToStop(activeMaster.getServerName(), 30000); LOG.info("Master has aborted"); // meta should remain where it was RegionState metaState = MetaTableLocator.getMetaRegionState(hrs.getZooKeeper()); assertEquals("hbase:meta should be online on RS", metaState.getServerName(), metaServerName); assertEquals("hbase:meta should be online on RS", State.OPEN, metaState.getState()); // Start up a new master LOG.info("Starting up a new master"); activeMaster = cluster.startMaster().getMaster(); LOG.info("Waiting for master to be ready"); cluster.waitForActiveAndReadyMaster(); LOG.info("Master is ready"); // ensure meta is still deployed on RS metaState = MetaTableLocator.getMetaRegionState(activeMaster.getZooKeeper()); assertEquals("hbase:meta should be online on RS", metaState.getServerName(), metaServerName); assertEquals("hbase:meta should be online on RS", State.OPEN, metaState.getState()); // Done, shutdown the cluster } finally { TEST_UTIL.shutdownMiniCluster(); } }
Example 15
Source File: TestMasterObserver.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testSnapshotOperations() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); cp.resetStates(); // create a table TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor = new TableDescriptorBuilder.ModifyableTableDescriptor(tableName); tableDescriptor.setColumnFamily( new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(TEST_FAMILY)); Admin admin = UTIL.getAdmin(); tableCreationLatch = new CountDownLatch(1); admin.createTable(tableDescriptor); tableCreationLatch.await(); tableCreationLatch = new CountDownLatch(1); admin.disableTable(tableName); assertTrue(admin.isTableDisabled(tableName)); try { // Test snapshot operation assertFalse("Coprocessor should not have been called yet", cp.wasSnapshotCalled()); admin.snapshot(TEST_SNAPSHOT, tableName); assertTrue("Coprocessor should have been called on snapshot", cp.wasSnapshotCalled()); //Test list operation admin.listSnapshots(); assertTrue("Coprocessor should have been called on snapshot list", cp.wasListSnapshotCalled()); // Test clone operation admin.cloneSnapshot(TEST_SNAPSHOT, TEST_CLONE); assertTrue("Coprocessor should have been called on snapshot clone", cp.wasCloneSnapshotCalled()); assertFalse("Coprocessor restore should not have been called on snapshot clone", cp.wasRestoreSnapshotCalled()); admin.disableTable(TEST_CLONE); assertTrue(admin.isTableDisabled(tableName)); deleteTable(admin, TEST_CLONE); // Test restore operation cp.resetStates(); admin.restoreSnapshot(TEST_SNAPSHOT); assertTrue("Coprocessor should have been called on snapshot restore", cp.wasRestoreSnapshotCalled()); assertFalse("Coprocessor clone should not have been called on snapshot restore", cp.wasCloneSnapshotCalled()); admin.deleteSnapshot(TEST_SNAPSHOT); assertTrue("Coprocessor should have been called on snapshot delete", cp.wasDeleteSnapshotCalled()); } finally { deleteTable(admin, tableName); } }
Example 16
Source File: TestHBCKSCP.java From hbase with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { // we are about to do one for it? MiniHBaseCluster cluster = this.util.getHBaseCluster(); // Assert that we have three RegionServers. Test depends on there being multiple. assertEquals(RS_COUNT, cluster.getLiveRegionServerThreads().size()); int count; try (Table table = createTable(TableName.valueOf(this.name.getMethodName()))) { // Load the table with a bit of data so some logs to split and some edits in each region. this.util.loadTable(table, HBaseTestingUtility.COLUMNS[0]); count = util.countRows(table); } assertTrue("expected some rows", count > 0); // Make the test easier by not working on server hosting meta... // Find another RS. Purge it from Master memory w/o running SCP (if // SCP runs, it will clear entries from hbase:meta which frustrates // our attempt at manufacturing 'Unknown Servers' condition). int metaIndex = this.util.getMiniHBaseCluster().getServerWithMeta(); int rsIndex = (metaIndex + 1) % RS_COUNT; ServerName rsServerName = cluster.getRegionServer(rsIndex).getServerName(); HMaster master = cluster.getMaster(); // Get a Region that is on the server. RegionInfo rsRI = master.getAssignmentManager().getRegionsOnServer(rsServerName).get(0); Result r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName()); // Assert region is OPEN. assertEquals(RegionState.State.OPEN.toString(), Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER))); ServerName serverName = CatalogFamilyFormat.getServerName(r, 0); assertEquals(rsServerName, serverName); // moveFrom adds to dead servers and adds it to processing list only we will // not be processing this server 'normally'. Remove it from processing by // calling 'finish' and then remove it from dead servers so rsServerName // becomes an 'Unknown Server' even though it is still around. master.getServerManager().moveFromOnlineToDeadServers(rsServerName); master.getServerManager().getDeadServers().finish(rsServerName); master.getServerManager().getDeadServers().removeDeadServer(rsServerName); master.getAssignmentManager().getRegionStates().removeServer(rsServerName); // Kill the server. Nothing should happen since an 'Unknown Server' as far // as the Master is concerned; i.e. no SCP. LOG.info("Killing {}", rsServerName); HRegionServer hrs = cluster.getRegionServer(rsServerName); hrs.abort("KILLED"); while (!hrs.isStopped()) { Threads.sleep(10); } LOG.info("Dead {}", rsServerName); // Now assert still references in hbase:meta to the 'dead' server -- they haven't been // cleaned up by an SCP or by anything else. assertTrue(searchMeta(master, rsServerName)); // Assert region is OPEN on dead server still. r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName()); assertEquals(RegionState.State.OPEN.toString(), Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER))); serverName = CatalogFamilyFormat.getServerName(r, 0); assertNotNull(cluster.getRegionServer(serverName)); assertEquals(rsServerName, serverName); // I now have 'Unknown Server' references in hbase:meta; i.e. Server references // with no corresponding SCP. Queue one. MasterProtos.ScheduleServerCrashProcedureResponse response = master.getMasterRpcServices().scheduleServerCrashProcedure(null, MasterProtos.ScheduleServerCrashProcedureRequest.newBuilder(). addServerName(ProtobufUtil.toServerName(rsServerName)).build()); assertEquals(1, response.getPidCount()); long pid = response.getPid(0); assertNotEquals(Procedure.NO_PROC_ID, pid); while (master.getMasterProcedureExecutor().getActiveProcIds().contains(pid)) { Threads.sleep(10); } // After SCP, assert region is OPEN on new server. r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName()); assertEquals(RegionState.State.OPEN.toString(), Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER))); serverName = CatalogFamilyFormat.getServerName(r, 0); assertNotNull(cluster.getRegionServer(serverName)); assertNotEquals(rsServerName, serverName); // Make sure no mention of old server post SCP. assertFalse(searchMeta(master, rsServerName)); }
Example 17
Source File: TestMaster.java From hbase with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings("deprecation") public void testMasterOpsWhileSplitting() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster m = cluster.getMaster(); try (Table ht = TEST_UTIL.createTable(TABLENAME, FAMILYNAME)) { assertTrue(m.getTableStateManager().isTableState(TABLENAME, TableState.State.ENABLED)); TEST_UTIL.loadTable(ht, FAMILYNAME, false); } List<Pair<RegionInfo, ServerName>> tableRegions = MetaTableAccessor.getTableRegionsAndLocations( m.getConnection(), TABLENAME); LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions)); assertEquals(1, tableRegions.size()); assertArrayEquals(HConstants.EMPTY_START_ROW, tableRegions.get(0).getFirst().getStartKey()); assertArrayEquals(HConstants.EMPTY_END_ROW, tableRegions.get(0).getFirst().getEndKey()); // Now trigger a split and stop when the split is in progress LOG.info("Splitting table"); TEST_UTIL.getAdmin().split(TABLENAME); LOG.info("Making sure we can call getTableRegions while opening"); while (tableRegions.size() < 3) { tableRegions = MetaTableAccessor.getTableRegionsAndLocations(m.getConnection(), TABLENAME, false); Thread.sleep(100); } LOG.info("Regions: " + Joiner.on(',').join(tableRegions)); // We have three regions because one is split-in-progress assertEquals(3, tableRegions.size()); LOG.info("Making sure we can call getTableRegionClosest while opening"); Pair<RegionInfo, ServerName> pair = getTableRegionForRow(m, TABLENAME, Bytes.toBytes("cde")); LOG.info("Result is: " + pair); Pair<RegionInfo, ServerName> tableRegionFromName = MetaTableAccessor.getRegion(m.getConnection(), pair.getFirst().getRegionName()); assertTrue(RegionInfo.COMPARATOR.compare(tableRegionFromName.getFirst(), pair.getFirst()) == 0); }
Example 18
Source File: TestMetaShutdownHandler.java From hbase with Apache License 2.0 | 4 votes |
/** * This test will test the expire handling of a meta-carrying * region server. * After HBaseMiniCluster is up, we will delete the ephemeral * node of the meta-carrying region server, which will trigger * the expire of this region server on the master. * On the other hand, we will slow down the abort process on * the region server so that it is still up during the master SSH. * We will check that the master SSH is still successfully done. */ @Test public void testExpireMetaRegionServer() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); RegionStates regionStates = master.getAssignmentManager().getRegionStates(); ServerName metaServerName = regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO); if (master.getServerName().equals(metaServerName) || metaServerName == null || !metaServerName.equals(cluster.getServerHoldingMeta())) { // Move meta off master metaServerName = cluster.getLiveRegionServerThreads().get(0).getRegionServer().getServerName(); master.move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), Bytes.toBytes(metaServerName.getServerName())); TEST_UTIL.waitUntilNoRegionsInTransition(60000); metaServerName = regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO); } RegionState metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper()); assertEquals("Wrong state for meta!", RegionState.State.OPEN, metaState.getState()); assertNotEquals("Meta is on master!", metaServerName, master.getServerName()); // Delete the ephemeral node of the meta-carrying region server. // This is trigger the expire of this region server on the master. String rsEphemeralNodePath = ZNodePaths.joinZNode(master.getZooKeeper().getZNodePaths().rsZNode, metaServerName.toString()); ZKUtil.deleteNode(master.getZooKeeper(), rsEphemeralNodePath); LOG.info("Deleted the znode for the RegionServer hosting hbase:meta; waiting on SSH"); // Wait for SSH to finish final ServerManager serverManager = master.getServerManager(); final ServerName priorMetaServerName = metaServerName; TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return !serverManager.isServerOnline(priorMetaServerName) && !serverManager.areDeadServersInProgress(); } }); LOG.info("Past wait on RIT"); TEST_UTIL.waitUntilNoRegionsInTransition(60000); // Now, make sure meta is assigned assertTrue("Meta should be assigned", regionStates.isRegionOnline(RegionInfoBuilder.FIRST_META_REGIONINFO)); // Now, make sure meta is registered in zk metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper()); assertEquals("Meta should not be in transition", RegionState.State.OPEN, metaState.getState()); assertEquals("Meta should be assigned", metaState.getServerName(), regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO)); assertNotEquals("Meta should be assigned on a different server", metaState.getServerName(), metaServerName); }
Example 19
Source File: TestHRegionOnCluster.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testDataCorrectnessReplayingRecoveredEdits() throws Exception { final int NUM_RS = 3; Admin hbaseAdmin = null; TEST_UTIL.startMiniCluster(NUM_RS); try { final TableName tableName = TableName.valueOf(name.getMethodName()); final byte[] FAMILY = Bytes.toBytes("family"); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); // Create table TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor = new TableDescriptorBuilder.ModifyableTableDescriptor(tableName); tableDescriptor.setColumnFamily( new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY)); hbaseAdmin = master.getConnection().getAdmin(); hbaseAdmin.createTable(tableDescriptor); assertTrue(hbaseAdmin.isTableAvailable(tableName)); // Put data: r1->v1 LOG.info("Loading r1 to v1 into " + tableName); Table table = TEST_UTIL.getConnection().getTable(tableName); putDataAndVerify(table, "r1", FAMILY, "v1", 1); TEST_UTIL.waitUntilAllRegionsAssigned(table.getName()); // Move region to target server RegionInfo regionInfo; try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) { regionInfo = locator.getRegionLocation(Bytes.toBytes("r1")).getRegion(); } int originServerNum = cluster.getServerWith(regionInfo.getRegionName()); HRegionServer originServer = cluster.getRegionServer(originServerNum); int targetServerNum = (originServerNum + 1) % NUM_RS; HRegionServer targetServer = cluster.getRegionServer(targetServerNum); assertFalse(originServer.equals(targetServer)); TEST_UTIL.waitUntilAllRegionsAssigned(table.getName()); LOG.info("Moving " + regionInfo.getEncodedName() + " to " + targetServer.getServerName()); hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(), targetServer.getServerName()); do { Thread.sleep(1); } while (cluster.getServerWith(regionInfo.getRegionName()) == originServerNum); // Put data: r2->v2 LOG.info("Loading r2 to v2 into " + tableName); putDataAndVerify(table, "r2", FAMILY, "v2", 2); TEST_UTIL.waitUntilAllRegionsAssigned(table.getName()); // Move region to origin server LOG.info("Moving " + regionInfo.getEncodedName() + " to " + originServer.getServerName()); hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(), originServer.getServerName()); do { Thread.sleep(1); } while (cluster.getServerWith(regionInfo.getRegionName()) == targetServerNum); // Put data: r3->v3 LOG.info("Loading r3 to v3 into " + tableName); putDataAndVerify(table, "r3", FAMILY, "v3", 3); // Kill target server LOG.info("Killing target server " + targetServer.getServerName()); targetServer.kill(); cluster.getRegionServerThreads().get(targetServerNum).join(); // Wait until finish processing of shutdown while (master.getServerManager().areDeadServersInProgress()) { Thread.sleep(5); } // Kill origin server LOG.info("Killing origin server " + targetServer.getServerName()); originServer.kill(); cluster.getRegionServerThreads().get(originServerNum).join(); // Put data: r4->v4 LOG.info("Loading r4 to v4 into " + tableName); putDataAndVerify(table, "r4", FAMILY, "v4", 4); } finally { if (hbaseAdmin != null) hbaseAdmin.close(); TEST_UTIL.shutdownMiniCluster(); } }
Example 20
Source File: TestMasterShutdown.java From hbase with Apache License 2.0 | 4 votes |
/** * Simple test of shutdown. * <p> * Starts with three masters. Tells the active master to shutdown the cluster. * Verifies that all masters are properly shutdown. */ @Test public void testMasterShutdown() throws Exception { // Create config to use for this cluster Configuration conf = HBaseConfiguration.create(); // Start the cluster try { htu = new HBaseTestingUtility(conf); StartMiniClusterOption option = StartMiniClusterOption.builder() .numMasters(3) .numRegionServers(1) .numDataNodes(1) .build(); final MiniHBaseCluster cluster = htu.startMiniCluster(option); // wait for all master thread to spawn and start their run loop. final long thirtySeconds = TimeUnit.SECONDS.toMillis(30); final long oneSecond = TimeUnit.SECONDS.toMillis(1); assertNotEquals(-1, htu.waitFor(thirtySeconds, oneSecond, () -> { final List<MasterThread> masterThreads = cluster.getMasterThreads(); return masterThreads != null && masterThreads.size() >= 3 && masterThreads.stream().allMatch(Thread::isAlive); })); // find the active master final HMaster active = cluster.getMaster(); assertNotNull(active); // make sure the other two are backup masters ClusterMetrics status = active.getClusterMetrics(); assertEquals(2, status.getBackupMasterNames().size()); // tell the active master to shutdown the cluster active.shutdown(); assertNotEquals(-1, htu.waitFor(thirtySeconds, oneSecond, () -> CollectionUtils.isEmpty(cluster.getLiveMasterThreads()))); assertNotEquals(-1, htu.waitFor(thirtySeconds, oneSecond, () -> CollectionUtils.isEmpty(cluster.getLiveRegionServerThreads()))); } finally { if (htu != null) { htu.shutdownMiniCluster(); htu = null; } } }