类org.apache.hadoop.hbase.HRegionLocation源码实例Demo

下面列出了怎么用org.apache.hadoop.hbase.HRegionLocation的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: phoenix   文件: BaseResultIterators.java
private List<Scan> addNewScan(List<List<Scan>> parallelScans, List<Scan> scans, Scan scan,
        byte[] startKey, boolean crossedRegionBoundary, HRegionLocation regionLocation) {
    boolean startNewScan = scanGrouper.shouldStartNewScan(plan, scans, startKey, crossedRegionBoundary);
    if (scan != null) {
        if (regionLocation.getServerName() != null) {
            scan.setAttribute(BaseScannerRegionObserver.SCAN_REGION_SERVER, regionLocation.getServerName().getVersionedBytes());
        }
        if (useStatsForParallelization || crossedRegionBoundary) {
            scans.add(scan);
        }
    }
    if (startNewScan && !scans.isEmpty()) {
        parallelScans.add(scans);
        scans = Lists.newArrayListWithExpectedSize(1);
    }
    return scans;
}
 
@Test
public void testGetSplitsWithSkipScanFilter() throws Exception {
    byte[][] splits = new byte[][] {Ka1A, Ka1B, Ka1E, Ka1G, Ka1I, Ka2A};
    long ts = nextTimestamp();
    createTestTable(getUrl(),DDL,splits, ts-2);
    String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + ts;
    Properties props = new Properties(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(url, props);
    PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
    TableRef tableRef = new TableRef(null,pconn.getPMetaData().getTable(SchemaUtil.getTableName(SCHEMA_NAME, TABLE_NAME)),ts, false);
    List<HRegionLocation> regions = pconn.getQueryServices().getAllTableRegions(tableRef.getTable().getPhysicalName().getBytes());
    
    conn.close();
    initTableValues();
    List<KeyRange> ranges = getSplits(tableRef, scan, regions, scanRanges);
    assertEquals("Unexpected number of splits: " + ranges.size(), expectedSplits.size(), ranges.size());
    for (int i=0; i<expectedSplits.size(); i++) {
        assertEquals(expectedSplits.get(i), ranges.get(i));
    }
}
 
源代码3 项目: beam   文件: HBaseUtils.java
/** Returns the list of ranges intersecting a list of regions for the given table and scan. */
static List<ByteKeyRange> getRanges(
    List<HRegionLocation> regionLocations, String tableId, ByteKeyRange range) {
  byte[] startRow = range.getStartKey().getBytes();
  byte[] stopRow = range.getEndKey().getBytes();

  final List<ByteKeyRange> splits = new ArrayList<>();
  final boolean scanWithNoLowerBound = startRow.length == 0;
  final boolean scanWithNoUpperBound = stopRow.length == 0;

  for (HRegionLocation regionLocation : regionLocations) {
    final byte[] startKey = regionLocation.getRegionInfo().getStartKey();
    final byte[] endKey = regionLocation.getRegionInfo().getEndKey();
    boolean isLastRegion = endKey.length == 0;

    final byte[] splitStart =
        (scanWithNoLowerBound || Bytes.compareTo(startKey, startRow) >= 0) ? startKey : startRow;
    final byte[] splitStop =
        (scanWithNoUpperBound || Bytes.compareTo(endKey, stopRow) <= 0) && !isLastRegion
            ? endKey
            : stopRow;
    splits.add(ByteKeyRange.of(ByteKey.copyFrom(splitStart), ByteKey.copyFrom(splitStop)));
  }
  return splits;
}
 
源代码4 项目: hbase   文件: ReopenTableRegionsProcedure.java
private List<HRegionLocation> getRegionLocationsForReopen(
    List<HRegionLocation> tableRegionsForReopen) {

  List<HRegionLocation> regionsToReopen = new ArrayList<>();
  if (CollectionUtils.isNotEmpty(regionNames) &&
    CollectionUtils.isNotEmpty(tableRegionsForReopen)) {
    for (byte[] regionName : regionNames) {
      for (HRegionLocation hRegionLocation : tableRegionsForReopen) {
        if (Bytes.equals(regionName, hRegionLocation.getRegion().getRegionName())) {
          regionsToReopen.add(hRegionLocation);
          break;
        }
      }
    }
  } else {
    regionsToReopen = tableRegionsForReopen;
  }
  return regionsToReopen;
}
 
源代码5 项目: phoenix   文件: ServerCacheClient.java
public ServerCache(byte[] id, Set<HRegionLocation> servers, ImmutableBytesWritable cachePtr,
        ConnectionQueryServices services, boolean storeCacheOnClient) throws IOException {
    maxServerCacheTTL = services.getProps().getInt(
            QueryServices.MAX_SERVER_CACHE_TIME_TO_LIVE_MS_ATTRIB,
            QueryServicesOptions.DEFAULT_MAX_SERVER_CACHE_TIME_TO_LIVE_MS);
    this.id = id;
    this.servers = new HashMap();
    long currentTime = EnvironmentEdgeManager.currentTimeMillis();
    for(HRegionLocation loc : servers) {
        this.servers.put(loc, currentTime);
    }
    this.size =  cachePtr.getLength();
    if (storeCacheOnClient) {
        try {
            this.chunk = services.getMemoryManager().allocate(cachePtr.getLength());
            this.cachePtr = cachePtr;
        } catch (InsufficientMemoryException e) {
            this.outputFile = File.createTempFile("HashJoinCacheSpooler", ".bin", new File(services.getProps()
                    .get(QueryServices.SPOOL_DIRECTORY, QueryServicesOptions.DEFAULT_SPOOL_DIRECTORY)));
            try (OutputStream fio = Files.newOutputStream(outputFile.toPath())) {
                fio.write(cachePtr.get(), cachePtr.getOffset(), cachePtr.getLength());
            }
        }
    }
    
}
 
源代码6 项目: hbase   文件: TestClientMetaServiceRPCs.java
/**
 * Verifies that the meta region locations RPC returns consistent results across all masters.
 */
@Test public void TestMetaLocations() throws Exception {
  HBaseRpcController rpcController = getRpcController();
  List<HRegionLocation> metaLocations = TEST_UTIL.getMiniHBaseCluster().getMaster()
      .getMetaRegionLocationCache().getMetaRegionLocations().get();
  Collections.sort(metaLocations);
  int rpcCount = 0;
  for (JVMClusterUtil.MasterThread masterThread:
    TEST_UTIL.getMiniHBaseCluster().getMasterThreads()) {
    ClientMetaService.BlockingInterface stub =
        getMasterStub(masterThread.getMaster().getServerName());
    GetMetaRegionLocationsResponse resp = stub.getMetaRegionLocations(
        rpcController, GetMetaRegionLocationsRequest.getDefaultInstance());
    List<HRegionLocation> result = new ArrayList<>();
    resp.getMetaLocationsList().forEach(
      location -> result.add(ProtobufUtil.toRegionLocation(location)));
    Collections.sort(result);
    assertEquals(metaLocations, result);
    rpcCount++;
  }
  assertEquals(MASTER_COUNT, rpcCount);
}
 
源代码7 项目: hbase   文件: TestAccessController.java
@Test
public void testMove() throws Exception {
  List<HRegionLocation> regions;
  try (RegionLocator locator = systemUserConnection.getRegionLocator(TEST_TABLE)) {
    regions = locator.getAllRegionLocations();
  }
  HRegionLocation location = regions.get(0);
  final RegionInfo hri = location.getRegion();
  final ServerName server = location.getServerName();
  AccessTestAction action = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      ACCESS_CONTROLLER.preMove(ObserverContextImpl.createAndPrepare(CP_ENV),
        hri, server, server);
      return null;
    }
  };

  verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_OWNER, USER_GROUP_ADMIN);
  verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ,
    USER_GROUP_WRITE, USER_GROUP_CREATE);
}
 
源代码8 项目: hbase   文件: TestAccessController.java
@Test
public void testUnassign() throws Exception {
  List<HRegionLocation> regions;
  try (RegionLocator locator = systemUserConnection.getRegionLocator(TEST_TABLE)) {
    regions = locator.getAllRegionLocations();
  }
  HRegionLocation location = regions.get(0);
  final RegionInfo hri = location.getRegion();
  AccessTestAction action = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      ACCESS_CONTROLLER.preUnassign(ObserverContextImpl.createAndPrepare(CP_ENV), hri, false);
      return null;
    }
  };

  verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_OWNER, USER_GROUP_ADMIN);
  verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ,
    USER_GROUP_WRITE, USER_GROUP_CREATE);
}
 
private static List<KeyRange> getSplits(Connection conn, long ts, final Scan scan)
        throws SQLException {
    TableRef tableRef = getTableRef(conn, ts);
    PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
    final List<HRegionLocation> regions =  pconn.getQueryServices().getAllTableRegions(tableRef.getTable().getPhysicalName().getBytes());
    StatementContext context = new StatementContext(new PhoenixStatement(pconn), null, Collections.emptyList(), scan);
    DefaultParallelIteratorRegionSplitter splitter = new DefaultParallelIteratorRegionSplitter(context, tableRef, HintNode.EMPTY_HINT_NODE) {
        @Override
        protected List<HRegionLocation> getAllRegions() throws SQLException {
            return DefaultParallelIteratorRegionSplitter.filterRegions(regions, scan.getStartRow(), scan.getStopRow());
        }
    };
    List<KeyRange> keyRanges = splitter.getSplits();
    Collections.sort(keyRanges, new Comparator<KeyRange>() {
        @Override
        public int compare(KeyRange o1, KeyRange o2) {
            return Bytes.compareTo(o1.getLowerRange(),o2.getLowerRange());
        }
    });
    return keyRanges;
}
 
源代码10 项目: hbase   文件: AsyncClientScanner.java
private CompletableFuture<OpenScannerResponse> callOpenScanner(HBaseRpcController controller,
    HRegionLocation loc, ClientService.Interface stub) {
  boolean isRegionServerRemote = isRemote(loc.getHostname());
  incRPCCallsMetrics(scanMetrics, isRegionServerRemote);
  if (openScannerTries.getAndIncrement() > 1) {
    incRPCRetriesMetrics(scanMetrics, isRegionServerRemote);
  }
  CompletableFuture<OpenScannerResponse> future = new CompletableFuture<>();
  try {
    ScanRequest request = RequestConverter.buildScanRequest(loc.getRegion().getRegionName(), scan,
      scan.getCaching(), false);
    stub.scan(controller, request, resp -> {
      if (controller.failed()) {
        future.completeExceptionally(controller.getFailed());
        return;
      }
      future.complete(new OpenScannerResponse(loc, isRegionServerRemote, stub, controller, resp));
    });
  } catch (IOException e) {
    future.completeExceptionally(e);
  }
  return future;
}
 
源代码11 项目: hbase   文件: TestMetaRegionLocationCache.java
private void verifyCachedMetaLocations(HMaster master) throws Exception {
  // Wait until initial meta locations are loaded.
  int retries = 0;
  while (!master.getMetaRegionLocationCache().getMetaRegionLocations().isPresent()) {
    Thread.sleep(1000);
    if (++retries == 10) {
      break;
    }
  }
  List<HRegionLocation> metaHRLs =
      master.getMetaRegionLocationCache().getMetaRegionLocations().get();
  assertFalse(metaHRLs.isEmpty());
  ZKWatcher zk = master.getZooKeeper();
  List<String> metaZnodes = zk.getMetaReplicaNodes();
  assertEquals(metaZnodes.size(), metaHRLs.size());
  List<HRegionLocation> actualHRLs = getCurrentMetaLocations(zk);
  Collections.sort(metaHRLs);
  Collections.sort(actualHRLs);
  assertEquals(actualHRLs, metaHRLs);
}
 
源代码12 项目: presto   文件: PhoenixSplitManager.java
private List<InputSplit> generateSplits(QueryPlan queryPlan, List<KeyRange> splits)
        throws IOException
{
    requireNonNull(queryPlan, "queryPlan is null");
    requireNonNull(splits, "splits is null");

    try (org.apache.hadoop.hbase.client.Connection connection = phoenixClient.getHConnection()) {
        RegionLocator regionLocator = connection.getRegionLocator(TableName.valueOf(queryPlan.getTableRef().getTable().getPhysicalName().toString()));
        long regionSize = -1;
        List<InputSplit> inputSplits = new ArrayList<>(splits.size());
        for (List<Scan> scans : queryPlan.getScans()) {
            HRegionLocation location = regionLocator.getRegionLocation(scans.get(0).getStartRow(), false);
            String regionLocation = location.getHostname();

            if (log.isDebugEnabled()) {
                log.debug(
                        "Scan count[%d] : %s ~ %s",
                        scans.size(),
                        Bytes.toStringBinary(scans.get(0).getStartRow()),
                        Bytes.toStringBinary(scans.get(scans.size() - 1).getStopRow()));
                log.debug("First scan : %swith scanAttribute : %s [scanCache, cacheBlock, scanBatch] : [%d, %s, %d] and  regionLocation : %s",
                        scans.get(0), scans.get(0).getAttributesMap(), scans.get(0).getCaching(), scans.get(0).getCacheBlocks(), scans.get(0).getBatch(), regionLocation);
                for (int i = 0, limit = scans.size(); i < limit; i++) {
                    log.debug("EXPECTED_UPPER_REGION_KEY[%d] : %s", i, Bytes.toStringBinary(scans.get(i).getAttribute(EXPECTED_UPPER_REGION_KEY)));
                }
            }
            inputSplits.add(new PhoenixInputSplit(scans, regionSize, regionLocation));
        }
        return inputSplits;
    }
}
 
源代码13 项目: pxf   文件: HBaseDataFragmenter.java
private void addFragment(HRegionLocation location,
        byte[] userData) throws IOException {
    ServerName serverInfo = location.getServerName();
    String[] hosts = new String[] {serverInfo.getHostname()};
    HRegionInfo region = location.getRegionInfo();
    byte[] fragmentMetadata = prepareFragmentMetadata(region);
    Fragment fragment = new Fragment(context.getDataSource(), hosts, fragmentMetadata, userData);
    fragments.add(fragment);
}
 
源代码14 项目: hbase   文件: MasterProcedureTestingUtility.java
private static int countMetaRegions(final HMaster master, final TableName tableName)
    throws IOException {
  final AtomicInteger actualRegCount = new AtomicInteger(0);
  final ClientMetaTableAccessor.Visitor visitor = new ClientMetaTableAccessor.Visitor() {
    @Override
    public boolean visit(Result rowResult) throws IOException {
      RegionLocations list = CatalogFamilyFormat.getRegionLocations(rowResult);
      if (list == null) {
        LOG.warn("No serialized RegionInfo in " + rowResult);
        return true;
      }
      HRegionLocation l = list.getRegionLocation();
      if (l == null) {
        return true;
      }
      if (!l.getRegion().getTable().equals(tableName)) {
        return false;
      }
      if (l.getRegion().isOffline() || l.getRegion().isSplit()) {
        return true;
      }

      HRegionLocation[] locations = list.getRegionLocations();
      for (HRegionLocation location : locations) {
        if (location == null) continue;
        ServerName serverName = location.getServerName();
        // Make sure that regions are assigned to server
        if (serverName != null && serverName.getAddress() != null) {
          actualRegCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaTableAccessor.scanMetaForTableRegions(master.getConnection(), visitor, tableName);
  return actualRegCount.get();
}
 
源代码15 项目: hbase   文件: RestartRsHoldingTableAction.java
@Override
public void perform() throws Exception {
  getLogger().info(
    "Performing action: Restart random RS holding table " + this.locator.getName());

  List<HRegionLocation> locations = locator.getAllRegionLocations();
  restartRs(locations.get(RandomUtils.nextInt(0, locations.size())).getServerName(), sleepTime);
}
 
源代码16 项目: phoenix   文件: ConnectionlessQueryServicesImpl.java
@Override
public List<HRegionLocation> getAllTableRegions(byte[] tableName) throws SQLException {
    List<HRegionLocation> regions = tableSplits.get(Bytes.toString(tableName));
    if (regions != null) {
        return regions;
    }
    RegionInfo hri =
            RegionInfoBuilder.newBuilder(TableName.valueOf(tableName))
                    .setStartKey(HConstants.EMPTY_START_ROW)
                    .setStartKey(HConstants.EMPTY_END_ROW).build();
    return Collections.singletonList(new HRegionLocation(hri, SERVER_NAME, -1));
}
 
源代码17 项目: hbase   文件: MultiThreadedReader.java
private void verifyResultsAndUpdateMetricsOnAPerGetBasis(boolean verify, Get get,
    Result result, Table table, boolean isNullExpected) throws IOException {
  if (!result.isEmpty()) {
    if (verify) {
      numKeysVerified.incrementAndGet();
    }
  } else {
    HRegionLocation hloc;
    try (RegionLocator locator = connection.getRegionLocator(tableName)) {
      hloc = locator.getRegionLocation(get.getRow());
    }
    String rowKey = Bytes.toString(get.getRow());
    LOG.info("Key = " + rowKey + ", Region location: " + hloc);
    if(isNullExpected) {
      nullResult.incrementAndGet();
      LOG.debug("Null result obtained for the key ="+rowKey);
      return;
    }
  }
  boolean isOk = verifyResultAgainstDataGenerator(result, verify, false);
  long numErrorsAfterThis = 0;
  if (isOk) {
    long cols = 0;
    // Count the columns for reporting purposes.
    for (byte[] cf : result.getMap().keySet()) {
      cols += result.getFamilyMap(cf).size();
    }
    numCols.addAndGet(cols);
  } else {
    if (writer != null) {
      LOG.error("At the time of failure, writer wrote " + writer.numKeys.get() + " keys");
    }
    numErrorsAfterThis = numReadErrors.incrementAndGet();
  }

  if (numErrorsAfterThis > maxErrors) {
    LOG.error("Aborting readers -- found more than " + maxErrors + " errors");
    aborted = true;
  }
}
 
源代码18 项目: phoenix   文件: ServerCacheClient.java
public boolean isExpired(HRegionLocation loc) {
    if(this.servers.containsKey(loc)) {
        Long time = this.servers.get(loc);
        if(EnvironmentEdgeManager.currentTimeMillis() - time > maxServerCacheTTL)
            return true; // cache was send more than maxTTL ms ago, expecting that it's expired
    } else {
        return false; // should be on server yet.
    }
    return false; // Unknown region location. Need to send the cache.
}
 
源代码19 项目: beam   文件: HBaseUtils.java
/** Returns a list of region locations for a given table and scan. */
static List<HRegionLocation> getRegionLocations(
    Connection connection, String tableId, ByteKeyRange range) throws Exception {
  byte[] startRow = range.getStartKey().getBytes();
  byte[] stopRow = range.getEndKey().getBytes();

  final List<HRegionLocation> regionLocations = new ArrayList<>();

  final boolean scanWithNoLowerBound = startRow.length == 0;
  final boolean scanWithNoUpperBound = stopRow.length == 0;

  TableName tableName = TableName.valueOf(tableId);
  RegionLocator regionLocator = connection.getRegionLocator(tableName);
  List<HRegionLocation> tableRegionInfos = regionLocator.getAllRegionLocations();
  for (HRegionLocation regionLocation : tableRegionInfos) {
    final byte[] startKey = regionLocation.getRegionInfo().getStartKey();
    final byte[] endKey = regionLocation.getRegionInfo().getEndKey();
    boolean isLastRegion = endKey.length == 0;
    // filters regions who are part of the scan
    if ((scanWithNoLowerBound || isLastRegion || Bytes.compareTo(startRow, endKey) < 0)
        && (scanWithNoUpperBound || Bytes.compareTo(stopRow, startKey) > 0)) {
      regionLocations.add(regionLocation);
    }
  }

  return regionLocations;
}
 
源代码20 项目: spliceengine   文件: AdapterPartition.java
private List<Partition> formatPartitions(List<HRegionLocation> tableLocations) {
    List<Partition> partitions=new ArrayList<>(tableLocations.size());
    for(HRegionLocation location : tableLocations){
        HRegionInfo regionInfo=location.getRegionInfo();
        partitions.add(new RangedClientPartition(this,regionInfo,new RLServer(location)));
    }
    return partitions;
}
 
源代码21 项目: hbase   文件: RawAsyncTableImpl.java
private <S, R> void onLocateComplete(Function<RpcChannel, S> stubMaker,
    ServiceCaller<S, R> callable, CoprocessorCallback<R> callback, List<HRegionLocation> locs,
    byte[] endKey, boolean endKeyInclusive, AtomicBoolean locateFinished,
    AtomicInteger unfinishedRequest, HRegionLocation loc, Throwable error) {
  if (error != null) {
    callback.onError(error);
    return;
  }
  unfinishedRequest.incrementAndGet();
  RegionInfo region = loc.getRegion();
  if (locateFinished(region, endKey, endKeyInclusive)) {
    locateFinished.set(true);
  } else {
    addListener(
      conn.getLocator().getRegionLocation(tableName, region.getEndKey(), RegionLocateType.CURRENT,
        operationTimeoutNs),
      (l, e) -> onLocateComplete(stubMaker, callable, callback, locs, endKey, endKeyInclusive,
        locateFinished, unfinishedRequest, l, e));
  }
  addListener(coprocessorService(stubMaker, callable, region, region.getStartKey()), (r, e) -> {
    if (e != null) {
      callback.onRegionError(region, e);
    } else {
      callback.onRegionComplete(region, r);
    }
    if (unfinishedRequest.decrementAndGet() == 0 && locateFinished.get()) {
      callback.onComplete();
    }
  });
}
 
源代码22 项目: hbase   文件: TestAsyncNonMetaRegionLocator.java
@Test
public void testRegionMove() throws IOException, InterruptedException, ExecutionException {
  createSingleRegionTable();
  ServerName serverName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
  HRegionLocation loc =
    getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get();
  assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, loc);
  ServerName newServerName = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream()
    .map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName)).findAny()
    .get();

  TEST_UTIL.getAdmin().move(Bytes.toBytes(loc.getRegion().getEncodedName()), newServerName);
  while (!TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName()
    .equals(newServerName)) {
    Thread.sleep(100);
  }
  // Should be same as it is in cache
  assertSame(loc,
    getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get());
  LOCATOR.updateCachedLocationOnError(loc, null);
  // null error will not trigger a cache cleanup
  assertSame(loc,
    getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get());
  LOCATOR.updateCachedLocationOnError(loc, new NotServingRegionException());
  assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, newServerName,
    getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get());
}
 
源代码23 项目: phoenix   文件: BaseResultIterators.java
private static List<byte[]> toBoundaries(List<HRegionLocation> regionLocations) {
    int nBoundaries = regionLocations.size() - 1;
    List<byte[]> ranges = Lists.newArrayListWithExpectedSize(nBoundaries);
    for (int i = 0; i < nBoundaries; i++) {
        HRegionInfo regionInfo = regionLocations.get(i).getRegionInfo();
        ranges.add(regionInfo.getEndKey());
    }
    return ranges;
}
 
源代码24 项目: hbase   文件: TestCatalogJanitorInMemoryStates.java
/**
 * Test clearing a split parent from memory.
 */
@Test
public void testInMemoryParentCleanup()
    throws IOException, InterruptedException, ExecutionException {
  final AssignmentManager am = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager();
  final ServerManager sm = TEST_UTIL.getHBaseCluster().getMaster().getServerManager();
  final CatalogJanitor janitor = TEST_UTIL.getHBaseCluster().getMaster().getCatalogJanitor();

  Admin admin = TEST_UTIL.getAdmin();
  admin.catalogJanitorSwitch(false);

  final TableName tableName = TableName.valueOf(name.getMethodName());
  Table t = TEST_UTIL.createTable(tableName, FAMILY);
  int rowCount = TEST_UTIL.loadTable(t, FAMILY, false);

  RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);
  List<HRegionLocation> allRegionLocations = locator.getAllRegionLocations();

  // We need to create a valid split with daughter regions
  HRegionLocation parent = allRegionLocations.get(0);
  List<HRegionLocation> daughters = splitRegion(parent.getRegion());
  LOG.info("Parent region: " + parent);
  LOG.info("Daughter regions: " + daughters);
  assertNotNull("Should have found daughter regions for " + parent, daughters);

  assertTrue("Parent region should exist in RegionStates",
      am.getRegionStates().isRegionInRegionStates(parent.getRegion()));
  assertTrue("Parent region should exist in ServerManager",
      sm.isRegionInServerManagerStates(parent.getRegion()));

  // clean the parent
  Result r = MetaMockingUtil.getMetaTableRowResult(parent.getRegion(), null,
      daughters.get(0).getRegion(), daughters.get(1).getRegion());
  janitor.cleanParent(parent.getRegion(), r);
  assertFalse("Parent region should have been removed from RegionStates",
      am.getRegionStates().isRegionInRegionStates(parent.getRegion()));
  assertFalse("Parent region should have been removed from ServerManager",
      sm.isRegionInServerManagerStates(parent.getRegion()));

}
 
源代码25 项目: hbase   文件: ThriftUtilities.java
public static List<THRegionLocation> regionLocationsFromHBase(List<HRegionLocation> locations) {
  List<THRegionLocation> tlocations = new ArrayList<>(locations.size());
  for (HRegionLocation hrl:locations) {
    tlocations.add(regionLocationFromHBase(hrl));
  }
  return tlocations;
}
 
源代码26 项目: phoenix   文件: MetaDataUtil.java
/**
 * This function checks if all regions of a table is online
 * @param table
 * @return true when all regions of a table are online
 * @throws IOException
 * @throws
 */
public static boolean tableRegionsOnline(Configuration conf, PTable table) {
    try (ClusterConnection hcon =
            (ClusterConnection) ConnectionFactory.createConnection(conf)) {
        List<HRegionLocation> locations = hcon.locateRegions(
          org.apache.hadoop.hbase.TableName.valueOf(table.getPhysicalName().getBytes()));

        for (HRegionLocation loc : locations) {
            try {
                ServerName sn = loc.getServerName();
                if (sn == null) continue;

                AdminService.BlockingInterface admin = hcon.getAdmin(sn);
                HBaseRpcController controller = hcon.getRpcControllerFactory().newController();
                org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil.getRegionInfo(controller,
                    admin, loc.getRegion().getRegionName());
            } catch (RemoteException e) {
                LOGGER.debug("Cannot get region " + loc.getRegion().getEncodedName() + " info due to error:" + e);
                return false;
            }
        }
    } catch (IOException ex) {
        LOGGER.warn("tableRegionsOnline failed due to:", ex);
        return false;
    }
    return true;
}
 
@Override
public List<HRegionLocation> getRegionBoundaries(StatementContext context,
        byte[] tableName) throws SQLException {
    List<HRegionLocation> regionLocations = super.getRegionBoundaries(context, tableName);
    numCallsToGetRegionBoundaries.incrementAndGet();
    return regionLocations;
}
 
public AsyncScanSingleRegionRpcRetryingCaller(Timer retryTimer, AsyncConnectionImpl conn,
    Scan scan, ScanMetrics scanMetrics, long scannerId, ScanResultCache resultCache,
    AdvancedScanResultConsumer consumer, Interface stub, HRegionLocation loc,
    boolean isRegionServerRemote, int priority, long scannerLeaseTimeoutPeriodNs, long pauseNs,
    long pauseForCQTBENs, int maxAttempts, long scanTimeoutNs, long rpcTimeoutNs,
    int startLogErrorsCnt) {
  this.retryTimer = retryTimer;
  this.scan = scan;
  this.scanMetrics = scanMetrics;
  this.scannerId = scannerId;
  this.resultCache = resultCache;
  this.consumer = consumer;
  this.stub = stub;
  this.loc = loc;
  this.regionServerRemote = isRegionServerRemote;
  this.scannerLeaseTimeoutPeriodNs = scannerLeaseTimeoutPeriodNs;
  this.pauseNs = pauseNs;
  this.pauseForCQTBENs = pauseForCQTBENs;
  this.maxAttempts = maxAttempts;
  this.scanTimeoutNs = scanTimeoutNs;
  this.rpcTimeoutNs = rpcTimeoutNs;
  this.startLogErrorsCnt = startLogErrorsCnt;
  if (scan.isReversed()) {
    completeWhenNoMoreResultsInRegion = this::completeReversedWhenNoMoreResultsInRegion;
  } else {
    completeWhenNoMoreResultsInRegion = this::completeWhenNoMoreResultsInRegion;
  }
  this.future = new CompletableFuture<>();
  this.priority = priority;
  this.controller = conn.rpcControllerFactory.newController();
  this.controller.setPriority(priority);
  this.exceptions = new ArrayList<>();
}
 
源代码29 项目: hbase   文件: RawAsyncTableImpl.java
private static <REQ, RESP> CompletableFuture<RESP> mutate(HBaseRpcController controller,
    HRegionLocation loc, ClientService.Interface stub, REQ req,
    Converter<MutateRequest, byte[], REQ> reqConvert,
    Converter<RESP, HBaseRpcController, MutateResponse> respConverter) {
  return ConnectionUtils.call(controller, loc, stub, req, reqConvert,
    (s, c, r, done) -> s.mutate(c, r, done), respConverter);
}
 
源代码30 项目: hbase   文件: RegionReplicaInfo.java
private RegionReplicaInfo(final Result result, final HRegionLocation location) {
  this.row = result != null ? result.getRow() : null;
  this.regionInfo = location != null ? location.getRegion() : null;
  this.regionState = (result != null && regionInfo != null)
    ? RegionStateStore.getRegionState(result, regionInfo)
    : null;
  this.serverName = location != null ? location.getServerName() : null;
  this.seqNum = (location != null) ? location.getSeqNum() : HConstants.NO_SEQNUM;
  this.targetServerName = (result != null && regionInfo != null)
    ? MetaTableAccessor.getTargetServerName(result, regionInfo.getReplicaId())
    : null;
  this.mergeRegionInfo = (result != null)
    ? MetaTableAccessor.getMergeRegionsWithName(result.rawCells())
    : null;

  if (result != null) {
    PairOfSameType<RegionInfo> daughterRegions = MetaTableAccessor.getDaughterRegions(result);
    this.splitRegionInfo = new LinkedHashMap<>();
    if (daughterRegions.getFirst() != null) {
      splitRegionInfo.put(HConstants.SPLITA_QUALIFIER_STR, daughterRegions.getFirst());
    }
    if (daughterRegions.getSecond() != null) {
      splitRegionInfo.put(HConstants.SPLITB_QUALIFIER_STR, daughterRegions.getSecond());
    }
  } else {
    this.splitRegionInfo = null;
  }
}
 
 类所在包
 同包方法