Package org.apache.hadoop.hbase.client

Examples of org.apache.hadoop.hbase.client.RegionLocator


    }
    return totalNumberOfRegions;
  }

  public static int getMetaRSPort(Configuration conf) throws IOException {
    RegionLocator table = new HTable(conf, TableName.META_TABLE_NAME);
    HRegionLocation hloc = table.getRegionLocation(Bytes.toBytes(""));
    table.close();
    return hloc.getPort();
  }
View Full Code Here


  private final long megabyte = 1024L * 1024L;

  @Test
  public void testSimpleTestCase() throws Exception {

    RegionLocator regionLocator = mockRegionLocator("region1", "region2", "region3");

    Admin admin = mockAdmin(
      mockServer(
        mockRegion("region1", 123),
        mockRegion("region3", 1232)
View Full Code Here

   * error caused by lost of precision.
   * */
  @Test
  public void testLargeRegion() throws Exception {

    RegionLocator regionLocator = mockRegionLocator("largeRegion");

    Admin admin = mockAdmin(
      mockServer(
        mockRegion("largeRegion", Integer.MAX_VALUE)
      )
View Full Code Here

  /** When calculator is disabled, it should return 0 for each request.*/
  @Test
  public void testDisabled() throws Exception {
    String regionName = "cz.goout:/index.html";
    RegionLocator table = mockRegionLocator(regionName);

    Admin admin = mockAdmin(
      mockServer(
        mockRegion(regionName, 999)
      )
View Full Code Here

  /**
   * Makes some table with given region names.
   * */
  private RegionLocator mockRegionLocator(String... regionNames) throws IOException {
    RegionLocator mockedTable = Mockito.mock(RegionLocator.class);
    when(mockedTable.getName()).thenReturn(TableName.valueOf("sizeTestTable"));
    List<HRegionLocation> regionLocations = new ArrayList<>();
    when(mockedTable.getAllRegionLocations()).thenReturn(regionLocations);

    for (String regionName : regionNames) {
      HRegionInfo info = Mockito.mock(HRegionInfo.class);
      when(info.getRegionName()).thenReturn(regionName.getBytes());
      regionLocations.add(new HRegionLocation(info, null));//we are not interested in values
View Full Code Here

      if (tableNameBytes == null)
        throw new IOException("A scan object did not have a table name");

      TableName tableName = TableName.valueOf(tableNameBytes);
      Table table = null;
      RegionLocator regionLocator = null;
      Connection conn = null;
      try {
        conn = ConnectionFactory.createConnection(context.getConfiguration());
        table = conn.getTable(tableName);
        regionLocator = conn.getRegionLocator(tableName);
        regionLocator = (RegionLocator) table;
        Pair<byte[][], byte[][]> keys = regionLocator.getStartEndKeys();
        if (keys == null || keys.getFirst() == null ||
            keys.getFirst().length == 0) {
          throw new IOException("Expecting at least one region for table : "
              + tableName.getNameAsString());
        }
        int count = 0;

        byte[] startRow = scan.getStartRow();
        byte[] stopRow = scan.getStopRow();

        RegionSizeCalculator sizeCalculator = new RegionSizeCalculator(
            regionLocator, conn.getAdmin());

        for (int i = 0; i < keys.getFirst().length; i++) {
          if (!includeRegionInSplit(keys.getFirst()[i], keys.getSecond()[i])) {
            continue;
          }
          HRegionLocation hregionLocation = regionLocator.getRegionLocation(
              keys.getFirst()[i], false);
          String regionHostname = hregionLocation.getHostname();
          HRegionInfo regionInfo = hregionLocation.getRegionInfo();

          // determine if the given start and stop keys fall into the range
          if ((startRow.length == 0 || keys.getSecond()[i].length == 0 ||
              Bytes.compareTo(startRow, keys.getSecond()[i]) < 0) &&
              (stopRow.length == 0 ||
                  Bytes.compareTo(stopRow, keys.getFirst()[i]) > 0)) {
            byte[] splitStart =
                startRow.length == 0 ||
                    Bytes.compareTo(keys.getFirst()[i], startRow) >= 0 ? keys
                    .getFirst()[i] : startRow;
            byte[] splitStop =
                (stopRow.length == 0 || Bytes.compareTo(keys.getSecond()[i],
                    stopRow) <= 0) && keys.getSecond()[i].length > 0 ? keys
                    .getSecond()[i] : stopRow;

            long regionSize = sizeCalculator.getRegionSize(regionInfo.getRegionName());
            TableSplit split =
                new TableSplit(regionLocator.getName(),
                    scan, splitStart, splitStop, regionHostname, regionSize);

            splits.add(split);
            if (LOG.isDebugEnabled())
              LOG.debug("getSplits: split -> " + (count++) + " -> " + split);
          }
        }
      } finally {
        if (null != table) table.close();
        if (null != regionLocator) regionLocator.close();
        if (null != conn) conn.close();
      }
    }
    return splits;
  }
View Full Code Here

    }
    return totalNumberOfRegions;
  }

  public static int getMetaRSPort(Configuration conf) throws IOException {
    RegionLocator table = new HTable(conf, TableName.META_TABLE_NAME);
    HRegionLocation hloc = table.getRegionLocation(Bytes.toBytes(""));
    table.close();
    return hloc.getPort();
  }
View Full Code Here

    HMaster master = masterThreads.get(0).getMaster();
    assertTrue(master.isActiveMaster());
    assertTrue(master.isInitialized());

    // Create a table with a region online
    RegionLocator onlineTable = TEST_UTIL.createTable(TableName.valueOf("onlineTable"), "family");

    // Create a table in META, so it has a region offline
    HTableDescriptor offlineTable = new HTableDescriptor(
      TableName.valueOf(Bytes.toBytes("offlineTable")));
    offlineTable.addFamily(new HColumnDescriptor(Bytes.toBytes("family")));

    FileSystem filesystem = FileSystem.get(conf);
    Path rootdir = FSUtils.getRootDir(conf);
    FSTableDescriptors fstd = new FSTableDescriptors(conf, filesystem, rootdir);
    fstd.createTableDescriptor(offlineTable);

    HRegionInfo hriOffline = new HRegionInfo(offlineTable.getTableName(), null, null);
    createRegion(hriOffline, rootdir, conf, offlineTable);
    MetaTableAccessor.addRegionToMeta(master.getShortCircuitConnection(), hriOffline);

    log("Regions in hbase:meta and namespace have been created");

    // at this point we only expect 3 regions to be assigned out
    // (catalogs and namespace, + 1 online region)
    assertEquals(3, cluster.countServedRegions());
    HRegionInfo hriOnline = onlineTable.getRegionLocation(
      HConstants.EMPTY_START_ROW).getRegionInfo();

    RegionStates regionStates = master.getAssignmentManager().getRegionStates();
    RegionStateStore stateStore = master.getAssignmentManager().getRegionStateStore();
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.client.RegionLocator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.