private void logException(int tries, Supplier<Stream<RegionRequest>> regionsSupplier, Throwable error, ServerName serverName) { if (tries > startLogErrorsCnt) { String regions = regionsSupplier.get().map(r -> "'" + r.loc.getRegion().getRegionNameAsString() + "'") .collect(Collectors.joining(",", "[", "]")); LOG.warn("Process batch for " + regions + " in " + tableName + " from " + serverName + " failed, tries=" + tries, error); } }
@Override public CompletableFuture<List<RegionInfo>> getRegions(TableName tableName) { if (tableName.equals(META_TABLE_NAME)) { return connection.getLocator().getRegionLocation(tableName, null, null, operationTimeoutNs) .thenApply(loc -> Collections.singletonList(loc.getRegion())); } else { return AsyncMetaTableAccessor.getTableHRegionLocations(metaTable, Optional.of(tableName)) .thenApply( locs -> locs.stream().map(loc -> loc.getRegion()).collect(Collectors.toList())); } }
@Override public boolean visit(Result r) throws IOException { current = getRegionLocations(r); if (!current.isPresent() || current.get().getRegionLocation().getRegion() == null) { LOG.warn("No serialized RegionInfo in " + r); return true; } RegionInfo hri = current.get().getRegionLocation().getRegion(); if (excludeOfflinedSplitParents && hri.isSplitParent()) return true; // Else call super and add this Result to the collection. return super.visit(r); }
@Override void add(Result r) { if (!current.isPresent()) { return; } for (HRegionLocation loc : current.get().getRegionLocations()) { if (loc != null) { this.results.add(new Pair<RegionInfo, ServerName>(loc.getRegion(), loc .getServerName())); } } } };
static RegionLocations createRegionLocations(HRegionLocation loc) { int replicaId = loc.getRegion().getReplicaId(); HRegionLocation[] locs = new HRegionLocation[replicaId + 1]; locs[replicaId] = loc; return new RegionLocations(locs); }
@Override public boolean visit(Result r) throws IOException { current = getRegionLocations(r); if (current == null || current.getRegionLocation().getRegion() == null) { LOG.warn("No serialized RegionInfo in " + r); return true; } RegionInfo hri = current.getRegionLocation().getRegion(); if (excludeOfflinedSplitParents && hri.isSplitParent()) return true; // Else call super and add this Result to the collection. return super.visit(r); }
@Override void add(Result r) { if (current == null) { return; } for (HRegionLocation loc : current.getRegionLocations()) { if (loc != null) { this.results.add(new Pair<>(loc.getRegion(), loc.getServerName())); } } } };
public void addAction(HRegionLocation loc, Action action) { computeIfAbsent(actionsByRegion, loc.getRegion().getRegionName(), () -> new RegionRequest(loc)).actions.add(action); } }
void updateCachedLocationOnError(HRegionLocation loc, Throwable exception) { if (loc.getRegion().isMetaRegion()) { metaRegionLocator.updateCachedLocationOnError(loc, exception); } else { nonMetaRegionLocator.updateCachedLocationOnError(loc, exception); } }
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(); }
private static Pair<byte[][], byte[][]> getStartEndKeys(List<RegionLocations> regions) { final byte[][] startKeyList = new byte[regions.size()][]; final byte[][] endKeyList = new byte[regions.size()][]; for (int i = 0; i < regions.size(); i++) { RegionInfo region = regions.get(i).getRegionLocation().getRegion(); startKeyList[i] = region.getStartKey(); endKeyList[i] = region.getEndKey(); } return new Pair<>(startKeyList, endKeyList); }
@Test public void testLocateBeforeLastRegion() throws IOException, InterruptedException, ExecutionException { createMultiRegionTable(); getDefaultRegionLocation(TABLE_NAME, SPLIT_KEYS[0], RegionLocateType.CURRENT, false).join(); HRegionLocation loc = getDefaultRegionLocation(TABLE_NAME, EMPTY_END_ROW, RegionLocateType.BEFORE, false).get(); // should locate to the last region assertArrayEquals(loc.getRegion().getEndKey(), EMPTY_END_ROW); }
@Test public void testOpeningReadOnlyRegionBasic() throws Exception { String snapshotDir = client.createSnapshot(baseDir, SNAPSHOT_NAME); RegionInfo firstRegion = TEST_UTIL.getConnection().getRegionLocator( table.getName()).getAllRegionLocations().stream().findFirst().get().getRegion(); Path tableDir = FSUtils.getTableDir(new Path(snapshotDir), TABLE_NAME); HRegion snapshottedRegion = openSnapshotRegion(firstRegion, tableDir); Assert.assertNotNull(snapshottedRegion); snapshottedRegion.close(); }
public static HBaseProtos.RegionLocation toRegionLocation(HRegionLocation loc) { HBaseProtos.RegionLocation.Builder builder = HBaseProtos.RegionLocation.newBuilder(); builder.setRegionInfo(toRegionInfo(loc.getRegion())); if (loc.getServerName() != null) { builder.setServerName(toServerName(loc.getServerName())); } builder.setSeqNum(loc.getSeqNum()); return builder.build(); }
@Override public Boolean rpcCall() throws Exception { SecureBulkLoadClient secureClient = null; byte[] regionName = getLocation().getRegion().getRegionName(); try (Table table = conn.getTable(getTableName())) { secureClient = new SecureBulkLoadClient(conf, table); return secureClient.secureBulkLoadHFiles(getStub(), famPaths, regionName, true, null, bulkToken); } } };
private void assertLocEquals(byte[] startKey, byte[] endKey, ServerName serverName, HRegionLocation loc) { RegionInfo info = loc.getRegion(); assertEquals(TABLE_NAME, info.getTable()); assertArrayEquals(startKey, info.getStartKey()); assertArrayEquals(endKey, info.getEndKey()); assertEquals(serverName, loc.getServerName()); }
private void assertMetaRegionLocation(HRegionLocation loc, int replicaId) { RegionInfo region = loc.getRegion(); assertArrayEquals(HConstants.EMPTY_START_ROW, region.getStartKey()); assertArrayEquals(HConstants.EMPTY_END_ROW, region.getEndKey()); assertEquals(replicaId, region.getReplicaId()); ServerName expected = findRegionLocation(TableName.META_TABLE_NAME, region.getStartKey(), replicaId); assertEquals(expected, loc.getServerName()); }
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()); }