use of org.apache.hadoop.hbase.MetaTableAccessor.Visitor in project hbase by apache.
the class TestMasterOperationsForRegionReplicas method validateNumberOfRowsInMeta.
private void validateNumberOfRowsInMeta(final TableName table, int numRegions, Connection connection) throws IOException {
assert (ADMIN.tableExists(table));
final AtomicInteger count = new AtomicInteger();
Visitor visitor = new Visitor() {
@Override
public boolean visit(Result r) throws IOException {
if (MetaTableAccessor.getHRegionInfo(r).getTable().equals(table))
count.incrementAndGet();
return true;
}
};
MetaTableAccessor.fullScanRegions(connection, visitor);
assert (count.get() == numRegions);
}
use of org.apache.hadoop.hbase.MetaTableAccessor.Visitor in project hbase by apache.
the class SnapshotOfRegionAssignmentFromMeta method initialize.
/**
* Initialize the region assignment snapshot by scanning the hbase:meta table
* @throws IOException
*/
public void initialize() throws IOException {
LOG.info("Start to scan the hbase:meta for the current region assignment " + "snappshot");
// TODO: at some point this code could live in the MetaTableAccessor
Visitor v = new Visitor() {
@Override
public boolean visit(Result result) throws IOException {
try {
if (result == null || result.isEmpty())
return true;
RegionLocations rl = MetaTableAccessor.getRegionLocations(result);
if (rl == null)
return true;
HRegionInfo hri = rl.getRegionLocation(0).getRegionInfo();
if (hri == null)
return true;
if (hri.getTable() == null)
return true;
if (disabledTables.contains(hri.getTable())) {
return true;
}
// Are we to include split parents in the list?
if (excludeOfflinedSplitParents && hri.isSplit())
return true;
HRegionLocation[] hrls = rl.getRegionLocations();
// Add the current assignment to the snapshot for all replicas
for (int i = 0; i < hrls.length; i++) {
if (hrls[i] == null)
continue;
hri = hrls[i].getRegionInfo();
if (hri == null)
continue;
addAssignment(hri, hrls[i].getServerName());
addRegion(hri);
}
hri = rl.getRegionLocation(0).getRegionInfo();
// the code below is to handle favored nodes
byte[] favoredNodes = result.getValue(HConstants.CATALOG_FAMILY, FavoredNodeAssignmentHelper.FAVOREDNODES_QUALIFIER);
if (favoredNodes == null)
return true;
// Add the favored nodes into assignment plan
ServerName[] favoredServerList = FavoredNodeAssignmentHelper.getFavoredNodesList(favoredNodes);
// Add the favored nodes into assignment plan
existingAssignmentPlan.updateFavoredNodesMap(hri, Arrays.asList(favoredServerList));
/*
* Typically there should be FAVORED_NODES_NUM favored nodes for a region in meta. If
* there is less than FAVORED_NODES_NUM, lets use as much as we can but log a warning.
*/
if (favoredServerList.length != FavoredNodeAssignmentHelper.FAVORED_NODES_NUM) {
LOG.warn("Insufficient favored nodes for region " + hri + " fn: " + Arrays.toString(favoredServerList));
}
for (int i = 0; i < favoredServerList.length; i++) {
if (i == PRIMARY.ordinal())
addPrimaryAssignment(hri, favoredServerList[i]);
if (i == SECONDARY.ordinal())
addSecondaryAssignment(hri, favoredServerList[i]);
if (i == TERTIARY.ordinal())
addTeritiaryAssignment(hri, favoredServerList[i]);
}
return true;
} catch (RuntimeException e) {
LOG.error("Catche remote exception " + e.getMessage() + " when processing" + result);
throw e;
}
}
};
// Scan hbase:meta to pick up user regions
MetaTableAccessor.fullScanRegions(connection, v);
//regionToRegionServerMap = regions;
LOG.info("Finished to scan the hbase:meta for the current region assignment" + "snapshot");
}
Aggregations