private Map<HRegionInfo, HServerAddress> waitOnSplit(final HTable t) throws IOException { Map<HRegionInfo, HServerAddress> regions = t.getRegionsInfo(); int originalCount = regions.size(); for (int i = 0; i < TEST_UTIL.getConfiguration().getInt("hbase.test.retries", 30); i++) { Thread.currentThread(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } regions = t.getRegionsInfo(); if (regions.size() > originalCount) break; } return regions; }
protected void verifyRoundRobinDistribution(HTable ht, int expectedRegions) throws IOException { int numRS = ht.getConnection().getCurrentNrHRS(); Map<HRegionInfo,HServerAddress> regions = ht.getRegionsInfo(); Map<HServerAddress, List<HRegionInfo>> server2Regions = new HashMap<HServerAddress, List<HRegionInfo>>(); for (Map.Entry<HRegionInfo,HServerAddress> entry : regions.entrySet()) { HServerAddress server = entry.getValue(); List<HRegionInfo> regs = server2Regions.get(server); if (regs == null) { regs = new ArrayList<HRegionInfo>(); server2Regions.put(server, regs); } regs.add(entry.getKey()); } float average = (float) expectedRegions/numRS; int min = (int)Math.floor(average); int max = (int)Math.ceil(average); for (List<HRegionInfo> regionList : server2Regions.values()) { assertTrue(regionList.size() == min || regionList.size() == max); } }
/** verify region boundaries obtained from HTable.getStartEndKeys() */ void verifyRegionsUsingHTable() throws IOException { HTable table = null; try { //HTable.getStartEndKeys() table = new HTable(conf, tableName); Pair<byte[][], byte[][]> keys = table.getStartEndKeys(); verifyStartEndKeys(keys); //HTable.getRegionsInfo() Map<HRegionInfo, HServerAddress> regions = table.getRegionsInfo(); verifyTableRegions(regions.keySet()); } finally { IOUtils.closeQuietly(table); } }
@Test public void testMove() throws Exception { Map<HRegionInfo, HServerAddress> regions; HTable table = new HTable(TEST_UTIL.getConfiguration(), TEST_TABLE); try { regions = table.getRegionsInfo(); } finally { table.close(); } final Map.Entry<HRegionInfo, HServerAddress> firstRegion = regions.entrySet().iterator().next(); final ServerName server = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName(); PrivilegedExceptionAction action = new PrivilegedExceptionAction() { public Object run() throws Exception { ACCESS_CONTROLLER.preMove(ObserverContext.createAndPrepare(CP_ENV, null), firstRegion.getKey(), server, server); return null; } }; verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_OWNER); verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE); }
@Test public void testAssign() throws Exception { Map<HRegionInfo, HServerAddress> regions; HTable table = new HTable(TEST_UTIL.getConfiguration(), TEST_TABLE); try { regions = table.getRegionsInfo(); } finally { table.close(); } final Map.Entry<HRegionInfo, HServerAddress> firstRegion = regions.entrySet().iterator().next(); PrivilegedExceptionAction action = new PrivilegedExceptionAction() { public Object run() throws Exception { ACCESS_CONTROLLER.preAssign(ObserverContext.createAndPrepare(CP_ENV, null), firstRegion.getKey()); return null; } }; verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_OWNER); verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE); }
@Test public void testUnassign() throws Exception { Map<HRegionInfo, HServerAddress> regions; HTable table = new HTable(TEST_UTIL.getConfiguration(), TEST_TABLE); try { regions = table.getRegionsInfo(); } finally { table.close(); } final Map.Entry<HRegionInfo, HServerAddress> firstRegion = regions.entrySet().iterator().next(); PrivilegedExceptionAction action = new PrivilegedExceptionAction() { public Object run() throws Exception { ACCESS_CONTROLLER.preUnassign(ObserverContext.createAndPrepare(CP_ENV, null), firstRegion.getKey(), false); return null; } }; verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_OWNER); verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE); }
/** * Read from <code>in</code> and deserialize the regions information. * * <p>It behaves similarly as {@link #getRegionsInfo getRegionsInfo}, except * that it loads the region map from a {@link DataInput} object. * * <p>It is supposed to be followed immediately by {@link * #prewarmRegionCache prewarmRegionCache}. * * <p> * Please refer to {@link #prewarmRegionCache prewarmRegionCache} for usage. * * @param in {@link DataInput} object. * @return A map of HRegionInfo with its server address. * @throws IOException if an I/O exception occurs. */ public Map<HRegionInfo, HServerAddress> deserializeRegionInfo(DataInput in) throws IOException { final Map<HRegionInfo, HServerAddress> allRegions = new TreeMap<HRegionInfo, HServerAddress>(); // the first integer is expected to be the size of records int regionsCount = in.readInt(); for (int i = 0; i < regionsCount; ++i) { HRegionInfo hri = new HRegionInfo(); hri.readFields(in); HServerAddress hsa = new HServerAddress(); hsa.readFields(in); allRegions.put(hri, hsa); } return allRegions; }
static public AServerAddress hsaToASA(HServerAddress hsa) throws IOException { AServerAddress asa = new AServerAddress(); asa.hostname = new Utf8(hsa.getHostname()); asa.inetSocketAddress = new Utf8(hsa.getInetSocketAddress().toString()); asa.port = hsa.getPort(); return asa; }
static public AServerInfo hsiToASI(ServerName sn, HServerLoad hsl) throws IOException { AServerInfo asi = new AServerInfo(); asi.infoPort = -1; asi.load = hslToASL(hsl); asi.serverAddress = hsaToASA(new HServerAddress(sn.getHostname(), sn.getPort())); asi.serverName = new Utf8(sn.toString()); asi.startCode = sn.getStartcode(); return asi; }
@Override public void prewarmRegionCache(byte[] tableName, Map<HRegionInfo, HServerAddress> regions) { for (Map.Entry<HRegionInfo, HServerAddress> e : regions.entrySet()) { HServerAddress hsa = e.getValue(); if (hsa == null || hsa.getInetSocketAddress() == null) continue; cacheLocation(tableName, new HRegionLocation(e.getKey(), hsa.getHostname(), hsa.getPort())); } }
/** * Read from <code>in</code> and deserialize the regions information. * <p> * It behaves similarly as {@link #getRegionsInfo getRegionsInfo}, except that it loads the region * map from a {@link DataInput} object. * <p> * It is supposed to be followed immediately by {@link #prewarmRegionCache prewarmRegionCache}. * <p> * Please refer to {@link #prewarmRegionCache prewarmRegionCache} for usage. * @param in {@link DataInput} object. * @return A map of HRegionInfo with its server address. * @throws IOException if an I/O exception occurs. */ public Map<HRegionInfo, HServerAddress> deserializeRegionInfo(DataInput in) throws IOException { final Map<HRegionInfo, HServerAddress> allRegions = new TreeMap<HRegionInfo, HServerAddress>(); // the first integer is expected to be the size of records int regionsCount = in.readInt(); for (int i = 0; i < regionsCount; ++i) { HRegionInfo hri = new HRegionInfo(); hri.readFields(in); HServerAddress hsa = new HServerAddress(); hsa.readFields(in); allRegions.put(hri, hsa); } return allRegions; }
/** * @param address * @return HServerLoad if serverName is known else null * @deprecated Use {@link #getLoad(HServerAddress)} */ public HServerLoad getLoad(final HServerAddress address) { ServerName sn = new ServerName(address.toString(), ServerName.NON_STARTCODE); ServerName actual = ServerName.findServerWithSameHostnamePort(this.getOnlineServersList(), sn); return actual == null? null: getLoad(actual); }