hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [08/25] hbase-site git commit: Published site at c8dff328cb39e5a3a5a42c6b73fca7af707a0bcb.
Date Sat, 31 Mar 2018 14:48:16 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/839437ee/devapidocs/src-html/org/apache/hadoop/hbase/tool/Canary.ZookeeperTask.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/tool/Canary.ZookeeperTask.html b/devapidocs/src-html/org/apache/hadoop/hbase/tool/Canary.ZookeeperTask.html
index eff4c63..799d58c 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/tool/Canary.ZookeeperTask.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/tool/Canary.ZookeeperTask.html
@@ -845,753 +845,752 @@
 <span class="sourceLineNo">837</span>  }<a name="line.837"></a>
 <span class="sourceLineNo">838</span><a name="line.838"></a>
 <span class="sourceLineNo">839</span>  private void printUsageAndExit() {<a name="line.839"></a>
-<span class="sourceLineNo">840</span>    System.err.printf(<a name="line.840"></a>
-<span class="sourceLineNo">841</span>      "Usage: hbase %s [opts] [table1 [table2]...] | [regionserver1 [regionserver2]..]%n",<a name="line.841"></a>
-<span class="sourceLineNo">842</span>        getClass().getName());<a name="line.842"></a>
-<span class="sourceLineNo">843</span>    System.err.println(" where [opts] are:");<a name="line.843"></a>
-<span class="sourceLineNo">844</span>    System.err.println("   -help          Show this help and exit.");<a name="line.844"></a>
-<span class="sourceLineNo">845</span>    System.err.println("   -regionserver  replace the table argument to regionserver,");<a name="line.845"></a>
-<span class="sourceLineNo">846</span>    System.err.println("      which means to enable regionserver mode");<a name="line.846"></a>
-<span class="sourceLineNo">847</span>    System.err.println("   -allRegions    Tries all regions on a regionserver,");<a name="line.847"></a>
-<span class="sourceLineNo">848</span>    System.err.println("      only works in regionserver mode.");<a name="line.848"></a>
-<span class="sourceLineNo">849</span>    System.err.println("   -zookeeper    Tries to grab zookeeper.znode.parent ");<a name="line.849"></a>
-<span class="sourceLineNo">850</span>    System.err.println("      on each zookeeper instance");<a name="line.850"></a>
-<span class="sourceLineNo">851</span>    System.err.println("   -daemon        Continuous check at defined intervals.");<a name="line.851"></a>
-<span class="sourceLineNo">852</span>    System.err.println("   -interval &lt;N&gt;  Interval between checks (sec)");<a name="line.852"></a>
-<span class="sourceLineNo">853</span>    System.err.println("   -e             Use table/regionserver as regular expression");<a name="line.853"></a>
-<span class="sourceLineNo">854</span>    System.err.println("      which means the table/regionserver is regular expression pattern");<a name="line.854"></a>
-<span class="sourceLineNo">855</span>    System.err.println("   -f &lt;B&gt;         stop whole program if first error occurs," +<a name="line.855"></a>
-<span class="sourceLineNo">856</span>        " default is true");<a name="line.856"></a>
-<span class="sourceLineNo">857</span>    System.err.println("   -t &lt;N&gt;         timeout for a check, default is 600000 (millisecs)");<a name="line.857"></a>
-<span class="sourceLineNo">858</span>    System.err.println("   -writeTableTimeout &lt;N&gt;         write timeout for the writeTable, default is 600000 (millisecs)");<a name="line.858"></a>
-<span class="sourceLineNo">859</span>    System.err.println("   -readTableTimeouts &lt;tableName&gt;=&lt;read timeout&gt;,&lt;tableName&gt;=&lt;read timeout&gt;, ...    "<a name="line.859"></a>
-<span class="sourceLineNo">860</span>        + "comma-separated list of read timeouts per table (no spaces), default is 600000 (millisecs)");<a name="line.860"></a>
-<span class="sourceLineNo">861</span>    System.err.println("   -writeSniffing enable the write sniffing in canary");<a name="line.861"></a>
-<span class="sourceLineNo">862</span>    System.err.println("   -treatFailureAsError treats read / write failure as error");<a name="line.862"></a>
-<span class="sourceLineNo">863</span>    System.err.println("   -writeTable    The table used for write sniffing."<a name="line.863"></a>
-<span class="sourceLineNo">864</span>        + " Default is hbase:canary");<a name="line.864"></a>
-<span class="sourceLineNo">865</span>    System.err.println("   -Dhbase.canary.read.raw.enabled=&lt;true/false&gt; Use this flag to enable or disable raw scan during read canary test"<a name="line.865"></a>
-<span class="sourceLineNo">866</span>        + " Default is false and raw is not enabled during scan");<a name="line.866"></a>
-<span class="sourceLineNo">867</span>    System.err<a name="line.867"></a>
-<span class="sourceLineNo">868</span>        .println("   -D&lt;configProperty&gt;=&lt;value&gt; assigning or override the configuration params");<a name="line.868"></a>
-<span class="sourceLineNo">869</span>    System.exit(USAGE_EXIT_CODE);<a name="line.869"></a>
-<span class="sourceLineNo">870</span>  }<a name="line.870"></a>
-<span class="sourceLineNo">871</span><a name="line.871"></a>
-<span class="sourceLineNo">872</span>  /**<a name="line.872"></a>
-<span class="sourceLineNo">873</span>   * A Factory method for {@link Monitor}.<a name="line.873"></a>
-<span class="sourceLineNo">874</span>   * Can be overridden by user.<a name="line.874"></a>
-<span class="sourceLineNo">875</span>   * @param index a start index for monitor target<a name="line.875"></a>
-<span class="sourceLineNo">876</span>   * @param args args passed from user<a name="line.876"></a>
-<span class="sourceLineNo">877</span>   * @return a Monitor instance<a name="line.877"></a>
-<span class="sourceLineNo">878</span>   */<a name="line.878"></a>
-<span class="sourceLineNo">879</span>  public Monitor newMonitor(final Connection connection, int index, String[] args) {<a name="line.879"></a>
-<span class="sourceLineNo">880</span>    Monitor monitor = null;<a name="line.880"></a>
-<span class="sourceLineNo">881</span>    String[] monitorTargets = null;<a name="line.881"></a>
-<span class="sourceLineNo">882</span><a name="line.882"></a>
-<span class="sourceLineNo">883</span>    if(index &gt;= 0) {<a name="line.883"></a>
-<span class="sourceLineNo">884</span>      int length = args.length - index;<a name="line.884"></a>
-<span class="sourceLineNo">885</span>      monitorTargets = new String[length];<a name="line.885"></a>
-<span class="sourceLineNo">886</span>      System.arraycopy(args, index, monitorTargets, 0, length);<a name="line.886"></a>
-<span class="sourceLineNo">887</span>    }<a name="line.887"></a>
-<span class="sourceLineNo">888</span><a name="line.888"></a>
-<span class="sourceLineNo">889</span>    if (this.sink instanceof RegionServerStdOutSink || this.regionServerMode) {<a name="line.889"></a>
-<span class="sourceLineNo">890</span>      monitor =<a name="line.890"></a>
-<span class="sourceLineNo">891</span>          new RegionServerMonitor(connection, monitorTargets, this.useRegExp,<a name="line.891"></a>
-<span class="sourceLineNo">892</span>              (StdOutSink) this.sink, this.executor, this.regionServerAllRegions,<a name="line.892"></a>
-<span class="sourceLineNo">893</span>              this.treatFailureAsError);<a name="line.893"></a>
-<span class="sourceLineNo">894</span>    } else if (this.sink instanceof ZookeeperStdOutSink || this.zookeeperMode) {<a name="line.894"></a>
-<span class="sourceLineNo">895</span>      monitor =<a name="line.895"></a>
-<span class="sourceLineNo">896</span>          new ZookeeperMonitor(connection, monitorTargets, this.useRegExp,<a name="line.896"></a>
-<span class="sourceLineNo">897</span>              (StdOutSink) this.sink, this.executor, this.treatFailureAsError);<a name="line.897"></a>
-<span class="sourceLineNo">898</span>    } else {<a name="line.898"></a>
-<span class="sourceLineNo">899</span>      monitor =<a name="line.899"></a>
-<span class="sourceLineNo">900</span>          new RegionMonitor(connection, monitorTargets, this.useRegExp,<a name="line.900"></a>
-<span class="sourceLineNo">901</span>              (StdOutSink) this.sink, this.executor, this.writeSniffing,<a name="line.901"></a>
-<span class="sourceLineNo">902</span>              this.writeTableName, this.treatFailureAsError, this.configuredReadTableTimeouts,<a name="line.902"></a>
-<span class="sourceLineNo">903</span>              this.configuredWriteTableTimeout);<a name="line.903"></a>
-<span class="sourceLineNo">904</span>    }<a name="line.904"></a>
-<span class="sourceLineNo">905</span>    return monitor;<a name="line.905"></a>
-<span class="sourceLineNo">906</span>  }<a name="line.906"></a>
-<span class="sourceLineNo">907</span><a name="line.907"></a>
-<span class="sourceLineNo">908</span>  // a Monitor super-class can be extended by users<a name="line.908"></a>
-<span class="sourceLineNo">909</span>  public static abstract class Monitor implements Runnable, Closeable {<a name="line.909"></a>
-<span class="sourceLineNo">910</span><a name="line.910"></a>
-<span class="sourceLineNo">911</span>    protected Connection connection;<a name="line.911"></a>
-<span class="sourceLineNo">912</span>    protected Admin admin;<a name="line.912"></a>
-<span class="sourceLineNo">913</span>    protected String[] targets;<a name="line.913"></a>
-<span class="sourceLineNo">914</span>    protected boolean useRegExp;<a name="line.914"></a>
-<span class="sourceLineNo">915</span>    protected boolean treatFailureAsError;<a name="line.915"></a>
-<span class="sourceLineNo">916</span>    protected boolean initialized = false;<a name="line.916"></a>
-<span class="sourceLineNo">917</span><a name="line.917"></a>
-<span class="sourceLineNo">918</span>    protected boolean done = false;<a name="line.918"></a>
-<span class="sourceLineNo">919</span>    protected int errorCode = 0;<a name="line.919"></a>
-<span class="sourceLineNo">920</span>    protected Sink sink;<a name="line.920"></a>
-<span class="sourceLineNo">921</span>    protected ExecutorService executor;<a name="line.921"></a>
-<span class="sourceLineNo">922</span><a name="line.922"></a>
-<span class="sourceLineNo">923</span>    public boolean isDone() {<a name="line.923"></a>
-<span class="sourceLineNo">924</span>      return done;<a name="line.924"></a>
-<span class="sourceLineNo">925</span>    }<a name="line.925"></a>
-<span class="sourceLineNo">926</span><a name="line.926"></a>
-<span class="sourceLineNo">927</span>    public boolean hasError() {<a name="line.927"></a>
-<span class="sourceLineNo">928</span>      return errorCode != 0;<a name="line.928"></a>
-<span class="sourceLineNo">929</span>    }<a name="line.929"></a>
-<span class="sourceLineNo">930</span><a name="line.930"></a>
-<span class="sourceLineNo">931</span>    public boolean finalCheckForErrors() {<a name="line.931"></a>
-<span class="sourceLineNo">932</span>      if (errorCode != 0) {<a name="line.932"></a>
-<span class="sourceLineNo">933</span>        return true;<a name="line.933"></a>
-<span class="sourceLineNo">934</span>      }<a name="line.934"></a>
-<span class="sourceLineNo">935</span>      if (treatFailureAsError &amp;&amp;<a name="line.935"></a>
-<span class="sourceLineNo">936</span>          (sink.getReadFailureCount() &gt; 0 || sink.getWriteFailureCount() &gt; 0)) {<a name="line.936"></a>
-<span class="sourceLineNo">937</span>        errorCode = FAILURE_EXIT_CODE;<a name="line.937"></a>
-<span class="sourceLineNo">938</span>        return true;<a name="line.938"></a>
-<span class="sourceLineNo">939</span>      }<a name="line.939"></a>
-<span class="sourceLineNo">940</span>      return false;<a name="line.940"></a>
-<span class="sourceLineNo">941</span>    }<a name="line.941"></a>
-<span class="sourceLineNo">942</span><a name="line.942"></a>
-<span class="sourceLineNo">943</span>    @Override<a name="line.943"></a>
-<span class="sourceLineNo">944</span>    public void close() throws IOException {<a name="line.944"></a>
-<span class="sourceLineNo">945</span>      if (this.admin != null) this.admin.close();<a name="line.945"></a>
-<span class="sourceLineNo">946</span>    }<a name="line.946"></a>
-<span class="sourceLineNo">947</span><a name="line.947"></a>
-<span class="sourceLineNo">948</span>    protected Monitor(Connection connection, String[] monitorTargets, boolean useRegExp, Sink sink,<a name="line.948"></a>
-<span class="sourceLineNo">949</span>        ExecutorService executor, boolean treatFailureAsError) {<a name="line.949"></a>
-<span class="sourceLineNo">950</span>      if (null == connection) throw new IllegalArgumentException("connection shall not be null");<a name="line.950"></a>
-<span class="sourceLineNo">951</span><a name="line.951"></a>
-<span class="sourceLineNo">952</span>      this.connection = connection;<a name="line.952"></a>
-<span class="sourceLineNo">953</span>      this.targets = monitorTargets;<a name="line.953"></a>
-<span class="sourceLineNo">954</span>      this.useRegExp = useRegExp;<a name="line.954"></a>
-<span class="sourceLineNo">955</span>      this.treatFailureAsError = treatFailureAsError;<a name="line.955"></a>
-<span class="sourceLineNo">956</span>      this.sink = sink;<a name="line.956"></a>
-<span class="sourceLineNo">957</span>      this.executor = executor;<a name="line.957"></a>
-<span class="sourceLineNo">958</span>    }<a name="line.958"></a>
-<span class="sourceLineNo">959</span><a name="line.959"></a>
-<span class="sourceLineNo">960</span>    @Override<a name="line.960"></a>
-<span class="sourceLineNo">961</span>    public abstract void run();<a name="line.961"></a>
-<span class="sourceLineNo">962</span><a name="line.962"></a>
-<span class="sourceLineNo">963</span>    protected boolean initAdmin() {<a name="line.963"></a>
-<span class="sourceLineNo">964</span>      if (null == this.admin) {<a name="line.964"></a>
-<span class="sourceLineNo">965</span>        try {<a name="line.965"></a>
-<span class="sourceLineNo">966</span>          this.admin = this.connection.getAdmin();<a name="line.966"></a>
-<span class="sourceLineNo">967</span>        } catch (Exception e) {<a name="line.967"></a>
-<span class="sourceLineNo">968</span>          LOG.error("Initial HBaseAdmin failed...", e);<a name="line.968"></a>
-<span class="sourceLineNo">969</span>          this.errorCode = INIT_ERROR_EXIT_CODE;<a name="line.969"></a>
-<span class="sourceLineNo">970</span>        }<a name="line.970"></a>
-<span class="sourceLineNo">971</span>      } else if (admin.isAborted()) {<a name="line.971"></a>
-<span class="sourceLineNo">972</span>        LOG.error("HBaseAdmin aborted");<a name="line.972"></a>
-<span class="sourceLineNo">973</span>        this.errorCode = INIT_ERROR_EXIT_CODE;<a name="line.973"></a>
-<span class="sourceLineNo">974</span>      }<a name="line.974"></a>
-<span class="sourceLineNo">975</span>      return !this.hasError();<a name="line.975"></a>
-<span class="sourceLineNo">976</span>    }<a name="line.976"></a>
-<span class="sourceLineNo">977</span>  }<a name="line.977"></a>
-<span class="sourceLineNo">978</span><a name="line.978"></a>
-<span class="sourceLineNo">979</span>  // a monitor for region mode<a name="line.979"></a>
-<span class="sourceLineNo">980</span>  private static class RegionMonitor extends Monitor {<a name="line.980"></a>
-<span class="sourceLineNo">981</span>    // 10 minutes<a name="line.981"></a>
-<span class="sourceLineNo">982</span>    private static final int DEFAULT_WRITE_TABLE_CHECK_PERIOD = 10 * 60 * 1000;<a name="line.982"></a>
-<span class="sourceLineNo">983</span>    // 1 days<a name="line.983"></a>
-<span class="sourceLineNo">984</span>    private static final int DEFAULT_WRITE_DATA_TTL = 24 * 60 * 60;<a name="line.984"></a>
-<span class="sourceLineNo">985</span><a name="line.985"></a>
-<span class="sourceLineNo">986</span>    private long lastCheckTime = -1;<a name="line.986"></a>
-<span class="sourceLineNo">987</span>    private boolean writeSniffing;<a name="line.987"></a>
-<span class="sourceLineNo">988</span>    private TableName writeTableName;<a name="line.988"></a>
-<span class="sourceLineNo">989</span>    private int writeDataTTL;<a name="line.989"></a>
-<span class="sourceLineNo">990</span>    private float regionsLowerLimit;<a name="line.990"></a>
-<span class="sourceLineNo">991</span>    private float regionsUpperLimit;<a name="line.991"></a>
-<span class="sourceLineNo">992</span>    private int checkPeriod;<a name="line.992"></a>
-<span class="sourceLineNo">993</span>    private boolean rawScanEnabled;<a name="line.993"></a>
-<span class="sourceLineNo">994</span>    private HashMap&lt;String, Long&gt; configuredReadTableTimeouts;<a name="line.994"></a>
-<span class="sourceLineNo">995</span>    private long configuredWriteTableTimeout;<a name="line.995"></a>
-<span class="sourceLineNo">996</span><a name="line.996"></a>
-<span class="sourceLineNo">997</span>    public RegionMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,<a name="line.997"></a>
-<span class="sourceLineNo">998</span>        StdOutSink sink, ExecutorService executor, boolean writeSniffing, TableName writeTableName,<a name="line.998"></a>
-<span class="sourceLineNo">999</span>        boolean treatFailureAsError, HashMap&lt;String, Long&gt; configuredReadTableTimeouts, long configuredWriteTableTimeout) {<a name="line.999"></a>
-<span class="sourceLineNo">1000</span>      super(connection, monitorTargets, useRegExp, sink, executor, treatFailureAsError);<a name="line.1000"></a>
-<span class="sourceLineNo">1001</span>      Configuration conf = connection.getConfiguration();<a name="line.1001"></a>
-<span class="sourceLineNo">1002</span>      this.writeSniffing = writeSniffing;<a name="line.1002"></a>
-<span class="sourceLineNo">1003</span>      this.writeTableName = writeTableName;<a name="line.1003"></a>
-<span class="sourceLineNo">1004</span>      this.writeDataTTL =<a name="line.1004"></a>
-<span class="sourceLineNo">1005</span>          conf.getInt(HConstants.HBASE_CANARY_WRITE_DATA_TTL_KEY, DEFAULT_WRITE_DATA_TTL);<a name="line.1005"></a>
-<span class="sourceLineNo">1006</span>      this.regionsLowerLimit =<a name="line.1006"></a>
-<span class="sourceLineNo">1007</span>          conf.getFloat(HConstants.HBASE_CANARY_WRITE_PERSERVER_REGIONS_LOWERLIMIT_KEY, 1.0f);<a name="line.1007"></a>
-<span class="sourceLineNo">1008</span>      this.regionsUpperLimit =<a name="line.1008"></a>
-<span class="sourceLineNo">1009</span>          conf.getFloat(HConstants.HBASE_CANARY_WRITE_PERSERVER_REGIONS_UPPERLIMIT_KEY, 1.5f);<a name="line.1009"></a>
-<span class="sourceLineNo">1010</span>      this.checkPeriod =<a name="line.1010"></a>
-<span class="sourceLineNo">1011</span>          conf.getInt(HConstants.HBASE_CANARY_WRITE_TABLE_CHECK_PERIOD_KEY,<a name="line.1011"></a>
-<span class="sourceLineNo">1012</span>            DEFAULT_WRITE_TABLE_CHECK_PERIOD);<a name="line.1012"></a>
-<span class="sourceLineNo">1013</span>      this.rawScanEnabled = conf.getBoolean(HConstants.HBASE_CANARY_READ_RAW_SCAN_KEY, false);<a name="line.1013"></a>
-<span class="sourceLineNo">1014</span>      this.configuredReadTableTimeouts = new HashMap&lt;&gt;(configuredReadTableTimeouts);<a name="line.1014"></a>
-<span class="sourceLineNo">1015</span>      this.configuredWriteTableTimeout = configuredWriteTableTimeout;<a name="line.1015"></a>
-<span class="sourceLineNo">1016</span>    }<a name="line.1016"></a>
-<span class="sourceLineNo">1017</span><a name="line.1017"></a>
-<span class="sourceLineNo">1018</span>    private RegionStdOutSink getSink() {<a name="line.1018"></a>
-<span class="sourceLineNo">1019</span>      if (!(sink instanceof RegionStdOutSink)) {<a name="line.1019"></a>
-<span class="sourceLineNo">1020</span>        throw new RuntimeException("Can only write to Region sink");<a name="line.1020"></a>
-<span class="sourceLineNo">1021</span>      }<a name="line.1021"></a>
-<span class="sourceLineNo">1022</span>      return ((RegionStdOutSink) sink);<a name="line.1022"></a>
-<span class="sourceLineNo">1023</span>    }<a name="line.1023"></a>
-<span class="sourceLineNo">1024</span><a name="line.1024"></a>
-<span class="sourceLineNo">1025</span>    @Override<a name="line.1025"></a>
-<span class="sourceLineNo">1026</span>    public void run() {<a name="line.1026"></a>
-<span class="sourceLineNo">1027</span>      if (this.initAdmin()) {<a name="line.1027"></a>
-<span class="sourceLineNo">1028</span>        try {<a name="line.1028"></a>
-<span class="sourceLineNo">1029</span>          List&lt;Future&lt;Void&gt;&gt; taskFutures = new LinkedList&lt;&gt;();<a name="line.1029"></a>
-<span class="sourceLineNo">1030</span>          RegionStdOutSink regionSink = this.getSink();<a name="line.1030"></a>
-<span class="sourceLineNo">1031</span>          if (this.targets != null &amp;&amp; this.targets.length &gt; 0) {<a name="line.1031"></a>
-<span class="sourceLineNo">1032</span>            String[] tables = generateMonitorTables(this.targets);<a name="line.1032"></a>
-<span class="sourceLineNo">1033</span>            // Check to see that each table name passed in the -readTableTimeouts argument is also passed as a monitor target.<a name="line.1033"></a>
-<span class="sourceLineNo">1034</span>            if (! new HashSet&lt;&gt;(Arrays.asList(tables)).containsAll(this.configuredReadTableTimeouts.keySet())) {<a name="line.1034"></a>
-<span class="sourceLineNo">1035</span>              LOG.error("-readTableTimeouts can only specify read timeouts for monitor targets passed via command line.");<a name="line.1035"></a>
-<span class="sourceLineNo">1036</span>              this.errorCode = USAGE_EXIT_CODE;<a name="line.1036"></a>
-<span class="sourceLineNo">1037</span>              return;<a name="line.1037"></a>
-<span class="sourceLineNo">1038</span>            }<a name="line.1038"></a>
-<span class="sourceLineNo">1039</span>            this.initialized = true;<a name="line.1039"></a>
-<span class="sourceLineNo">1040</span>            for (String table : tables) {<a name="line.1040"></a>
-<span class="sourceLineNo">1041</span>              LongAdder readLatency = regionSink.initializeAndGetReadLatencyForTable(table);<a name="line.1041"></a>
-<span class="sourceLineNo">1042</span>              taskFutures.addAll(Canary.sniff(admin, regionSink, table, executor, TaskType.READ,<a name="line.1042"></a>
-<span class="sourceLineNo">1043</span>                this.rawScanEnabled, readLatency));<a name="line.1043"></a>
-<span class="sourceLineNo">1044</span>            }<a name="line.1044"></a>
-<span class="sourceLineNo">1045</span>          } else {<a name="line.1045"></a>
-<span class="sourceLineNo">1046</span>            taskFutures.addAll(sniff(TaskType.READ, regionSink));<a name="line.1046"></a>
-<span class="sourceLineNo">1047</span>          }<a name="line.1047"></a>
-<span class="sourceLineNo">1048</span><a name="line.1048"></a>
-<span class="sourceLineNo">1049</span>          if (writeSniffing) {<a name="line.1049"></a>
-<span class="sourceLineNo">1050</span>            if (EnvironmentEdgeManager.currentTime() - lastCheckTime &gt; checkPeriod) {<a name="line.1050"></a>
-<span class="sourceLineNo">1051</span>              try {<a name="line.1051"></a>
-<span class="sourceLineNo">1052</span>                checkWriteTableDistribution();<a name="line.1052"></a>
-<span class="sourceLineNo">1053</span>              } catch (IOException e) {<a name="line.1053"></a>
-<span class="sourceLineNo">1054</span>                LOG.error("Check canary table distribution failed!", e);<a name="line.1054"></a>
-<span class="sourceLineNo">1055</span>              }<a name="line.1055"></a>
-<span class="sourceLineNo">1056</span>              lastCheckTime = EnvironmentEdgeManager.currentTime();<a name="line.1056"></a>
-<span class="sourceLineNo">1057</span>            }<a name="line.1057"></a>
-<span class="sourceLineNo">1058</span>            // sniff canary table with write operation<a name="line.1058"></a>
-<span class="sourceLineNo">1059</span>            regionSink.initializeWriteLatency();<a name="line.1059"></a>
-<span class="sourceLineNo">1060</span>            LongAdder writeTableLatency = regionSink.getWriteLatency();<a name="line.1060"></a>
-<span class="sourceLineNo">1061</span>            taskFutures.addAll(Canary.sniff(admin, regionSink, admin.getTableDescriptor(writeTableName),<a name="line.1061"></a>
-<span class="sourceLineNo">1062</span>              executor, TaskType.WRITE, this.rawScanEnabled, writeTableLatency));<a name="line.1062"></a>
-<span class="sourceLineNo">1063</span>          }<a name="line.1063"></a>
-<span class="sourceLineNo">1064</span><a name="line.1064"></a>
-<span class="sourceLineNo">1065</span>          for (Future&lt;Void&gt; future : taskFutures) {<a name="line.1065"></a>
-<span class="sourceLineNo">1066</span>            try {<a name="line.1066"></a>
-<span class="sourceLineNo">1067</span>              future.get();<a name="line.1067"></a>
-<span class="sourceLineNo">1068</span>            } catch (ExecutionException e) {<a name="line.1068"></a>
-<span class="sourceLineNo">1069</span>              LOG.error("Sniff region failed!", e);<a name="line.1069"></a>
-<span class="sourceLineNo">1070</span>            }<a name="line.1070"></a>
-<span class="sourceLineNo">1071</span>          }<a name="line.1071"></a>
-<span class="sourceLineNo">1072</span>          Map&lt;String, LongAdder&gt; actualReadTableLatency = regionSink.getReadLatencyMap();<a name="line.1072"></a>
-<span class="sourceLineNo">1073</span>          for (Map.Entry&lt;String, Long&gt; entry : configuredReadTableTimeouts.entrySet()) {<a name="line.1073"></a>
-<span class="sourceLineNo">1074</span>            String tableName = entry.getKey();<a name="line.1074"></a>
-<span class="sourceLineNo">1075</span>            if (actualReadTableLatency.containsKey(tableName)) {<a name="line.1075"></a>
-<span class="sourceLineNo">1076</span>              Long actual = actualReadTableLatency.get(tableName).longValue();<a name="line.1076"></a>
-<span class="sourceLineNo">1077</span>              Long configured = entry.getValue();<a name="line.1077"></a>
-<span class="sourceLineNo">1078</span>              LOG.info("Read operation for " + tableName + " took " + actual +<a name="line.1078"></a>
-<span class="sourceLineNo">1079</span>                " ms. The configured read timeout was " + configured + " ms.");<a name="line.1079"></a>
-<span class="sourceLineNo">1080</span>              if (actual &gt; configured) {<a name="line.1080"></a>
-<span class="sourceLineNo">1081</span>                LOG.error("Read operation for " + tableName + " exceeded the configured read timeout.");<a name="line.1081"></a>
-<span class="sourceLineNo">1082</span>              }<a name="line.1082"></a>
-<span class="sourceLineNo">1083</span>            } else {<a name="line.1083"></a>
-<span class="sourceLineNo">1084</span>              LOG.error("Read operation for " + tableName + " failed!");<a name="line.1084"></a>
-<span class="sourceLineNo">1085</span>            }<a name="line.1085"></a>
-<span class="sourceLineNo">1086</span>          }<a name="line.1086"></a>
-<span class="sourceLineNo">1087</span>          if (this.writeSniffing) {<a name="line.1087"></a>
-<span class="sourceLineNo">1088</span>            String writeTableStringName = this.writeTableName.getNameAsString();<a name="line.1088"></a>
-<span class="sourceLineNo">1089</span>            long actualWriteLatency = regionSink.getWriteLatency().longValue();<a name="line.1089"></a>
-<span class="sourceLineNo">1090</span>            LOG.info("Write operation for " + writeTableStringName + " took " + actualWriteLatency + " ms. The configured write timeout was " +<a name="line.1090"></a>
-<span class="sourceLineNo">1091</span>              this.configuredWriteTableTimeout + " ms.");<a name="line.1091"></a>
-<span class="sourceLineNo">1092</span>            // Check that the writeTable write operation latency does not exceed the configured timeout.<a name="line.1092"></a>
-<span class="sourceLineNo">1093</span>            if (actualWriteLatency &gt; this.configuredWriteTableTimeout) {<a name="line.1093"></a>
-<span class="sourceLineNo">1094</span>              LOG.error("Write operation for " + writeTableStringName + " exceeded the configured write timeout.");<a name="line.1094"></a>
-<span class="sourceLineNo">1095</span>            }<a name="line.1095"></a>
-<span class="sourceLineNo">1096</span>          }<a name="line.1096"></a>
-<span class="sourceLineNo">1097</span>        } catch (Exception e) {<a name="line.1097"></a>
-<span class="sourceLineNo">1098</span>          LOG.error("Run regionMonitor failed", e);<a name="line.1098"></a>
-<span class="sourceLineNo">1099</span>          this.errorCode = ERROR_EXIT_CODE;<a name="line.1099"></a>
-<span class="sourceLineNo">1100</span>        } finally {<a name="line.1100"></a>
-<span class="sourceLineNo">1101</span>          this.done = true;<a name="line.1101"></a>
-<span class="sourceLineNo">1102</span>  }<a name="line.1102"></a>
-<span class="sourceLineNo">1103</span>      }<a name="line.1103"></a>
-<span class="sourceLineNo">1104</span>      this.done = true;<a name="line.1104"></a>
-<span class="sourceLineNo">1105</span>    }<a name="line.1105"></a>
-<span class="sourceLineNo">1106</span><a name="line.1106"></a>
-<span class="sourceLineNo">1107</span>    private String[] generateMonitorTables(String[] monitorTargets) throws IOException {<a name="line.1107"></a>
-<span class="sourceLineNo">1108</span>      String[] returnTables = null;<a name="line.1108"></a>
-<span class="sourceLineNo">1109</span><a name="line.1109"></a>
-<span class="sourceLineNo">1110</span>      if (this.useRegExp) {<a name="line.1110"></a>
-<span class="sourceLineNo">1111</span>        Pattern pattern = null;<a name="line.1111"></a>
-<span class="sourceLineNo">1112</span>        HTableDescriptor[] tds = null;<a name="line.1112"></a>
-<span class="sourceLineNo">1113</span>        Set&lt;String&gt; tmpTables = new TreeSet&lt;&gt;();<a name="line.1113"></a>
-<span class="sourceLineNo">1114</span>        try {<a name="line.1114"></a>
-<span class="sourceLineNo">1115</span>          if (LOG.isDebugEnabled()) {<a name="line.1115"></a>
-<span class="sourceLineNo">1116</span>            LOG.debug(String.format("reading list of tables"));<a name="line.1116"></a>
-<span class="sourceLineNo">1117</span>          }<a name="line.1117"></a>
-<span class="sourceLineNo">1118</span>          tds = this.admin.listTables(pattern);<a name="line.1118"></a>
-<span class="sourceLineNo">1119</span>          if (tds == null) {<a name="line.1119"></a>
-<span class="sourceLineNo">1120</span>            tds = new HTableDescriptor[0];<a name="line.1120"></a>
-<span class="sourceLineNo">1121</span>          }<a name="line.1121"></a>
-<span class="sourceLineNo">1122</span>          for (String monitorTarget : monitorTargets) {<a name="line.1122"></a>
-<span class="sourceLineNo">1123</span>            pattern = Pattern.compile(monitorTarget);<a name="line.1123"></a>
-<span class="sourceLineNo">1124</span>            for (HTableDescriptor td : tds) {<a name="line.1124"></a>
-<span class="sourceLineNo">1125</span>              if (pattern.matcher(td.getNameAsString()).matches()) {<a name="line.1125"></a>
-<span class="sourceLineNo">1126</span>                tmpTables.add(td.getNameAsString());<a name="line.1126"></a>
-<span class="sourceLineNo">1127</span>              }<a name="line.1127"></a>
-<span class="sourceLineNo">1128</span>            }<a name="line.1128"></a>
-<span class="sourceLineNo">1129</span>          }<a name="line.1129"></a>
-<span class="sourceLineNo">1130</span>        } catch (IOException e) {<a name="line.1130"></a>
-<span class="sourceLineNo">1131</span>          LOG.error("Communicate with admin failed", e);<a name="line.1131"></a>
-<span class="sourceLineNo">1132</span>          throw e;<a name="line.1132"></a>
-<span class="sourceLineNo">1133</span>        }<a name="line.1133"></a>
-<span class="sourceLineNo">1134</span><a name="line.1134"></a>
-<span class="sourceLineNo">1135</span>        if (tmpTables.size() &gt; 0) {<a name="line.1135"></a>
-<span class="sourceLineNo">1136</span>          returnTables = tmpTables.toArray(new String[tmpTables.size()]);<a name="line.1136"></a>
-<span class="sourceLineNo">1137</span>        } else {<a name="line.1137"></a>
-<span class="sourceLineNo">1138</span>          String msg = "No HTable found, tablePattern:" + Arrays.toString(monitorTargets);<a name="line.1138"></a>
-<span class="sourceLineNo">1139</span>          LOG.error(msg);<a name="line.1139"></a>
-<span class="sourceLineNo">1140</span>          this.errorCode = INIT_ERROR_EXIT_CODE;<a name="line.1140"></a>
-<span class="sourceLineNo">1141</span>          throw new TableNotFoundException(msg);<a name="line.1141"></a>
-<span class="sourceLineNo">1142</span>        }<a name="line.1142"></a>
-<span class="sourceLineNo">1143</span>      } else {<a name="line.1143"></a>
-<span class="sourceLineNo">1144</span>        returnTables = monitorTargets;<a name="line.1144"></a>
-<span class="sourceLineNo">1145</span>      }<a name="line.1145"></a>
-<span class="sourceLineNo">1146</span><a name="line.1146"></a>
-<span class="sourceLineNo">1147</span>      return returnTables;<a name="line.1147"></a>
-<span class="sourceLineNo">1148</span>    }<a name="line.1148"></a>
-<span class="sourceLineNo">1149</span><a name="line.1149"></a>
-<span class="sourceLineNo">1150</span>    /*<a name="line.1150"></a>
-<span class="sourceLineNo">1151</span>     * canary entry point to monitor all the tables.<a name="line.1151"></a>
-<span class="sourceLineNo">1152</span>     */<a name="line.1152"></a>
-<span class="sourceLineNo">1153</span>    private List&lt;Future&lt;Void&gt;&gt; sniff(TaskType taskType, RegionStdOutSink regionSink) throws Exception {<a name="line.1153"></a>
-<span class="sourceLineNo">1154</span>      if (LOG.isDebugEnabled()) {<a name="line.1154"></a>
-<span class="sourceLineNo">1155</span>        LOG.debug(String.format("reading list of tables"));<a name="line.1155"></a>
-<span class="sourceLineNo">1156</span>      }<a name="line.1156"></a>
-<span class="sourceLineNo">1157</span>      List&lt;Future&lt;Void&gt;&gt; taskFutures = new LinkedList&lt;&gt;();<a name="line.1157"></a>
-<span class="sourceLineNo">1158</span>      for (HTableDescriptor table : admin.listTables()) {<a name="line.1158"></a>
-<span class="sourceLineNo">1159</span>        if (admin.isTableEnabled(table.getTableName())<a name="line.1159"></a>
-<span class="sourceLineNo">1160</span>            &amp;&amp; (!table.getTableName().equals(writeTableName))) {<a name="line.1160"></a>
-<span class="sourceLineNo">1161</span>          LongAdder readLatency = regionSink.initializeAndGetReadLatencyForTable(table.getNameAsString());<a name="line.1161"></a>
-<span class="sourceLineNo">1162</span>          taskFutures.addAll(Canary.sniff(admin, sink, table, executor, taskType, this.rawScanEnabled, readLatency));<a name="line.1162"></a>
-<span class="sourceLineNo">1163</span>        }<a name="line.1163"></a>
-<span class="sourceLineNo">1164</span>      }<a name="line.1164"></a>
-<span class="sourceLineNo">1165</span>      return taskFutures;<a name="line.1165"></a>
-<span class="sourceLineNo">1166</span>    }<a name="line.1166"></a>
-<span class="sourceLineNo">1167</span><a name="line.1167"></a>
-<span class="sourceLineNo">1168</span>    private void checkWriteTableDistribution() throws IOException {<a name="line.1168"></a>
-<span class="sourceLineNo">1169</span>      if (!admin.tableExists(writeTableName)) {<a name="line.1169"></a>
-<span class="sourceLineNo">1170</span>        int numberOfServers =<a name="line.1170"></a>
-<span class="sourceLineNo">1171</span>            admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().size();<a name="line.1171"></a>
-<span class="sourceLineNo">1172</span>        if (numberOfServers == 0) {<a name="line.1172"></a>
-<span class="sourceLineNo">1173</span>          throw new IllegalStateException("No live regionservers");<a name="line.1173"></a>
-<span class="sourceLineNo">1174</span>        }<a name="line.1174"></a>
-<span class="sourceLineNo">1175</span>        createWriteTable(numberOfServers);<a name="line.1175"></a>
-<span class="sourceLineNo">1176</span>      }<a name="line.1176"></a>
-<span class="sourceLineNo">1177</span><a name="line.1177"></a>
-<span class="sourceLineNo">1178</span>      if (!admin.isTableEnabled(writeTableName)) {<a name="line.1178"></a>
-<span class="sourceLineNo">1179</span>        admin.enableTable(writeTableName);<a name="line.1179"></a>
-<span class="sourceLineNo">1180</span>      }<a name="line.1180"></a>
-<span class="sourceLineNo">1181</span><a name="line.1181"></a>
-<span class="sourceLineNo">1182</span>      ClusterMetrics status =<a name="line.1182"></a>
-<span class="sourceLineNo">1183</span>          admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS, Option.MASTER));<a name="line.1183"></a>
-<span class="sourceLineNo">1184</span>      int numberOfServers = status.getLiveServerMetrics().size();<a name="line.1184"></a>
-<span class="sourceLineNo">1185</span>      if (status.getLiveServerMetrics().containsKey(status.getMasterName())) {<a name="line.1185"></a>
-<span class="sourceLineNo">1186</span>        numberOfServers -= 1;<a name="line.1186"></a>
-<span class="sourceLineNo">1187</span>      }<a name="line.1187"></a>
-<span class="sourceLineNo">1188</span><a name="line.1188"></a>
-<span class="sourceLineNo">1189</span>      List&lt;Pair&lt;RegionInfo, ServerName&gt;&gt; pairs =<a name="line.1189"></a>
-<span class="sourceLineNo">1190</span>          MetaTableAccessor.getTableRegionsAndLocations(connection, writeTableName);<a name="line.1190"></a>
-<span class="sourceLineNo">1191</span>      int numberOfRegions = pairs.size();<a name="line.1191"></a>
-<span class="sourceLineNo">1192</span>      if (numberOfRegions &lt; numberOfServers * regionsLowerLimit<a name="line.1192"></a>
-<span class="sourceLineNo">1193</span>          || numberOfRegions &gt; numberOfServers * regionsUpperLimit) {<a name="line.1193"></a>
-<span class="sourceLineNo">1194</span>        admin.disableTable(writeTableName);<a name="line.1194"></a>
-<span class="sourceLineNo">1195</span>        admin.deleteTable(writeTableName);<a name="line.1195"></a>
-<span class="sourceLineNo">1196</span>        createWriteTable(numberOfServers);<a name="line.1196"></a>
-<span class="sourceLineNo">1197</span>      }<a name="line.1197"></a>
-<span class="sourceLineNo">1198</span>      HashSet&lt;ServerName&gt; serverSet = new HashSet&lt;&gt;();<a name="line.1198"></a>
-<span class="sourceLineNo">1199</span>      for (Pair&lt;RegionInfo, ServerName&gt; pair : pairs) {<a name="line.1199"></a>
-<span class="sourceLineNo">1200</span>        serverSet.add(pair.getSecond());<a name="line.1200"></a>
-<span class="sourceLineNo">1201</span>      }<a name="line.1201"></a>
-<span class="sourceLineNo">1202</span>      int numberOfCoveredServers = serverSet.size();<a name="line.1202"></a>
-<span class="sourceLineNo">1203</span>      if (numberOfCoveredServers &lt; numberOfServers) {<a name="line.1203"></a>
-<span class="sourceLineNo">1204</span>        admin.balancer();<a name="line.1204"></a>
-<span class="sourceLineNo">1205</span>      }<a name="line.1205"></a>
-<span class="sourceLineNo">1206</span>    }<a name="line.1206"></a>
-<span class="sourceLineNo">1207</span><a name="line.1207"></a>
-<span class="sourceLineNo">1208</span>    private void createWriteTable(int numberOfServers) throws IOException {<a name="line.1208"></a>
-<span class="sourceLineNo">1209</span>      int numberOfRegions = (int)(numberOfServers * regionsLowerLimit);<a name="line.1209"></a>
-<span class="sourceLineNo">1210</span>      LOG.info("Number of live regionservers: " + numberOfServers + ", "<a name="line.1210"></a>
-<span class="sourceLineNo">1211</span>          + "pre-splitting the canary table into " + numberOfRegions + " regions "<a name="line.1211"></a>
-<span class="sourceLineNo">1212</span>          + "(current lower limit of regions per server is " + regionsLowerLimit<a name="line.1212"></a>
-<span class="sourceLineNo">1213</span>          + " and you can change it by config: "<a name="line.1213"></a>
-<span class="sourceLineNo">1214</span>          + HConstants.HBASE_CANARY_WRITE_PERSERVER_REGIONS_LOWERLIMIT_KEY + " )");<a name="line.1214"></a>
-<span class="sourceLineNo">1215</span>      HTableDescriptor desc = new HTableDescriptor(writeTableName);<a name="line.1215"></a>
-<span class="sourceLineNo">1216</span>      HColumnDescriptor family = new HColumnDescriptor(CANARY_TABLE_FAMILY_NAME);<a name="line.1216"></a>
-<span class="sourceLineNo">1217</span>      family.setMaxVersions(1);<a name="line.1217"></a>
-<span class="sourceLineNo">1218</span>      family.setTimeToLive(writeDataTTL);<a name="line.1218"></a>
-<span class="sourceLineNo">1219</span><a name="line.1219"></a>
-<span class="sourceLineNo">1220</span>      desc.addFamily(family);<a name="line.1220"></a>
-<span class="sourceLineNo">1221</span>      byte[][] splits = new RegionSplitter.HexStringSplit().split(numberOfRegions);<a name="line.1221"></a>
-<span class="sourceLineNo">1222</span>      admin.createTable(desc, splits);<a name="line.1222"></a>
-<span class="sourceLineNo">1223</span>    }<a name="line.1223"></a>
-<span class="sourceLineNo">1224</span>  }<a name="line.1224"></a>
-<span class="sourceLineNo">1225</span><a name="line.1225"></a>
-<span class="sourceLineNo">1226</span>  /**<a name="line.1226"></a>
-<span class="sourceLineNo">1227</span>   * Canary entry point for specified table.<a name="line.1227"></a>
-<span class="sourceLineNo">1228</span>   * @throws Exception<a name="line.1228"></a>
-<span class="sourceLineNo">1229</span>   */<a name="line.1229"></a>
-<span class="sourceLineNo">1230</span>  private static List&lt;Future&lt;Void&gt;&gt; sniff(final Admin admin, final Sink sink, String tableName,<a name="line.1230"></a>
-<span class="sourceLineNo">1231</span>      ExecutorService executor, TaskType taskType, boolean rawScanEnabled, LongAdder readLatency) throws Exception {<a name="line.1231"></a>
-<span class="sourceLineNo">1232</span>    if (LOG.isDebugEnabled()) {<a name="line.1232"></a>
-<span class="sourceLineNo">1233</span>      LOG.debug(String.format("checking table is enabled and getting table descriptor for table %s",<a name="line.1233"></a>
-<span class="sourceLineNo">1234</span>        tableName));<a name="line.1234"></a>
-<span class="sourceLineNo">1235</span>    }<a name="line.1235"></a>
-<span class="sourceLineNo">1236</span>    if (admin.isTableEnabled(TableName.valueOf(tableName))) {<a name="line.1236"></a>
-<span class="sourceLineNo">1237</span>      return Canary.sniff(admin, sink, admin.getTableDescriptor(TableName.valueOf(tableName)),<a name="line.1237"></a>
-<span class="sourceLineNo">1238</span>        executor, taskType, rawScanEnabled, readLatency);<a name="line.1238"></a>
-<span class="sourceLineNo">1239</span>    } else {<a name="line.1239"></a>
-<span class="sourceLineNo">1240</span>      LOG.warn(String.format("Table %s is not enabled", tableName));<a name="line.1240"></a>
-<span class="sourceLineNo">1241</span>    }<a name="line.1241"></a>
-<span class="sourceLineNo">1242</span>    return new LinkedList&lt;&gt;();<a name="line.1242"></a>
-<span class="sourceLineNo">1243</span>  }<a name="line.1243"></a>
-<span class="sourceLineNo">1244</span><a name="line.1244"></a>
-<span class="sourceLineNo">1245</span>  /*<a name="line.1245"></a>
-<span class="sourceLineNo">1246</span>   * Loops over regions that owns this table, and output some information about the state.<a name="line.1246"></a>
-<span class="sourceLineNo">1247</span>   */<a name="line.1247"></a>
-<span class="sourceLineNo">1248</span>  private static List&lt;Future&lt;Void&gt;&gt; sniff(final Admin admin, final Sink sink,<a name="line.1248"></a>
-<span class="sourceLineNo">1249</span>      HTableDescriptor tableDesc, ExecutorService executor, TaskType taskType,<a name="line.1249"></a>
-<span class="sourceLineNo">1250</span>      boolean rawScanEnabled, LongAdder rwLatency) throws Exception {<a name="line.1250"></a>
-<span class="sourceLineNo">1251</span><a name="line.1251"></a>
-<span class="sourceLineNo">1252</span>    if (LOG.isDebugEnabled()) {<a name="line.1252"></a>
-<span class="sourceLineNo">1253</span>      LOG.debug(String.format("reading list of regions for table %s", tableDesc.getTableName()));<a name="line.1253"></a>
-<span class="sourceLineNo">1254</span>    }<a name="line.1254"></a>
-<span class="sourceLineNo">1255</span><a name="line.1255"></a>
-<span class="sourceLineNo">1256</span>    Table table = null;<a name="line.1256"></a>
-<span class="sourceLineNo">1257</span>    try {<a name="line.1257"></a>
-<span class="sourceLineNo">1258</span>      table = admin.getConnection().getTable(tableDesc.getTableName());<a name="line.1258"></a>
-<span class="sourceLineNo">1259</span>    } catch (TableNotFoundException e) {<a name="line.1259"></a>
-<span class="sourceLineNo">1260</span>      return new ArrayList&lt;&gt;();<a name="line.1260"></a>
-<span class="sourceLineNo">1261</span>    }<a name="line.1261"></a>
-<span class="sourceLineNo">1262</span>    finally {<a name="line.1262"></a>
-<span class="sourceLineNo">1263</span>      if (table !=null) {<a name="line.1263"></a>
-<span class="sourceLineNo">1264</span>        table.close();<a name="line.1264"></a>
-<span class="sourceLineNo">1265</span>      }<a name="line.1265"></a>
-<span class="sourceLineNo">1266</span>    }<a name="line.1266"></a>
-<span class="sourceLineNo">1267</span><a name="line.1267"></a>
-<span class="sourceLineNo">1268</span>    List&lt;RegionTask&gt; tasks = new ArrayList&lt;&gt;();<a name="line.1268"></a>
-<span class="sourceLineNo">1269</span>    RegionLocator regionLocator = null;<a name="line.1269"></a>
-<span class="sourceLineNo">1270</span>    try {<a name="line.1270"></a>
-<span class="sourceLineNo">1271</span>      regionLocator = admin.getConnection().getRegionLocator(tableDesc.getTableName());<a name="line.1271"></a>
-<span class="sourceLineNo">1272</span>      for (HRegionLocation location : regionLocator.getAllRegionLocations()) {<a name="line.1272"></a>
-<span class="sourceLineNo">1273</span>        ServerName rs = location.getServerName();<a name="line.1273"></a>
-<span class="sourceLineNo">1274</span>        RegionInfo region = location.getRegionInfo();<a name="line.1274"></a>
-<span class="sourceLineNo">1275</span>        tasks.add(new RegionTask(admin.getConnection(), region, rs, (RegionStdOutSink) sink, taskType, rawScanEnabled,<a name="line.1275"></a>
-<span class="sourceLineNo">1276</span>          rwLatency));<a name="line.1276"></a>
-<span class="sourceLineNo">1277</span>      }<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>    } finally {<a name="line.1278"></a>
-<span class="sourceLineNo">1279</span>      if (regionLocator != null) {<a name="line.1279"></a>
-<span class="sourceLineNo">1280</span>        regionLocator.close();<a name="line.1280"></a>
-<span class="sourceLineNo">1281</span>      }<a name="line.1281"></a>
-<span class="sourceLineNo">1282</span>    }<a name="line.1282"></a>
-<span class="sourceLineNo">1283</span>    return executor.invokeAll(tasks);<a name="line.1283"></a>
-<span class="sourceLineNo">1284</span>  }<a name="line.1284"></a>
-<span class="sourceLineNo">1285</span><a name="line.1285"></a>
-<span class="sourceLineNo">1286</span>  //  monitor for zookeeper mode<a name="line.1286"></a>
-<span class="sourceLineNo">1287</span>  private static class ZookeeperMonitor extends Monitor {<a name="line.1287"></a>
-<span class="sourceLineNo">1288</span>    private List&lt;String&gt; hosts;<a name="line.1288"></a>
-<span class="sourceLineNo">1289</span>    private final String znode;<a name="line.1289"></a>
-<span class="sourceLineNo">1290</span>    private final int timeout;<a name="line.1290"></a>
-<span class="sourceLineNo">1291</span><a name="line.1291"></a>
-<span class="sourceLineNo">1292</span>    protected ZookeeperMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,<a name="line.1292"></a>
-<span class="sourceLineNo">1293</span>        StdOutSink sink, ExecutorService executor, boolean treatFailureAsError)  {<a name="line.1293"></a>
-<span class="sourceLineNo">1294</span>      super(connection, monitorTargets, useRegExp, sink, executor, treatFailureAsError);<a name="line.1294"></a>
-<span class="sourceLineNo">1295</span>      Configuration configuration = connection.getConfiguration();<a name="line.1295"></a>
-<span class="sourceLineNo">1296</span>      znode =<a name="line.1296"></a>
-<span class="sourceLineNo">1297</span>          configuration.get(ZOOKEEPER_ZNODE_PARENT,<a name="line.1297"></a>
-<span class="sourceLineNo">1298</span>              DEFAULT_ZOOKEEPER_ZNODE_PARENT);<a name="line.1298"></a>
-<span class="sourceLineNo">1299</span>      timeout = configuration<a name="line.1299"></a>
-<span class="sourceLineNo">1300</span>          .getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);<a name="line.1300"></a>
-<span class="sourceLineNo">1301</span>      ConnectStringParser parser =<a name="line.1301"></a>
-<span class="sourceLineNo">1302</span>          new ConnectStringParser(ZKConfig.getZKQuorumServersString(configuration));<a name="line.1302"></a>
-<span class="sourceLineNo">1303</span>      hosts = Lists.newArrayList();<a name="line.1303"></a>
-<span class="sourceLineNo">1304</span>      for (InetSocketAddress server : parser.getServerAddresses()) {<a name="line.1304"></a>
-<span class="sourceLineNo">1305</span>        hosts.add(server.toString());<a name="line.1305"></a>
-<span class="sourceLineNo">1306</span>      }<a name="line.1306"></a>
-<span class="sourceLineNo">1307</span>    }<a name="line.1307"></a>
-<span class="sourceLineNo">1308</span><a name="line.1308"></a>
-<span class="sourceLineNo">1309</span>    @Override public void run() {<a name="line.1309"></a>
-<span class="sourceLineNo">1310</span>      List&lt;ZookeeperTask&gt; tasks = Lists.newArrayList();<a name="line.1310"></a>
-<span class="sourceLineNo">1311</span>      ZookeeperStdOutSink zkSink = null;<a name="line.1311"></a>
-<span class="sourceLineNo">1312</span>      try {<a name="line.1312"></a>
-<span class="sourceLineNo">1313</span>        zkSink = this.getSink();<a name="line.1313"></a>
-<span class="sourceLineNo">1314</span>      } catch (RuntimeException e) {<a name="line.1314"></a>
-<span class="sourceLineNo">1315</span>        LOG.error("Run ZooKeeperMonitor failed!", e);<a name="line.1315"></a>
-<span class="sourceLineNo">1316</span>        this.errorCode = ERROR_EXIT_CODE;<a name="line.1316"></a>
-<span class="sourceLineNo">1317</span>      }<a name="line.1317"></a>
-<span class="sourceLineNo">1318</span>      this.initialized = true;<a name="line.1318"></a>
-<span class="sourceLineNo">1319</span>      for (final String host : hosts) {<a name="line.1319"></a>
-<span class="sourceLineNo">1320</span>        tasks.add(new ZookeeperTask(connection, host, znode, timeout, zkSink));<a name="line.1320"></a>
-<span class="sourceLineNo">1321</span>      }<a name="line.1321"></a>
-<span class="sourceLineNo">1322</span>      try {<a name="line.1322"></a>
-<span class="sourceLineNo">1323</span>        for (Future&lt;Void&gt; future : this.executor.invokeAll(tasks)) {<a name="line.1323"></a>
-<span class="sourceLineNo">1324</span>          try {<a name="line.1324"></a>
-<span class="sourceLineNo">1325</span>            future.get();<a name="line.1325"></a>
-<span class="sourceLineNo">1326</span>          } catch (ExecutionException e) {<a name="line.1326"></a>
-<span class="sourceLineNo">1327</span>            LOG.error("Sniff zookeeper failed!", e);<a name="line.1327"></a>
-<span class="sourceLineNo">1328</span>            this.errorCode = ERROR_EXIT_CODE;<a name="line.1328"></a>
-<span class="sourceLineNo">1329</span>          }<a name="line.1329"></a>
-<span class="sourceLineNo">1330</span>        }<a name="line.1330"></a>
-<span class="sourceLineNo">1331</span>      } catch (InterruptedException e) {<a name="line.1331"></a>
-<span class="sourceLineNo">1332</span>        this.errorCode = ERROR_EXIT_CODE;<a name="line.1332"></a>
-<span class="sourceLineNo">1333</span>        Thread.currentThread().interrupt();<a name="line.1333"></a>
-<span class="sourceLineNo">1334</span>        LOG.error("Sniff zookeeper interrupted!", e);<a name="line.1334"></a>
-<span class="sourceLineNo">1335</span>      }<a name="line.1335"></a>
-<span class="sourceLineNo">1336</span>      this.done = true;<a name="line.1336"></a>
-<span class="sourceLineNo">1337</span>    }<a name="line.1337"></a>
-<span class="sourceLineNo">1338</span><a name="line.1338"></a>
-<span class="sourceLineNo">1339</span>    private ZookeeperStdOutSink getSink() {<a name="line.1339"></a>
-<span class="sourceLineNo">1340</span>      if (!(sink instanceof ZookeeperStdOutSink)) {<a name="line.1340"></a>
-<span class="sourceLineNo">1341</span>        throw new RuntimeException("Can only write to zookeeper sink");<a name="line.1341"></a>
-<span class="sourceLineNo">1342</span>      }<a name="line.1342"></a>
-<span class="sourceLineNo">1343</span>      return ((ZookeeperStdOutSink) sink);<a name="line.1343"></a>
-<span class="sourceLineNo">1344</span>    }<a name="line.1344"></a>
-<span class="sourceLineNo">1345</span>  }<a name="line.1345"></a>
+<span class="sourceLineNo">840</span>    System.err.println(<a name="line.840"></a>
+<span class="sourceLineNo">841</span>      "Usage: hbase canary [opts] [table1 [table2]...] | [regionserver1 [regionserver2]..]");<a name="line.841"></a>
+<span class="sourceLineNo">842</span>    System.err.println(" where [opts] are:");<a name="line.842"></a>
+<span class="sourceLineNo">843</span>    System.err.println("   -help          Show this help and exit.");<a name="line.843"></a>
+<span class="sourceLineNo">844</span>    System.err.println("   -regionserver  replace the table argument to regionserver,");<a name="line.844"></a>
+<span class="sourceLineNo">845</span>    System.err.println("      which means to enable regionserver mode");<a name="line.845"></a>
+<span class="sourceLineNo">846</span>    System.err.println("   -allRegions    Tries all regions on a regionserver,");<a name="line.846"></a>
+<span class="sourceLineNo">847</span>    System.err.println("      only works in regionserver mode.");<a name="line.847"></a>
+<span class="sourceLineNo">848</span>    System.err.println("   -zookeeper    Tries to grab zookeeper.znode.parent ");<a name="line.848"></a>
+<span class="sourceLineNo">849</span>    System.err.println("      on each zookeeper instance");<a name="line.849"></a>
+<span class="sourceLineNo">850</span>    System.err.println("   -daemon        Continuous check at defined intervals.");<a name="line.850"></a>
+<span class="sourceLineNo">851</span>    System.err.println("   -interval &lt;N&gt;  Interval between checks (sec)");<a name="line.851"></a>
+<span class="sourceLineNo">852</span>    System.err.println("   -e             Use table/regionserver as regular expression");<a name="line.852"></a>
+<span class="sourceLineNo">853</span>    System.err.println("      which means the table/regionserver is regular expression pattern");<a name="line.853"></a>
+<span class="sourceLineNo">854</span>    System.err.println("   -f &lt;B&gt;         stop whole program if first error occurs," +<a name="line.854"></a>
+<span class="sourceLineNo">855</span>        " default is true");<a name="line.855"></a>
+<span class="sourceLineNo">856</span>    System.err.println("   -t &lt;N&gt;         timeout for a check, default is 600000 (millisecs)");<a name="line.856"></a>
+<span class="sourceLineNo">857</span>    System.err.println("   -writeTableTimeout &lt;N&gt;         write timeout for the writeTable, default is 600000 (millisecs)");<a name="line.857"></a>
+<span class="sourceLineNo">858</span>    System.err.println("   -readTableTimeouts &lt;tableName&gt;=&lt;read timeout&gt;,&lt;tableName&gt;=&lt;read timeout&gt;, ...    "<a name="line.858"></a>
+<span class="sourceLineNo">859</span>        + "comma-separated list of read timeouts per table (no spaces), default is 600000 (millisecs)");<a name="line.859"></a>
+<span class="sourceLineNo">860</span>    System.err.println("   -writeSniffing enable the write sniffing in canary");<a name="line.860"></a>
+<span class="sourceLineNo">861</span>    System.err.println("   -treatFailureAsError treats read / write failure as error");<a name="line.861"></a>
+<span class="sourceLineNo">862</span>    System.err.println("   -writeTable    The table used for write sniffing."<a name="line.862"></a>
+<span class="sourceLineNo">863</span>        + " Default is hbase:canary");<a name="line.863"></a>
+<span class="sourceLineNo">864</span>    System.err.println("   -Dhbase.canary.read.raw.enabled=&lt;true/false&gt; Use this flag to enable or disable raw scan during read canary test"<a name="line.864"></a>
+<span class="sourceLineNo">865</span>        + " Default is false and raw is not enabled during scan");<a name="line.865"></a>
+<span class="sourceLineNo">866</span>    System.err<a name="line.866"></a>
+<span class="sourceLineNo">867</span>        .println("   -D&lt;configProperty&gt;=&lt;value&gt; assigning or override the configuration params");<a name="line.867"></a>
+<span class="sourceLineNo">868</span>    System.exit(USAGE_EXIT_CODE);<a name="line.868"></a>
+<span class="sourceLineNo">869</span>  }<a name="line.869"></a>
+<span class="sourceLineNo">870</span><a name="line.870"></a>
+<span class="sourceLineNo">871</span>  /**<a name="line.871"></a>
+<span class="sourceLineNo">872</span>   * A Factory method for {@link Monitor}.<a name="line.872"></a>
+<span class="sourceLineNo">873</span>   * Can be overridden by user.<a name="line.873"></a>
+<span class="sourceLineNo">874</span>   * @param index a start index for monitor target<a name="line.874"></a>
+<span class="sourceLineNo">875</span>   * @param args args passed from user<a name="line.875"></a>
+<span class="sourceLineNo">876</span>   * @return a Monitor instance<a name="line.876"></a>
+<span class="sourceLineNo">877</span>   */<a name="line.877"></a>
+<span class="sourceLineNo">878</span>  public Monitor newMonitor(final Connection connection, int index, String[] args) {<a name="line.878"></a>
+<span class="sourceLineNo">879</span>    Monitor monitor = null;<a name="line.879"></a>
+<span class="sourceLineNo">880</span>    String[] monitorTargets = null;<a name="line.880"></a>
+<span class="sourceLineNo">881</span><a name="line.881"></a>
+<span class="sourceLineNo">882</span>    if(index &gt;= 0) {<a name="line.882"></a>
+<span class="sourceLineNo">883</span>      int length = args.length - index;<a name="line.883"></a>
+<span class="sourceLineNo">884</span>      monitorTargets = new String[length];<a name="line.884"></a>
+<span class="sourceLineNo">885</span>      System.arraycopy(args, index, monitorTargets, 0, length);<a name="line.885"></a>
+<span class="sourceLineNo">886</span>    }<a name="line.886"></a>
+<span class="sourceLineNo">887</span><a name="line.887"></a>
+<span class="sourceLineNo">888</span>    if (this.sink instanceof RegionServerStdOutSink || this.regionServerMode) {<a name="line.888"></a>
+<span class="sourceLineNo">889</span>      monitor =<a name="line.889"></a>
+<span class="sourceLineNo">890</span>          new RegionServerMonitor(connection, monitorTargets, this.useRegExp,<a name="line.890"></a>
+<span class="sourceLineNo">891</span>              (StdOutSink) this.sink, this.executor, this.regionServerAllRegions,<a name="line.891"></a>
+<span class="sourceLineNo">892</span>              this.treatFailureAsError);<a name="line.892"></a>
+<span class="sourceLineNo">893</span>    } else if (this.sink instanceof ZookeeperStdOutSink || this.zookeeperMode) {<a name="line.893"></a>
+<span class="sourceLineNo">894</span>      monitor =<a name="line.894"></a>
+<span class="sourceLineNo">895</span>          new ZookeeperMonitor(connection, monitorTargets, this.useRegExp,<a name="line.895"></a>
+<span class="sourceLineNo">896</span>              (StdOutSink) this.sink, this.executor, this.treatFailureAsError);<a name="line.896"></a>
+<span class="sourceLineNo">897</span>    } else {<a name="line.897"></a>
+<span class="sourceLineNo">898</span>      monitor =<a name="line.898"></a>
+<span class="sourceLineNo">899</span>          new RegionMonitor(connection, monitorTargets, this.useRegExp,<a name="line.899"></a>
+<span class="sourceLineNo">900</span>              (StdOutSink) this.sink, this.executor, this.writeSniffing,<a name="line.900"></a>
+<span class="sourceLineNo">901</span>              this.writeTableName, this.treatFailureAsError, this.configuredReadTableTimeouts,<a name="line.901"></a>
+<span class="sourceLineNo">902</span>              this.configuredWriteTableTimeout);<a name="line.902"></a>
+<span class="sourceLineNo">903</span>    }<a name="line.903"></a>
+<span class="sourceLineNo">904</span>    return monitor;<a name="line.904"></a>
+<span class="sourceLineNo">905</span>  }<a name="line.905"></a>
+<span class="sourceLineNo">906</span><a name="line.906"></a>
+<span class="sourceLineNo">907</span>  // a Monitor super-class can be extended by users<a name="line.907"></a>
+<span class="sourceLineNo">908</span>  public static abstract class Monitor implements Runnable, Closeable {<a name="line.908"></a>
+<span class="sourceLineNo">909</span><a name="line.909"></a>
+<span class="sourceLineNo">910</span>    protected Connection connection;<a name="line.910"></a>
+<span class="sourceLineNo">911</span>    protected Admin admin;<a name="line.911"></a>
+<span class="sourceLineNo">912</span>    protected String[] targets;<a name="line.912"></a>
+<span class="sourceLineNo">913</span>    protected boolean useRegExp;<a name="line.913"></a>
+<span class="sourceLineNo">914</span>    protected boolean treatFailureAsError;<a name="line.914"></a>
+<span class="sourceLineNo">915</span>    protected boolean initialized = false;<a name="line.915"></a>
+<span class="sourceLineNo">916</span><a name="line.916"></a>
+<span class="sourceLineNo">917</span>    protected boolean done = false;<a name="line.917"></a>
+<span class="sourceLineNo">918</span>    protected int errorCode = 0;<a name="line.918"></a>
+<span class="sourceLineNo">919</span>    protected Sink sink;<a name="line.919"></a>
+<span class="sourceLineNo">920</span>    protected ExecutorService executor;<a name="line.920"></a>
+<span class="sourceLineNo">921</span><a name="line.921"></a>
+<span class="sourceLineNo">922</span>    public boolean isDone() {<a name="line.922"></a>
+<span class="sourceLineNo">923</span>      return done;<a name="line.923"></a>
+<span class="sourceLineNo">924</span>    }<a name="line.924"></a>
+<span class="sourceLineNo">925</span><a name="line.925"></a>
+<span class="sourceLineNo">926</span>    public boolean hasError() {<a name="line.926"></a>
+<span class="sourceLineNo">927</span>      return errorCode != 0;<a name="line.927"></a>
+<span class="sourceLineNo">928</span>    }<a name="line.928"></a>
+<span class="sourceLineNo">929</span><a name="line.929"></a>
+<span class="sourceLineNo">930</span>    public boolean finalCheckForErrors() {<a name="line.930"></a>
+<span class="sourceLineNo">931</span>      if (errorCode != 0) {<a name="line.931"></a>
+<span class="sourceLineNo">932</span>        return true;<a name="line.932"></a>
+<span class="sourceLineNo">933</span>      }<a name="line.933"></a>
+<span class="sourceLineNo">934</span>      if (treatFailureAsError &amp;&amp;<a name="line.934"></a>
+<span class="sourceLineNo">935</span>          (sink.getReadFailureCount() &gt; 0 || sink.getWriteFailureCount() &gt; 0)) {<a name="line.935"></a>
+<span class="sourceLineNo">936</span>        errorCode = FAILURE_EXIT_CODE;<a name="line.936"></a>
+<span class="sourceLineNo">937</span>        return true;<a name="line.937"></a>
+<span class="sourceLineNo">938</span>      }<a name="line.938"></a>
+<span class="sourceLineNo">939</span>      return false;<a name="line.939"></a>
+<span class="sourceLineNo">940</span>    }<a name="line.940"></a>
+<span class="sourceLineNo">941</span><a name="line.941"></a>
+<span class="sourceLineNo">942</span>    @Override<a name="line.942"></a>
+<span class="sourceLineNo">943</span>    public void close() throws IOException {<a name="line.943"></a>
+<span class="sourceLineNo">944</span>      if (this.admin != null) this.admin.close();<a name="line.944"></a>
+<span class="sourceLineNo">945</span>    }<a name="line.945"></a>
+<span class="sourceLineNo">946</span><a name="line.946"></a>
+<span class="sourceLineNo">947</span>    protected Monitor(Connection connection, String[] monitorTargets, boolean useRegExp, Sink sink,<a name="line.947"></a>
+<span class="sourceLineNo">948</span>        ExecutorService executor, boolean treatFailureAsError) {<a name="line.948"></a>
+<span class="sourceLineNo">949</span>      if (null == connection) throw new IllegalArgumentException("connection shall not be null");<a name="line.949"></a>
+<span class="sourceLineNo">950</span><a name="line.950"></a>
+<span class="sourceLineNo">951</span>      this.connection = connection;<a name="line.951"></a>
+<span class="sourceLineNo">952</span>      this.targets = monitorTargets;<a name="line.952"></a>
+<span class="sourceLineNo">953</span>      this.useRegExp = useRegExp;<a name="line.953"></a>
+<span class="sourceLineNo">954</span>      this.treatFailureAsError = treatFailureAsError;<a name="line.954"></a>
+<span class="sourceLineNo">955</span>      this.sink = sink;<a name="line.955"></a>
+<span class="sourceLineNo">956</span>      this.executor = executor;<a name="line.956"></a>
+<span class="sourceLineNo">957</span>    }<a name="line.957"></a>
+<span class="sourceLineNo">958</span><a name="line.958"></a>
+<span class="sourceLineNo">959</span>    @Override<a name="line.959"></a>
+<span class="sourceLineNo">960</span>    public abstract void run();<a name="line.960"></a>
+<span class="sourceLineNo">961</span><a name="line.961"></a>
+<span class="sourceLineNo">962</span>    protected boolean initAdmin() {<a name="line.962"></a>
+<span class="sourceLineNo">963</span>      if (null == this.admin) {<a name="line.963"></a>
+<span class="sourceLineNo">964</span>        try {<a name="line.964"></a>
+<span class="sourceLineNo">965</span>          this.admin = this.connection.getAdmin();<a name="line.965"></a>
+<span class="sourceLineNo">966</span>        } catch (Exception e) {<a name="line.966"></a>
+<span class="sourceLineNo">967</span>          LOG.error("Initial HBaseAdmin failed...", e);<a name="line.967"></a>
+<span class="sourceLineNo">968</span>          this.errorCode = INIT_ERROR_EXIT_CODE;<a name="line.968"></a>
+<span class="sourceLineNo">969</span>        }<a name="line.969"></a>
+<span class="sourceLineNo">970</span>      } else if (admin.isAborted()) {<a name="line.970"></a>
+<span class="sourceLineNo">971</span>        LOG.error("HBaseAdmin aborted");<a name="line.971"></a>
+<span class="sourceLineNo">972</span>        this.errorCode = INIT_ERROR_EXIT_CODE;<a name="line.972"></a>
+<span class="sourceLineNo">973</span>      }<a name="line.973"></a>
+<span class="sourceLineNo">974</span>      return !this.hasError();<a name="line.974"></a>
+<span class="sourceLineNo">975</span>    }<a name="line.975"></a>
+<span class="sourceLineNo">976</span>  }<a name="line.976"></a>
+<span class="sourceLineNo">977</span><a name="line.977"></a>
+<span class="sourceLineNo">978</span>  // a monitor for region mode<a name="line.978"></a>
+<span class="sourceLineNo">979</span>  private static class RegionMonitor extends Monitor {<a name="line.979"></a>
+<span class="sourceLineNo">980</span>    // 10 minutes<a name="line.980"></a>
+<span class="sourceLineNo">981</span>    private static final int DEFAULT_WRITE_TABLE_CHECK_PERIOD = 10 * 60 * 1000;<a name="line.981"></a>
+<span class="sourceLineNo">982</span>    // 1 days<a name="line.982"></a>
+<span class="sourceLineNo">983</span>    private static final int DEFAULT_WRITE_DATA_TTL = 24 * 60 * 60;<a name="line.983"></a>
+<span class="sourceLineNo">984</span><a name="line.984"></a>
+<span class="sourceLineNo">985</span>    private long lastCheckTime = -1;<a name="line.985"></a>
+<span class="sourceLineNo">986</span>    private boolean writeSniffing;<a name="line.986"></a>
+<span class="sourceLineNo">987</span>    private TableName writeTableName;<a name="line.987"></a>
+<span class="sourceLineNo">988</span>    private int writeDataTTL;<a name="line.988"></a>
+<span class="sourceLineNo">989</span>    private float regionsLowerLimit;<a name="line.989"></a>
+<span class="sourceLineNo">990</span>    private float regionsUpperLimit;<a name="line.990"></a>
+<span class="sourceLineNo">991</span>    private int checkPeriod;<a name="line.991"></a>
+<span class="sourceLineNo">992</span>    private boolean rawScanEnabled;<a name="line.992"></a>
+<span class="sourceLineNo">993</span>    private HashMap&lt;String, Long&gt; configuredReadTableTimeouts;<a name="line.993"></a>
+<span class="sourceLineNo">994</span>    private long configuredWriteTableTimeout;<a name="line.994"></a>
+<span class="sourceLineNo">995</span><a name="line.995"></a>
+<span class="sourceLineNo">996</span>    public RegionMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,<a name="line.996"></a>
+<span class="sourceLineNo">997</span>        StdOutSink sink, ExecutorService executor, boolean writeSniffing, TableName writeTableName,<a name="line.997"></a>
+<span class="sourceLineNo">998</span>        boolean treatFailureAsError, HashMap&lt;String, Long&gt; configuredReadTableTimeouts, long configuredWriteTableTimeout) {<a name="line.998"></a>
+<span class="sourceLineNo">999</span>      super(connection, monitorTargets, useRegExp, sink, executor, treatFailureAsError);<a name="line.999"></a>
+<span class="sourceLineNo">1000</span>      Configuration conf = connection.getConfiguration();<a name="line.1000"></a>
+<span class="sourceLineNo">1001</span>      this.writeSniffing = writeSniffing;<a name="line.1001"></a>
+<span class="sourceLineNo">1002</span>      this.writeTableName = writeTableName;<a name="line.1002"></a>
+<span class="sourceLineNo">1003</span>      this.writeDataTTL =<a name="line.1003"></a>
+<span class="sourceLineNo">1004</span>          conf.getInt(HConstants.HBASE_CANARY_WRITE_DATA_TTL_KEY, DEFAULT_WRITE_DATA_TTL);<a name="line.1004"></a>
+<span class="sourceLineNo">1005</span>      this.regionsLowerLimit =<a name="line.1005"></a>
+<span class="sourceLineNo">1006</span>          conf.getFloat(HConstants.HBASE_CANARY_WRITE_PERSERVER_REGIONS_LOWERLIMIT_KEY, 1.0f);<a name="line.1006"></a>
+<span class="sourceLineNo">1007</span>      this.regionsUpperLimit =<a name="line.1007"></a>
+<span class="sourceLineNo">1008</span>          conf.getFloat(HConstants.HBASE_CANARY_WRITE_PERSERVER_REGIONS_UPPERLIMIT_KEY, 1.5f);<a name="line.1008"></a>
+<span class="sourceLineNo">1009</span>      this.checkPeriod =<a name="line.1009"></a>
+<span class="sourceLineNo">1010</span>          conf.getInt(HConstants.HBASE_CANARY_WRITE_TABLE_CHECK_PERIOD_KEY,<a name="line.1010"></a>
+<span class="sourceLineNo">1011</span>            DEFAULT_WRITE_TABLE_CHECK_PERIOD);<a name="line.1011"></a>
+<span class="sourceLineNo">1012</span>      this.rawScanEnabled = conf.getBoolean(HConstants.HBASE_CANARY_READ_RAW_SCAN_KEY, false);<a name="line.1012"></a>
+<span class="sourceLineNo">1013</span>      this.configuredReadTableTimeouts = new HashMap&lt;&gt;(configuredReadTableTimeouts);<a name="line.1013"></a>
+<span class="sourceLineNo">1014</span>      this.configuredWriteTableTimeout = configuredWriteTableTimeout;<a name="line.1014"></a>
+<span class="sourceLineNo">1015</span>    }<a name="line.1015"></a>
+<span class="sourceLineNo">1016</span><a name="line.1016"></a>
+<span class="sourceLineNo">1017</span>    private RegionStdOutSink getSink() {<a name="line.1017"></a>
+<span class="sourceLineNo">1018</span>      if (!(sink instanceof RegionStdOutSink)) {<a name="line.1018"></a>
+<span class="sourceLineNo">1019</span>        throw new RuntimeException("Can only write to Region sink");<a name="line.1019"></a>
+<span class="sourceLineNo">1020</span>      }<a name="line.1020"></a>
+<span class="sourceLineNo">1021</span>      return ((RegionStdOutSink) sink);<a name="line.1021"></a>
+<span class="sourceLineNo">1022</span>    }<a name="line.1022"></a>
+<span class="sourceLineNo">1023</span><a name="line.1023"></a>
+<span class="sourceLineNo">1024</span>    @Override<a name="line.1024"></a>
+<span class="sourceLineNo">1025</span>    public void run() {<a name="line.1025"></a>
+<span class="sourceLineNo">1026</span>      if (this.initAdmin()) {<a name="line.1026"></a>
+<span class="sourceLineNo">1027</span>        try {<a name="line.1027"></a>
+<span class="sourceLineNo">1028</span>          List&lt;Future&lt;Void&gt;&gt; taskFutures = new LinkedList&lt;&gt;();<a name="line.1028"></a>
+<span class="sourceLineNo">1029</span>          RegionStdOutSink regionSink = this.getSink();<a name="line.1029"></a>
+<span class="sourceLineNo">1030</span>          if (this.targets != null &amp;&amp; this.targets.length &gt; 0) {<a name="line.1030"></a>
+<span class="sourceLineNo">1031</span>            String[] tables = generateMonitorTables(this.targets);<a name="line.1031"></a>
+<span class="sourceLineNo">1032</span>            // Check to see that each table name passed in the -readTableTimeouts argument is also passed as a monitor target.<a name="line.1032"></a>
+<span class="sourceLineNo">1033</span>            if (! new HashSet&lt;&gt;(Arrays.asList(tables)).containsAll(this.configuredReadTableTimeouts.keySet())) {<a name="line.1033"></a>
+<span class="sourceLineNo">1034</span>              LOG.error("-readTableTimeouts can only specify read timeouts for monitor targets passed via command line.");<a name="line.1034"></a>
+<span class="sourceLineNo">1035</span>              this.errorCode = USAGE_EXIT_CODE;<a name="line.1035"></a>
+<span class="sourceLineNo">1036</span>              return;<a name="line.1036"></a>
+<span class="sourceLineNo">1037</span>            }<a name="line.1037"></a>
+<span class="sourceLineNo">1038</span>            this.initialized = true;<a name="line.1038"></a>
+<span class="sourceLineNo">1039</span>            for (String table : tables) {<a name="line.1039"></a>
+<span class="sourceLineNo">1040</span>              LongAdder readLatency = regionSink.initializeAndGetReadLatencyForTable(table);<a name="line.1040"></a>
+<span class="sourceLineNo">1041</span>              taskFutures.addAll(Canary.sniff(admin, regionSink, table, executor, TaskType.READ,<a name="line.1041"></a>
+<span class="sourceLineNo">1042</span>                this.rawScanEnabled, readLatency));<a name="line.1042"></a>
+<span class="sourceLineNo">1043</span>            }<a name="line.1043"></a>
+<span class="sourceLineNo">1044</span>          } else {<a name="line.1044"></a>
+<span class="sourceLineNo">1045</span>            taskFutures.addAll(sniff(TaskType.READ, regionSink));<a name="line.1045"></a>
+<span class="sourceLineNo">1046</span>          }<a name="line.1046"></a>
+<span class="sourceLineNo">1047</span><a name="line.1047"></a>
+<span class="sourceLineNo">1048</span>          if (writeSniffing) {<a name="line.1048"></a>
+<span class="sourceLineNo">1049</span>            if (EnvironmentEdgeManager.currentTime() - lastCheckTime &gt; checkPeriod) {<a name="line.1049"></a>
+<span class="sourceLineNo">1050</span>              try {<a name="line.1050"></a>
+<span class="sourceLineNo">1051</span>                checkWriteTableDistribution();<a name="line.1051"></a>
+<span class="sourceLineNo">1052</span>              } catch (IOException e) {<a name="line.1052"></a>
+<span class="sourceLineNo">1053</span>                LOG.error("Check canary table distribution failed!", e);<a name="line.1053"></a>
+<span class="sourceLineNo">1054</span>              }<a name="line.1054"></a>
+<span class="sourceLineNo">1055</span>              lastCheckTime = EnvironmentEdgeManager.currentTime();<a name="line.1055"></a>
+<span class="sourceLineNo">1056</span>            }<a name="line.1056"></a>
+<span class="sourceLineNo">1057</span>            // sniff canary table with write operation<a name="line.1057"></a>
+<span class="sourceLineNo">1058</span>            regionSink.initializeWriteLatency();<a name="line.1058"></a>
+<span class="sourceLineNo">1059</span>            LongAdder writeTableLatency = regionSink.getWriteLatency();<a name="line.1059"></a>
+<span class="sourceLineNo">1060</span>            taskFutures.addAll(Canary.sniff(admin, regionSink, admin.getTableDescriptor(writeTableName),<a name="line.1060"></a>
+<span class="sourceLineNo">1061</span>              executor, TaskType.WRITE, this.rawScanEnabled, writeTableLatency));<a name="line.1061"></a>
+<span class="sourceLineNo">1062</span>          }<a name="line.1062"></a>
+<span class="sourceLineNo">1063</span><a name="line.1063"></a>
+<span class="sourceLineNo">1064</span>          for (Future&lt;Void&gt; future : taskFutures) {<a name="line.1064"></a>
+<span class="sourceLineNo">1065</span>            try {<a name="line.1065"></a>
+<span class="sourceLineNo">1066</span>              future.get();<a name="line.1066"></a>
+<span class="sourceLineNo">1067</span>            } catch (ExecutionException e) {<a name="line.1067"></a>
+<span class="sourceLineNo">1068</span>              LOG.error("Sniff region failed!", e);<a name="line.1068"></a>
+<span class="sourceLineNo">1069</span>            }<a name="line.1069"></a>
+<span class="sourceLineNo">1070</span>          }<a name="line.1070"></a>
+<span class="sourceLineNo">1071</span>          Map&lt;String, LongAdder&gt; actualReadTableLatency = regionSink.getReadLatencyMap();<a name="line.1071"></a>
+<span class="sourceLineNo">1072</span>          for (Map.Entry&lt;String, Long&gt; entry : configuredReadTableTimeouts.entrySet()) {<a name="line.1072"></a>
+<span class="sourceLineNo">1073</span>            String tableName = entry.getKey();<a name="line.1073"></a>
+<span class="sourceLineNo">1074</span>            if (actualReadTableLatency.containsKey(tableName)) {<a name="line.1074"></a>
+<span class="sourceLineNo">1075</span>              Long actual = actualReadTableLatency.get(tableName).longValue();<a name="line.1075"></a>
+<span class="sourceLineNo">1076</span>              Long configured = entry.getValue();<a name="line.1076"></a>
+<span class="sourceLineNo">1077</span>              LOG.info("Read operation for " + tableName + " took " + actual +<a name="line.1077"></a>
+<span class="sourceLineNo">1078</span>                " ms. The configured read timeout was " + configured + " ms.");<a name="line.1078"></a>
+<span class="sourceLineNo">1079</span>              if (actual &gt; configured) {<a name="line.1079"></a>
+<span class="sourceLineNo">1080</span>                LOG.error("Read operation for " + tableName + " exceeded the configured read timeout.");<a name="line.1080"></a>
+<span class="sourceLineNo">1081</span>              }<a name="line.1081"></a>
+<span class="sourceLineNo">1082</span>            } else {<a name="line.1082"></a>
+<span class="sourceLineNo">1083</span>              LOG.error("Read operation for " + tableName + " failed!");<a name="line.1083"></a>
+<span class="sourceLineNo">1084</span>            }<a name="line.1084"></a>
+<span class="sourceLineNo">1085</span>          }<a name="line.1085"></a>
+<span class="sourceLineNo">1086</span>          if (this.writeSniffing) {<a name="line.1086"></a>
+<span class="sourceLineNo">1087</span>            String writeTableStringName = this.writeTableName.getNameAsString();<a name="line.1087"></a>
+<span class="sourceLineNo">1088</span>            long actualWriteLatency = regionSink.getWriteLatency().longValue();<a name="line.1088"></a>
+<span class="sourceLineNo">1089</span>            LOG.info("Write operation for " + writeTableStringName + " took " + actualWriteLatency + " ms. The configured write timeout was " +<a name="line.1089"></a>
+<span class="sourceLineNo">1090</span>              this.configuredWriteTableTimeout + " ms.");<a name="line.1090"></a>
+<span class="sourceLineNo">1091</span>            // Check that the writeTable write operation latency does not exceed the configured timeout.<a name="line.1091"></a>
+<span class="sourceLineNo">1092</span>            if (actualWriteLatency &gt; this.configuredWriteTableTimeout) {<a name="line.1092"></a>
+<span class="sourceLineNo">1093</span>              LOG.error("Write operation for " + writeTableStringName + " exceeded the configured write timeout.");<a name="line.1093"></a>
+<span class="sourceLineNo">1094</span>            }<a name="line.1094"></a>
+<span class="sourceLineNo">1095</span>          }<a name="line.1095"></a>
+<span class="sourceLineNo">1096</span>        } catch (Exception e) {<a name="line.1096"></a>
+<span class="sourceLineNo">1097</span>          LOG.error("Run regionMonitor failed", e);<a name="line.1097"></a>
+<span class="sourceLineNo">1098</span>          this.errorCode = ERROR_EXIT_CODE;<a name="line.1098"></a>
+<span class="sourceLineNo">1099</span>        } finally {<a name="line.1099"></a>
+<span class="sourceLineNo">1100</span>          this.done = true;<a name="line.1100"></a>
+<span class="sourceLineNo">1101</span>  }<a name="line.1101"></a>
+<span class="sourceLineNo">1102</span>      }<a name="line.1102"></a>
+<span class="sourceLineNo">1103</span>      this.done = true;<a name="line.1103"></a>
+<span class="sourceLineNo">1104</span>    }<a name="line.1104"></a>
+<span class="sourceLineNo">1105</span><a name="line.1105"></a>
+<span class="sourceLineNo">1106</span>    private String[] generateMonitorTables(String[] monitorTargets) throws IOException {<a name="line.1106"></a>
+<span class="sourceLineNo">1107</span>      String[] returnTables = null;<a name="line.1107"></a>
+<span class="sourceLineNo">1108</span><a name="line.1108"></a>
+<span class="sourceLineNo">1109</span>      if (this.useRegExp) {<a name="line.1109"></a>
+<span class="sourceLineNo">1110</span>        Pattern pattern = null;<a name="line.1110"></a>
+<span class="sourceLineNo">1111</span>        HTableDescriptor[] tds = null;<a name="line.1111"></a>
+<span class="sourceLineNo">1112</span>        Set&lt;String&gt; tmpTables = new TreeSet&lt;&gt;();<a name="line.1112"></a>
+<span class="sourceLineNo">1113</span>        try {<a name="line.1113"></a>
+<span class="sourceLineNo">1114</span>          if (LOG.isDebugEnabled()) {<a name="line.1114"></a>
+<span class="sourceLineNo">1115</span>            LOG.debug(String.format("reading list of tables"));<a name="line.1115"></a>
+<span class="sourceLineNo">1116</span>          }<a name="line.1116"></a>
+<span class="sourceLineNo">1117</span>          tds = this.admin.listTables(pattern);<a name="line.1117"></a>
+<span class="sourceLineNo">1118</span>          if (tds == null) {<a name="line.1118"></a>
+<span class="sourceLineNo">1119</span>            tds = new HTableDescriptor[0];<a name="line.1119"></a>
+<span class="sourceLineNo">1120</span>          }<a name="line.1120"></a>
+<span class="sourceLineNo">1121</span>          for (String monitorTarget : monitorTargets) {<a name="line.1121"></a>
+<span class="sourceLineNo">1122</span>            pattern = Pattern.compile(monitorTarget);<a name="line.1122"></a>
+<span class="sourceLineNo">1123</span>            for (HTableDescriptor td : tds) {<a name="line.1123"></a>
+<span class="sourceLineNo">1124</span>              if (pattern.matcher(td.getNameAsString()).matches()) {<a name="line.1124"></a>
+<span class="sourceLineNo">1125</span>                tmpTables.add(td.getNameAsString());<a name="line.1125"></a>
+<span class="sourceLineNo">1126</span>              }<a name="line.1126"></a>
+<span class="sourceLineNo">1127</span>            }<a name="line.1127"></a>
+<span class="sourceLineNo">1128</span>          }<a name="line.1128"></a>
+<span class="sourceLineNo">1129</span>        } catch (IOException e) {<a name="line.1129"></a>
+<span class="sourceLineNo">1130</span>          LOG.error("Communicate with admin failed", e);<a name="line.1130"></a>
+<span class="sourceLineNo">1131</span>          throw e;<a name="line.1131"></a>
+<span class="sourceLineNo">1132</span>        }<a name="line.1132"></a>
+<span class="sourceLineNo">1133</span><a name="line.1133"></a>
+<span class="sourceLineNo">1134</span>        if (tmpTables.size() &gt; 0) {<a name="line.1134"></a>
+<span class="sourceLineNo">1135</span>          returnTables = tmpTables.toArray(new String[tmpTables.size()]);<a name="line.1135"></a>
+<span class="sourceLineNo">1136</span>        } else {<a name="line.1136"></a>
+<span class="sourceLineNo">1137</span>          String msg = "No HTable found, tablePattern:" + Arrays.toString(monitorTargets);<a name="line.1137"></a>
+<span class="sourceLineNo">1138</span>          LOG.error(msg);<a name="line.1138"></a>
+<span class="sourceLineNo">1139</span>          this.errorCode = INIT_ERROR_EXIT_CODE;<a name="line.1139"></a>
+<span class="sourceLineNo">1140</span>          throw new TableNotFoundException(msg);<a name="line.1140"></a>
+<span class="sourceLineNo">1141</span>        }<a name="line.1141"></a>
+<span class="sourceLineNo">1142</span>      } else {<a name="line.1142"></a>
+<span class="sourceLineNo">1143</span>        returnTables = monitorTargets;<a name="line.1143"></a>
+<span class="sourceLineNo">1144</span>      }<a name="line.1144"></a>
+<span class="sourceLineNo">1145</span><a name="line.1145"></a>
+<span class="sourceLineNo">1146</span>      return returnTables;<a name="line.1146"></a>
+<span class="sourceLineNo">1147</span>    }<a name="line.1147"></a>
+<span class="sourceLineNo">1148</span><a name="line.1148"></a>
+<span class="sourceLineNo">1149</span>    /*<a name="line.1149"></a>
+<span class="sourceLineNo">1150</span>     * canary entry point to monitor all the tables.<a name="line.1150"></a>
+<span class="sourceLineNo">1151</span>     */<a name="line.1151"></a>
+<span class="sourceLineNo">1152</span>    private List&lt;Future&lt;Void&gt;&gt; sniff(TaskType taskType, RegionStdOutSink regionSink) throws Exception {<a name="line.1152"></a>
+<span class="sourceLineNo">1153</span>      if (LOG.isDebugEnabled()) {<a name="line.1153"></a>
+<span class="sourceLineNo">1154</span>        LOG.debug(String.format("reading list of tables"));<a name="line.1154"></a>
+<span class="sourceLineNo">1155</span>      }<a name="line.1155"></a>
+<span class="sourceLineNo">1156</span>      List&lt;Future&lt;Void&gt;&gt; taskFutures = new LinkedList&lt;&gt;();<a name="line.1156"></a>
+<span class="sourceLineNo">1157</span>      for (HTableDescriptor table : admin.listTables()) {<a name="line.1157"></a>
+<span class="sourceLineNo">1158</span>        if (admin.isTableEnabled(table.getTableName())<a name="line.1158"></a>
+<span class="sourceLineNo">1159</span>            &amp;&amp; (!table.getTableName().equals(writeTableName))) {<a name="line.1159"></a>
+<span class="sourceLineNo">1160</span>          LongAdder readLatency = regionSink.initializeAndGetReadLatencyForTable(table.getNameAsString());<a name="line.1160"></a>
+<span class="sourceLineNo">1161</span>          taskFutures.addAll(Canary.sniff(admin, sink, table, executor, taskType, this.rawScanEnabled, readLatency));<a name="line.1161"></a>
+<span class="sourceLineNo">1162</span>        }<a name="line.1162"></a>
+<span class="sourceLineNo">1163</span>      }<a name="line.1163"></a>
+<span class="sourceLineNo">1164</span>      return taskFutures;<a name="line.1164"></a>
+<span class="sourceLineNo">1165</span>    }<a name="line.1165"></a>
+<span class="sourceLineNo">1166</span><a name="line.1166"></a>
+<span class="sourceLineNo">1167</span>    private void checkWriteTableDistribution() throws IOException {<a name="line.1167"></a>
+<span class="sourceLineNo">1168</span>      if (!admin.tableExists(writeTableName)) {<a name="line.1168"></a>
+<span class="sourceLineNo">1169</span>        int numberOfServers =<a name="line.1169"></a>
+<span class="sourceLineNo">1170</span>            admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().size();<a name="line.1170"></a>
+<span class="sourceLineNo">1171</span>        if (numberOfServers == 0) {<a name="line.1171"></a>
+<span class="sourceLineNo">1172</span>          throw new IllegalStateException("No live regionservers");<a name="line.1172"></a>
+<span class="sourceLineNo">1173</span>        }<a name="line.1173"></a>
+<span class="sourceLineNo">1174</span>        createWriteTable(numberOfServers);<a name="line.1174"></a>
+<span class="sourceLineNo">1175</span>      }<a name="line.1175"></a>
+<span class="sourceLineNo">1176</span><a name="line.1176"></a>
+<span class="sourceLineNo">1177</span>      if (!admin.isTableEnabled(writeTableName)) {<a name="line.1177"></a>
+<span class="sourceLineNo">1178</span

<TRUNCATED>

Mime
View raw message