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

The following examples show how to use org.apache.hadoop.hbase.HRegionInfo#getStartKey() . 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: 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 3
Source File: HBaseStreamPartitioner.java    From opensoc-streaming with Apache License 2.0 6 votes vote down vote up
private void refreshRegionInfo(String tableName) throws IOException {

    System.out.println("in refreshRegionInfo ");

    Map<HRegionInfo, ServerName> regionMap = hTable.getRegionLocations();

    synchronized (regionStartKeys) {
      synchronized (regionStartKeyRegionNameMap) {
        regionStartKeys = new String[regionMap.size()];
        int index = 0;
        String startKey = null;
        regionStartKeyRegionNameMap.clear();
        for (HRegionInfo regionInfo : regionMap.keySet()) {
          startKey = new String(regionInfo.getStartKey());
          regionStartKeyRegionNameMap.put(startKey, regionInfo.getRegionNameAsString());
          regionStartKeys[index] = startKey;
          index++;
        }

        Arrays.sort(regionStartKeys);
        regionCheckTime = System.currentTimeMillis();
      }
    }
  }
 
Example 4
Source File: IndexLoadBalancer.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private ServerName getDestServerForIdxRegion(HRegionInfo hri) {
    // Every time we calculate the table name because in case of master restart the index
    // regions
    // may be coming for different index tables.
    TableName actualTable = getMappedTableToColocate(hri.getTable());
    ImmutableBytesWritable startkey = new ImmutableBytesWritable(hri.getStartKey());
    synchronized (this.colocationInfo) {

        Map<ImmutableBytesWritable, ServerName> tableKeys = colocationInfo.get(actualTable);
        if (null == tableKeys) {
            // Can this case come
            return null;
        }
        if (tableKeys.containsKey(startkey)) {
            // put index region location if corresponding user region found in regionLocation
            // map.
            ServerName sn = tableKeys.get(startkey);
            regionOnline(hri, sn);
            return sn;
        }
    }
    return null;
}
 
Example 5
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 6
Source File: SplitHexStringTest.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitWithHexStringUpcaseRule() throws Exception {
    List<HRegionInfo> regionInfoList;

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(1, regionInfoList.size());

    String[] argsParam = {"zookeeper", tableName, "Rule", "hexString_up", "5", "--force-proceed"};
    Args args = new ManagerArgs(argsParam);
    assertEquals("zookeeper", args.getZookeeperQuorum());
    Split command = new Split(admin, args);

    command.run();
    waitForSplitting(5);

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(5, regionInfoList.size());
    for (HRegionInfo hRegionInfo : regionInfoList) {
        byte[] startKey = hRegionInfo.getStartKey();
        if (startKey.length > 0) {
            assertTrue(Bytes.toString(startKey).matches("[A-Z0-9]*"));
            assertFalse(Bytes.toString(startKey).matches("[a-z]*"));
        }
    }
}
 
Example 7
Source File: SplitHexStringTest.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitWithHexStringDowncaseRule() throws Exception {
    List<HRegionInfo> regionInfoList;

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(1, regionInfoList.size());

    String[] argsParam = {"zookeeper", tableName, "Rule", "hexString_down", "5", "--force-proceed"};
    Args args = new ManagerArgs(argsParam);
    assertEquals("zookeeper", args.getZookeeperQuorum());
    Split command = new Split(admin, args);

    command.run();
    waitForSplitting(5);

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(5, regionInfoList.size());
    for (HRegionInfo hRegionInfo : regionInfoList) {
        byte[] startKey = hRegionInfo.getStartKey();
        if (startKey.length > 0) {
            assertTrue(Bytes.toString(startKey).matches("[a-z0-9]*"));
            assertFalse(Bytes.toString(startKey).matches("[A-Z]*"));
        }
    }
}
 
Example 8
Source File: SplitTest.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitWithDecimalString() throws Exception {
    List<HRegionInfo> regionInfoList;

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(1, regionInfoList.size());

    String[] argsParam = {"zookeeper", tableName, "Rule", "decimalString", "3", "10", "--force-proceed"};
    Args args = new ManagerArgs(argsParam);
    assertEquals("zookeeper", args.getZookeeperQuorum());
    Split command = new Split(admin, args);

    command.run();
    waitForSplitting(3);

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(3, regionInfoList.size());
    for (HRegionInfo hRegionInfo : regionInfoList) {
        byte[] startKey = hRegionInfo.getStartKey();
        if (startKey.length > 0) {
            assertTrue(Bytes.toString(startKey).matches("[0-9]*"));
            assertFalse(Bytes.toString(startKey).matches("[A-Za-z]*"));
        }
    }
}
 
Example 9
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 10
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 11
Source File: SplitHexStringTest.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitWithHexStringUpcaseRule() throws Exception {
    List<HRegionInfo> regionInfoList;

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(1, regionInfoList.size());

    String[] argsParam = {"zookeeper", tableName, "Rule", "hexString_up", "5", "--force-proceed"};
    Args args = new ManagerArgs(argsParam);
    assertEquals("zookeeper", args.getZookeeperQuorum());
    Split command = new Split(admin, args);

    command.run();
    waitForSplitting(5);

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(5, regionInfoList.size());
    for (HRegionInfo hRegionInfo : regionInfoList) {
        byte[] startKey = hRegionInfo.getStartKey();
        if (startKey.length > 0) {
            assertTrue(Bytes.toString(startKey).matches("[A-Z0-9]*"));
            assertFalse(Bytes.toString(startKey).matches("[a-z]*"));
        }
    }
}
 
Example 12
Source File: SplitHexStringTest.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitWithHexStringDowncaseRule() throws Exception {
    List<HRegionInfo> regionInfoList;

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(1, regionInfoList.size());

    String[] argsParam = {"zookeeper", tableName, "Rule", "hexString_down", "5", "--force-proceed"};
    Args args = new ManagerArgs(argsParam);
    assertEquals("zookeeper", args.getZookeeperQuorum());
    Split command = new Split(admin, args);

    command.run();
    waitForSplitting(5);

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(5, regionInfoList.size());
    for (HRegionInfo hRegionInfo : regionInfoList) {
        byte[] startKey = hRegionInfo.getStartKey();
        if (startKey.length > 0) {
            assertTrue(Bytes.toString(startKey).matches("[a-z0-9]*"));
            assertFalse(Bytes.toString(startKey).matches("[A-Z]*"));
        }
    }
}
 
Example 13
Source File: SplitTest.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitWithDecimalString() throws Exception {
    List<HRegionInfo> regionInfoList;

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(1, regionInfoList.size());

    String[] argsParam = {"zookeeper", tableName, "Rule", "decimalString", "3", "10", "--force-proceed"};
    Args args = new ManagerArgs(argsParam);
    assertEquals("zookeeper", args.getZookeeperQuorum());
    Split command = new Split(admin, args);

    command.run();
    waitForSplitting(3);

    regionInfoList = getRegionInfoList(tableName);
    assertEquals(3, regionInfoList.size());
    for (HRegionInfo hRegionInfo : regionInfoList) {
        byte[] startKey = hRegionInfo.getStartKey();
        if (startKey.length > 0) {
            assertTrue(Bytes.toString(startKey).matches("[0-9]*"));
            assertFalse(Bytes.toString(startKey).matches("[A-Za-z]*"));
        }
    }
}
 
Example 14
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 15
Source File: IndexLoadBalancer.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void updateServer(Map<ImmutableBytesWritable, ServerName> tableKeys, ServerName sn,
        HRegionInfo hri) {
    ImmutableBytesWritable startKey = new ImmutableBytesWritable(hri.getStartKey());
    ServerName existingServer = tableKeys.get(startKey);
    if (!sn.equals(existingServer)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("There is a mismatch in the existing server name for the region " + hri
                    + ".  Replacing the server " + existingServer + " with " + sn + ".");
        }
        tableKeys.put(startKey, sn);
    }
}
 
Example 16
Source File: IndexLoadBalancer.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private ServerName getServerNameFromMap(HRegionInfo regionInfo, List<ServerName> onlineServers) {
    TableName tableName = regionInfo.getTable();
    TableName mappedTable = getMappedTableToColocate(regionInfo.getTable());
    ImmutableBytesWritable startKey = new ImmutableBytesWritable(regionInfo.getStartKey());
    synchronized (this.colocationInfo) {
        Map<ImmutableBytesWritable, ServerName> correspondingTableKeys =
                this.colocationInfo.get(mappedTable);
        Map<ImmutableBytesWritable, ServerName> actualTableKeys =
                this.colocationInfo.get(tableName);

        if (null != correspondingTableKeys) {
            if (correspondingTableKeys.containsKey(startKey)) {
                ServerName previousServer = null;
                if (null != actualTableKeys) {
                    previousServer = actualTableKeys.get(startKey);
                }
                ServerName sn = correspondingTableKeys.get(startKey);
                if (null != previousServer) {
                    // if servername of index region and user region are same in colocationInfo
                    // clean
                    // previous plans and return null
                    if (previousServer.equals(sn)) {
                        correspondingTableKeys.remove(startKey);
                        actualTableKeys.remove(startKey);
                        if (LOG.isDebugEnabled()) {
                            LOG
                                    .debug("Both user region plan and corresponding index region plan "
                                            + "in colocation info are same. Hence clearing the plans to select new plan"
                                            + " for the region "
                                            + regionInfo.getRegionNameAsString() + ".");
                        }
                        return null;
                    }
                }
                if (sn != null && onlineServers.contains(sn)) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Updating the region plan of the region "
                                + regionInfo.getRegionNameAsString() + " with server " + sn);
                    }
                    regionOnline(regionInfo, sn);
                    return sn;
                } else if (sn != null) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("The location " + sn + " of region with start key"
                                + Bytes.toStringBinary(regionInfo.getStartKey())
                                + " is not in online. Selecting other region server.");
                    }
                    return null;
                }
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No region plans in colocationInfo for table " + mappedTable);
            }
        }
        return null;
    }
}
 
Example 17
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;
}