@Override public RSGroupInfo getRSGroupInfoOfTable(TableName tableName) throws IOException { // We are reading across two Maps in the below with out synchronizing across // them; should be safe most of the time. String groupName = rsGroupInfoManager.getRSGroupOfTable(tableName); return groupName == null? null: rsGroupInfoManager.getRSGroup(groupName); }
protected static RSGroupInfoManager getMockedGroupInfoManager() throws IOException { RSGroupInfoManager gm = Mockito.mock(RSGroupInfoManager.class); Mockito.when(gm.getRSGroup(Mockito.any())).thenAnswer(new Answer<RSGroupInfo>() { @Override public RSGroupInfo answer(InvocationOnMock invocation) throws Throwable { return groupMap.get(invocation.getArgument(0)); } }); Mockito.when(gm.listRSGroups()).thenReturn( Lists.newLinkedList(groupMap.values())); Mockito.when(gm.isOnline()).thenReturn(true); Mockito.when(gm.getRSGroupOfTable(Mockito.any())) .thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { return tableMap.get(invocation.getArgument(0)); } }); return gm; }
RSGroupInfo destGroup = rsGroupInfoManager.getRSGroup(targetGroup); if(destGroup == null) { throw new ConstraintException("Target " + targetGroup + " RSGroup does not exist."); String srcGroup = rsGroupInfoManager.getRSGroupOfTable(table); if(srcGroup != null && srcGroup.equals(targetGroup)) { throw new ConstraintException( rsGroupInfoManager.moveTables(tables, targetGroup);
RegionInfo regionInfo = region.getKey(); ServerName assignedServer = region.getValue(); String groupName = rsGroupInfoManager.getRSGroupOfTable(regionInfo.getTable()); if (groupName == null) { LOG.info("Group not found for table " + regionInfo.getTable() + ", using default"); groupName = RSGroupInfo.DEFAULT_GROUP; RSGroupInfo info = rsGroupInfoManager.getRSGroup(groupName); if (assignedServer == null) { LOG.debug("There is no assigned server for {}", region); continue; RSGroupInfo otherInfo = rsGroupInfoManager.getRSGroupOfServer(assignedServer.getAddress()); if (info == null && otherInfo == null) { LOG.warn("Couldn't obtain rs group information for {} on {}", region, assignedServer);
RSGroupInfo rsGroupInfo = rsGroupInfoManager.getRSGroup(name); if (rsGroupInfo == null) { throw new ConstraintException("RSGroup " + name + " does not exist"); rsGroupInfoManager.removeRSGroup(name);
RSGroupInfo tmpSrcGrp = rsGroupInfoManager.getRSGroupOfServer(firstServer); if (tmpSrcGrp == null) { String tmpGroup = rsGroupInfoManager.getRSGroupOfServer(server).getName(); if (!tmpGroup.equals(srcGrp.getName())) { throw new ConstraintException("Move server request should only come from one source " + String tmpGroup = rsGroupInfoManager.getRSGroupOfTable(table); if (!tmpGroup.equals(srcGrp.getName())) { throw new ConstraintException("Move table request should only come from one source " +
@Override public List<RSGroupInfo> listRSGroups() throws IOException { return rsGroupInfoManager.listRSGroups(); }
protected TableName getTableName(ServerName sn) throws IOException { TableName tableName = null; RSGroupInfoManager gm = getMockedGroupInfoManager(); RSGroupInfo groupOfServer = null; for(RSGroupInfo gInfo : gm.listRSGroups()){ if(gInfo.containsServer(sn.getAddress())){ groupOfServer = gInfo; break; } } for(TableDescriptor desc : tableDescs){ if(gm.getRSGroupOfTable(desc.getTableName()).endsWith(groupOfServer.getName())){ tableName = desc.getTableName(); } } return tableName; } }
.getMasterCoprocessorHost().findCoprocessor(RSGroupAdminEndpoint.class).getGroupInfoManager(); assertFalse(groupMgr.isOnline()); assertEquals(newGroup, groupMgr.getRSGroupOfTable(RSGroupInfoManager.RSGROUP_TABLE_NAME)); assertEquals(RSGroupInfo.DEFAULT_GROUP, groupMgr.getRSGroupOfTable(failoverTable));
RSGroupInfo srcGrp = rsGroupInfoManager.getRSGroupOfServer(firstServer); if (srcGrp == null) { String tmpGroup = rsGroupInfoManager.getRSGroupOfServer(server).getName(); if (!tmpGroup.equals(srcGrp.getName())) { throw new ConstraintException("Move server request should only come from one source " + Set<Address> movedServers = rsGroupInfoManager.moveServers(servers, srcGrp.getName(), targetGroupName); List<Address> editableMovedServers = Lists.newArrayList(movedServers);
@Override public RSGroupInfo getRSGroupInfo(String groupName) throws IOException { return rsGroupInfoManager.getRSGroup(groupName); }
public boolean isOnline() { if (this.rsGroupInfoManager == null) { return false; } return this.rsGroupInfoManager.isOnline(); }
@Test public void testMisplacedRegions() throws Exception { final TableName tableName = TableName.valueOf(tablePrefix + "_testMisplacedRegions"); LOG.info("testMisplacedRegions"); final RSGroupInfo RSGroupInfo = addGroup("testMisplacedRegions", 1); TEST_UTIL.createMultiRegionTable(tableName, new byte[] { 'f' }, 15); TEST_UTIL.waitUntilAllRegionsAssigned(tableName); rsGroupAdminEndpoint.getGroupInfoManager().moveTables(Sets.newHashSet(tableName), RSGroupInfo.getName()); admin.balancerSwitch(true, true); assertTrue(rsGroupAdmin.balanceRSGroup(RSGroupInfo.getName())); admin.balancerSwitch(false, true); assertTrue(observer.preBalanceRSGroupCalled); assertTrue(observer.postBalanceRSGroupCalled); TEST_UTIL.waitFor(60000, new Predicate<Exception>() { @Override public boolean evaluate() throws Exception { ServerName serverName = ServerName.valueOf(RSGroupInfo.getServers().iterator().next().toString(), 1); return admin.getConnection().getAdmin().getRegions(serverName).size() == 15; } }); }
@Override public void addRSGroup(String name) throws IOException { rsGroupInfoManager.addRSGroup(new RSGroupInfo(name)); }
@Override public RSGroupInfo getRSGroupOfServer(Address hostPort) throws IOException { return rsGroupInfoManager.getRSGroupOfServer(hostPort); }
@Override public void moveServersAndTables(Set<Address> servers, Set<TableName> tables, String targetGroup) throws IOException { if (servers == null || servers.isEmpty()) { throw new ConstraintException("The list of servers to move cannot be null or empty."); } if (tables == null || tables.isEmpty()) { throw new ConstraintException("The list of tables to move cannot be null or empty."); } //check target group getAndCheckRSGroupInfo(targetGroup); // Hold a lock on the manager instance while moving servers and tables to prevent // another writer changing our state while we are working. synchronized (rsGroupInfoManager) { //check servers and tables status checkServersAndTables(servers, tables, targetGroup); //Move servers and tables to a new group. String srcGroup = getRSGroupOfServer(servers.iterator().next()).getName(); rsGroupInfoManager.moveServersAndTables(servers, tables, srcGroup, targetGroup); //move regions which should not belong to these tables moveRegionsFromServers(servers, tables, targetGroup); //move regions which should belong to these servers moveRegionsToServers(servers, tables, targetGroup); } LOG.info("Move servers and tables done. Severs :" + servers + " , Tables : " + tables + " => " + targetGroup); }
@VisibleForTesting public Set<RegionInfo> getMisplacedRegions( Map<RegionInfo, ServerName> regions) throws IOException { Set<RegionInfo> misplacedRegions = new HashSet<>(); for(Map.Entry<RegionInfo, ServerName> region : regions.entrySet()) { RegionInfo regionInfo = region.getKey(); ServerName assignedServer = region.getValue(); RSGroupInfo info = rsGroupInfoManager.getRSGroup(rsGroupInfoManager. getRSGroupOfTable(regionInfo.getTable())); if (assignedServer == null) { LOG.debug("There is no assigned server for {}", region); continue; } RSGroupInfo otherInfo = rsGroupInfoManager.getRSGroupOfServer(assignedServer.getAddress()); if (info == null && otherInfo == null) { LOG.warn("Couldn't obtain rs group information for {} on {}", region, assignedServer); continue; } if ((info == null || !info.containsServer(assignedServer.getAddress()))) { LOG.debug("Found misplaced region: " + regionInfo.getRegionNameAsString() + " on server: " + assignedServer + " found in group: " + otherInfo + " outside of group: " + (info == null ? "UNKNOWN" : info.getName())); misplacedRegions.add(regionInfo); } } return misplacedRegions; }
RSGroupInfo rsGroupInfo = rsGroupInfoManager.getRSGroup(name); if (rsGroupInfo == null) { throw new ConstraintException("RSGroup " + name + " does not exist"); rsGroupInfoManager.removeRSGroup(name);
RSGroupInfo tmpSrcGrp = rsGroupInfoManager.getRSGroupOfServer(firstServer); if (tmpSrcGrp == null) { String tmpGroup = rsGroupInfoManager.getRSGroupOfServer(server).getName(); if (!tmpGroup.equals(srcGrp.getName())) { throw new ConstraintException("Move server request should only come from one source " + String tmpGroup = rsGroupInfoManager.getRSGroupOfTable(table); if (!tmpGroup.equals(srcGrp.getName())) { throw new ConstraintException("Move table request should only come from one source " +
for (RSGroupInfo rsgroup : rsGroupInfoManager.listRSGroups()) { Map<ServerName, List<RegionInfo>> groupClusterState = new HashMap<>(); Map<TableName, Map<ServerName, List<RegionInfo>>> groupClusterLoad = new HashMap<>();