Java Code Examples for org.apache.hadoop.hbase.MiniHBaseCluster#getRegionServer()
The following examples show how to use
org.apache.hadoop.hbase.MiniHBaseCluster#getRegionServer() .
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: WALRecoveryRegionPostOpenIT.java From phoenix with Apache License 2.0 | 6 votes |
private void moveIndexTableRegionIfSameRegionSErver(MiniHBaseCluster miniHBaseCluster) throws IOException, InterruptedException { List<HRegion> dataTableRegions = miniHBaseCluster.getRegions(Bytes.toBytes(DATA_TABLE_NAME)); assertEquals(1, dataTableRegions.size()); List<HRegion> indexTableRegions = miniHBaseCluster.getRegions(Bytes.toBytes(INDEX_TABLE_NAME)); assertEquals(1, indexTableRegions.size()); HRegion dataTableRegion=dataTableRegions.get(0); HRegion indexTableRegion=indexTableRegions.get(0); int dataTableRegionServerIndex = miniHBaseCluster.getServerWith(dataTableRegion.getRegionInfo().getRegionName()); int indexTableRegionServerIndex=miniHBaseCluster.getServerWith(indexTableRegion.getRegionInfo().getRegionName()); if(dataTableRegionServerIndex != indexTableRegionServerIndex) { return; } int newRegionServerIndex=0; while(newRegionServerIndex == indexTableRegionServerIndex) { newRegionServerIndex++; } HRegionServer newRegionServer = miniHBaseCluster.getRegionServer(newRegionServerIndex); this.moveRegionAndWait(miniHBaseCluster,indexTableRegion, newRegionServer); }
Example 2
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testRegionServerPort() { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HRegionServer regionServer = cluster.getRegionServer(0); String rsName = regionServer.getServerName().getHostname(); final int PORT = 16021; Configuration conf = TEST_UTIL.getConfiguration(); String originalPort = conf.get(HConstants.REGIONSERVER_PORT); conf.set(HConstants.REGIONSERVER_PORT, Integer.toString(PORT)); RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rsName, conf); assertEquals(PORT, rmBuilder.port); if (originalPort != null) { conf.set(HConstants.REGIONSERVER_PORT, originalPort); } }
Example 3
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 4
Source File: TestRegionServerCoprocessorExceptionWithAbort.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testExceptionDuringInitialization() throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); // Let's fail fast. conf.setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, true); conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, ""); TEST_UTIL.startMiniCluster(2); try { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); // Trigger one regionserver to fail as if it came up with a coprocessor // that fails during initialization final HRegionServer regionServer = cluster.getRegionServer(0); conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, FailedInitializationObserver.class.getName()); regionServer.getRegionServerCoprocessorHost().loadSystemCoprocessors(conf, CoprocessorHost.REGION_COPROCESSOR_CONF_KEY); TEST_UTIL.waitFor(10000, 1000, new Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return regionServer.isAborted(); } }); } finally { TEST_UTIL.shutdownMiniCluster(); } }
Example 5
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testWithAck() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HRegionServer regionServer = cluster.getRegionServer(0); String rsName = regionServer.getServerName().getAddress().toString(); int numRegions = regionServer.getNumberOfOnlineRegions(); RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).maxthreads(8); try (RegionMover rm = rmBuilder.build()) { LOG.info("Unloading " + regionServer.getServerName()); rm.unload(); assertEquals(0, regionServer.getNumberOfOnlineRegions()); LOG.info("Successfully Unloaded\nNow Loading"); rm.load(); assertEquals(numRegions, regionServer.getNumberOfOnlineRegions()); // Repeat the same load. It should be very fast because all regions are already moved. rm.load(); } }
Example 6
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 5 votes |
/** * To test that we successfully exclude a server from the unloading process We test for the number * of regions on Excluded server and also test that regions are unloaded successfully */ @Test public void testExclude() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); File excludeFile = new File(TEST_UTIL.getDataTestDir().toUri().getPath(), "exclude_file"); FileWriter fos = new FileWriter(excludeFile); HRegionServer excludeServer = cluster.getRegionServer(1); String excludeHostname = excludeServer.getServerName().getHostname(); int excludeServerPort = excludeServer.getServerName().getPort(); int regionsExcludeServer = excludeServer.getNumberOfOnlineRegions(); String excludeServerName = excludeHostname + ":" + Integer.toString(excludeServerPort); fos.write(excludeServerName); fos.close(); HRegionServer regionServer = cluster.getRegionServer(0); String rsName = regionServer.getServerName().getHostname(); int port = regionServer.getServerName().getPort(); String rs = rsName + ":" + Integer.toString(port); RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rs, TEST_UTIL.getConfiguration()) .ack(true).excludeFile(excludeFile.getCanonicalPath()); try (RegionMover rm = rmBuilder.build()) { rm.unload(); LOG.info("Unloading " + rs); assertEquals(0, regionServer.getNumberOfOnlineRegions()); assertEquals(regionsExcludeServer, cluster.getRegionServer(1).getNumberOfOnlineRegions()); LOG.info("Before:" + regionsExcludeServer + " After:" + cluster.getRegionServer(1).getNumberOfOnlineRegions()); } }
Example 7
Source File: CoprocessorHConnectionTableFactoryIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testCachedConnections() throws Exception { final String tableName = generateUniqueName(); final String index1Name = generateUniqueName(); final Connection conn = DriverManager.getConnection(getUrl()); final HBaseAdmin admin = getUtility().getHBaseAdmin(); final MiniHBaseCluster cluster = getUtility().getHBaseCluster(); final HRegionServer regionServer = cluster.getRegionServer(0); Configuration conf = admin.getConfiguration(); final int noOfOrgs = 20; final AtomicBoolean flag = new AtomicBoolean(); flag.set(false); // create table and indices String createTableSql = "CREATE TABLE " + tableName + "(org_id VARCHAR NOT NULL PRIMARY KEY, v1 INTEGER, v2 INTEGER, v3 INTEGER) VERSIONS=1 SPLIT ON ('" + ORG_PREFIX + "-" + noOfOrgs / 2 + "')"; conn.createStatement().execute(createTableSql); conn.createStatement().execute("CREATE INDEX " + index1Name + " ON " + tableName + "(v1)"); List<HRegionInfo> regions = admin.getTableRegions(TableName.valueOf(tableName)); final HRegionInfo regionInfo = regions.get(0); writeToTable(tableName, conn, noOfOrgs); int beforeRegionCloseCount = getActiveConnections(regionServer, conf); int regionsCount = admin.getOnlineRegions(regionServer.getServerName()).size(); admin.unassign(regionInfo.getEncodedNameAsBytes(), true); while(!(admin.getOnlineRegions(regionServer.getServerName()).size() < regionsCount)); int afterRegionCloseCount = getActiveConnections(regionServer, conf); assertTrue("Cached connections not closed when region closes: ", afterRegionCloseCount == beforeRegionCloseCount && afterRegionCloseCount > 0); }
Example 8
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testExcludeAndDecomServers() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); File excludeFile = new File(TEST_UTIL.getDataTestDir().toUri().getPath(), "exclude_file"); FileWriter fos = new FileWriter(excludeFile); HRegionServer excludeServer = cluster.getRegionServer(1); String excludeHostname = excludeServer.getServerName().getHostname(); int excludeServerPort = excludeServer.getServerName().getPort(); String excludeServerName = excludeHostname + ":" + Integer.toString(excludeServerPort); fos.write(excludeServerName); fos.close(); HRegionServer decomServer = cluster.getRegionServer(2); TEST_UTIL.getAdmin().decommissionRegionServers( Collections.singletonList(decomServer.getServerName()), false); waitForServerDecom(decomServer); HRegionServer regionServer = cluster.getRegionServer(0); String rsName = regionServer.getServerName().getHostname(); int port = regionServer.getServerName().getPort(); String sourceServer = rsName + ":" + Integer.toString(port); RegionMoverBuilder rmBuilder = new RegionMoverBuilder(sourceServer, TEST_UTIL.getConfiguration()) .ack(true) .excludeFile(excludeFile.getCanonicalPath()); try (RegionMover regionMover = rmBuilder.build()) { Assert.assertFalse(regionMover.unload()); } TEST_UTIL.getAdmin().recommissionRegionServer(decomServer.getServerName(), Collections.emptyList()); }
Example 9
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 5 votes |
/** * Test to unload a regionserver first and then load it using no Ack mode. */ @Test public void testWithoutAck() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HRegionServer regionServer = cluster.getRegionServer(0); String rsName = regionServer.getServerName().getAddress().toString(); int numRegions = regionServer.getNumberOfOnlineRegions(); RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(false); try (RegionMover rm = rmBuilder.build()) { LOG.info("Unloading " + regionServer.getServerName()); rm.unload(); TEST_UTIL.waitFor(30000, 1000, new Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return regionServer.getNumberOfOnlineRegions() == 0; } }); LOG.info("Successfully Unloaded\nNow Loading"); rm.load(); // In UT we only have 10 regions so it is not likely to fail, so here we check for all // regions, in the real production this may not be true. TEST_UTIL.waitFor(30000, 1000, new Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return regionServer.getNumberOfOnlineRegions() == numRegions; } }); } }
Example 10
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 11
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 12
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testDecomServerExclusionWithAck() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HRegionServer excludeServer = cluster.getRegionServer(1); List<HRegion> regions = excludeServer.getRegions(); int regionsExcludeServer = excludeServer.getNumberOfOnlineRegions(); TEST_UTIL.getAdmin().decommissionRegionServers( Collections.singletonList(excludeServer.getServerName()), false); waitForServerDecom(excludeServer); HRegionServer regionServer = cluster.getRegionServer(0); String rsName = regionServer.getServerName().getHostname(); int port = regionServer.getServerName().getPort(); String hostname = rsName + ":" + Integer.toString(port); RegionMoverBuilder rmBuilder = new RegionMoverBuilder(hostname, TEST_UTIL.getConfiguration()) .ack(true); int targetServerRegions = cluster.getRegionServer(2).getRegions().size(); int sourceServerRegions = regionServer.getRegions().size(); try (RegionMover regionMover = rmBuilder.build()) { Assert.assertTrue(regionMover.unload()); LOG.info("Unloading {}", hostname); assertEquals(0, regionServer.getNumberOfOnlineRegions()); assertEquals(regionsExcludeServer, cluster.getRegionServer(1).getNumberOfOnlineRegions()); LOG.info("Before:" + regionsExcludeServer + " After:" + cluster.getRegionServer(1).getNumberOfOnlineRegions()); List<HRegion> regionList = cluster.getRegionServer(1).getRegions(); int index = 0; for (HRegion hRegion : regionList) { Assert.assertEquals(hRegion, regions.get(index++)); } Assert.assertEquals(targetServerRegions + sourceServerRegions, cluster.getRegionServer(2).getNumberOfOnlineRegions()); Assert.assertTrue(regionMover.load()); } TEST_UTIL.getAdmin().recommissionRegionServer(excludeServer.getServerName(), Collections.emptyList()); }
Example 13
Source File: TestRegionMover.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testDecomServerExclusion() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HRegionServer excludeServer = cluster.getRegionServer(0); List<HRegion> regions = excludeServer.getRegions(); int regionsExcludeServer = excludeServer.getNumberOfOnlineRegions(); TEST_UTIL.getAdmin().decommissionRegionServers( Collections.singletonList(excludeServer.getServerName()), false); waitForServerDecom(excludeServer); HRegionServer sourceRegionServer = cluster.getRegionServer(1); String rsName = sourceRegionServer.getServerName().getHostname(); int port = sourceRegionServer.getServerName().getPort(); String hostname = rsName + ":" + Integer.toString(port); RegionMoverBuilder rmBuilder = new RegionMoverBuilder(hostname, TEST_UTIL.getConfiguration()).ack(false); int targetServerRegions = cluster.getRegionServer(2).getRegions().size(); int sourceServerRegions = sourceRegionServer.getRegions().size(); try (RegionMover regionMover = rmBuilder.build()) { Assert.assertTrue(regionMover.unload()); LOG.info("Unloading {}", hostname); assertEquals(0, sourceRegionServer.getNumberOfOnlineRegions()); assertEquals(regionsExcludeServer, cluster.getRegionServer(0).getNumberOfOnlineRegions()); LOG.info("Before:" + regionsExcludeServer + " After:" + cluster.getRegionServer(1).getNumberOfOnlineRegions()); List<HRegion> regionList = cluster.getRegionServer(0).getRegions(); int index = 0; for (HRegion hRegion : regionList) { Assert.assertEquals(hRegion, regions.get(index++)); } Assert.assertEquals(targetServerRegions + sourceServerRegions, cluster.getRegionServer(2).getNumberOfOnlineRegions()); Assert.assertTrue(regionMover.load()); } TEST_UTIL.getAdmin().recommissionRegionServer(excludeServer.getServerName(), Collections.emptyList()); }
Example 14
Source File: TestRegionPlacement.java From hbase with Apache License 2.0 | 4 votes |
/** * Verify all the online region servers has been updated to the * latest assignment plan * @param plan * @throws IOException */ private void verifyRegionServerUpdated(FavoredNodesPlan plan) throws IOException { // Verify all region servers contain the correct favored nodes information MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); for (int i = 0; i < SLAVES; i++) { HRegionServer rs = cluster.getRegionServer(i); for (Region region: rs.getRegions(TableName.valueOf("testRegionAssignment"))) { InetSocketAddress[] favoredSocketAddress = rs.getFavoredNodesForRegion( region.getRegionInfo().getEncodedName()); String regionName = region.getRegionInfo().getRegionNameAsString(); List<ServerName> favoredServerList = plan.getAssignmentMap().get(regionName); // All regions are supposed to have favored nodes, // except for hbase:meta and ROOT if (favoredServerList == null) { TableDescriptor desc = region.getTableDescriptor(); // Verify they are ROOT and hbase:meta regions since no favored nodes assertNull(favoredSocketAddress); assertTrue("User region " + region.getTableDescriptor().getTableName() + " should have favored nodes", desc.isMetaRegion()); } else { // For user region, the favored nodes in the region server should be // identical to favored nodes in the assignmentPlan assertTrue(favoredSocketAddress.length == favoredServerList.size()); assertTrue(favoredServerList.size() > 0); for (int j = 0; j < favoredServerList.size(); j++) { InetSocketAddress addrFromRS = favoredSocketAddress[j]; InetSocketAddress addrFromPlan = InetSocketAddress.createUnresolved( favoredServerList.get(j).getHostname(), favoredServerList.get(j).getPort()); assertNotNull(addrFromRS); assertNotNull(addrFromPlan); assertTrue("Region server " + rs.getServerName().getAddress() + " has the " + positions[j] + " for region " + region.getRegionInfo().getRegionNameAsString() + " is " + addrFromRS + " which is inconsistent with the plan " + addrFromPlan, addrFromRS.equals(addrFromPlan)); } } } } }
Example 15
Source File: AbstractTestWALReplay.java From hbase with Apache License 2.0 | 4 votes |
/** * * @throws Exception */ @Test public void testReplayEditsAfterRegionMovedWithMultiCF() throws Exception { final TableName tableName = TableName.valueOf("testReplayEditsAfterRegionMovedWithMultiCF"); byte[] family1 = Bytes.toBytes("cf1"); byte[] family2 = Bytes.toBytes("cf2"); byte[] qualifier = Bytes.toBytes("q"); byte[] value = Bytes.toBytes("testV"); byte[][] familys = { family1, family2 }; TEST_UTIL.createTable(tableName, familys); Table htable = TEST_UTIL.getConnection().getTable(tableName); Put put = new Put(Bytes.toBytes("r1")); put.addColumn(family1, qualifier, value); htable.put(put); ResultScanner resultScanner = htable.getScanner(new Scan()); int count = 0; while (resultScanner.next() != null) { count++; } resultScanner.close(); assertEquals(1, count); MiniHBaseCluster hbaseCluster = TEST_UTIL.getMiniHBaseCluster(); List<HRegion> regions = hbaseCluster.getRegions(tableName); assertEquals(1, regions.size()); // move region to another regionserver Region destRegion = regions.get(0); int originServerNum = hbaseCluster.getServerWith(destRegion.getRegionInfo().getRegionName()); assertTrue("Please start more than 1 regionserver", hbaseCluster.getRegionServerThreads().size() > 1); int destServerNum = 0; while (destServerNum == originServerNum) { destServerNum++; } HRegionServer originServer = hbaseCluster.getRegionServer(originServerNum); HRegionServer destServer = hbaseCluster.getRegionServer(destServerNum); // move region to destination regionserver TEST_UTIL.moveRegionAndWait(destRegion.getRegionInfo(), destServer.getServerName()); // delete the row Delete del = new Delete(Bytes.toBytes("r1")); htable.delete(del); resultScanner = htable.getScanner(new Scan()); count = 0; while (resultScanner.next() != null) { count++; } resultScanner.close(); assertEquals(0, count); // flush region and make major compaction HRegion region = (HRegion) destServer.getOnlineRegion(destRegion.getRegionInfo().getRegionName()); region.flush(true); // wait to complete major compaction for (HStore store : region.getStores()) { store.triggerMajorCompaction(); } region.compact(true); // move region to origin regionserver TEST_UTIL.moveRegionAndWait(destRegion.getRegionInfo(), originServer.getServerName()); // abort the origin regionserver originServer.abort("testing"); // see what we get Result result = htable.get(new Get(Bytes.toBytes("r1"))); if (result != null) { assertTrue("Row is deleted, but we get" + result.toString(), (result == null) || result.isEmpty()); } resultScanner.close(); }
Example 16
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 17
Source File: TestSeparateClientZKCluster.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testMetaMoveDuringClientZkClusterRestart() throws Exception { TableName tn = TableName.valueOf(name.getMethodName()); // create table Connection conn = TEST_UTIL.getConnection(); try (Admin admin = conn.getAdmin(); Table table = conn.getTable(tn)) { ColumnFamilyDescriptorBuilder cfDescBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family); TableDescriptorBuilder tableDescBuilder = TableDescriptorBuilder.newBuilder(tn).setColumnFamily(cfDescBuilder.build()); admin.createTable(tableDescBuilder.build()); // put some data Put put = new Put(row); put.addColumn(family, qualifier, value); table.put(put); // invalid connection cache conn.clearRegionLocationCache(); // stop client zk cluster clientZkCluster.shutdown(); // stop current meta server and confirm the server shutdown process // is not affected by client ZK crash MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); int metaServerId = cluster.getServerWithMeta(); HRegionServer metaServer = cluster.getRegionServer(metaServerId); metaServer.stop("Stop current RS holding meta region"); while (!metaServer.isShutDown()) { Thread.sleep(200); } // wait for meta region online AssignmentTestingUtil.waitForAssignment(cluster.getMaster().getAssignmentManager(), RegionInfoBuilder.FIRST_META_REGIONINFO); // wait some long time to make sure we will retry sync data to client ZK until data set Thread.sleep(10000); clientZkCluster.startup(clientZkDir); // new request should pass Get get = new Get(row); Result result = table.get(get); LOG.debug("Result: " + Bytes.toString(result.getValue(family, qualifier))); Assert.assertArrayEquals(value, result.getValue(family, qualifier)); } }
Example 18
Source File: TestReplicationSource.java From hbase with Apache License 2.0 | 4 votes |
/** * Tests that recovered queues are preserved on a regionserver shutdown. * See HBASE-18192 */ @Test public void testServerShutdownRecoveredQueue() throws Exception { try { // Ensure single-threaded WAL conf.set("hbase.wal.provider", "defaultProvider"); conf.setInt("replication.sleep.before.failover", 2000); // Introduces a delay in regionserver shutdown to give the race condition a chance to kick in. conf.set(HConstants.REGION_SERVER_IMPL, ShutdownDelayRegionServer.class.getName()); MiniHBaseCluster cluster = TEST_UTIL.startMiniCluster(2); TEST_UTIL_PEER.startMiniCluster(1); HRegionServer serverA = cluster.getRegionServer(0); final ReplicationSourceManager managerA = ((Replication) serverA.getReplicationSourceService()).getReplicationManager(); HRegionServer serverB = cluster.getRegionServer(1); final ReplicationSourceManager managerB = ((Replication) serverB.getReplicationSourceService()).getReplicationManager(); final Admin admin = TEST_UTIL.getAdmin(); final String peerId = "TestPeer"; admin.addReplicationPeer(peerId, ReplicationPeerConfig.newBuilder().setClusterKey(TEST_UTIL_PEER.getClusterKey()).build()); // Wait for replication sources to come up Waiter.waitFor(conf, 20000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return !(managerA.getSources().isEmpty() || managerB.getSources().isEmpty()); } }); // Disabling peer makes sure there is at least one log to claim when the server dies // The recovered queue will also stay there until the peer is disabled even if the // WALs it contains have no data. admin.disableReplicationPeer(peerId); // Stopping serverA // It's queues should be claimed by the only other alive server i.e. serverB cluster.stopRegionServer(serverA.getServerName()); Waiter.waitFor(conf, 20000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return managerB.getOldSources().size() == 1; } }); final HRegionServer serverC = cluster.startRegionServer().getRegionServer(); serverC.waitForServerOnline(); Waiter.waitFor(conf, 20000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return serverC.getReplicationSourceService() != null; } }); final ReplicationSourceManager managerC = ((Replication) serverC.getReplicationSourceService()).getReplicationManager(); // Sanity check assertEquals(0, managerC.getOldSources().size()); // Stopping serverB // Now serverC should have two recovered queues: // 1. The serverB's normal queue // 2. serverA's recovered queue on serverB cluster.stopRegionServer(serverB.getServerName()); Waiter.waitFor(conf, 20000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return managerC.getOldSources().size() == 2; } }); admin.enableReplicationPeer(peerId); Waiter.waitFor(conf, 20000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return managerC.getOldSources().size() == 0; } }); } finally { conf.set(HConstants.REGION_SERVER_IMPL, HRegionServer.class.getName()); } }