Java Code Examples for org.apache.hadoop.hbase.regionserver.Region#getRegionInfo()

The following examples show how to use org.apache.hadoop.hbase.regionserver.Region#getRegionInfo() . 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: AccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void preOpen(ObserverContext<RegionCoprocessorEnvironment> c)
    throws IOException {
  RegionCoprocessorEnvironment env = c.getEnvironment();
  final Region region = env.getRegion();
  if (region == null) {
    LOG.error("NULL region from RegionCoprocessorEnvironment in preOpen()");
  } else {
    RegionInfo regionInfo = region.getRegionInfo();
    if (regionInfo.getTable().isSystemTable()) {
      checkSystemOrSuperUser(getActiveUser(c));
    } else {
      requirePermission(c, "preOpen", Action.ADMIN);
    }
  }
}
 
Example 2
Source File: UngroupedAggregateRegionObserver.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private void separateLocalAndRemoteMutations(Table targetHTable, Region region, List<Mutation> mutations,
                                             List<Mutation> localRegionMutations, List<Mutation> remoteRegionMutations,
                                             boolean isPKChanging){
    boolean areMutationsInSameTable = areMutationsInSameTable(targetHTable, region);
    //if we're writing to the same table, but the PK can change, that means that some
    //mutations might be in our current region, and others in a different one.
    if (areMutationsInSameTable && isPKChanging) {
        RegionInfo regionInfo = region.getRegionInfo();
        for (Mutation mutation : mutations){
            if (regionInfo.containsRow(mutation.getRow())){
                localRegionMutations.add(mutation);
            } else {
                remoteRegionMutations.add(mutation);
            }
        }
    } else if (areMutationsInSameTable && !isPKChanging) {
        localRegionMutations.addAll(mutations);
    } else {
        remoteRegionMutations.addAll(mutations);
    }
}
 
Example 3
Source File: AccessController.java    From hbase with Apache License 2.0 5 votes vote down vote up
private TableName getTableName(Region region) {
  RegionInfo regionInfo = region.getRegionInfo();
  if (regionInfo != null) {
    return regionInfo.getTable();
  }
  return null;
}
 
Example 4
Source File: TestFileSystemUtilizationChore.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a region which is the parent of a split.
 *
 * @param storeSizes A list of sizes for each Store.
 * @return A mocked Region.
 */
private Region mockSplitParentRegionWithSize(Collection<Long> storeSizes) {
  final Region r = mockRegionWithSize(storeSizes);
  final RegionInfo info = r.getRegionInfo();
  when(info.isSplitParent()).thenReturn(true);
  return r;
}
 
Example 5
Source File: TestFileSystemUtilizationChore.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a region who has a replicaId of <code>1</code>.
 *
 * @param storeSizes A list of sizes for each Store.
 * @return A mocked Region.
 */
private Region mockRegionReplicaWithSize(Collection<Long> storeSizes) {
  final Region r = mockRegionWithSize(storeSizes);
  final RegionInfo info = r.getRegionInfo();
  when(info.getReplicaId()).thenReturn(1);
  return r;
}
 
Example 6
Source File: UngroupedAggregateRegionObserver.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private RegionScanner collectStats(final RegionScanner innerScanner, StatisticsCollector stats,
        final Region region, final Scan scan, Configuration config) throws IOException {
    StatsCollectionCallable callable =
            new StatsCollectionCallable(stats, region, innerScanner, config, scan);
    byte[] asyncBytes = scan.getAttribute(BaseScannerRegionObserver.RUN_UPDATE_STATS_ASYNC_ATTRIB);
    boolean async = false;
    if (asyncBytes != null) {
        async = Bytes.toBoolean(asyncBytes);
    }
    long rowCount = 0; // in case of async, we report 0 as number of rows updated
    StatisticsCollectionRunTracker statsRunTracker =
            StatisticsCollectionRunTracker.getInstance(config);
    final boolean runUpdateStats = statsRunTracker.addUpdateStatsCommandRegion(region.getRegionInfo(),scan.getFamilyMap().keySet());
    if (runUpdateStats) {
        if (!async) {
            rowCount = callable.call();
        } else {
            statsRunTracker.runTask(callable);
        }
    } else {
        rowCount = CONCURRENT_UPDATE_STATS_ROW_COUNT;
        LOGGER.info("UPDATE STATISTICS didn't run because another UPDATE STATISTICS command was already running on the region "
                + region.getRegionInfo().getRegionNameAsString());
    }
    byte[] rowCountBytes = PLong.INSTANCE.toBytes(Long.valueOf(rowCount));
    final Cell aggKeyValue =
            PhoenixKeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY, SINGLE_COLUMN_FAMILY,
                SINGLE_COLUMN, AGG_TIMESTAMP, rowCountBytes, 0, rowCountBytes.length);
    RegionScanner scanner = new BaseRegionScanner(innerScanner) {
        @Override
        public RegionInfo getRegionInfo() {
            return region.getRegionInfo();
        }

        @Override
        public boolean isFilterDone() {
            return true;
        }

        @Override
        public void close() throws IOException {
            // If we ran/scheduled StatsCollectionCallable the delegate
            // scanner is closed there. Otherwise close it here.
            if (!runUpdateStats) {
                super.close();
            }
        }

        @Override
        public boolean next(List<Cell> results) throws IOException {
            results.add(aggKeyValue);
            return false;
        }

        @Override
        public long getMaxResultSize() {
            return scan.getMaxResultSize();
        }
    };
    return scanner;
}