Skip to content

Commit

Permalink
HBASE-28356 RegionServer Canary should use Scan just like Region Cana…
Browse files Browse the repository at this point in the history
…ry with option to enable Raw Scan (#5676)

Signed-off-by: David Manning <[email protected]>
Signed-off-by: Viraj Jasani <[email protected]>
  • Loading branch information
mihir6692 authored Feb 13, 2024
1 parent e2ff158 commit a4002d6
Showing 1 changed file with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -670,14 +670,16 @@ static class RegionServerTask implements Callable<Void> {
private String serverName;
private RegionInfo region;
private RegionServerStdOutSink sink;
private Boolean rawScanEnabled;
private AtomicLong successes;

RegionServerTask(Connection connection, String serverName, RegionInfo region,
RegionServerStdOutSink sink, AtomicLong successes) {
RegionServerStdOutSink sink, Boolean rawScanEnabled, AtomicLong successes) {
this.connection = connection;
this.serverName = serverName;
this.region = region;
this.sink = sink;
this.rawScanEnabled = rawScanEnabled;
this.successes = successes;
}

Expand All @@ -702,22 +704,35 @@ public Void call() {
get = new Get(startKey);
get.setCacheBlocks(false);
get.setFilter(new FirstKeyOnlyFilter());
stopWatch.start();
table.get(get);
stopWatch.stop();
// Converting get object to scan to enable RAW SCAN.
// This will work for all the regions of the HBase tables except first region.
scan = new Scan(get);

} else {
scan = new Scan();
// In case of first region of the HBase Table, we do not have start-key for the region.
// For Region Canary, we only need scan a single row/cell in the region to make sure that
// region is accessible.
//
// When HBase table has more than 1 empty regions at start of the row-key space, Canary
// will create multiple scan object to find first available row in the table by scanning
// all the regions in sequence until it can find first available row.
//
// Since First region of the table doesn't have any start key, We should set End Key as
// stop row and set inclusive=false to limit scan to first region only.
scan.withStopRow(region.getEndKey(), false);
scan.setCacheBlocks(false);
scan.setFilter(new FirstKeyOnlyFilter());
scan.setCaching(1);
scan.setMaxResultSize(1L);
scan.setOneRowLimit();
stopWatch.start();
ResultScanner s = table.getScanner(scan);
s.next();
s.close();
stopWatch.stop();
}
scan.setRaw(rawScanEnabled);
stopWatch.start();
ResultScanner s = table.getScanner(scan);
s.next();
s.close();
stopWatch.stop();
successes.incrementAndGet();
sink.publishReadTiming(tableName.getNameAsString(), serverName, stopWatch.getTime());
} catch (TableNotFoundException tnfe) {
Expand Down Expand Up @@ -1778,13 +1793,16 @@ private ZookeeperStdOutSink getSink() {
* A monitor for regionserver mode
*/
private static class RegionServerMonitor extends Monitor {
private boolean rawScanEnabled;
private boolean allRegions;

public RegionServerMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,
Sink sink, ExecutorService executor, boolean allRegions, boolean treatFailureAsError,
long allowedFailures) {
super(connection, monitorTargets, useRegExp, sink, executor, treatFailureAsError,
allowedFailures);
Configuration conf = connection.getConfiguration();
this.rawScanEnabled = conf.getBoolean(HConstants.HBASE_CANARY_READ_RAW_SCAN_KEY, false);
this.allRegions = allRegions;
}

Expand Down Expand Up @@ -1857,14 +1875,14 @@ private void monitorRegionServers(Map<String, List<RegionInfo>> rsAndRMap,
} else if (this.allRegions) {
for (RegionInfo region : entry.getValue()) {
tasks.add(new RegionServerTask(this.connection, serverName, region, regionServerSink,
successes));
this.rawScanEnabled, successes));
}
} else {
// random select a region if flag not set
RegionInfo region =
entry.getValue().get(ThreadLocalRandom.current().nextInt(entry.getValue().size()));
tasks.add(
new RegionServerTask(this.connection, serverName, region, regionServerSink, successes));
tasks.add(new RegionServerTask(this.connection, serverName, region, regionServerSink,
this.rawScanEnabled, successes));
}
}
try {
Expand Down

0 comments on commit a4002d6

Please sign in to comment.