private static List<Pair<String, Supplier<Scan>>> getScanCreator() { return Arrays.asList(Pair.newPair("normal", AbstractTestAsyncTableScan::createNormalScan), Pair.newPair("batch", AbstractTestAsyncTableScan::createBatchScan), Pair.newPair("smallResultSize", AbstractTestAsyncTableScan::createSmallResultSizeScan), Pair.newPair("batchSmallResultSize", AbstractTestAsyncTableScan::createBatchSmallResultSizeScan)); }
/** * Set the EventLoopGroup and channel class for {@code AsyncFSWALProvider}. */ public static void setEventLoopConfig(Configuration conf, EventLoopGroup group, Class<? extends Channel> channelClass) { Preconditions.checkNotNull(group, "group is null"); Preconditions.checkNotNull(channelClass, "channel class is null"); conf.set(EVENT_LOOP_CONFIG, CONFIG_NAME); EVENT_LOOP_CONFIG_MAP.put(CONFIG_NAME, Pair.<EventLoopGroup, Class<? extends Channel>> newPair(group, channelClass)); }
/** * Set the EventLoopGroup and channel class for {@code AsyncRpcClient}. */ public static void setEventLoopConfig(Configuration conf, EventLoopGroup group, Class<? extends Channel> channelClass) { Preconditions.checkNotNull(group, "group is null"); Preconditions.checkNotNull(channelClass, "channel class is null"); conf.set(EVENT_LOOP_CONFIG, CONFIG_NAME); EVENT_LOOP_CONFIG_MAP.put(CONFIG_NAME, Pair.<EventLoopGroup, Class<? extends Channel>> newPair(group, channelClass)); }
@Override public void notExecuted(Store store, String reason) { notExecutedStores.add(Pair.newPair(store, reason)); }
static Pair<EventLoopGroup, Class<? extends Channel>> getEventLoopConfig(Configuration conf) { String name = conf.get(EVENT_LOOP_CONFIG); if (StringUtils.isBlank(name)) { // create new event loop group if config is empty return Pair.<EventLoopGroup, Class<? extends Channel>> newPair( new NioEventLoopGroup(0, new DefaultThreadFactory("AsyncFSWAL", true, Thread.MAX_PRIORITY)), NioSocketChannel.class); } return EVENT_LOOP_CONFIG_MAP.get(name); }
/** * Gets the starting and ending row keys for every region in the currently open table. * <p> * This is mainly useful for the MapReduce integration. * @return Pair of arrays of region starting and ending row keys * @throws IOException if a remote or network exception occurs */ default CompletableFuture<List<Pair<byte[], byte[]>>> getStartEndKeys() throws IOException { return getAllRegionLocations().thenApply( locs -> locs.stream().filter(loc -> RegionReplicaUtil.isDefaultReplica(loc.getRegion())) .map(HRegionLocation::getRegion).map(r -> Pair.newPair(r.getStartKey(), r.getEndKey())) .collect(Collectors.toList())); }
public Pair<SyncReplicationState, SyncReplicationState> getSyncReplicationStateAndNewState() { int bits = this.syncReplicationStateBits; return Pair.newPair(getSyncReplicationState(bits), getNewSyncReplicationState(bits)); }
/** * Gets the starting and ending row keys for every region in the currently open table. * <p> * This is mainly useful for the MapReduce integration. * @return Pair of arrays of region starting and ending row keys * @throws IOException if a remote or network exception occurs */ default Pair<byte[][], byte[][]> getStartEndKeys() throws IOException { List<HRegionLocation> regions = getAllRegionLocations().stream() .filter(loc -> RegionReplicaUtil.isDefaultReplica(loc.getRegion())) .collect(Collectors.toList()); byte[][] startKeys = new byte[regions.size()][]; byte[][] endKeys = new byte[regions.size()][]; for (int i = 0, n = regions.size(); i < n; i++) { RegionInfo region = regions.get(i).getRegion(); startKeys[i] = region.getStartKey(); endKeys[i] = region.getEndKey(); } return Pair.newPair(startKeys, endKeys); }
public static List<Pair<String, Long>> getTableEncodedRegionNameAndLastBarrier(Connection conn, TableName tableName) throws IOException { List<Pair<String, Long>> list = new ArrayList<>(); scanMeta(conn, getTableStartRowForMeta(tableName, QueryType.REPLICATION), getTableStopRowForMeta(tableName, QueryType.REPLICATION), QueryType.REPLICATION, r -> { byte[] value = r.getValue(HConstants.REPLICATION_BARRIER_FAMILY, HConstants.SEQNUM_QUALIFIER); if (value == null) { return true; } long lastBarrier = Bytes.toLong(value); String encodedRegionName = RegionInfo.encodeRegionName(r.getRow()); list.add(Pair.newPair(encodedRegionName, lastBarrier)); return true; }); return list; }
/** * Return the {lastPushedSequenceId, ZNodeDataVersion} pair. if ZNodeDataVersion is -1, it means * that the ZNode does not exist. */ @VisibleForTesting protected Pair<Long, Integer> getLastSequenceIdWithVersion(String encodedRegionName, String peerId) throws KeeperException { Stat stat = new Stat(); String path = getSerialReplicationRegionPeerNode(encodedRegionName, peerId); byte[] data = ZKUtil.getDataNoWatch(zookeeper, path, stat); if (data == null) { // ZNode does not exist, so just return version -1 to indicate that no node exist. return Pair.newPair(HConstants.NO_SEQNUM, -1); } try { return Pair.newPair(ZKUtil.parseWALPositionFrom(data), stat.getVersion()); } catch (DeserializationException de) { LOG.warn("Failed to parse log position (region=" + encodedRegionName + ", peerId=" + peerId + "), data=" + Bytes.toStringBinary(data)); } return Pair.newPair(HConstants.NO_SEQNUM, stat.getVersion()); }
@Override public Optional<Pair<String, String>> getPeerIdAndRemoteWALDir(TableName table) { if (table != null && table.equals(TABLE)) { return Optional.of(Pair.newPair(PEER_ID, REMOTE_WAL_DIR)); } else { return Optional.empty(); } }
@Override public Optional<Pair<String, String>> getPeerIdAndRemoteWALDir(TableName table) { if (table == null) { return Optional.empty(); } String peerId = mapping.getPeerId(table); if (peerId == null) { return Optional.empty(); } ReplicationPeerImpl peer = replicationPeers.getPeer(peerId); if (peer == null) { return Optional.empty(); } Pair<SyncReplicationState, SyncReplicationState> states = peer.getSyncReplicationStateAndNewState(); if ((states.getFirst() == SyncReplicationState.ACTIVE && states.getSecond() == SyncReplicationState.NONE) || (states.getFirst() == SyncReplicationState.DOWNGRADE_ACTIVE && states.getSecond() == SyncReplicationState.ACTIVE)) { return Optional.of(Pair.newPair(peerId, peer.getPeerConfig().getRemoteWALDir())); } else { return Optional.empty(); } }
@Override protected Pair<byte[][], byte[][]> getStartEndKeys(TableName tableName) throws IOException { List<Pair<byte[], byte[]>> startEndKeys = get(CONN.getRegionLocator(tableName).getStartEndKeys()); byte[][] startKeys = new byte[startEndKeys.size()][]; byte[][] endKeys = new byte[startEndKeys.size()][]; for (int i = 0, n = startEndKeys.size(); i < n; i++) { Pair<byte[], byte[]> pair = startEndKeys.get(i); startKeys[i] = pair.getFirst(); endKeys[i] = pair.getSecond(); } return Pair.newPair(startKeys, endKeys); }
private static Pair<HRegion, HRegionServer> getRegionWithName(TableName tableName) { MiniHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster(); List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads(); for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) { HRegionServer hrs = rsts.get(i).getRegionServer(); for (HRegion region : hrs.getRegions(tableName)) { return Pair.newPair(region, hrs); } } return null; }
private static Pair<List<Result>, ScanMetrics> doScanWithAsyncTableScanner(Scan scan) throws IOException { try (ResultScanner scanner = CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()).getScanner(scan)) { List<Result> results = new ArrayList<>(); for (Result result; (result = scanner.next()) != null;) { results.add(result); } return Pair.newPair(results, scanner.getScanMetrics()); } }
private static Pair<List<Result>, ScanMetrics> doScanWithRawAsyncTable(Scan scan) throws IOException, InterruptedException { BufferingScanResultConsumer consumer = new BufferingScanResultConsumer(); CONN.getTable(TABLE_NAME).scan(scan, consumer); List<Result> results = new ArrayList<>(); for (Result result; (result = consumer.take()) != null;) { results.add(result); } return Pair.newPair(results, consumer.getScanMetrics()); }
private Pair<RegionState.State, ServerName> getStateAndServerName( ZooKeeperProtos.MetaRegionServer proto) { RegionState.State state; if (proto.hasState()) { state = RegionState.State.convert(proto.getState()); } else { state = RegionState.State.OPEN; } HBaseProtos.ServerName snProto = proto.getServer(); return Pair.newPair(state, ServerName.valueOf(snProto.getHostName(), snProto.getPort(), snProto.getStartCode())); }
@Test public void testGetAllHFileRefsCversionChange() throws IOException, ReplicationException { ZKReplicationQueueStorage storage = createWithUnstableVersion(); storage.addPeerToHFileRefs("1"); Path p = new Path("/test"); storage.addHFileRefs("1", Arrays.asList(Pair.newPair(p, p))); // This should return eventually when cversion stabilizes Set<String> allHFileRefs = storage.getAllHFileRefs(); assertEquals(1, allHFileRefs.size()); assertThat(allHFileRefs, hasItems("test")); }
private static Pair<List<Result>, ScanMetrics> doScanWithAsyncTableScan(Scan scan) throws Exception { SimpleScanResultConsumer consumer = new SimpleScanResultConsumer(); CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()).scan(scan, consumer); return Pair.newPair(consumer.getAll(), consumer.getScanMetrics()); }