HBASE-14145 added flag to canary to try all regions in regionserver mode

Signed-off-by: Elliott Clark <eclark@apache.org>
This commit is contained in:
Sanjeev Srivatsa 2015-09-08 17:28:11 -07:00 committed by Elliott Clark
parent 1e90df8aa8
commit 9e7f9b621a
1 changed files with 48 additions and 8 deletions

View File

@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -307,13 +308,15 @@ public final class Canary implements Tool {
private String serverName; private String serverName;
private HRegionInfo region; private HRegionInfo region;
private ExtendedSink sink; private ExtendedSink sink;
private AtomicLong successes;
RegionServerTask(Connection connection, String serverName, HRegionInfo region, RegionServerTask(Connection connection, String serverName, HRegionInfo region,
ExtendedSink sink) { ExtendedSink sink, AtomicLong successes) {
this.connection = connection; this.connection = connection;
this.serverName = serverName; this.serverName = serverName;
this.region = region; this.region = region;
this.sink = sink; this.sink = sink;
this.successes = successes;
} }
@Override @Override
@ -349,12 +352,14 @@ public final class Canary implements Tool {
s.close(); s.close();
stopWatch.stop(); stopWatch.stop();
} }
successes.incrementAndGet();
sink.publishReadTiming(tableName.getNameAsString(), serverName, stopWatch.getTime()); sink.publishReadTiming(tableName.getNameAsString(), serverName, stopWatch.getTime());
} catch (TableNotFoundException tnfe) { } catch (TableNotFoundException tnfe) {
LOG.error("Table may be deleted", tnfe); LOG.error("Table may be deleted", tnfe);
// This is ignored because it doesn't imply that the regionserver is dead // This is ignored because it doesn't imply that the regionserver is dead
} catch (TableNotEnabledException tnee) { } catch (TableNotEnabledException tnee) {
// This is considered a success since we got a response. // This is considered a success since we got a response.
successes.incrementAndGet();
LOG.debug("The targeted table was disabled. Assuming success."); LOG.debug("The targeted table was disabled. Assuming success.");
} catch (DoNotRetryIOException dnrioe) { } catch (DoNotRetryIOException dnrioe) {
sink.publishReadFailure(tableName.getNameAsString(), serverName); sink.publishReadFailure(tableName.getNameAsString(), serverName);
@ -403,6 +408,7 @@ public final class Canary implements Tool {
private long timeout = DEFAULT_TIMEOUT; private long timeout = DEFAULT_TIMEOUT;
private boolean failOnError = true; private boolean failOnError = true;
private boolean regionServerMode = false; private boolean regionServerMode = false;
private boolean regionServerAllRegions = false;
private boolean writeSniffing = false; private boolean writeSniffing = false;
private TableName writeTableName = DEFAULT_WRITE_TABLE_NAME; private TableName writeTableName = DEFAULT_WRITE_TABLE_NAME;
@ -463,6 +469,8 @@ public final class Canary implements Tool {
} }
} else if(cmd.equals("-regionserver")) { } else if(cmd.equals("-regionserver")) {
this.regionServerMode = true; this.regionServerMode = true;
} else if(cmd.equals("-allRegions")) {
this.regionServerAllRegions = true;
} else if(cmd.equals("-writeSniffing")) { } else if(cmd.equals("-writeSniffing")) {
this.writeSniffing = true; this.writeSniffing = true;
} else if (cmd.equals("-e")) { } else if (cmd.equals("-e")) {
@ -509,6 +517,10 @@ public final class Canary implements Tool {
index = i; index = i;
} }
} }
if (this.regionServerAllRegions && !this.regionServerMode) {
System.err.println("-allRegions can only be specified in regionserver mode.");
printUsageAndExit();
}
return index; return index;
} }
@ -594,6 +606,8 @@ public final class Canary implements Tool {
System.err.println(" -help Show this help and exit."); System.err.println(" -help Show this help and exit.");
System.err.println(" -regionserver replace the table argument to regionserver,"); System.err.println(" -regionserver replace the table argument to regionserver,");
System.err.println(" which means to enable regionserver mode"); System.err.println(" which means to enable regionserver mode");
System.err.println(" -allRegions Tries all regions on a regionserver,");
System.err.println(" only works in regionserver mode.");
System.err.println(" -daemon Continuous check at defined intervals."); System.err.println(" -daemon Continuous check at defined intervals.");
System.err.println(" -interval <N> Interval between checks (sec)"); System.err.println(" -interval <N> Interval between checks (sec)");
System.err.println(" -e Use region/regionserver as regular expression"); System.err.println(" -e Use region/regionserver as regular expression");
@ -627,7 +641,7 @@ public final class Canary implements Tool {
if (this.regionServerMode) { if (this.regionServerMode) {
monitor = monitor =
new RegionServerMonitor(connection, monitorTargets, this.useRegExp, new RegionServerMonitor(connection, monitorTargets, this.useRegExp,
(ExtendedSink) this.sink, this.executor); (ExtendedSink) this.sink, this.executor, this.regionServerAllRegions);
} else { } else {
monitor = monitor =
new RegionMonitor(connection, monitorTargets, this.useRegExp, this.sink, this.executor, new RegionMonitor(connection, monitorTargets, this.useRegExp, this.sink, this.executor,
@ -996,9 +1010,12 @@ public final class Canary implements Tool {
// a monitor for regionserver mode // a monitor for regionserver mode
private static class RegionServerMonitor extends Monitor { private static class RegionServerMonitor extends Monitor {
private boolean allRegions;
public RegionServerMonitor(Connection connection, String[] monitorTargets, boolean useRegExp, public RegionServerMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,
ExtendedSink sink, ExecutorService executor) { ExtendedSink sink, ExecutorService executor, boolean allRegions) {
super(connection, monitorTargets, useRegExp, sink, executor); super(connection, monitorTargets, useRegExp, sink, executor);
this.allRegions = allRegions;
} }
private ExtendedSink getSink() { private ExtendedSink getSink() {
@ -1047,13 +1064,29 @@ public final class Canary implements Tool {
private void monitorRegionServers(Map<String, List<HRegionInfo>> rsAndRMap) { private void monitorRegionServers(Map<String, List<HRegionInfo>> rsAndRMap) {
List<RegionServerTask> tasks = new ArrayList<RegionServerTask>(); List<RegionServerTask> tasks = new ArrayList<RegionServerTask>();
Random rand =new Random(); Map<String, AtomicLong> successMap = new HashMap<String, AtomicLong>();
// monitor one region on every region server Random rand = new Random();
for (Map.Entry<String, List<HRegionInfo>> entry : rsAndRMap.entrySet()) { for (Map.Entry<String, List<HRegionInfo>> entry : rsAndRMap.entrySet()) {
String serverName = entry.getKey(); String serverName = entry.getKey();
// random select a region AtomicLong successes = new AtomicLong(0);
HRegionInfo region = entry.getValue().get(rand.nextInt(entry.getValue().size())); successMap.put(serverName, successes);
tasks.add(new RegionServerTask(this.connection, serverName, region, getSink())); if (this.allRegions) {
for (HRegionInfo region : entry.getValue()) {
tasks.add(new RegionServerTask(this.connection,
serverName,
region,
getSink(),
successes));
}
} else {
// random select a region if flag not set
HRegionInfo region = entry.getValue().get(rand.nextInt(entry.getValue().size()));
tasks.add(new RegionServerTask(this.connection,
serverName,
region,
getSink(),
successes));
}
} }
try { try {
for (Future<Void> future : this.executor.invokeAll(tasks)) { for (Future<Void> future : this.executor.invokeAll(tasks)) {
@ -1064,6 +1097,13 @@ public final class Canary implements Tool {
this.errorCode = ERROR_EXIT_CODE; this.errorCode = ERROR_EXIT_CODE;
} }
} }
if (this.allRegions) {
for (Map.Entry<String, List<HRegionInfo>> entry : rsAndRMap.entrySet()) {
String serverName = entry.getKey();
LOG.info("Successfully read " + successMap.get(serverName) + " regions out of "
+ entry.getValue().size() + " on regionserver:" + serverName);
}
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
this.errorCode = ERROR_EXIT_CODE; this.errorCode = ERROR_EXIT_CODE;
LOG.error("Sniff regionserver failed!", e); LOG.error("Sniff regionserver failed!", e);