/** * Get the end key for display. Optionally hide the real end key. * @return the endkey */ public static byte[] getEndKeyForDisplay(RegionInfo ri, Configuration conf) { boolean displayKey = conf.getBoolean(DISPLAY_KEYS_KEY, true); if (displayKey) return ri.getEndKey(); return HIDDEN_END_KEY; }
@Override public byte[] getEndKey() { if (this.metaEntry != null) { return this.metaEntry.getEndKey(); } else if (this.hdfsEntry != null) { return this.hdfsEntry.hri.getEndKey(); } else { LOG.error("Entry " + this + " has no meta or hdfs region start key."); return null; } }
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)); }
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; }
static boolean noMoreResultsForScan(Scan scan, RegionInfo info) { if (isEmptyStopRow(info.getEndKey())) { return true; } if (isEmptyStopRow(scan.getStopRow())) { return false; } int c = Bytes.compareTo(info.getEndKey(), scan.getStopRow()); // 1. if our stop row is less than the endKey of the region // 2. if our stop row is equal to the endKey of the region and we do not include the stop row // for scan. return c > 0 || (c == 0 && !scan.includeStopRow()); }
private void completeWhenNoMoreResultsInRegion() { if (noMoreResultsForScan(scan, loc.getRegion())) { completeNoMoreResults(); } else { completeWithNextStartRow(loc.getRegion().getEndKey(), true); } }
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); }
void verifyTableRegions(Set<RegionInfo> regions) { log("Verifying " + regions.size() + " regions: " + regions); byte[][] startKeys = new byte[regions.size()][]; byte[][] endKeys = new byte[regions.size()][]; int i=0; for (RegionInfo region : regions) { startKeys[i] = region.getStartKey(); endKeys[i] = region.getEndKey(); i++; } Pair<byte[][], byte[][]> keys = new Pair<>(startKeys, endKeys); verifyStartEndKeys(keys); }
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { if (e.getEnvironment().getRegionInfo().getEndKey().length == 0) { throw new DoNotRetryRegionException("Inject Error"); } } }
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()); }
@Test public void testLocateBeforeLastRegion() throws IOException, InterruptedException, ExecutionException { createMultiRegionTable(); getDefaultRegionLocation(TABLE_NAME, SPLIT_KEYS[0], RegionLocateType.CURRENT, false).join(); HRegionLocation loc = getDefaultRegionLocation(TABLE_NAME, EMPTY_END_ROW, RegionLocateType.BEFORE, false).get(); // should locate to the last region assertArrayEquals(loc.getRegion().getEndKey(), EMPTY_END_ROW); }
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) + "'"); } }
protected final void splitRegion(RegionInfo regionInfo) throws IOException { byte[][] splitPoints = Bytes.split(regionInfo.getStartKey(), regionInfo.getEndKey(), 1); admin.split(regionInfo.getTable(), splitPoints[1]); }
public static RegionInfo cloneRegionInfo(TableName tableName, RegionInfo snapshotRegionInfo) { return RegionInfoBuilder.newBuilder(tableName) .setStartKey(snapshotRegionInfo.getStartKey()) .setEndKey(snapshotRegionInfo.getEndKey()) .setSplit(snapshotRegionInfo.isSplit()) .setRegionId(snapshotRegionInfo.getRegionId()) .setOffline(snapshotRegionInfo.isOffline()) .build(); }
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 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()); }
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()); }