Java Code Examples for org.apache.hadoop.hbase.master.HMaster#getAssignmentManager()
The following examples show how to use
org.apache.hadoop.hbase.master.HMaster#getAssignmentManager() .
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: HBaseTestingUtility.java From hbase with Apache License 2.0 | 6 votes |
/** * Returns a {@link Predicate} for checking that there are no regions in transition in master */ public ExplainingPredicate<IOException> predicateNoRegionsInTransition() { return new ExplainingPredicate<IOException>() { @Override public String explainFailure() throws IOException { final RegionStates regionStates = getMiniHBaseCluster().getMaster() .getAssignmentManager().getRegionStates(); return "found in transition: " + regionStates.getRegionsInTransition().toString(); } @Override public boolean evaluate() throws IOException { HMaster master = getMiniHBaseCluster().getMaster(); if (master == null) return false; AssignmentManager am = master.getAssignmentManager(); if (am == null) return false; return !am.hasRegionsInTransition(); } }; }
Example 2
Source File: TestTransitRegionStateProcedure.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testRecoveryAndDoubleExecutionUnassignAndAssign() throws Exception { HMaster master = UTIL.getMiniHBaseCluster().getMaster(); MasterProcedureEnv env = master.getMasterProcedureExecutor().getEnvironment(); HRegion region = UTIL.getMiniHBaseCluster().getRegions(tableName).get(0); RegionInfo regionInfo = region.getRegionInfo(); long openSeqNum = region.getOpenSeqNum(); TransitRegionStateProcedure unassign = TransitRegionStateProcedure.unassign(env, regionInfo); testRecoveryAndDoubleExcution(unassign); AssignmentManager am = master.getAssignmentManager(); assertTrue(am.getRegionStates().getRegionState(regionInfo).isClosed()); TransitRegionStateProcedure assign = TransitRegionStateProcedure.assign(env, regionInfo, null); testRecoveryAndDoubleExcution(assign); HRegion region2 = UTIL.getMiniHBaseCluster().getRegions(tableName).get(0); long openSeqNum2 = region2.getOpenSeqNum(); // confirm that the region is successfully opened assertTrue(openSeqNum2 > openSeqNum); }
Example 3
Source File: TestReopenTableRegionsProcedureInfiniteLoop.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testInfiniteLoop() throws IOException { HMaster master = UTIL.getMiniHBaseCluster().getMaster(); AssignmentManager am = master.getAssignmentManager(); ProcedureExecutor<MasterProcedureEnv> exec = master.getMasterProcedureExecutor(); RegionInfo regionInfo = UTIL.getAdmin().getRegions(TABLE_NAME).get(0); RegionStateNode regionNode = am.getRegionStates().getRegionStateNode(regionInfo); long procId; ReopenTableRegionsProcedure proc = new ReopenTableRegionsProcedure(TABLE_NAME); regionNode.lock(); try { procId = exec.submitProcedure(proc); UTIL.waitFor(30000, () -> proc.hasLock()); TransitRegionStateProcedure trsp = TransitRegionStateProcedure.reopen(exec.getEnvironment(), regionInfo); regionNode.setProcedure(trsp); exec.submitProcedure(trsp); } finally { regionNode.unlock(); } UTIL.waitFor(60000, () -> exec.isFinished(procId)); }
Example 4
Source File: BaseTest.java From phoenix with Apache License 2.0 | 6 votes |
/** * Ensures each region of SYSTEM.CATALOG is on a different region server */ private static void moveRegion(HRegionInfo regionInfo, ServerName srcServerName, ServerName dstServerName) throws Exception { Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); HBaseTestingUtility util = getUtility(); MiniHBaseCluster cluster = util.getHBaseCluster(); HMaster master = cluster.getMaster(); AssignmentManager am = master.getAssignmentManager(); HRegionServer dstServer = util.getHBaseCluster().getRegionServer(dstServerName); HRegionServer srcServer = util.getHBaseCluster().getRegionServer(srcServerName); byte[] encodedRegionNameInBytes = regionInfo.getEncodedNameAsBytes(); admin.move(encodedRegionNameInBytes, Bytes.toBytes(dstServer.getServerName().getServerName())); while (dstServer.getOnlineRegion(regionInfo.getRegionName()) == null || dstServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes) || srcServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes)) { // wait for the move to be finished Thread.sleep(100); } }
Example 5
Source File: TestAsyncRegionAdminApi.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testAssignRegionAndUnassignRegion() throws Exception { createTableWithDefaultConf(tableName); // assign region. HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); AssignmentManager am = master.getAssignmentManager(); RegionInfo hri = am.getRegionStates().getRegionsOfTable(tableName).get(0); // assert region on server RegionStates regionStates = am.getRegionStates(); ServerName serverName = regionStates.getRegionServerOfRegion(hri); TEST_UTIL.assertRegionOnServer(hri, serverName, 200); assertTrue(regionStates.getRegionState(hri).isOpened()); // Region is assigned now. Let's assign it again. // Master should not abort, and region should stay assigned. try { admin.assign(hri.getRegionName()).get(); fail("Should fail when assigning an already onlined region"); } catch (ExecutionException e) { // Expected assertThat(e.getCause(), instanceOf(DoNotRetryRegionException.class)); } assertFalse(am.getRegionStates().getRegionStateNode(hri).isInTransition()); assertTrue(regionStates.getRegionState(hri).isOpened()); // unassign region admin.unassign(hri.getRegionName(), true).get(); assertFalse(am.getRegionStates().getRegionStateNode(hri).isInTransition()); assertTrue(regionStates.getRegionState(hri).isClosed()); }
Example 6
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 7
Source File: TestFailedMetaReplicaAssigment.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testFailedReplicaAssignment() throws InterruptedException { HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); // waiting for master to come up TEST_UTIL.waitFor(30000, () -> master.isInitialized()); AssignmentManager am = master.getAssignmentManager(); // showing one of the replicas got assigned RegionInfo metaReplicaHri = RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, 1); // we use assignAsync so we need to wait a bit TEST_UTIL.waitFor(30000, () -> { RegionStateNode metaReplicaRegionNode = am.getRegionStates().getOrCreateRegionStateNode(metaReplicaHri); return metaReplicaRegionNode.getRegionLocation() != null; }); // showing one of the replicas failed to be assigned RegionInfo metaReplicaHri2 = RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, 2); RegionStateNode metaReplicaRegionNode2 = am.getRegionStates().getOrCreateRegionStateNode(metaReplicaHri2); // wait for several seconds to make sure that it is not assigned for (int i = 0; i < 3; i++) { Thread.sleep(2000); assertNull(metaReplicaRegionNode2.getRegionLocation()); } // showing master is active and running assertFalse(master.isStopping()); assertFalse(master.isStopped()); assertTrue(master.isActiveMaster()); }
Example 8
Source File: TestAssignmentManagerUtil.java From hbase with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { UTIL.startMiniCluster(1); UTIL.getAdmin().balancerSwitch(false, true); UTIL.createTable(TableDescriptorBuilder.newBuilder(TABLE_NAME) .setColumnFamily(ColumnFamilyDescriptorBuilder.of("cf")) .setRegionReplication(REGION_REPLICATION).build(), new byte[][] { Bytes.toBytes(0) }); UTIL.waitTableAvailable(TABLE_NAME); HMaster master = UTIL.getMiniHBaseCluster().getMaster(); ENV = master.getMasterProcedureExecutor().getEnvironment(); AM = master.getAssignmentManager(); }
Example 9
Source File: TestTransitRegionStateProcedure.java From hbase with Apache License 2.0 | 5 votes |
private void testRecoveryAndDoubleExcution(TransitRegionStateProcedure proc) throws Exception { HMaster master = UTIL.getHBaseCluster().getMaster(); AssignmentManager am = master.getAssignmentManager(); RegionStateNode regionNode = am.getRegionStates().getRegionStateNode(proc.getRegion()); assertFalse(regionNode.isInTransition()); regionNode.setProcedure(proc); assertTrue(regionNode.isInTransition()); ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor(); ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true); long procId = procExec.submitProcedure(proc); MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId); regionNode = am.getRegionStates().getRegionStateNode(proc.getRegion()); assertFalse(regionNode.isInTransition()); }
Example 10
Source File: TestSCPGetRegionsRace.java From hbase with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { RegionInfo region = Iterables.getOnlyElement(UTIL.getMiniHBaseCluster().getRegions(NAME)).getRegionInfo(); HMaster master = UTIL.getMiniHBaseCluster().getMaster(); AssignmentManager am = master.getAssignmentManager(); RegionStateNode rsn = am.getRegionStates().getRegionStateNode(region); ServerName source = rsn.getRegionLocation(); ServerName dest = UTIL.getAdmin().getRegionServers().stream().filter(sn -> !sn.equals(source)).findAny().get(); ARRIVE_REPORT = new CountDownLatch(1); RESUME_REPORT = new CountDownLatch(1); Future<?> future = am.moveAsync(new RegionPlan(region, source, dest)); ARRIVE_REPORT.await(); ARRIVE_REPORT = null; // let's get procedure lock to stop the TRSP IdLock procExecutionLock = master.getMasterProcedureExecutor().getProcExecutionLock(); long procId = master.getProcedures().stream() .filter(p -> p instanceof RegionRemoteProcedureBase).findAny().get().getProcId(); IdLock.Entry lockEntry = procExecutionLock.getLockEntry(procId); RESUME_REPORT.countDown(); // kill the source region server ARRIVE_GET = new CountDownLatch(1); RESUME_GET = new CountDownLatch(1); UTIL.getMiniHBaseCluster().killRegionServer(source); // wait until we try to get the region list of the region server ARRIVE_GET.await(); ARRIVE_GET = null; // release the procedure lock and let the TRSP to finish procExecutionLock.releaseLockEntry(lockEntry); future.get(); // resume the SCP EXCLUDE_SERVERS.add(dest); RESUME_GET.countDown(); // wait until there are no SCPs and TRSPs UTIL.waitFor(60000, () -> master.getProcedures().stream().allMatch(p -> p.isFinished() || (!(p instanceof ServerCrashProcedure) && !(p instanceof TransitRegionStateProcedure)))); // assert the region is only on the dest server. HRegionServer rs = UTIL.getMiniHBaseCluster().getRegionServer(dest); assertNotNull(rs.getRegion(region.getEncodedName())); assertNull(UTIL.getOtherRegionServer(rs).getRegion(region.getEncodedName())); }
Example 11
Source File: PhoenixServerRpcIT.java From phoenix with Apache License 2.0 | 4 votes |
/** * Verifies that the given tables each have a single region and are on * different region servers. If they are on the same server moves tableName2 * to the other region server. */ private void ensureTablesOnDifferentRegionServers(String tableName1, String tableName2) throws Exception { byte[] table1 = Bytes.toBytes(tableName1); byte[] table2 = Bytes.toBytes(tableName2); Admin admin = driver.getConnectionQueryServices(getUrl(), TEST_PROPERTIES).getAdmin(); HBaseTestingUtility util = getUtility(); MiniHBaseCluster cluster = util.getHBaseCluster(); HMaster master = cluster.getMaster(); AssignmentManager am = master.getAssignmentManager(); // verify there is only a single region for data table List<RegionInfo> tableRegions = admin.getRegions(TableName.valueOf(table1)); assertEquals("Expected single region for " + table1, tableRegions.size(), 1); RegionInfo hri1 = tableRegions.get(0); // verify there is only a single region for index table tableRegions = admin.getRegions(TableName.valueOf(table2)); RegionInfo hri2 = tableRegions.get(0); assertEquals("Expected single region for " + table2, tableRegions.size(), 1); ServerName serverName1 = am.getRegionStates().getRegionServerOfRegion(hri1); ServerName serverName2 = am.getRegionStates().getRegionServerOfRegion(hri2); // if data table and index table are on same region server, move the index table to the other region server if (serverName1.equals(serverName2)) { HRegionServer server1 = util.getHBaseCluster().getRegionServer(0); HRegionServer server2 = util.getHBaseCluster().getRegionServer(1); HRegionServer dstServer = null; HRegionServer srcServer = null; if (server1.getServerName().equals(serverName2)) { dstServer = server2; srcServer = server1; } else { dstServer = server1; srcServer = server2; } byte[] encodedRegionNameInBytes = hri2.getEncodedNameAsBytes(); admin.move(encodedRegionNameInBytes, Bytes.toBytes(dstServer.getServerName().getServerName())); while (dstServer.getOnlineRegion(hri2.getRegionName()) == null || dstServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes) || srcServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes) || master.getAssignmentManager().getRegionStates().isRegionInTransition(hri2)) { // wait for the move to be finished Thread.sleep(1); } } hri1 = admin.getRegions(TableName.valueOf(table1)).get(0); serverName1 = am.getRegionStates().getRegionServerOfRegion(hri1); hri2 = admin.getRegions(TableName.valueOf(table2)).get(0); serverName2 = am.getRegionStates().getRegionServerOfRegion(hri2); // verify index and data tables are on different servers assertNotEquals("Tables " + tableName1 + " and " + tableName2 + " should be on different region servers", serverName1, serverName2); }