ServerName currServer = entry.getValue(); RegionInfo currRegion = entry.getKey(); if (rsGroupInfo.getTables().contains(currTable)) { assignments.putIfAbsent(currTable, new HashMap<>()); assignments.get(currTable).putIfAbsent(currServer, new ArrayList<>()); for(TableName tableName : rsGroupInfo.getTables()) { if(assignments.containsKey(tableName)) { result.put(tableName, new HashMap<>());
private synchronized void updateDefaultServers(SortedSet<Address> servers) throws IOException { RSGroupInfo info = rsGroupMap.get(RSGroupInfo.DEFAULT_GROUP); RSGroupInfo newInfo = new RSGroupInfo(info.getName(), servers, info.getTables()); HashMap<String, RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap); newGroupMap.put(newInfo.getName(), newInfo); flushConfig(newGroupMap); }
private synchronized Map<TableName, String> flushConfigTable(Map<String, RSGroupInfo> groupMap) throws IOException { Map<TableName, String> newTableMap = Maps.newHashMap(); List<Mutation> mutations = Lists.newArrayList(); // populate deletes for (String groupName : prevRSGroups) { if (!groupMap.containsKey(groupName)) { Delete d = new Delete(Bytes.toBytes(groupName)); mutations.add(d); } } // populate puts for (RSGroupInfo RSGroupInfo : groupMap.values()) { RSGroupProtos.RSGroupInfo proto = RSGroupProtobufUtil.toProtoGroupInfo(RSGroupInfo); Put p = new Put(Bytes.toBytes(RSGroupInfo.getName())); p.addColumn(META_FAMILY_BYTES, META_QUALIFIER_BYTES, proto.toByteArray()); mutations.add(p); for (TableName entry : RSGroupInfo.getTables()) { newTableMap.put(entry, RSGroupInfo.getName()); } } if (mutations.size() > 0) { multiMutate(mutations); } return newTableMap; }
static RSGroupProtos.RSGroupInfo toProtoGroupInfo(RSGroupInfo pojo) { List<HBaseProtos.TableName> tables = new ArrayList<>(pojo.getTables().size()); for(TableName arg: pojo.getTables()) { tables.add(ProtobufUtil.toProtoTableName(arg)); } List<HBaseProtos.ServerName> hostports = new ArrayList<>(pojo.getServers().size()); for(Address el: pojo.getServers()) { hostports.add(HBaseProtos.ServerName.newBuilder() .setHostName(el.getHostname()) .setPort(el.getPort()) .build()); } return RSGroupProtos.RSGroupInfo.newBuilder().setName(pojo.getName()) .addAllServers(hostports) .addAllTables(tables).build(); } }
private Map<String, RegionState> rsGroupGetRegionsInTransition(String groupName) throws IOException { Map<String, RegionState> rit = Maps.newTreeMap(); AssignmentManager am = master.getAssignmentManager(); for(TableName tableName : getRSGroupInfo(groupName).getTables()) { for(RegionInfo regionInfo: am.getRegionStates().getRegionsOfTable(tableName)) { RegionState state = am.getRegionStates().getRegionTransitionState(regionInfo); if(state != null) { rit.put(regionInfo.getEncodedName(), state); } } } return rit; }
if (srcGrp.getServers().size() <= servers.size() && srcGrp.getTables().size() > 0) { throw new ConstraintException("Cannot leave a RSGroup " + srcGrp.getName() + " that contains tables without servers to host them.");
if (srcGrp.getServers().size() <= servers.size() && srcGrp.getTables().size() > tables.size()) { throw new ConstraintException("Cannot leave a RSGroup " + srcGrp.getName() + " that contains tables without servers to host them.");
throw new ConstraintException("RSGroup " + name + " does not exist"); int tableCount = rsGroupInfo.getTables().size(); if (tableCount > 0) { throw new ConstraintException("RSGroup " + name + " has " + tableCount +
tables = rsGroupInfo.getTables().size(); totalTables += tables; double avgLoad = onlineServers == 0 ? 0 :
public void removeGroup(String groupName) throws IOException { RSGroupInfo groupInfo = rsGroupAdmin.getRSGroupInfo(groupName); rsGroupAdmin.moveTables(groupInfo.getTables(), RSGroupInfo.DEFAULT_GROUP); rsGroupAdmin.moveServers(groupInfo.getServers(), RSGroupInfo.DEFAULT_GROUP); rsGroupAdmin.removeRSGroup(groupName); }
public void deleteGroups() throws IOException { RSGroupAdmin groupAdmin = new RSGroupAdminClient(TEST_UTIL.getConnection()); for(RSGroupInfo group: groupAdmin.listRSGroups()) { if(!group.getName().equals(RSGroupInfo.DEFAULT_GROUP)) { groupAdmin.moveTables(group.getTables(), RSGroupInfo.DEFAULT_GROUP); groupAdmin.moveServers(group.getServers(), RSGroupInfo.DEFAULT_GROUP); groupAdmin.removeRSGroup(group.getName()); } } }
rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getTables(); assertFalse(DefaultTables.contains(tableNameA)); assertFalse(DefaultTables.contains(tableNameB)); Set<TableName> newGroupTables = rsGroupAdmin.getRSGroupInfo(newGroupName).getTables(); assertTrue(newGroupTables.contains(tableNameA)); assertTrue(newGroupTables.contains(tableNameB));
rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size(); int oldDefaultGroupTableSize = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getTables().size(); rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size()); Assert.assertEquals(oldDefaultGroupTableSize, rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getTables().size()); Assert.assertEquals(0, rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables().size()); rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getTables(); assertFalse(defaultTables.contains(tableName)); Set<TableName> newGroupTables = rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables(); assertTrue(newGroupTables.contains(tableName));
List<TableName> rsGroupTables = new ArrayList<>(); rsGroupServers.addAll(rsGroupInfo.getServers()); rsGroupTables.addAll(rsGroupInfo.getTables()); Collections.sort(rsGroupServers); rsGroupTables.sort((o1, o2) -> {
@Test public void testFailRemoveGroup() throws IOException, InterruptedException { int initNumGroups = rsGroupAdmin.listRSGroups().size(); addGroup("bar", 3); TEST_UTIL.createTable(tableName, Bytes.toBytes("f")); rsGroupAdmin.moveTables(Sets.newHashSet(tableName), "bar"); RSGroupInfo barGroup = rsGroupAdmin.getRSGroupInfo("bar"); // group is not empty therefore it should fail try { rsGroupAdmin.removeRSGroup(barGroup.getName()); fail("Expected remove group to fail"); } catch (IOException e) { } // group cannot lose all it's servers therefore it should fail try { rsGroupAdmin.moveServers(barGroup.getServers(), RSGroupInfo.DEFAULT_GROUP); fail("Expected move servers to fail"); } catch (IOException e) { } rsGroupAdmin.moveTables(barGroup.getTables(), RSGroupInfo.DEFAULT_GROUP); try { rsGroupAdmin.removeRSGroup(barGroup.getName()); fail("Expected move servers to fail"); } catch (IOException e) { } rsGroupAdmin.moveServers(barGroup.getServers(), RSGroupInfo.DEFAULT_GROUP); rsGroupAdmin.removeRSGroup(barGroup.getName()); Assert.assertEquals(initNumGroups, rsGroupAdmin.listRSGroups().size()); }
private synchronized void updateDefaultServers(SortedSet<Address> servers) throws IOException { RSGroupInfo info = rsGroupMap.get(RSGroupInfo.DEFAULT_GROUP); RSGroupInfo newInfo = new RSGroupInfo(info.getName(), servers, info.getTables()); HashMap<String, RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap); newGroupMap.put(newInfo.getName(), newInfo); flushConfig(newGroupMap); }