public static byte[] getRowForRegion(RegionInfo hri) { byte[] startKey = hri.getStartKey(); if (startKey.length == 0) { // empty row key is not allowed in mutations because it is both the start key and the end key // we return the smallest byte[] that is bigger (in lex comparison) than byte[0]. return new byte[] {0}; } return startKey; }
/** * Gets the start key from the specified region name. * @param regionName * @return Start key. * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 * Use {@link org.apache.hadoop.hbase.client.RegionInfo#getStartKey(byte[])}. */ @Deprecated public static byte[] getStartKey(final byte[] regionName) throws IOException { return RegionInfo.getStartKey(regionName); }
/** * Get the start key for display. Optionally hide the real start key. * @param ri * @param conf * @return the startkey */ public static byte[] getStartKeyForDisplay(RegionInfo ri, Configuration conf) { boolean displayKey = conf.getBoolean(DISPLAY_KEYS_KEY, true); if (displayKey) return ri.getStartKey(); return HIDDEN_START_KEY; }
@Override protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException { if (resp.getFirstPartCount() > 0) { map.put(region.getStartKey(), getPromotedValueFromProto(ci, resp, firstPartIndex)); } }
public static boolean rowIsInRange(RegionInfo info, final byte [] row, final int offset, final short length) { return ((info.getStartKey().length == 0) || (Bytes.compareTo(info.getStartKey(), 0, info.getStartKey().length, row, offset, length) <= 0)) && ((info.getEndKey().length == 0) || (Bytes.compareTo(info.getEndKey(), 0, info.getEndKey().length, row, offset, length) > 0)); }
@Override public Long answer(InvocationOnMock invocationOnMock) throws Throwable { Object [] args = invocationOnMock.getArguments(); byte [] regionId = (byte [])args[0]; byte[] startKey = RegionInfo.getStartKey(regionId); return SIZE_MAP.get(startKey); } });
public FlushRegionCallable(ClusterConnection connection, RpcControllerFactory rpcControllerFactory, RegionInfo regionInfo, boolean writeFlushWalMarker) { this(connection, rpcControllerFactory, regionInfo.getTable(), regionInfo.getRegionName(), regionInfo.getStartKey(), writeFlushWalMarker); }
static boolean noMoreResultsForReverseScan(Scan scan, RegionInfo info) { if (isEmptyStartRow(info.getStartKey())) { return true; } if (isEmptyStopRow(scan.getStopRow())) { return false; } // no need to test the inclusive of the stop row as the start key of a region is included in // the region. return Bytes.compareTo(info.getStartKey(), scan.getStopRow()) <= 0; }
@Override public HRegionLocation locateRegion(final byte[] regionName) throws IOException { RegionLocations locations = locateRegion(RegionInfo.getTable(regionName), RegionInfo.getStartKey(regionName), false, true); return locations == null ? null : locations.getRegionLocation(); }
private static List<RegionInfo> recreateRegionInfo(final List<RegionInfo> regions) { ArrayList<RegionInfo> newRegions = new ArrayList<>(regions.size()); for (RegionInfo hri: regions) { newRegions.add(RegionInfoBuilder.newBuilder(hri.getTable()) .setStartKey(hri.getStartKey()) .setEndKey(hri.getEndKey()) .build()); } return newRegions; }
private void checkTableRegions(final RegionStates stateMap, final TableName tableName, final int nregions) { List<RegionInfo> hris = stateMap.getRegionsOfTable(tableName, true); assertEquals(nregions, hris.size()); for (int i = 1; i < hris.size(); ++i) { long a = Bytes.toLong(hris.get(i - 1).getStartKey()); long b = Bytes.toLong(hris.get(i + 0).getStartKey()); assertEquals(b, a + 1); } }
private void completeReversedWhenNoMoreResultsInRegion() { if (noMoreResultsForReverseScan(scan, loc.getRegion())) { completeNoMoreResults(); } else { completeWithNextStartRow(loc.getRegion().getStartKey(), false); } }
private static Pair<byte[][], byte[][]> getStartEndKeys(List<RegionLocations> regions) { final byte[][] startKeyList = new byte[regions.size()][]; final byte[][] endKeyList = new byte[regions.size()][]; for (int i = 0; i < regions.size(); i++) { RegionInfo region = regions.get(i).getRegionLocation().getRegion(); startKeyList[i] = region.getStartKey(); endKeyList[i] = region.getEndKey(); } return new Pair<>(startKeyList, endKeyList); }
private ServerName[] getLocations(byte[][] startKeys) { ServerName[] serverNames = new ServerName[startKeys.length]; TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()) .forEach(rs -> { rs.getRegions(TABLE_NAME).forEach(r -> { serverNames[Arrays.binarySearch(startKeys, r.getRegionInfo().getStartKey(), Bytes::compareTo)] = rs.getServerName(); }); }); return serverNames; }
private boolean isValidRegion(RegionInfo hri) { // An offline split parent region should be excluded. if (hri.isOffline() && (hri.isSplit() || hri.isSplitParent())) { return false; } return PrivateCellUtil.overlappingKeys(scan.getStartRow(), scan.getStopRow(), hri.getStartKey(), hri.getEndKey()); }
private RegionInfoBuilder(RegionInfo regionInfo) { this.tableName = regionInfo.getTable(); this.startKey = regionInfo.getStartKey(); this.endKey = regionInfo.getEndKey(); this.offLine = regionInfo.isOffline(); this.split = regionInfo.isSplit(); this.regionId = regionInfo.getRegionId(); this.replicaId = regionInfo.getReplicaId(); this.regionName = regionInfo.getRegionName(); this.encodedName = regionInfo.getEncodedName(); }
/** Make sure this is a valid row for the HRegion */ void checkRow(byte[] row, String op) throws IOException { if (!rowIsInRange(getRegionInfo(), row)) { throw new WrongRegionException("Requested row out of range for " + op + " on HRegion " + this + ", startKey='" + Bytes.toStringBinary(getRegionInfo().getStartKey()) + "', getEndKey()='" + Bytes.toStringBinary(getRegionInfo().getEndKey()) + "', row='" + Bytes.toStringBinary(row) + "'"); } }
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 HRegionInfo convert(RegionInfo ri) { HRegionInfo hri = new HRegionInfo( ri.getTable(), ri.getStartKey(), ri.getEndKey(), ri.isSplit(), ri.getRegionId()); hri.setOffline(ri.isOffline()); return hri; } }
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()); }