org.apache.hadoop.hbase.HRegionLocation Java Examples

The following examples show how to use org.apache.hadoop.hbase.HRegionLocation. 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: TestAccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: HBaseUtils.java    From beam with Apache License 2.0 6 votes vote down vote up
/** 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;
}
 
Example #3
Source File: ServerCacheClient.java    From phoenix with Apache License 2.0 6 votes vote down vote up
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());
            }
        }
    }
    
}
 
Example #4
Source File: SkipRangeParallelIteratorRegionSplitterTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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));
    }
}
 
Example #5
Source File: ReopenTableRegionsProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: TestClientMetaServiceRPCs.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #7
Source File: TestAccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #8
Source File: DefaultParallelIteratorsRegionSplitterTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example #9
Source File: AsyncClientScanner.java    From hbase with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #10
Source File: TestMetaRegionLocationCache.java    From hbase with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #11
Source File: BaseResultIterators.java    From phoenix with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #12
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public GetMetaRegionLocationsResponse getMetaRegionLocations(RpcController rpcController,
    GetMetaRegionLocationsRequest request) throws ServiceException {
  GetMetaRegionLocationsResponse.Builder response = GetMetaRegionLocationsResponse.newBuilder();
  Optional<List<HRegionLocation>> metaLocations =
      master.getMetaRegionLocationCache().getMetaRegionLocations();
  metaLocations.ifPresent(hRegionLocations -> hRegionLocations.forEach(
    location -> response.addMetaLocations(ProtobufUtil.toRegionLocation(location))));
  return response.build();
}
 
Example #13
Source File: AsyncNonMetaRegionLocator.java    From hbase with Apache License 2.0 5 votes vote down vote up
private boolean onScanNext(TableName tableName, LocateRequest req, Result result) {
  RegionLocations locs = CatalogFamilyFormat.getRegionLocations(result);
  if (LOG.isDebugEnabled()) {
    LOG.debug("The fetched location of '{}', row='{}', locateType={} is {}", tableName,
      Bytes.toStringBinary(req.row), req.locateType, locs);
  }
  // remove HRegionLocation with null location, i.e, getServerName returns null.
  if (locs != null) {
    locs = locs.removeElementsWithNullLocation();
  }

  // the default region location should always be presented when fetching from meta, otherwise
  // let's fail the request.
  if (locs == null || locs.getDefaultRegionLocation() == null) {
    complete(tableName, req, null,
      new HBaseIOException(String.format("No location found for '%s', row='%s', locateType=%s",
        tableName, Bytes.toStringBinary(req.row), req.locateType)));
    return true;
  }
  HRegionLocation loc = locs.getDefaultRegionLocation();
  RegionInfo info = loc.getRegion();
  if (info == null) {
    complete(tableName, req, null,
      new HBaseIOException(String.format("HRegionInfo is null for '%s', row='%s', locateType=%s",
        tableName, Bytes.toStringBinary(req.row), req.locateType)));
    return true;
  }
  if (info.isSplitParent()) {
    return false;
  }
  complete(tableName, req, locs, null);
  return true;
}
 
Example #14
Source File: SimpleRequestController.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyFinal(ReturnCode code, HRegionLocation loc, long heapSizeOfRow) {
  if (code == ReturnCode.INCLUDE) {
    long currentRequestSize = serverRequestSizes.containsKey(loc.getServerName())
            ? serverRequestSizes.get(loc.getServerName()) : 0L;
    serverRequestSizes.put(loc.getServerName(), currentRequestSize + heapSizeOfRow);
  }
}
 
Example #15
Source File: SimpleRequestController.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyFinal(ReturnCode code, HRegionLocation loc, long heapSizeOfRow) {
  if (code == ReturnCode.INCLUDE) {
    regionsIncluded.add(loc.getRegion());
    serversIncluded.add(loc.getServerName());
  }
  busyRegions.add(loc.getRegion().getRegionName());
}
 
Example #16
Source File: TestRegionServerMetrics.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void assertRegionMetrics(String metric, long expectedValue) throws Exception {
  try (RegionLocator locator = connection.getRegionLocator(tableName)) {
    for ( HRegionLocation location: locator.getAllRegionLocations()) {
      RegionInfo hri = location.getRegion();
      MetricsRegionAggregateSource agg =
          rs.getRegion(hri.getRegionName()).getMetrics().getSource().getAggregateSource();
      String prefix = "namespace_" + NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR +
          "_table_" + tableName.getNameAsString() +
          "_region_" + hri.getEncodedName()+
          "_metric_";
      metricsHelper.assertCounter(prefix + metric, expectedValue, agg);
    }
  }
}
 
Example #17
Source File: LazyPartitionServer.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String getHostname(){
    try(RegionLocator rl = connection.getRegionLocator(tableName)){
        HRegionLocation hrl =rl.getRegionLocation(regionInfo.getStartKey());
        return hrl.getHostname();
    }catch(IOException e){
        throw new RuntimeException(e);
    }
}
 
Example #18
Source File: AsyncTableRegionLocatorImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<List<HRegionLocation>> getAllRegionLocations() {
  if (TableName.isMetaTableName(tableName)) {
    return conn.registry.getMetaRegionLocations()
      .thenApply(locs -> Arrays.asList(locs.getRegionLocations()));
  }
  return ClientMetaTableAccessor
    .getTableHRegionLocations(conn.getTable(TableName.META_TABLE_NAME), tableName);
}
 
Example #19
Source File: TestMetaRegionLocationCache.java    From hbase with Apache License 2.0 5 votes vote down vote up
private List<HRegionLocation> getCurrentMetaLocations(ZKWatcher zk) throws Exception {
  List<HRegionLocation> result = new ArrayList<>();
  for (String znode: zk.getMetaReplicaNodes()) {
    String path = ZNodePaths.joinZNode(zk.getZNodePaths().baseZNode, znode);
    int replicaId = zk.getZNodePaths().getMetaReplicaIdFromPath(path);
    RegionState state = MetaTableLocator.getMetaRegionState(zk, replicaId);
    result.add(new HRegionLocation(state.getRegion(), state.getServerName()));
  }
  return result;
}
 
Example #20
Source File: HBaseOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
public List<ByteArray> getTableRegions(final String tableNameStr) {
  final ArrayList<ByteArray> regionIdList = Lists.newArrayList();

  try (final RegionLocator locator = getRegionLocator(tableNameStr)) {
    for (final HRegionLocation regionLocation : locator.getAllRegionLocations()) {
      regionIdList.add(new ByteArray(regionLocation.getRegionInfo().getRegionName()));
    }
  } catch (final IOException e) {
    LOGGER.error("Error accessing region locator for " + tableNameStr, e);
  }

  return regionIdList;
}
 
Example #21
Source File: TestCatalogJanitorInMemoryStates.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * 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()));

}
 
Example #22
Source File: AbstractTestRegionLocator.java    From hbase with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #23
Source File: ReopenTableRegionsProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
private boolean canSchedule(MasterProcedureEnv env, HRegionLocation loc) {
  if (loc.getSeqNum() < 0) {
    return false;
  }
  RegionStateNode regionNode =
    env.getAssignmentManager().getRegionStates().getRegionStateNode(loc.getRegion());
  // If the region node is null, then at least in the next round we can remove this region to make
  // progress. And the second condition is a normal one, if there are no TRSP with it then we can
  // schedule one to make progress.
  return regionNode == null || !regionNode.isInTransition();
}
 
Example #24
Source File: RegionReplicaInfo.java    From hbase with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example #25
Source File: RawAsyncTableImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #26
Source File: AsyncScanSingleRegionRpcRetryingCaller.java    From hbase with Apache License 2.0 5 votes vote down vote up
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<>();
}
 
Example #27
Source File: TestingMapReduceParallelScanGrouper.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public List<HRegionLocation> getRegionBoundaries(StatementContext context,
        byte[] tableName) throws SQLException {
    List<HRegionLocation> regionLocations = super.getRegionBoundaries(context, tableName);
    numCallsToGetRegionBoundaries.incrementAndGet();
    return regionLocations;
}
 
Example #28
Source File: PhoenixSplitManager.java    From presto with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #29
Source File: ThriftUtilities.java    From hbase with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #30
Source File: MetaDataUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}