/** * Utility. Whether to include region in list of regions. Default is to * weed out split and offline regions. * @return True if we should include the <code>node</code> (do not include * if split or offline unless <code>offline</code> is set to true. */ boolean include(final RegionStateNode node, final boolean offline) { if (LOG.isTraceEnabled()) { LOG.trace("WORKING ON " + node + " " + node.getRegionInfo()); } if (node.isInState(State.SPLIT)) return false; if (node.isInState(State.OFFLINE) && !offline) return false; final RegionInfo hri = node.getRegionInfo(); return (!hri.isOffline() && !hri.isSplit()) || ((hri.isOffline() || hri.isSplit()) && offline); }
@Override public boolean visit(Result rowResult) throws IOException { RegionInfo info = getRegionInfo(rowResult); if (info == null) { return true; } //skip over offline and split regions if (!(info.isOffline() || info.isSplit())) { return visitInternal(rowResult); } return true; } }
/** * Create any replicas for the regions (the default replicas that was already created is passed to * the method) * @param tableDescriptor descriptor to use * @param regions existing regions * @param oldReplicaCount existing replica count * @param newReplicaCount updated replica count due to modify table * @return the combined list of default and non-default replicas */ public static List<RegionInfo> addReplicas(final TableDescriptor tableDescriptor, final List<RegionInfo> regions, int oldReplicaCount, int newReplicaCount) { if ((newReplicaCount - 1) <= 0) { return regions; } List<RegionInfo> hRegionInfos = new ArrayList<>((newReplicaCount) * regions.size()); for (RegionInfo ri : regions) { if (RegionReplicaUtil.isDefaultReplica(ri) && (!ri.isOffline() || (!ri.isSplit() && !ri.isSplitParent()))) { // region level replica index starts from 0. So if oldReplicaCount was 2 then the max replicaId for // the existing regions would be 1 for (int j = oldReplicaCount; j < newReplicaCount; j++) { hRegionInfos.add(RegionReplicaUtil.getRegionInfoForReplica(ri, j)); } } } hRegionInfos.addAll(regions); return hRegionInfos; } }
.filter(l -> !l.getRegion().isOffline()).filter(l -> l.getServerName() != null) .collect(Collectors.groupingBy(l -> l.getServerName(), Collectors.mapping(l -> l.getRegion(), Collectors.toList())));
/** * {@inheritDoc} */ @Override public CacheEvictionStats clearBlockCache(final TableName tableName) throws IOException { checkTableExists(tableName); CacheEvictionStatsBuilder cacheEvictionStats = CacheEvictionStats.builder(); List<Pair<RegionInfo, ServerName>> pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName); Map<ServerName, List<RegionInfo>> regionInfoByServerName = pairs.stream() .filter(pair -> !(pair.getFirst().isOffline())) .filter(pair -> pair.getSecond() != null) .collect(Collectors.groupingBy(pair -> pair.getSecond(), Collectors.mapping(pair -> pair.getFirst(), Collectors.toList()))); for (Map.Entry<ServerName, List<RegionInfo>> entry : regionInfoByServerName.entrySet()) { CacheEvictionStats stats = clearBlockCache(entry.getKey(), entry.getValue()); cacheEvictionStats = cacheEvictionStats.append(stats); if (stats.getExceptionCount() > 0) { for (Map.Entry<byte[], Throwable> exception : stats.getExceptions().entrySet()) { LOG.debug("Failed to clear block cache for " + Bytes.toStringBinary(exception.getKey()) + " on " + entry.getKey() + ": ", exception.getValue()); } } } return cacheEvictionStats.build(); }
.filter(l -> !l.getRegion().isOffline()).filter(l -> l.getServerName() != null) .map(l -> compact(l.getServerName(), l.getRegion(), major, columnFamily)) .toArray(CompletableFuture<?>[]::new);
private boolean isValidRegion(RegionInfo hri) { // An offline split parent region should be excluded. if (hri.isOffline() && (hri.isSplit() || hri.isSplitParent())) { return false; } return PrivateCellUtil.overlappingKeys(scan.getStartRow(), scan.getStopRow(), hri.getStartKey(), hri.getEndKey()); }
/** * Costruct a copy of another HRegionInfo * * @param other */ public HRegionInfo(RegionInfo other) { super(); this.endKey = other.getEndKey(); this.offLine = other.isOffline(); this.regionId = other.getRegionId(); this.regionName = other.getRegionName(); this.split = other.isSplit(); this.startKey = other.getStartKey(); this.hashCode = other.hashCode(); this.encodedName = other.getEncodedName(); this.tableName = other.getTable(); this.replicaId = other.getReplicaId(); }
if (info == null || info.isOffline() || info.isSplitParent()) { continue;
private RegionInfoBuilder(RegionInfo regionInfo) { this.tableName = regionInfo.getTable(); this.startKey = regionInfo.getStartKey(); this.endKey = regionInfo.getEndKey(); this.offLine = regionInfo.isOffline(); this.split = regionInfo.isSplit(); this.regionId = regionInfo.getRegionId(); this.replicaId = regionInfo.getReplicaId(); this.regionName = regionInfo.getRegionName(); this.encodedName = regionInfo.getEncodedName(); }
assert regionLocation != null : "found null region location for " + regionNode; regionStates.addRegionToServer(regionNode); } else if (localState == State.OFFLINE || regionInfo.isOffline()) { regionStates.addToOfflineRegions(regionNode);
.filter(r -> !r.isOffline()) .map(RegionInfo::getRegionName) .findFirst()
public static RegionInfo cloneRegionInfo(TableName tableName, RegionInfo snapshotRegionInfo) { return RegionInfoBuilder.newBuilder(tableName) .setStartKey(snapshotRegionInfo.getStartKey()) .setEndKey(snapshotRegionInfo.getEndKey()) .setSplit(snapshotRegionInfo.isSplit()) .setRegionId(snapshotRegionInfo.getRegionId()) .setOffline(snapshotRegionInfo.isOffline()) .build(); }
return false; if (parentHRI.isSplit() || parentHRI.isOffline()) { LOG.info("Split of " + parentHRI + " skipped because offline/split."); return false;
private HRegionInfo convert(RegionInfo ri) { HRegionInfo hri = new HRegionInfo( ri.getTable(), ri.getStartKey(), ri.getEndKey(), ri.isSplit(), ri.getRegionId()); hri.setOffline(ri.isOffline()); return hri; } }
private HRegionInfo convert(RegionInfo ri) { HRegionInfo hri =new HRegionInfo(ri.getTable(), ri.getStartKey(), ri.getEndKey(), ri.isSplit(), ri.getRegionId()); hri.setOffline(ri.isOffline()); return hri; } }
public void checkOnline() throws DoNotRetryRegionException { RegionInfo ri = getRegionInfo(); State s = state; if (s != State.OPEN) { throw new DoNotRetryRegionException(ri.getEncodedName() + " is no OPEN; state=" + s); } if (ri.isSplitParent()) { throw new DoNotRetryRegionException( ri.getEncodedName() + " is not online (splitParent=true)"); } if (ri.isSplit()) { throw new DoNotRetryRegionException(ri.getEncodedName() + " has split=true"); } if (ri.isOffline()) { // RegionOfflineException is not instance of DNRIOE so wrap it. throw new DoNotRetryRegionException(new RegionOfflineException(ri.getEncodedName())); } }
/** * Convert a RegionInfo to a Proto RegionInfo * * @param info the RegionInfo to convert * @return the converted Proto RegionInfo */ public static HBaseProtos.RegionInfo toRegionInfo(final org.apache.hadoop.hbase.client.RegionInfo info) { if (info == null) return null; HBaseProtos.RegionInfo.Builder builder = HBaseProtos.RegionInfo.newBuilder(); builder.setTableName(ProtobufUtil.toProtoTableName(info.getTable())); builder.setRegionId(info.getRegionId()); if (info.getStartKey() != null) { builder.setStartKey(UnsafeByteOperations.unsafeWrap(info.getStartKey())); } if (info.getEndKey() != null) { builder.setEndKey(UnsafeByteOperations.unsafeWrap(info.getEndKey())); } builder.setOffline(info.isOffline()); builder.setSplit(info.isSplit()); builder.setReplicaId(info.getReplicaId()); return builder.build(); }
@Test public void testBuilder() { TableName tn = TableName.valueOf("test"); RegionInfoBuilder builder = RegionInfoBuilder.newBuilder(tn); byte[] startKey = Bytes.toBytes("a"); builder.setStartKey(startKey); byte[] endKey = Bytes.toBytes("z"); builder.setEndKey(endKey); int regionId = 1; builder.setRegionId(1); int replicaId = 2; builder.setReplicaId(replicaId); boolean offline = true; builder.setOffline(offline); boolean isSplit = true; builder.setSplit(isSplit); RegionInfo ri = builder.build(); assertEquals(tn, ri.getTable()); assertArrayEquals(startKey, ri.getStartKey()); assertArrayEquals(endKey, ri.getEndKey()); assertEquals(regionId, ri.getRegionId()); assertEquals(replicaId, ri.getReplicaId()); assertEquals(offline, ri.isOffline()); assertEquals(isSplit, ri.isSplit()); }