@Override public void notifyFinal(ReturnCode code, HRegionLocation loc, long heapSizeOfRow) { if (code == ReturnCode.INCLUDE) { long currentRequestSize = serverRequestSizes.containsKey(loc.getServerName()) ? serverRequestSizes.get(loc.getServerName()) : 0L; serverRequestSizes.put(loc.getServerName(), currentRequestSize + heapSizeOfRow); } } }
@Override public ReturnCode canTakeOperation(HRegionLocation loc, long heapSizeOfRow) { // Is it ok for limit of request size? long currentRequestSize = serverRequestSizes.containsKey(loc.getServerName()) ? serverRequestSizes.get(loc.getServerName()) : 0L; // accept at least one request if (currentRequestSize == 0 || currentRequestSize + heapSizeOfRow <= maxHeapSizePerRequest) { return ReturnCode.INCLUDE; } return ReturnCode.SKIP; }
@Override public ReturnCode canTakeOperation(HRegionLocation loc, long heapSizeOfRow) { long currentRows = serverRows.containsKey(loc.getServerName()) ? serverRows.get(loc.getServerName()) : 0L; // accept at least one row if (currentRows == 0 || currentRows < maxRowsPerRequest) { return ReturnCode.INCLUDE; } return ReturnCode.SKIP; }
@Override public void notifyFinal(ReturnCode code, HRegionLocation loc, long heapSizeOfRow) { if (code == ReturnCode.INCLUDE) { long currentRows = serverRows.containsKey(loc.getServerName()) ? serverRows.get(loc.getServerName()) : 0L; serverRows.put(loc.getServerName(), currentRows + 1); } } }
@Override public FastFailInterceptorContext prepare(RetryingCallable<?> callable, int tries) { if (callable instanceof RegionServerCallable) { RegionServerCallable<?, ?> retryingCallable = (RegionServerCallable<?, ?>) callable; server = retryingCallable.getLocation().getServerName(); } this.tries = tries; return this; } }
static boolean isGood(RegionLocations locs, int replicaId) { if (locs == null) { return false; } HRegionLocation loc = locs.getRegionLocation(replicaId); return loc != null && loc.getServerName() != null; } }
private void addToCachedServers(RegionLocations locations) { for (HRegionLocation loc : locations.getRegionLocations()) { if (loc != null) { cachedServers.add(loc.getServerName()); } } }
@Override public int compareTo(HRegionLocation o) { return serverName.compareTo(o.getServerName()); } }
private Set<ServerName> getRegionServersOfTable(RegionLocator regionLocator) throws IOException { Set<ServerName> tableServers = Sets.newHashSet(); for (HRegionLocation regionLocation : regionLocator.getAllRegionLocations()) { tableServers.add(regionLocation.getServerName()); } return tableServers; }
@Override public void notifyFinal(ReturnCode code, HRegionLocation loc, long heapSizeOfRow) { if (code == ReturnCode.INCLUDE) { regionsIncluded.add(loc.getRegionInfo()); serversIncluded.add(loc.getServerName()); } busyRegions.add(loc.getRegionInfo().getRegionName()); } }
@Override void add(Result r) { if (current == null) { return; } for (HRegionLocation loc : current.getRegionLocations()) { if (loc != null) { this.results.add(new Pair<>(loc.getRegion(), loc.getServerName())); } } } };
@Override public void throwable(Throwable t, boolean retrying) { if (location != null) { connection.updateCachedLocations(tableName, location.getRegionInfo().getRegionName(), row, t, location.getServerName()); } }
@Override public void prepare(boolean reload) throws IOException { // Use the location we were given in the constructor rather than go look it up. setStub(getConnection().getClient(this.location.getServerName())); }
@Override public void throwable(Throwable t, boolean retrying) { if (location != null) { getConnection().updateCachedLocations(tableName, location.getRegionInfo().getRegionName(), row, t, location.getServerName()); } }
public static HBaseProtos.RegionLocation toRegionLocation(HRegionLocation loc) { HBaseProtos.RegionLocation.Builder builder = HBaseProtos.RegionLocation.newBuilder(); builder.setRegionInfo(toRegionInfo(loc.getRegion())); if (loc.getServerName() != null) { builder.setServerName(toServerName(loc.getServerName())); } builder.setSeqNum(loc.getSeqNum()); return builder.build(); }
@Override public void perform() throws Exception { LOG.info("Performing action: Restart random RS holding table " + this.locator.getName()); List<HRegionLocation> locations = locator.getAllRegionLocations(); restartRs(locations.get(RandomUtils.nextInt(0, locations.size())).getServerName(), sleepTime); } }
@Override public ServerName getServerHoldingRegion(TableName tn, byte[] regionName) throws IOException { byte[] startKey = RegionInfo.getStartKey(regionName); HRegionLocation regionLoc = null; try (RegionLocator locator = connection.getRegionLocator(tn)) { regionLoc = locator.getRegionLocation(startKey, true); } if (regionLoc == null) { LOG.warn("Cannot find region server holding region " + Bytes.toStringBinary(regionName)); return null; } return regionLoc.getServerName(); }
private void assertLocEquals(byte[] startKey, byte[] endKey, ServerName serverName, HRegionLocation loc) { RegionInfo info = loc.getRegion(); assertEquals(TABLE_NAME, info.getTable()); assertArrayEquals(startKey, info.getStartKey()); assertArrayEquals(endKey, info.getEndKey()); assertEquals(serverName, loc.getServerName()); }
private void assertMetaRegionLocation(HRegionLocation loc, int replicaId) { RegionInfo region = loc.getRegion(); assertArrayEquals(HConstants.EMPTY_START_ROW, region.getStartKey()); assertArrayEquals(HConstants.EMPTY_END_ROW, region.getEndKey()); assertEquals(replicaId, region.getReplicaId()); ServerName expected = findRegionLocation(TableName.META_TABLE_NAME, region.getStartKey(), replicaId); assertEquals(expected, loc.getServerName()); }
private void assertRegionLocation(HRegionLocation loc, int index, int replicaId) { RegionInfo region = loc.getRegion(); byte[] startKey = getStartKey(index); assertArrayEquals(startKey, region.getStartKey()); assertArrayEquals(getEndKey(index), region.getEndKey()); assertEquals(replicaId, region.getReplicaId()); ServerName expected = findRegionLocation(TABLE_NAME, region.getStartKey(), replicaId); assertEquals(expected, loc.getServerName()); }