public RegionReplicaReplayCallable(ClusterConnection connection, RpcControllerFactory rpcControllerFactory, TableName tableName, HRegionLocation location, RegionInfo regionInfo, byte[] row,List<Entry> entries, AtomicLong skippedEntries) { super(connection, rpcControllerFactory, location, tableName, row, regionInfo.getReplicaId()); this.entries = entries; this.skippedEntries = skippedEntries; this.initialEncodedRegionName = regionInfo.getEncodedNameAsBytes(); }
/** * Get the replica id of this region. */ @Override public int getReplicaId() { return region.getRegionInfo().getReplicaId(); }
@Override public boolean isPrimaryReplicaStore() { return getRegionInfo().getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID; }
public synchronized void addServer(RegionInfo hri, ServerName server) { OnlineEntry rse = new OnlineEntry() ; rse.hri = hri; rse.hsa = server; this.deployedEntries.add(rse); this.deployedOn.add(server); // save the replicaId that we see deployed in the cluster this.deployedReplicaId = hri.getReplicaId(); this.primaryHRIForDeployedReplica = RegionReplicaUtil.getRegionInfoForDefaultReplica(hri); }
private void updateMetaLocation(RegionInfo regionInfo, ServerName serverName, State state) throws IOException { try { MetaTableLocator.setMetaLocation(master.getZooKeeper(), serverName, regionInfo.getReplicaId(), state); } catch (KeeperException e) { throw new IOException(e); } }
private HRegionLocation getCacheLocation(HRegionLocation loc) { RegionLocations locs = metaRegionLocations.get(); return locs != null ? locs.getRegionLocation(loc.getRegion().getReplicaId()) : null; }
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 Result get(final Get get) throws IOException { prepareGet(get); List<Cell> results = get(get, true); boolean stale = this.getRegionInfo().getReplicaId() != 0; return Result.create(results, get.isCheckExistenceOnly() ? !results.isEmpty() : null, stale); }
/** * 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; }
/** * @param region the region which we want to get a WAL for it. Could be null. */ public WAL getWAL(RegionInfo region) throws IOException { // use different WAL for hbase:meta if (region != null && region.isMetaRegion() && region.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) { return getMetaProvider().getWAL(region); } else { return provider.getWAL(region); } }
private HRegion findSplittableRegion(final List<HRegion> regions) throws InterruptedException { for (int i = 0; i < 5; ++i) { for (HRegion r: regions) { if (r.isSplittable() && r.getRegionInfo().getReplicaId() == 0) { return(r); } } Thread.sleep(100); } return(null); }
private ServerName findRegionLocation(TableName tableName, byte[] startKey, int replicaId) { return UTIL.getMiniHBaseCluster().getRegionServerThreads().stream() .map(t -> t.getRegionServer()) .filter(rs -> rs.getRegions(tableName).stream().map(Region::getRegionInfo) .anyMatch(r -> r.containsRow(startKey) && r.getReplicaId() == replicaId)) .findFirst().get().getServerName(); }
static Optional<ServerName> getRSCarryingReplica(HBaseTestingUtility util, TableName tableName, int replicaId) { return util.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()) .filter(rs -> rs.getRegions(tableName).stream() .anyMatch(r -> r.getRegionInfo().getReplicaId() == replicaId)) .findAny().map(rs -> rs.getServerName()); }
private HRegionLocation getCachedLocation(HRegionLocation loc) { TableCache tableCache = cache.get(loc.getRegion().getTable()); if (tableCache == null) { return null; } RegionLocations locs = tableCache.cache.get(loc.getRegion().getStartKey()); return locs != null ? locs.getRegionLocation(loc.getRegion().getReplicaId()) : null; }
@Override public void postWALWrite(ObserverContext<? extends WALCoprocessorEnvironment> ctx, RegionInfo info, WALKey logKey, WALEdit logEdit) throws IOException { // only keep primary region's edits if (logKey.getTableName().equals(tableName) && info.getReplicaId() == 0) { // Presume type is a WALKeyImpl entries.add(new Entry((WALKeyImpl)logKey, logEdit)); } } }
private void recordAndTryFail(ObserverContext<RegionCoprocessorEnvironment> c) throws IOException { RegionInfo region = c.getEnvironment().getRegionInfo(); if (!region.getTable().equals(TABLE_NAME)) { return; } REPLICA_ID_TO_COUNT.computeIfAbsent(region.getReplicaId(), k -> new AtomicInteger()) .incrementAndGet(); if (region.getRegionId() == RegionReplicaUtil.DEFAULT_REPLICA_ID && FAIL_PRIMARY_GET) { throw new IOException("Inject error"); } }
@Override public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> e, final Get get, final List<Cell> results) throws IOException { int replicaId = e.getEnvironment().getRegion().getRegionInfo().getReplicaId(); // Fail for the primary replica and replica 1 if (e.getEnvironment().getRegion().getRegionInfo().getReplicaId() <= 1) { LOG.info("Throw Region Server Stopped Exceptoin for replica id " + replicaId); throw new RegionServerStoppedException("Server " + e.getEnvironment().getServerName() + " not running"); } else { LOG.info("We're replica region " + replicaId); } }
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(); }
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()); }