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(); }
private static boolean isRegionStillOpening( RegionInfo regionInfo, RegionServerServices rsServices) { byte[] encodedName = regionInfo.getEncodedNameAsBytes(); Boolean action = rsServices.getRegionsInTransitionInRS().get(encodedName); return Boolean.TRUE.equals(action); // true means opening for RIT }
/** * Called by delete table and similar to notify the ServerManager that a region was removed. */ public void removeRegion(final RegionInfo regionInfo) { final byte[] encodedName = regionInfo.getEncodedNameAsBytes(); storeFlushedSequenceIdsByRegion.remove(encodedName); flushedSequenceIdByRegion.remove(encodedName); }
@VisibleForTesting public boolean isRegionInServerManagerStates(final RegionInfo hri) { final byte[] encodedName = hri.getEncodedNameAsBytes(); return (storeFlushedSequenceIdsByRegion.containsKey(encodedName) || flushedSequenceIdByRegion.containsKey(encodedName)); }
private static boolean isMetaRegion(final byte[] regionName) { return Bytes.equals(regionName, RegionInfoBuilder.FIRST_META_REGIONINFO.getRegionName()) || Bytes.equals(regionName, RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes()); } }
private void cleanUpAndReportFailure(IOException error) throws IOException { LOG.warn("Failed to open region {}, will report to master", regionInfo.getRegionNameAsString(), error); RegionServerServices rs = getServer(); rs.getRegionsInTransitionInRS().remove(regionInfo.getEncodedNameAsBytes(), Boolean.TRUE); if (!rs.reportRegionStateTransition(new RegionStateTransitionContext(TransitionCode.FAILED_OPEN, HConstants.NO_SEQNUM, masterSystemTime, regionInfo))) { throw new IOException( "Failed to report failed open to master: " + regionInfo.getRegionNameAsString()); } }
private Entry createEntry(RegionInfo region, long seqId) { WALKeyImpl key = mock(WALKeyImpl.class); when(key.getTableName()).thenReturn(tableName); when(key.getEncodedRegionName()).thenReturn(region.getEncodedNameAsBytes()); when(key.getSequenceId()).thenReturn(seqId); Entry entry = mock(Entry.class); when(entry.getKey()).thenReturn(key); return entry; }
static void moveRegion(Admin admin, ServerName [] servers, RegionInfo regionInfo) { try { String destServerName = servers[RandomUtils.nextInt(0, servers.length)].getServerName(); LOG.debug("Moving {} to {}", regionInfo.getRegionNameAsString(), destServerName); admin.move(regionInfo.getEncodedNameAsBytes(), Bytes.toBytes(destServerName)); } catch (Exception ex) { LOG.warn("Move failed, might be caused by other chaos: {}", ex.getMessage()); } } }
private boolean isCompacting(MajorCompactionRequest request) throws Exception { CompactionState compactionState = connection.getAdmin() .getCompactionStateForRegion(request.getRegion().getEncodedNameAsBytes()); return compactionState.equals(CompactionState.MAJOR) || compactionState .equals(CompactionState.MAJOR_AND_MINOR); }
private static WAL.Entry generateEdit(int i, RegionInfo hri, TableName tableName, byte[] row, int columnCount, long timestamp, MultiVersionConcurrencyControl mvcc) { WALKeyImpl key = new WALKeyImpl(hri.getEncodedNameAsBytes(), tableName, i, timestamp, HConstants.DEFAULT_CLUSTER_ID, mvcc); WALEdit edit = new WALEdit(); int prefix = i; IntStream.range(0, columnCount).mapToObj(j -> toValue(prefix, j)) .map(value -> new KeyValue(row, row, row, timestamp, value)).forEachOrdered(edit::add); return new WAL.Entry(key, edit); }
private long appendToLog(int count) throws IOException { return log.append(info, new WALKeyImpl(info.getEncodedNameAsBytes(), tableName, System.currentTimeMillis(), mvcc, scopes), getWALEdits(count), true); }
private PairOfSameType<RegionInfo> requestMergeRegion( HMaster master, TableName tablename, int regionAnum, int regionBnum) throws Exception { List<Pair<RegionInfo, ServerName>> tableRegions = MetaTableAccessor .getTableRegionsAndLocations( TEST_UTIL.getConnection(), tablename); RegionInfo regionA = tableRegions.get(regionAnum).getFirst(); RegionInfo regionB = tableRegions.get(regionBnum).getFirst(); ADMIN.mergeRegionsAsync( regionA.getEncodedNameAsBytes(), regionB.getEncodedNameAsBytes(), false); return new PairOfSameType<>(regionA, regionB); }
@Test(timeout = 30000) public void test() throws Exception { RegionInfo regionInfo = UTIL.getAdmin().getRegions(TableName.valueOf(TABLENAME)).get(0); //See HBASE-21754 //There is Only one handler, if ReportRegionStateTransitionRequest executes in the same kind // of thread with moveRegion, it will lock each other. Making the move operation can not finish. UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes(), null); LOG.info("Region move complete"); }
private void move() throws IOException, InterruptedException { RegionInfo region = UTIL.getHBaseCluster().getRegions(tableName).stream().findAny().get().getRegionInfo(); HRegionServer rs = UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()) .filter(r -> !r.getOnlineTables().contains(tableName)).findAny().get(); UTIL.getAdmin().move(region.getEncodedNameAsBytes(), Bytes.toBytes(rs.getServerName().getServerName())); while (UTIL.getRSForFirstRegionInTable(tableName) != rs) { Thread.sleep(100); } }
@Override public void updateLowestUnflushedSequenceIdInWAL(boolean onlyIfGreater) { long minSequenceId = pipeline.getMinSequenceId(); if(minSequenceId != Long.MAX_VALUE) { byte[] encodedRegionName = getRegionServices().getRegionInfo().getEncodedNameAsBytes(); byte[] familyName = getFamilyNameInBytes(); WAL WAL = getRegionServices().getWAL(); if (WAL != null) { WAL.updateStore(encodedRegionName, familyName, minSequenceId, onlyIfGreater); } } }
private void appendToLog(String key) throws IOException { final long txid = log.append(info, new WALKeyImpl(info.getEncodedNameAsBytes(), tableName, System.currentTimeMillis(), mvcc, scopes), getWALEdit(key), true); log.sync(txid); }
private WALKeyImpl getWalKey(final long time, RegionInfo hri, final long startPoint) { return new WALKeyImpl(hri.getEncodedNameAsBytes(), tableName, time, new MultiVersionConcurrencyControl(startPoint)); }
private void addEdits(WAL log, RegionInfo hri, TableDescriptor htd, int times, NavigableMap<byte[], Integer> scopes) throws IOException { final byte[] row = Bytes.toBytes("row"); for (int i = 0; i < times; i++) { long timestamp = System.currentTimeMillis(); WALEdit cols = new WALEdit(); cols.add(new KeyValue(row, row, row, timestamp, row)); log.append(hri, getWalKey(hri.getEncodedNameAsBytes(), htd.getTableName(), timestamp, scopes), cols, true); } log.sync(); }
private Entry createWALEntry(byte[] row, byte[] value) { WALKeyImpl key = new WALKeyImpl(regionInfo.getEncodedNameAsBytes(), tableName, 1); WALEdit edit = new WALEdit(); edit.add(new KeyValue(row, family, qualifier, timestamp, value)); return new Entry(key, edit); } }
private void moveRegion(Table table, int index) throws IOException{ List<Pair<RegionInfo, ServerName>> regions = MetaTableAccessor .getTableRegionsAndLocations(TEST_UTIL.getConnection(), table.getName()); assertEquals(1, regions.size()); RegionInfo regionInfo = regions.get(0).getFirst(); ServerName name = TEST_UTIL.getHBaseCluster().getRegionServer(index).getServerName(); TEST_UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes(), Bytes.toBytes(name.getServerName())); }