Java Code Examples for org.apache.hadoop.hbase.HRegionInfo#getEndKey()

The following examples show how to use org.apache.hadoop.hbase.HRegionInfo#getEndKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
public static boolean isReallyEmptyRegion(HConnection connection,
    String tableName, HRegionInfo regionInfo) throws IOException {
    boolean emptyRegion = false;
    // verify really empty region by scanning records
    try (HTableInterface table = connection.getTable(tableName)) {
        Scan scan = new Scan(regionInfo.getStartKey(), regionInfo.getEndKey());
        FilterList filterList = new FilterList();
        filterList.addFilter(new KeyOnlyFilter());
        filterList.addFilter(new FirstKeyOnlyFilter());
        scan.setFilter(filterList);
        scan.setCacheBlocks(false);
        scan.setSmall(true);
        scan.setCaching(1);

        try (ResultScanner scanner = table.getScanner(scan)) {
            if (scanner.next() == null) emptyRegion = true;
        }
    }
    return emptyRegion;
}
 
Example 2
Source File: Merge.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
private boolean isRegionBoundaryOfPhoenixSaltingTable(HRegionInfo regionInfo) {
    byte[] endKey = regionInfo.getEndKey();
    boolean boundaryRegionForPhoenix = true;

    if (endKey.length > 0) {
        for (int i = 1, limit = endKey.length; i < limit; i++) {
            if (endKey[i] != 0) {
                boundaryRegionForPhoenix = false;
                break;
            }
        }
    }

    if (boundaryRegionForPhoenix) {
        Util.printVerboseMessage(args, regionInfo.getEncodedName() + " is boundary region of phoenix : "
                + Bytes.toStringBinary(regionInfo.getStartKey()) + " ~ " + Bytes.toStringBinary(regionInfo.getEndKey()));
    }

    return boundaryRegionForPhoenix;
}
 
Example 3
Source File: Merge.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
private boolean isRegionBoundaryOfPhoenixSaltingTable(HRegionInfo regionInfo) {
    byte[] endKey = regionInfo.getEndKey();
    boolean boundaryRegionForPhoenix = true;

    if (endKey.length > 0) {
        for (int i = 1, limit = endKey.length; i < limit; i++) {
            if (endKey[i] != 0) {
                boundaryRegionForPhoenix = false;
                break;
            }
        }
    }

    if (boundaryRegionForPhoenix) {
        Util.printVerboseMessage(args, regionInfo.getEncodedName() + " is boundary region of phoenix : "
                + Bytes.toStringBinary(regionInfo.getStartKey()) + " ~ " + Bytes.toStringBinary(regionInfo.getEndKey()));
    }

    return boundaryRegionForPhoenix;
}
 
Example 4
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
public static boolean isReallyEmptyRegion(HConnection connection,
    String tableName, HRegionInfo regionInfo) throws IOException {
    boolean emptyRegion = false;
    // verify really empty region by scanning records
    try (HTableInterface table = connection.getTable(tableName)) {
        Scan scan = new Scan(regionInfo.getStartKey(), regionInfo.getEndKey());
        FilterList filterList = new FilterList();
        filterList.addFilter(new KeyOnlyFilter());
        filterList.addFilter(new FirstKeyOnlyFilter());
        scan.setFilter(filterList);
        scan.setCacheBlocks(false);
        scan.setSmall(true);
        scan.setCaching(1);

        try (ResultScanner scanner = table.getScanner(scan)) {
            if (scanner.next() == null) emptyRegion = true;
        }
    }
    return emptyRegion;
}
 
Example 5
Source File: Merge.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
private boolean isRegionBoundaryOfPhoenixSaltingTable(HRegionInfo regionInfo) {
    byte[] endKey = regionInfo.getEndKey();
    boolean boundaryRegionForPhoenix = true;

    if (endKey.length > 0) {
        for (int i = 1, limit = endKey.length; i < limit; i++) {
            if (endKey[i] != 0) {
                boundaryRegionForPhoenix = false;
                break;
            }
        }
    }

    if (boundaryRegionForPhoenix) {
        Util.printVerboseMessage(args, regionInfo.getEncodedName() + " is boundary region of phoenix : "
                + Bytes.toStringBinary(regionInfo.getStartKey()) + " ~ " + Bytes.toStringBinary(regionInfo.getEndKey()));
    }

    return boundaryRegionForPhoenix;
}
 
Example 6
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
public static boolean isReallyEmptyRegion(HConnection connection,
    String tableName, HRegionInfo regionInfo) throws IOException {
    boolean emptyRegion = false;
    // verify really empty region by scanning records
    try (HTableInterface table = connection.getTable(tableName)) {
        Scan scan = new Scan(regionInfo.getStartKey(), regionInfo.getEndKey());
        FilterList filterList = new FilterList();
        filterList.addFilter(new KeyOnlyFilter());
        filterList.addFilter(new FirstKeyOnlyFilter());
        scan.setFilter(filterList);
        scan.setCacheBlocks(false);
        scan.setSmall(true);
        scan.setCaching(1);

        try (ResultScanner scanner = table.getScanner(scan)) {
            if (scanner.next() == null) emptyRegion = true;
        }
    }
    return emptyRegion;
}
 
Example 7
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
public static boolean isReallyEmptyRegion(HConnection connection,
    String tableName, HRegionInfo regionInfo) throws IOException {
    boolean emptyRegion = false;
    // verify really empty region by scanning records
    try (HTableInterface table = connection.getTable(tableName)) {
        Scan scan = new Scan(regionInfo.getStartKey(), regionInfo.getEndKey());
        FilterList filterList = new FilterList();
        filterList.addFilter(new KeyOnlyFilter());
        filterList.addFilter(new FirstKeyOnlyFilter());
        scan.setFilter(filterList);
        scan.setCacheBlocks(false);
        scan.setSmall(true);
        scan.setCaching(1);

        try (ResultScanner scanner = table.getScanner(scan)) {
            if (scanner.next() == null) emptyRegion = true;
        }
    }
    return emptyRegion;
}
 
Example 8
Source File: Merge.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
private boolean isRegionBoundaryOfPhoenixSaltingTable(HRegionInfo regionInfo) {
    byte[] endKey = regionInfo.getEndKey();
    boolean boundaryRegionForPhoenix = true;

    if (endKey.length > 0) {
        for (int i = 1, limit = endKey.length; i < limit; i++) {
            if (endKey[i] != 0) {
                boundaryRegionForPhoenix = false;
                break;
            }
        }
    }

    if (boundaryRegionForPhoenix) {
        Util.printVerboseMessage(args, regionInfo.getEncodedName() + " is boundary region of phoenix : "
                + Bytes.toStringBinary(regionInfo.getStartKey()) + " ~ " + Bytes.toStringBinary(regionInfo.getEndKey()));
    }

    return boundaryRegionForPhoenix;
}
 
Example 9
Source File: Merge.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
private boolean isRegionBoundaryOfPhoenixSaltingTable(HRegionInfo regionInfo) {
    byte[] endKey = regionInfo.getEndKey();
    boolean boundaryRegionForPhoenix = true;

    if (endKey.length > 0) {
        for (int i = 1, limit = endKey.length; i < limit; i++) {
            if (endKey[i] != 0) {
                boundaryRegionForPhoenix = false;
                break;
            }
        }
    }

    if (boundaryRegionForPhoenix) {
        Util.printVerboseMessage(args, regionInfo.getEncodedName() + " is boundary region of phoenix : "
                + Bytes.toStringBinary(regionInfo.getStartKey()) + " ~ " + Bytes.toStringBinary(regionInfo.getEndKey()));
    }

    return boundaryRegionForPhoenix;
}
 
Example 10
Source File: IndexSplitTransaction.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Does checks on split inputs.
 * @return <code>true</code> if the region is splittable else
 * <code>false</code> if it is not (e.g. its already closed, etc.).
 */
public boolean prepare() {
  if (!this.parent.isSplittable()) return false;
  // Split key can be null if this region is unsplittable; i.e. has refs.
  if (this.splitrow == null) return false;
  HRegionInfo hri = this.parent.getRegionInfo();
  parent.prepareToSplit();
  // Check splitrow.
  byte [] startKey = hri.getStartKey();
  byte [] endKey = hri.getEndKey();
  if (Bytes.equals(startKey, splitrow) ||
      !this.parent.getRegionInfo().containsRow(splitrow)) {
    LOG.info("Split row is not inside region key range or is equal to " +
        "startkey: " + Bytes.toStringBinary(this.splitrow));
    return false;
  }
  long rid = getDaughterRegionIdTimestamp(hri);
  this.hri_a = new HRegionInfo(hri.getTable(), startKey, this.splitrow, false, rid);
  this.hri_b = new HRegionInfo(hri.getTable(), this.splitrow, endKey, false, rid);
  return true;
}
 
Example 11
Source File: HBaseSplitsProvider.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected static void binFullRange(
    final Map<HRegionLocation, Map<HRegionInfo, List<ByteArrayRange>>> binnedRanges,
    final RegionLocator regionLocator) throws IOException {

  final List<HRegionLocation> locations = regionLocator.getAllRegionLocations();

  for (final HRegionLocation location : locations) {
    Map<HRegionInfo, List<ByteArrayRange>> regionInfoMap = binnedRanges.get(location);
    if (regionInfoMap == null) {
      regionInfoMap = new HashMap<>();
      binnedRanges.put(location, regionInfoMap);
    }

    final HRegionInfo regionInfo = location.getRegionInfo();
    List<ByteArrayRange> rangeList = regionInfoMap.get(regionInfo);
    if (rangeList == null) {
      rangeList = new ArrayList<>();
      regionInfoMap.put(regionInfo, rangeList);
    }

    final ByteArrayRange regionRange =
        new ByteArrayRange(regionInfo.getStartKey(), regionInfo.getEndKey());
    rangeList.add(regionRange);
  }
}
 
Example 12
Source File: HBaseSplitsProvider.java    From geowave with Apache License 2.0 4 votes vote down vote up
protected static List<ByteArrayRange> binRanges(
    final List<ByteArrayRange> inputRanges,
    final Map<HRegionLocation, Map<HRegionInfo, List<ByteArrayRange>>> binnedRanges,
    final RegionLocator regionLocator) throws IOException {

  // Loop through ranges, getting RegionLocation and RegionInfo for
  // startKey, clipping range by that regionInfo's extent, and leaving
  // remainder in the List to be region'd
  final ListIterator<ByteArrayRange> i = inputRanges.listIterator();
  while (i.hasNext()) {
    final ByteArrayRange range = i.next();
    final byte[] startKey = range == null ? HConstants.EMPTY_BYTE_ARRAY : range.getStart();
    final byte[] endKey = range == null ? HConstants.EMPTY_BYTE_ARRAY : range.getEnd();

    final HRegionLocation location = regionLocator.getRegionLocation(startKey);

    Map<HRegionInfo, List<ByteArrayRange>> regionInfoMap = binnedRanges.get(location);
    if (regionInfoMap == null) {
      regionInfoMap = new HashMap<>();
      binnedRanges.put(location, regionInfoMap);
    }

    final HRegionInfo regionInfo = location.getRegionInfo();
    List<ByteArrayRange> rangeList = regionInfoMap.get(regionInfo);
    if (rangeList == null) {
      rangeList = new ArrayList<>();
      regionInfoMap.put(regionInfo, rangeList);
    }

    // Check if region contains range or if it's the last range
    if ((endKey == HConstants.EMPTY_BYTE_ARRAY) || regionInfo.containsRange(startKey, endKey)) {
      rangeList.add(range);
      i.remove();
    } else {
      final ByteArrayRange thisRange = new ByteArrayRange(startKey, endKey);
      final ByteArrayRange regionRange =
          new ByteArrayRange(regionInfo.getStartKey(), regionInfo.getEndKey());

      final ByteArrayRange overlappingRange = thisRange.intersection(regionRange);

      rangeList.add(new ByteArrayRange(overlappingRange.getStart(), overlappingRange.getEnd()));
      i.remove();

      i.add(new ByteArrayRange(regionInfo.getEndKey(), endKey));
    }
  }
  // the underlying assumption is that by the end of this any input range
  // at least has the partition key portion and is the same partition key
  // for start and end keys on the range, because thats really by
  // definition what a region or tablets is using split points
  return inputRanges;
}