hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [14/51] [partial] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd.
Date Wed, 19 Jul 2017 22:07:30 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/9eba7fcf/devapidocs/src-html/org/apache/hadoop/hbase/tool/Canary.RegionMonitor.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/tool/Canary.RegionMonitor.html b/devapidocs/src-html/org/apache/hadoop/hbase/tool/Canary.RegionMonitor.html
index e1fbce4..873e17f 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/tool/Canary.RegionMonitor.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/tool/Canary.RegionMonitor.html
@@ -1089,497 +1089,498 @@
 <span class="sourceLineNo">1081</span>            }<a name="line.1081"></a>
 <span class="sourceLineNo">1082</span>          }<a name="line.1082"></a>
 <span class="sourceLineNo">1083</span>          Map&lt;String, AtomicLong&gt; actualReadTableLatency = regionSink.getReadLatencyMap();<a name="line.1083"></a>
-<span class="sourceLineNo">1084</span>          for (String tableName : this.configuredReadTableTimeouts.keySet()) {<a name="line.1084"></a>
-<span class="sourceLineNo">1085</span>            if (actualReadTableLatency.containsKey(tableName)) {<a name="line.1085"></a>
-<span class="sourceLineNo">1086</span>              Long actual = actualReadTableLatency.get(tableName).longValue();<a name="line.1086"></a>
-<span class="sourceLineNo">1087</span>              Long configured = this.configuredReadTableTimeouts.get(tableName);<a name="line.1087"></a>
-<span class="sourceLineNo">1088</span>              LOG.info("Read operation for " + tableName + " took " + actual +<a name="line.1088"></a>
-<span class="sourceLineNo">1089</span>                " ms. The configured read timeout was " + configured + " ms.");<a name="line.1089"></a>
-<span class="sourceLineNo">1090</span>              if (actual &gt; configured) {<a name="line.1090"></a>
-<span class="sourceLineNo">1091</span>                LOG.error("Read operation for " + tableName + " exceeded the configured read timeout.");<a name="line.1091"></a>
-<span class="sourceLineNo">1092</span>              }<a name="line.1092"></a>
-<span class="sourceLineNo">1093</span>            } else {<a name="line.1093"></a>
-<span class="sourceLineNo">1094</span>              LOG.error("Read operation for " + tableName + " failed!");<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>          if (this.writeSniffing) {<a name="line.1097"></a>
-<span class="sourceLineNo">1098</span>            String writeTableStringName = this.writeTableName.getNameAsString();<a name="line.1098"></a>
-<span class="sourceLineNo">1099</span>            long actualWriteLatency = regionSink.getWriteLatency().longValue();<a name="line.1099"></a>
-<span class="sourceLineNo">1100</span>            LOG.info("Write operation for " + writeTableStringName + " took " + actualWriteLatency + " ms. The configured write timeout was " +<a name="line.1100"></a>
-<span class="sourceLineNo">1101</span>              this.configuredWriteTableTimeout + " ms.");<a name="line.1101"></a>
-<span class="sourceLineNo">1102</span>            // Check that the writeTable write operation latency does not exceed the configured timeout.<a name="line.1102"></a>
-<span class="sourceLineNo">1103</span>            if (actualWriteLatency &gt; this.configuredWriteTableTimeout) {<a name="line.1103"></a>
-<span class="sourceLineNo">1104</span>              LOG.error("Write operation for " + writeTableStringName + " exceeded the configured write timeout.");<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>        } catch (Exception e) {<a name="line.1107"></a>
-<span class="sourceLineNo">1108</span>          LOG.error("Run regionMonitor failed", e);<a name="line.1108"></a>
-<span class="sourceLineNo">1109</span>          this.errorCode = ERROR_EXIT_CODE;<a name="line.1109"></a>
-<span class="sourceLineNo">1110</span>        }<a name="line.1110"></a>
-<span class="sourceLineNo">1111</span>      }<a name="line.1111"></a>
-<span class="sourceLineNo">1112</span>      this.done = true;<a name="line.1112"></a>
-<span class="sourceLineNo">1113</span>    }<a name="line.1113"></a>
-<span class="sourceLineNo">1114</span><a name="line.1114"></a>
-<span class="sourceLineNo">1115</span>    private String[] generateMonitorTables(String[] monitorTargets) throws IOException {<a name="line.1115"></a>
-<span class="sourceLineNo">1116</span>      String[] returnTables = null;<a name="line.1116"></a>
-<span class="sourceLineNo">1117</span><a name="line.1117"></a>
-<span class="sourceLineNo">1118</span>      if (this.useRegExp) {<a name="line.1118"></a>
-<span class="sourceLineNo">1119</span>        Pattern pattern = null;<a name="line.1119"></a>
-<span class="sourceLineNo">1120</span>        HTableDescriptor[] tds = null;<a name="line.1120"></a>
-<span class="sourceLineNo">1121</span>        Set&lt;String&gt; tmpTables = new TreeSet&lt;&gt;();<a name="line.1121"></a>
-<span class="sourceLineNo">1122</span>        try {<a name="line.1122"></a>
-<span class="sourceLineNo">1123</span>          if (LOG.isDebugEnabled()) {<a name="line.1123"></a>
-<span class="sourceLineNo">1124</span>            LOG.debug(String.format("reading list of tables"));<a name="line.1124"></a>
-<span class="sourceLineNo">1125</span>          }<a name="line.1125"></a>
-<span class="sourceLineNo">1126</span>          tds = this.admin.listTables(pattern);<a name="line.1126"></a>
-<span class="sourceLineNo">1127</span>          if (tds == null) {<a name="line.1127"></a>
-<span class="sourceLineNo">1128</span>            tds = new HTableDescriptor[0];<a name="line.1128"></a>
-<span class="sourceLineNo">1129</span>          }<a name="line.1129"></a>
-<span class="sourceLineNo">1130</span>          for (String monitorTarget : monitorTargets) {<a name="line.1130"></a>
-<span class="sourceLineNo">1131</span>            pattern = Pattern.compile(monitorTarget);<a name="line.1131"></a>
-<span class="sourceLineNo">1132</span>            for (HTableDescriptor td : tds) {<a name="line.1132"></a>
-<span class="sourceLineNo">1133</span>              if (pattern.matcher(td.getNameAsString()).matches()) {<a name="line.1133"></a>
-<span class="sourceLineNo">1134</span>                tmpTables.add(td.getNameAsString());<a name="line.1134"></a>
-<span class="sourceLineNo">1135</span>              }<a name="line.1135"></a>
-<span class="sourceLineNo">1136</span>            }<a name="line.1136"></a>
-<span class="sourceLineNo">1137</span>          }<a name="line.1137"></a>
-<span class="sourceLineNo">1138</span>        } catch (IOException e) {<a name="line.1138"></a>
-<span class="sourceLineNo">1139</span>          LOG.error("Communicate with admin failed", e);<a name="line.1139"></a>
-<span class="sourceLineNo">1140</span>          throw e;<a name="line.1140"></a>
-<span class="sourceLineNo">1141</span>        }<a name="line.1141"></a>
-<span class="sourceLineNo">1142</span><a name="line.1142"></a>
-<span class="sourceLineNo">1143</span>        if (tmpTables.size() &gt; 0) {<a name="line.1143"></a>
-<span class="sourceLineNo">1144</span>          returnTables = tmpTables.toArray(new String[tmpTables.size()]);<a name="line.1144"></a>
-<span class="sourceLineNo">1145</span>        } else {<a name="line.1145"></a>
-<span class="sourceLineNo">1146</span>          String msg = "No HTable found, tablePattern:" + Arrays.toString(monitorTargets);<a name="line.1146"></a>
-<span class="sourceLineNo">1147</span>          LOG.error(msg);<a name="line.1147"></a>
-<span class="sourceLineNo">1148</span>          this.errorCode = INIT_ERROR_EXIT_CODE;<a name="line.1148"></a>
-<span class="sourceLineNo">1149</span>          throw new TableNotFoundException(msg);<a name="line.1149"></a>
-<span class="sourceLineNo">1150</span>        }<a name="line.1150"></a>
-<span class="sourceLineNo">1151</span>      } else {<a name="line.1151"></a>
-<span class="sourceLineNo">1152</span>        returnTables = monitorTargets;<a name="line.1152"></a>
-<span class="sourceLineNo">1153</span>      }<a name="line.1153"></a>
-<span class="sourceLineNo">1154</span><a name="line.1154"></a>
-<span class="sourceLineNo">1155</span>      return returnTables;<a name="line.1155"></a>
-<span class="sourceLineNo">1156</span>    }<a name="line.1156"></a>
-<span class="sourceLineNo">1157</span><a name="line.1157"></a>
-<span class="sourceLineNo">1158</span>    /*<a name="line.1158"></a>
-<span class="sourceLineNo">1159</span>     * canary entry point to monitor all the tables.<a name="line.1159"></a>
-<span class="sourceLineNo">1160</span>     */<a name="line.1160"></a>
-<span class="sourceLineNo">1161</span>    private List&lt;Future&lt;Void&gt;&gt; sniff(TaskType taskType, RegionStdOutSink regionSink) throws Exception {<a name="line.1161"></a>
-<span class="sourceLineNo">1162</span>      if (LOG.isDebugEnabled()) {<a name="line.1162"></a>
-<span class="sourceLineNo">1163</span>        LOG.debug(String.format("reading list of tables"));<a name="line.1163"></a>
-<span class="sourceLineNo">1164</span>      }<a name="line.1164"></a>
-<span class="sourceLineNo">1165</span>      List&lt;Future&lt;Void&gt;&gt; taskFutures = new LinkedList&lt;&gt;();<a name="line.1165"></a>
-<span class="sourceLineNo">1166</span>      for (HTableDescriptor table : admin.listTables()) {<a name="line.1166"></a>
-<span class="sourceLineNo">1167</span>        if (admin.isTableEnabled(table.getTableName())<a name="line.1167"></a>
-<span class="sourceLineNo">1168</span>            &amp;&amp; (!table.getTableName().equals(writeTableName))) {<a name="line.1168"></a>
-<span class="sourceLineNo">1169</span>          AtomicLong readLatency = regionSink.initializeAndGetReadLatencyForTable(table.getNameAsString());<a name="line.1169"></a>
-<span class="sourceLineNo">1170</span>          taskFutures.addAll(Canary.sniff(admin, sink, table, executor, taskType, this.rawScanEnabled, readLatency));<a name="line.1170"></a>
-<span class="sourceLineNo">1171</span>        }<a name="line.1171"></a>
-<span class="sourceLineNo">1172</span>      }<a name="line.1172"></a>
-<span class="sourceLineNo">1173</span>      return taskFutures;<a name="line.1173"></a>
-<span class="sourceLineNo">1174</span>    }<a name="line.1174"></a>
-<span class="sourceLineNo">1175</span><a name="line.1175"></a>
-<span class="sourceLineNo">1176</span>    private void checkWriteTableDistribution() throws IOException {<a name="line.1176"></a>
-<span class="sourceLineNo">1177</span>      if (!admin.tableExists(writeTableName)) {<a name="line.1177"></a>
-<span class="sourceLineNo">1178</span>        int numberOfServers = admin.getClusterStatus().getServers().size();<a name="line.1178"></a>
-<span class="sourceLineNo">1179</span>        if (numberOfServers == 0) {<a name="line.1179"></a>
-<span class="sourceLineNo">1180</span>          throw new IllegalStateException("No live regionservers");<a name="line.1180"></a>
-<span class="sourceLineNo">1181</span>        }<a name="line.1181"></a>
-<span class="sourceLineNo">1182</span>        createWriteTable(numberOfServers);<a name="line.1182"></a>
-<span class="sourceLineNo">1183</span>      }<a name="line.1183"></a>
-<span class="sourceLineNo">1184</span><a name="line.1184"></a>
-<span class="sourceLineNo">1185</span>      if (!admin.isTableEnabled(writeTableName)) {<a name="line.1185"></a>
-<span class="sourceLineNo">1186</span>        admin.enableTable(writeTableName);<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>      ClusterStatus status = admin.getClusterStatus();<a name="line.1189"></a>
-<span class="sourceLineNo">1190</span>      int numberOfServers = status.getServersSize();<a name="line.1190"></a>
-<span class="sourceLineNo">1191</span>      if (status.getServers().contains(status.getMaster())) {<a name="line.1191"></a>
-<span class="sourceLineNo">1192</span>        numberOfServers -= 1;<a name="line.1192"></a>
-<span class="sourceLineNo">1193</span>      }<a name="line.1193"></a>
-<span class="sourceLineNo">1194</span><a name="line.1194"></a>
-<span class="sourceLineNo">1195</span>      List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; pairs =<a name="line.1195"></a>
-<span class="sourceLineNo">1196</span>          MetaTableAccessor.getTableRegionsAndLocations(connection, writeTableName);<a name="line.1196"></a>
-<span class="sourceLineNo">1197</span>      int numberOfRegions = pairs.size();<a name="line.1197"></a>
-<span class="sourceLineNo">1198</span>      if (numberOfRegions &lt; numberOfServers * regionsLowerLimit<a name="line.1198"></a>
-<span class="sourceLineNo">1199</span>          || numberOfRegions &gt; numberOfServers * regionsUpperLimit) {<a name="line.1199"></a>
-<span class="sourceLineNo">1200</span>        admin.disableTable(writeTableName);<a name="line.1200"></a>
-<span class="sourceLineNo">1201</span>        admin.deleteTable(writeTableName);<a name="line.1201"></a>
-<span class="sourceLineNo">1202</span>        createWriteTable(numberOfServers);<a name="line.1202"></a>
-<span class="sourceLineNo">1203</span>      }<a name="line.1203"></a>
-<span class="sourceLineNo">1204</span>      HashSet&lt;ServerName&gt; serverSet = new HashSet&lt;&gt;();<a name="line.1204"></a>
-<span class="sourceLineNo">1205</span>      for (Pair&lt;HRegionInfo, ServerName&gt; pair : pairs) {<a name="line.1205"></a>
-<span class="sourceLineNo">1206</span>        serverSet.add(pair.getSecond());<a name="line.1206"></a>
-<span class="sourceLineNo">1207</span>      }<a name="line.1207"></a>
-<span class="sourceLineNo">1208</span>      int numberOfCoveredServers = serverSet.size();<a name="line.1208"></a>
-<span class="sourceLineNo">1209</span>      if (numberOfCoveredServers &lt; numberOfServers) {<a name="line.1209"></a>
-<span class="sourceLineNo">1210</span>        admin.balancer();<a name="line.1210"></a>
-<span class="sourceLineNo">1211</span>      }<a name="line.1211"></a>
-<span class="sourceLineNo">1212</span>    }<a name="line.1212"></a>
-<span class="sourceLineNo">1213</span><a name="line.1213"></a>
-<span class="sourceLineNo">1214</span>    private void createWriteTable(int numberOfServers) throws IOException {<a name="line.1214"></a>
-<span class="sourceLineNo">1215</span>      int numberOfRegions = (int)(numberOfServers * regionsLowerLimit);<a name="line.1215"></a>
-<span class="sourceLineNo">1216</span>      LOG.info("Number of live regionservers: " + numberOfServers + ", "<a name="line.1216"></a>
-<span class="sourceLineNo">1217</span>          + "pre-splitting the canary table into " + numberOfRegions + " regions "<a name="line.1217"></a>
-<span class="sourceLineNo">1218</span>          + "(current lower limit of regions per server is " + regionsLowerLimit<a name="line.1218"></a>
-<span class="sourceLineNo">1219</span>          + " and you can change it by config: "<a name="line.1219"></a>
-<span class="sourceLineNo">1220</span>          + HConstants.HBASE_CANARY_WRITE_PERSERVER_REGIONS_LOWERLIMIT_KEY + " )");<a name="line.1220"></a>
-<span class="sourceLineNo">1221</span>      HTableDescriptor desc = new HTableDescriptor(writeTableName);<a name="line.1221"></a>
-<span class="sourceLineNo">1222</span>      HColumnDescriptor family = new HColumnDescriptor(CANARY_TABLE_FAMILY_NAME);<a name="line.1222"></a>
-<span class="sourceLineNo">1223</span>      family.setMaxVersions(1);<a name="line.1223"></a>
-<span class="sourceLineNo">1224</span>      family.setTimeToLive(writeDataTTL);<a name="line.1224"></a>
-<span class="sourceLineNo">1225</span><a name="line.1225"></a>
-<span class="sourceLineNo">1226</span>      desc.addFamily(family);<a name="line.1226"></a>
-<span class="sourceLineNo">1227</span>      byte[][] splits = new RegionSplitter.HexStringSplit().split(numberOfRegions);<a name="line.1227"></a>
-<span class="sourceLineNo">1228</span>      admin.createTable(desc, splits);<a name="line.1228"></a>
-<span class="sourceLineNo">1229</span>    }<a name="line.1229"></a>
-<span class="sourceLineNo">1230</span>  }<a name="line.1230"></a>
-<span class="sourceLineNo">1231</span><a name="line.1231"></a>
-<span class="sourceLineNo">1232</span>  /**<a name="line.1232"></a>
-<span class="sourceLineNo">1233</span>   * Canary entry point for specified table.<a name="line.1233"></a>
-<span class="sourceLineNo">1234</span>   * @throws Exception<a name="line.1234"></a>
-<span class="sourceLineNo">1235</span>   */<a name="line.1235"></a>
-<span class="sourceLineNo">1236</span>  private static List&lt;Future&lt;Void&gt;&gt; sniff(final Admin admin, final Sink sink, String tableName,<a name="line.1236"></a>
-<span class="sourceLineNo">1237</span>      ExecutorService executor, TaskType taskType, boolean rawScanEnabled, AtomicLong readLatency) throws Exception {<a name="line.1237"></a>
-<span class="sourceLineNo">1238</span>    if (LOG.isDebugEnabled()) {<a name="line.1238"></a>
-<span class="sourceLineNo">1239</span>      LOG.debug(String.format("checking table is enabled and getting table descriptor for table %s",<a name="line.1239"></a>
-<span class="sourceLineNo">1240</span>        tableName));<a name="line.1240"></a>
-<span class="sourceLineNo">1241</span>    }<a name="line.1241"></a>
-<span class="sourceLineNo">1242</span>    if (admin.isTableEnabled(TableName.valueOf(tableName))) {<a name="line.1242"></a>
-<span class="sourceLineNo">1243</span>      return Canary.sniff(admin, sink, admin.getTableDescriptor(TableName.valueOf(tableName)),<a name="line.1243"></a>
-<span class="sourceLineNo">1244</span>        executor, taskType, rawScanEnabled, readLatency);<a name="line.1244"></a>
-<span class="sourceLineNo">1245</span>    } else {<a name="line.1245"></a>
-<span class="sourceLineNo">1246</span>      LOG.warn(String.format("Table %s is not enabled", tableName));<a name="line.1246"></a>
-<span class="sourceLineNo">1247</span>    }<a name="line.1247"></a>
-<span class="sourceLineNo">1248</span>    return new LinkedList&lt;&gt;();<a name="line.1248"></a>
-<span class="sourceLineNo">1249</span>  }<a name="line.1249"></a>
-<span class="sourceLineNo">1250</span><a name="line.1250"></a>
-<span class="sourceLineNo">1251</span>  /*<a name="line.1251"></a>
-<span class="sourceLineNo">1252</span>   * Loops over regions that owns this table, and output some information about the state.<a name="line.1252"></a>
-<span class="sourceLineNo">1253</span>   */<a name="line.1253"></a>
-<span class="sourceLineNo">1254</span>  private static List&lt;Future&lt;Void&gt;&gt; sniff(final Admin admin, final Sink sink,<a name="line.1254"></a>
-<span class="sourceLineNo">1255</span>      HTableDescriptor tableDesc, ExecutorService executor, TaskType taskType,<a name="line.1255"></a>
-<span class="sourceLineNo">1256</span>      boolean rawScanEnabled, AtomicLong rwLatency) throws Exception {<a name="line.1256"></a>
-<span class="sourceLineNo">1257</span><a name="line.1257"></a>
-<span class="sourceLineNo">1258</span>    if (LOG.isDebugEnabled()) {<a name="line.1258"></a>
-<span class="sourceLineNo">1259</span>      LOG.debug(String.format("reading list of regions for table %s", tableDesc.getTableName()));<a name="line.1259"></a>
-<span class="sourceLineNo">1260</span>    }<a name="line.1260"></a>
-<span class="sourceLineNo">1261</span><a name="line.1261"></a>
-<span class="sourceLineNo">1262</span>    Table table = null;<a name="line.1262"></a>
-<span class="sourceLineNo">1263</span>    try {<a name="line.1263"></a>
-<span class="sourceLineNo">1264</span>      table = admin.getConnection().getTable(tableDesc.getTableName());<a name="line.1264"></a>
-<span class="sourceLineNo">1265</span>    } catch (TableNotFoundException e) {<a name="line.1265"></a>
-<span class="sourceLineNo">1266</span>      return new ArrayList&lt;&gt;();<a name="line.1266"></a>
-<span class="sourceLineNo">1267</span>    }<a name="line.1267"></a>
-<span class="sourceLineNo">1268</span>    finally {<a name="line.1268"></a>
-<span class="sourceLineNo">1269</span>      if (table !=null) {<a name="line.1269"></a>
-<span class="sourceLineNo">1270</span>        table.close();<a name="line.1270"></a>
-<span class="sourceLineNo">1271</span>      }<a name="line.1271"></a>
-<span class="sourceLineNo">1272</span>    }<a name="line.1272"></a>
-<span class="sourceLineNo">1273</span><a name="line.1273"></a>
-<span class="sourceLineNo">1274</span>    List&lt;RegionTask&gt; tasks = new ArrayList&lt;&gt;();<a name="line.1274"></a>
-<span class="sourceLineNo">1275</span>    RegionLocator regionLocator = null;<a name="line.1275"></a>
-<span class="sourceLineNo">1276</span>    try {<a name="line.1276"></a>
-<span class="sourceLineNo">1277</span>      regionLocator = admin.getConnection().getRegionLocator(tableDesc.getTableName());<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>      for (HRegionLocation location : regionLocator.getAllRegionLocations()) {<a name="line.1278"></a>
-<span class="sourceLineNo">1279</span>        ServerName rs = location.getServerName();<a name="line.1279"></a>
-<span class="sourceLineNo">1280</span>        HRegionInfo region = location.getRegionInfo();<a name="line.1280"></a>
-<span class="sourceLineNo">1281</span>        tasks.add(new RegionTask(admin.getConnection(), region, rs, (RegionStdOutSink) sink, taskType, rawScanEnabled,<a name="line.1281"></a>
-<span class="sourceLineNo">1282</span>          rwLatency));<a name="line.1282"></a>
-<span class="sourceLineNo">1283</span>      }<a name="line.1283"></a>
-<span class="sourceLineNo">1284</span>    } finally {<a name="line.1284"></a>
-<span class="sourceLineNo">1285</span>      if (regionLocator != null) {<a name="line.1285"></a>
-<span class="sourceLineNo">1286</span>        regionLocator.close();<a name="line.1286"></a>
-<span class="sourceLineNo">1287</span>      }<a name="line.1287"></a>
-<span class="sourceLineNo">1288</span>    }<a name="line.1288"></a>
-<span class="sourceLineNo">1289</span>    return executor.invokeAll(tasks);<a name="line.1289"></a>
-<span class="sourceLineNo">1290</span>  }<a name="line.1290"></a>
-<span class="sourceLineNo">1291</span><a name="line.1291"></a>
-<span class="sourceLineNo">1292</span>  //  monitor for zookeeper mode<a name="line.1292"></a>
-<span class="sourceLineNo">1293</span>  private static class ZookeeperMonitor extends Monitor {<a name="line.1293"></a>
-<span class="sourceLineNo">1294</span>    private List&lt;String&gt; hosts;<a name="line.1294"></a>
-<span class="sourceLineNo">1295</span>    private final String znode;<a name="line.1295"></a>
-<span class="sourceLineNo">1296</span>    private final int timeout;<a name="line.1296"></a>
-<span class="sourceLineNo">1297</span><a name="line.1297"></a>
-<span class="sourceLineNo">1298</span>    protected ZookeeperMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,<a name="line.1298"></a>
-<span class="sourceLineNo">1299</span>        ExtendedSink sink, ExecutorService executor, boolean treatFailureAsError)  {<a name="line.1299"></a>
-<span class="sourceLineNo">1300</span>      super(connection, monitorTargets, useRegExp, sink, executor, treatFailureAsError);<a name="line.1300"></a>
-<span class="sourceLineNo">1301</span>      Configuration configuration = connection.getConfiguration();<a name="line.1301"></a>
-<span class="sourceLineNo">1302</span>      znode =<a name="line.1302"></a>
-<span class="sourceLineNo">1303</span>          configuration.get(ZOOKEEPER_ZNODE_PARENT,<a name="line.1303"></a>
-<span class="sourceLineNo">1304</span>              DEFAULT_ZOOKEEPER_ZNODE_PARENT);<a name="line.1304"></a>
-<span class="sourceLineNo">1305</span>      timeout = configuration<a name="line.1305"></a>
-<span class="sourceLineNo">1306</span>          .getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);<a name="line.1306"></a>
-<span class="sourceLineNo">1307</span>      ConnectStringParser parser =<a name="line.1307"></a>
-<span class="sourceLineNo">1308</span>          new ConnectStringParser(ZKConfig.getZKQuorumServersString(configuration));<a name="line.1308"></a>
-<span class="sourceLineNo">1309</span>      hosts = Lists.newArrayList();<a name="line.1309"></a>
-<span class="sourceLineNo">1310</span>      for (InetSocketAddress server : parser.getServerAddresses()) {<a name="line.1310"></a>
-<span class="sourceLineNo">1311</span>        hosts.add(server.toString());<a name="line.1311"></a>
-<span class="sourceLineNo">1312</span>      }<a name="line.1312"></a>
-<span class="sourceLineNo">1313</span>    }<a name="line.1313"></a>
-<span class="sourceLineNo">1314</span><a name="line.1314"></a>
-<span class="sourceLineNo">1315</span>    @Override public void run() {<a name="line.1315"></a>
-<span class="sourceLineNo">1316</span>      List&lt;ZookeeperTask&gt; tasks = Lists.newArrayList();<a name="line.1316"></a>
-<span class="sourceLineNo">1317</span>      for (final String host : hosts) {<a name="line.1317"></a>
-<span class="sourceLineNo">1318</span>        tasks.add(new ZookeeperTask(connection, host, znode, timeout, getSink()));<a name="line.1318"></a>
-<span class="sourceLineNo">1319</span>      }<a name="line.1319"></a>
-<span class="sourceLineNo">1320</span>      try {<a name="line.1320"></a>
-<span class="sourceLineNo">1321</span>        for (Future&lt;Void&gt; future : this.executor.invokeAll(tasks)) {<a name="line.1321"></a>
-<span class="sourceLineNo">1322</span>          try {<a name="line.1322"></a>
-<span class="sourceLineNo">1323</span>            future.get();<a name="line.1323"></a>
-<span class="sourceLineNo">1324</span>          } catch (ExecutionException e) {<a name="line.1324"></a>
-<span class="sourceLineNo">1325</span>            LOG.error("Sniff zookeeper failed!", e);<a name="line.1325"></a>
-<span class="sourceLineNo">1326</span>            this.errorCode = ERROR_EXIT_CODE;<a name="line.1326"></a>
-<span class="sourceLineNo">1327</span>          }<a name="line.1327"></a>
-<span class="sourceLineNo">1328</span>        }<a name="line.1328"></a>
-<span class="sourceLineNo">1329</span>      } catch (InterruptedException e) {<a name="line.1329"></a>
-<span class="sourceLineNo">1330</span>        this.errorCode = ERROR_EXIT_CODE;<a name="line.1330"></a>
-<span class="sourceLineNo">1331</span>        Thread.currentThread().interrupt();<a name="line.1331"></a>
-<span class="sourceLineNo">1332</span>        LOG.error("Sniff zookeeper interrupted!", e);<a name="line.1332"></a>
-<span class="sourceLineNo">1333</span>      }<a name="line.1333"></a>
-<span class="sourceLineNo">1334</span>      this.done = true;<a name="line.1334"></a>
-<span class="sourceLineNo">1335</span>    }<a name="line.1335"></a>
-<span class="sourceLineNo">1336</span><a name="line.1336"></a>
+<span class="sourceLineNo">1084</span>          for (Map.Entry&lt;String, Long&gt; entry : configuredReadTableTimeouts.entrySet()) {<a name="line.1084"></a>
+<span class="sourceLineNo">1085</span>            String tableName = entry.getKey();<a name="line.1085"></a>
+<span class="sourceLineNo">1086</span>            if (actualReadTableLatency.containsKey(tableName)) {<a name="line.1086"></a>
+<span class="sourceLineNo">1087</span>              Long actual = actualReadTableLatency.get(tableName).longValue();<a name="line.1087"></a>
+<span class="sourceLineNo">1088</span>              Long configured = entry.getValue();<a name="line.1088"></a>
+<span class="sourceLineNo">1089</span>              LOG.info("Read operation for " + tableName + " took " + actual +<a name="line.1089"></a>
+<span class="sourceLineNo">1090</span>                " ms. The configured read timeout was " + configured + " ms.");<a name="line.1090"></a>
+<span class="sourceLineNo">1091</span>              if (actual &gt; configured) {<a name="line.1091"></a>
+<span class="sourceLineNo">1092</span>                LOG.error("Read operation for " + tableName + " exceeded the configured read timeout.");<a name="line.1092"></a>
+<span class="sourceLineNo">1093</span>              }<a name="line.1093"></a>
+<span class="sourceLineNo">1094</span>            } else {<a name="line.1094"></a>
+<span class="sourceLineNo">1095</span>              LOG.error("Read operation for " + tableName + " failed!");<a name="line.1095"></a>
+<span class="sourceLineNo">1096</span>            }<a name="line.1096"></a>
+<span class="sourceLineNo">1097</span>          }<a name="line.1097"></a>
+<span class="sourceLineNo">1098</span>          if (this.writeSniffing) {<a name="line.1098"></a>
+<span class="sourceLineNo">1099</span>            String writeTableStringName = this.writeTableName.getNameAsString();<a name="line.1099"></a>
+<span class="sourceLineNo">1100</span>            long actualWriteLatency = regionSink.getWriteLatency().longValue();<a name="line.1100"></a>
+<span class="sourceLineNo">1101</span>            LOG.info("Write operation for " + writeTableStringName + " took " + actualWriteLatency + " ms. The configured write timeout was " +<a name="line.1101"></a>
+<span class="sourceLineNo">1102</span>              this.configuredWriteTableTimeout + " ms.");<a name="line.1102"></a>
+<span class="sourceLineNo">1103</span>            // Check that the writeTable write operation latency does not exceed the configured timeout.<a name="line.1103"></a>
+<span class="sourceLineNo">1104</span>            if (actualWriteLatency &gt; this.configuredWriteTableTimeout) {<a name="line.1104"></a>
+<span class="sourceLineNo">1105</span>              LOG.error("Write operation for " + writeTableStringName + " exceeded the configured write timeout.");<a name="line.1105"></a>
+<span class="sourceLineNo">1106</span>            }<a name="line.1106"></a>
+<span class="sourceLineNo">1107</span>          }<a name="line.1107"></a>
+<span class="sourceLineNo">1108</span>        } catch (Exception e) {<a name="line.1108"></a>
+<span class="sourceLineNo">1109</span>          LOG.error("Run regionMonitor failed", e);<a name="line.1109"></a>
+<span class="sourceLineNo">1110</span>          this.errorCode = ERROR_EXIT_CODE;<a name="line.1110"></a>
+<span class="sourceLineNo">1111</span>        }<a name="line.1111"></a>
+<span class="sourceLineNo">1112</span>      }<a name="line.1112"></a>
+<span class="sourceLineNo">1113</span>      this.done = true;<a name="line.1113"></a>
+<span class="sourceLineNo">1114</span>    }<a name="line.1114"></a>
+<span class="sourceLineNo">1115</span><a name="line.1115"></a>
+<span class="sourceLineNo">1116</span>    private String[] generateMonitorTables(String[] monitorTargets) throws IOException {<a name="line.1116"></a>
+<span class="sourceLineNo">1117</span>      String[] returnTables = null;<a name="line.1117"></a>
+<span class="sourceLineNo">1118</span><a name="line.1118"></a>
+<span class="sourceLineNo">1119</span>      if (this.useRegExp) {<a name="line.1119"></a>
+<span class="sourceLineNo">1120</span>        Pattern pattern = null;<a name="line.1120"></a>
+<span class="sourceLineNo">1121</span>        HTableDescriptor[] tds = null;<a name="line.1121"></a>
+<span class="sourceLineNo">1122</span>        Set&lt;String&gt; tmpTables = new TreeSet&lt;&gt;();<a name="line.1122"></a>
+<span class="sourceLineNo">1123</span>        try {<a name="line.1123"></a>
+<span class="sourceLineNo">1124</span>          if (LOG.isDebugEnabled()) {<a name="line.1124"></a>
+<span class="sourceLineNo">1125</span>            LOG.debug(String.format("reading list of tables"));<a name="line.1125"></a>
+<span class="sourceLineNo">1126</span>          }<a name="line.1126"></a>
+<span class="sourceLineNo">1127</span>          tds = this.admin.listTables(pattern);<a name="line.1127"></a>
+<span class="sourceLineNo">1128</span>          if (tds == null) {<a name="line.1128"></a>
+<span class="sourceLineNo">1129</span>            tds = new HTableDescriptor[0];<a name="line.1129"></a>
+<span class="sourceLineNo">1130</span>          }<a name="line.1130"></a>
+<span class="sourceLineNo">1131</span>          for (String monitorTarget : monitorTargets) {<a name="line.1131"></a>
+<span class="sourceLineNo">1132</span>            pattern = Pattern.compile(monitorTarget);<a name="line.1132"></a>
+<span class="sourceLineNo">1133</span>            for (HTableDescriptor td : tds) {<a name="line.1133"></a>
+<span class="sourceLineNo">1134</span>              if (pattern.matcher(td.getNameAsString()).matches()) {<a name="line.1134"></a>
+<span class="sourceLineNo">1135</span>                tmpTables.add(td.getNameAsString());<a name="line.1135"></a>
+<span class="sourceLineNo">1136</span>              }<a name="line.1136"></a>
+<span class="sourceLineNo">1137</span>            }<a name="line.1137"></a>
+<span class="sourceLineNo">1138</span>          }<a name="line.1138"></a>
+<span class="sourceLineNo">1139</span>        } catch (IOException e) {<a name="line.1139"></a>
+<span class="sourceLineNo">1140</span>          LOG.error("Communicate with admin failed", e);<a name="line.1140"></a>
+<span class="sourceLineNo">1141</span>          throw e;<a name="line.1141"></a>
+<span class="sourceLineNo">1142</span>        }<a name="line.1142"></a>
+<span class="sourceLineNo">1143</span><a name="line.1143"></a>
+<span class="sourceLineNo">1144</span>        if (tmpTables.size() &gt; 0) {<a name="line.1144"></a>
+<span class="sourceLineNo">1145</span>          returnTables = tmpTables.toArray(new String[tmpTables.size()]);<a name="line.1145"></a>
+<span class="sourceLineNo">1146</span>        } else {<a name="line.1146"></a>
+<span class="sourceLineNo">1147</span>          String msg = "No HTable found, tablePattern:" + Arrays.toString(monitorTargets);<a name="line.1147"></a>
+<span class="sourceLineNo">1148</span>          LOG.error(msg);<a name="line.1148"></a>
+<span class="sourceLineNo">1149</span>          this.errorCode = INIT_ERROR_EXIT_CODE;<a name="line.1149"></a>
+<span class="sourceLineNo">1150</span>          throw new TableNotFoundException(msg);<a name="line.1150"></a>
+<span class="sourceLineNo">1151</span>        }<a name="line.1151"></a>
+<span class="sourceLineNo">1152</span>      } else {<a name="line.1152"></a>
+<span class="sourceLineNo">1153</span>        returnTables = monitorTargets;<a name="line.1153"></a>
+<span class="sourceLineNo">1154</span>      }<a name="line.1154"></a>
+<span class="sourceLineNo">1155</span><a name="line.1155"></a>
+<span class="sourceLineNo">1156</span>      return returnTables;<a name="line.1156"></a>
+<span class="sourceLineNo">1157</span>    }<a name="line.1157"></a>
+<span class="sourceLineNo">1158</span><a name="line.1158"></a>
+<span class="sourceLineNo">1159</span>    /*<a name="line.1159"></a>
+<span class="sourceLineNo">1160</span>     * canary entry point to monitor all the tables.<a name="line.1160"></a>
+<span class="sourceLineNo">1161</span>     */<a name="line.1161"></a>
+<span class="sourceLineNo">1162</span>    private List&lt;Future&lt;Void&gt;&gt; sniff(TaskType taskType, RegionStdOutSink regionSink) throws Exception {<a name="line.1162"></a>
+<span class="sourceLineNo">1163</span>      if (LOG.isDebugEnabled()) {<a name="line.1163"></a>
+<span class="sourceLineNo">1164</span>        LOG.debug(String.format("reading list of tables"));<a name="line.1164"></a>
+<span class="sourceLineNo">1165</span>      }<a name="line.1165"></a>
+<span class="sourceLineNo">1166</span>      List&lt;Future&lt;Void&gt;&gt; taskFutures = new LinkedList&lt;&gt;();<a name="line.1166"></a>
+<span class="sourceLineNo">1167</span>      for (HTableDescriptor table : admin.listTables()) {<a name="line.1167"></a>
+<span class="sourceLineNo">1168</span>        if (admin.isTableEnabled(table.getTableName())<a name="line.1168"></a>
+<span class="sourceLineNo">1169</span>            &amp;&amp; (!table.getTableName().equals(writeTableName))) {<a name="line.1169"></a>
+<span class="sourceLineNo">1170</span>          AtomicLong readLatency = regionSink.initializeAndGetReadLatencyForTable(table.getNameAsString());<a name="line.1170"></a>
+<span class="sourceLineNo">1171</span>          taskFutures.addAll(Canary.sniff(admin, sink, table, executor, taskType, this.rawScanEnabled, readLatency));<a name="line.1171"></a>
+<span class="sourceLineNo">1172</span>        }<a name="line.1172"></a>
+<span class="sourceLineNo">1173</span>      }<a name="line.1173"></a>
+<span class="sourceLineNo">1174</span>      return taskFutures;<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>    private void checkWriteTableDistribution() throws IOException {<a name="line.1177"></a>
+<span class="sourceLineNo">1178</span>      if (!admin.tableExists(writeTableName)) {<a name="line.1178"></a>
+<span class="sourceLineNo">1179</span>        int numberOfServers = admin.getClusterStatus().getServers().size();<a name="line.1179"></a>
+<span class="sourceLineNo">1180</span>        if (numberOfServers == 0) {<a name="line.1180"></a>
+<span class="sourceLineNo">1181</span>          throw new IllegalStateException("No live regionservers");<a name="line.1181"></a>
+<span class="sourceLineNo">1182</span>        }<a name="line.1182"></a>
+<span class="sourceLineNo">1183</span>        createWriteTable(numberOfServers);<a name="line.1183"></a>
+<span class="sourceLineNo">1184</span>      }<a name="line.1184"></a>
+<span class="sourceLineNo">1185</span><a name="line.1185"></a>
+<span class="sourceLineNo">1186</span>      if (!admin.isTableEnabled(writeTableName)) {<a name="line.1186"></a>
+<span class="sourceLineNo">1187</span>        admin.enableTable(writeTableName);<a name="line.1187"></a>
+<span class="sourceLineNo">1188</span>      }<a name="line.1188"></a>
+<span class="sourceLineNo">1189</span><a name="line.1189"></a>
+<span class="sourceLineNo">1190</span>      ClusterStatus status = admin.getClusterStatus();<a name="line.1190"></a>
+<span class="sourceLineNo">1191</span>      int numberOfServers = status.getServersSize();<a name="line.1191"></a>
+<span class="sourceLineNo">1192</span>      if (status.getServers().contains(status.getMaster())) {<a name="line.1192"></a>
+<span class="sourceLineNo">1193</span>        numberOfServers -= 1;<a name="line.1193"></a>
+<span class="sourceLineNo">1194</span>      }<a name="line.1194"></a>
+<span class="sourceLineNo">1195</span><a name="line.1195"></a>
+<span class="sourceLineNo">1196</span>      List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; pairs =<a name="line.1196"></a>
+<span class="sourceLineNo">1197</span>          MetaTableAccessor.getTableRegionsAndLocations(connection, writeTableName);<a name="line.1197"></a>
+<span class="sourceLineNo">1198</span>      int numberOfRegions = pairs.size();<a name="line.1198"></a>
+<span class="sourceLineNo">1199</span>      if (numberOfRegions &lt; numberOfServers * regionsLowerLimit<a name="line.1199"></a>
+<span class="sourceLineNo">1200</span>          || numberOfRegions &gt; numberOfServers * regionsUpperLimit) {<a name="line.1200"></a>
+<span class="sourceLineNo">1201</span>        admin.disableTable(writeTableName);<a name="line.1201"></a>
+<span class="sourceLineNo">1202</span>        admin.deleteTable(writeTableName);<a name="line.1202"></a>
+<span class="sourceLineNo">1203</span>        createWriteTable(numberOfServers);<a name="line.1203"></a>
+<span class="sourceLineNo">1204</span>      }<a name="line.1204"></a>
+<span class="sourceLineNo">1205</span>      HashSet&lt;ServerName&gt; serverSet = new HashSet&lt;&gt;();<a name="line.1205"></a>
+<span class="sourceLineNo">1206</span>      for (Pair&lt;HRegionInfo, ServerName&gt; pair : pairs) {<a name="line.1206"></a>
+<span class="sourceLineNo">1207</span>        serverSet.add(pair.getSecond());<a name="line.1207"></a>
+<span class="sourceLineNo">1208</span>      }<a name="line.1208"></a>
+<span class="sourceLineNo">1209</span>      int numberOfCoveredServers = serverSet.size();<a name="line.1209"></a>
+<span class="sourceLineNo">1210</span>      if (numberOfCoveredServers &lt; numberOfServers) {<a name="line.1210"></a>
+<span class="sourceLineNo">1211</span>        admin.balancer();<a name="line.1211"></a>
+<span class="sourceLineNo">1212</span>      }<a name="line.1212"></a>
+<span class="sourceLineNo">1213</span>    }<a name="line.1213"></a>
+<span class="sourceLineNo">1214</span><a name="line.1214"></a>
+<span class="sourceLineNo">1215</span>    private void createWriteTable(int numberOfServers) throws IOException {<a name="line.1215"></a>
+<span class="sourceLineNo">1216</span>      int numberOfRegions = (int)(numberOfServers * regionsLowerLimit);<a name="line.1216"></a>
+<span class="sourceLineNo">1217</span>      LOG.info("Number of live regionservers: " + numberOfServers + ", "<a name="line.1217"></a>
+<span class="sourceLineNo">1218</span>          + "pre-splitting the canary table into " + numberOfRegions + " regions "<a name="line.1218"></a>
+<span class="sourceLineNo">1219</span>          + "(current lower limit of regions per server is " + regionsLowerLimit<a name="line.1219"></a>
+<span class="sourceLineNo">1220</span>          + " and you can change it by config: "<a name="line.1220"></a>
+<span class="sourceLineNo">1221</span>          + HConstants.HBASE_CANARY_WRITE_PERSERVER_REGIONS_LOWERLIMIT_KEY + " )");<a name="line.1221"></a>
+<span class="sourceLineNo">1222</span>      HTableDescriptor desc = new HTableDescriptor(writeTableName);<a name="line.1222"></a>
+<span class="sourceLineNo">1223</span>      HColumnDescriptor family = new HColumnDescriptor(CANARY_TABLE_FAMILY_NAME);<a name="line.1223"></a>
+<span class="sourceLineNo">1224</span>      family.setMaxVersions(1);<a name="line.1224"></a>
+<span class="sourceLineNo">1225</span>      family.setTimeToLive(writeDataTTL);<a name="line.1225"></a>
+<span class="sourceLineNo">1226</span><a name="line.1226"></a>
+<span class="sourceLineNo">1227</span>      desc.addFamily(family);<a name="line.1227"></a>
+<span class="sourceLineNo">1228</span>      byte[][] splits = new RegionSplitter.HexStringSplit().split(numberOfRegions);<a name="line.1228"></a>
+<span class="sourceLineNo">1229</span>      admin.createTable(desc, splits);<a name="line.1229"></a>
+<span class="sourceLineNo">1230</span>    }<a name="line.1230"></a>
+<span class="sourceLineNo">1231</span>  }<a name="line.1231"></a>
+<span class="sourceLineNo">1232</span><a name="line.1232"></a>
+<span class="sourceLineNo">1233</span>  /**<a name="line.1233"></a>
+<span class="sourceLineNo">1234</span>   * Canary entry point for specified table.<a name="line.1234"></a>
+<span class="sourceLineNo">1235</span>   * @throws Exception<a name="line.1235"></a>
+<span class="sourceLineNo">1236</span>   */<a name="line.1236"></a>
+<span class="sourceLineNo">1237</span>  private static List&lt;Future&lt;Void&gt;&gt; sniff(final Admin admin, final Sink sink, String tableName,<a name="line.1237"></a>
+<span class="sourceLineNo">1238</span>      ExecutorService executor, TaskType taskType, boolean rawScanEnabled, AtomicLong readLatency) throws Exception {<a name="line.1238"></a>
+<span class="sourceLineNo">1239</span>    if (LOG.isDebugEnabled()) {<a name="line.1239"></a>
+<span class="sourceLineNo">1240</span>      LOG.debug(String.format("checking table is enabled and getting table descriptor for table %s",<a name="line.1240"></a>
+<span class="sourceLineNo">1241</span>        tableName));<a name="line.1241"></a>
+<span class="sourceLineNo">1242</span>    }<a name="line.1242"></a>
+<span class="sourceLineNo">1243</span>    if (admin.isTableEnabled(TableName.valueOf(tableName))) {<a name="line.1243"></a>
+<span class="sourceLineNo">1244</span>      return Canary.sniff(admin, sink, admin.getTableDescriptor(TableName.valueOf(tableName)),<a name="line.1244"></a>
+<span class="sourceLineNo">1245</span>        executor, taskType, rawScanEnabled, readLatency);<a name="line.1245"></a>
+<span class="sourceLineNo">1246</span>    } else {<a name="line.1246"></a>
+<span class="sourceLineNo">1247</span>      LOG.warn(String.format("Table %s is not enabled", tableName));<a name="line.1247"></a>
+<span class="sourceLineNo">1248</span>    }<a name="line.1248"></a>
+<span class="sourceLineNo">1249</span>    return new LinkedList&lt;&gt;();<a name="line.1249"></a>
+<span class="sourceLineNo">1250</span>  }<a name="line.1250"></a>
+<span class="sourceLineNo">1251</span><a name="line.1251"></a>
+<span class="sourceLineNo">1252</span>  /*<a name="line.1252"></a>
+<span class="sourceLineNo">1253</span>   * Loops over regions that owns this table, and output some information about the state.<a name="line.1253"></a>
+<span class="sourceLineNo">1254</span>   */<a name="line.1254"></a>
+<span class="sourceLineNo">1255</span>  private static List&lt;Future&lt;Void&gt;&gt; sniff(final Admin admin, final Sink sink,<a name="line.1255"></a>
+<span class="sourceLineNo">1256</span>      HTableDescriptor tableDesc, ExecutorService executor, TaskType taskType,<a name="line.1256"></a>
+<span class="sourceLineNo">1257</span>      boolean rawScanEnabled, AtomicLong rwLatency) throws Exception {<a name="line.1257"></a>
+<span class="sourceLineNo">1258</span><a name="line.1258"></a>
+<span class="sourceLineNo">1259</span>    if (LOG.isDebugEnabled()) {<a name="line.1259"></a>
+<span class="sourceLineNo">1260</span>      LOG.debug(String.format("reading list of regions for table %s", tableDesc.getTableName()));<a name="line.1260"></a>
+<span class="sourceLineNo">1261</span>    }<a name="line.1261"></a>
+<span class="sourceLineNo">1262</span><a name="line.1262"></a>
+<span class="sourceLineNo">1263</span>    Table table = null;<a name="line.1263"></a>
+<span class="sourceLineNo">1264</span>    try {<a name="line.1264"></a>
+<span class="sourceLineNo">1265</span>      table = admin.getConnection().getTable(tableDesc.getTableName());<a name="line.1265"></a>
+<span class="sourceLineNo">1266</span>    } catch (TableNotFoundException e) {<a name="line.1266"></a>
+<span class="sourceLineNo">1267</span>      return new ArrayList&lt;&gt;();<a name="line.1267"></a>
+<span class="sourceLineNo">1268</span>    }<a name="line.1268"></a>
+<span class="sourceLineNo">1269</span>    finally {<a name="line.1269"></a>
+<span class="sourceLineNo">1270</span>      if (table !=null) {<a name="line.1270"></a>
+<span class="sourceLineNo">1271</span>        table.close();<a name="line.1271"></a>
+<span class="sourceLineNo">1272</span>      }<a name="line.1272"></a>
+<span class="sourceLineNo">1273</span>    }<a name="line.1273"></a>
+<span class="sourceLineNo">1274</span><a name="line.1274"></a>
+<span class="sourceLineNo">1275</span>    List&lt;RegionTask&gt; tasks = new ArrayList&lt;&gt;();<a name="line.1275"></a>
+<span class="sourceLineNo">1276</span>    RegionLocator regionLocator = null;<a name="line.1276"></a>
+<span class="sourceLineNo">1277</span>    try {<a name="line.1277"></a>
+<span class="sourceLineNo">1278</span>      regionLocator = admin.getConnection().getRegionLocator(tableDesc.getTableName());<a name="line.1278"></a>
+<span class="sourceLineNo">1279</span>      for (HRegionLocation location : regionLocator.getAllRegionLocations()) {<a name="line.1279"></a>
+<span class="sourceLineNo">1280</span>        ServerName rs = location.getServerName();<a name="line.1280"></a>
+<span class="sourceLineNo">1281</span>        HRegionInfo region = location.getRegionInfo();<a name="line.1281"></a>
+<span class="sourceLineNo">1282</span>        tasks.add(new RegionTask(admin.getConnection(), region, rs, (RegionStdOutSink) sink, taskType, rawScanEnabled,<a name="line.1282"></a>
+<span class="sourceLineNo">1283</span>          rwLatency));<a name="line.1283"></a>
+<span class="sourceLineNo">1284</span>      }<a name="line.1284"></a>
+<span class="sourceLineNo">1285</span>    } finally {<a name="line.1285"></a>
+<span class="sourceLineNo">1286</span>      if (regionLocator != null) {<a name="line.1286"></a>
+<span class="sourceLineNo">1287</span>        regionLocator.close();<a name="line.1287"></a>
+<span class="sourceLineNo">1288</span>      }<a name="line.1288"></a>
+<span class="sourceLineNo">1289</span>    }<a name="line.1289"></a>
+<span class="sourceLineNo">1290</span>    return executor.invokeAll(tasks);<a name="line.1290"></a>
+<span class="sourceLineNo">1291</span>  }<a name="line.1291"></a>
+<span class="sourceLineNo">1292</span><a name="line.1292"></a>
+<span class="sourceLineNo">1293</span>  //  monitor for zookeeper mode<a name="line.1293"></a>
+<span class="sourceLineNo">1294</span>  private static class ZookeeperMonitor extends Monitor {<a name="line.1294"></a>
+<span class="sourceLineNo">1295</span>    private List&lt;String&gt; hosts;<a name="line.1295"></a>
+<span class="sourceLineNo">1296</span>    private final String znode;<a name="line.1296"></a>
+<span class="sourceLineNo">1297</span>    private final int timeout;<a name="line.1297"></a>
+<span class="sourceLineNo">1298</span><a name="line.1298"></a>
+<span class="sourceLineNo">1299</span>    protected ZookeeperMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,<a name="line.1299"></a>
+<span class="sourceLineNo">1300</span>        ExtendedSink sink, ExecutorService executor, boolean treatFailureAsError)  {<a name="line.1300"></a>
+<span class="sourceLineNo">1301</span>      super(connection, monitorTargets, useRegExp, sink, executor, treatFailureAsError);<a name="line.1301"></a>
+<span class="sourceLineNo">1302</span>      Configuration configuration = connection.getConfiguration();<a name="line.1302"></a>
+<span class="sourceLineNo">1303</span>      znode =<a name="line.1303"></a>
+<span class="sourceLineNo">1304</span>          configuration.get(ZOOKEEPER_ZNODE_PARENT,<a name="line.1304"></a>
+<span class="sourceLineNo">1305</span>              DEFAULT_ZOOKEEPER_ZNODE_PARENT);<a name="line.1305"></a>
+<span class="sourceLineNo">1306</span>      timeout = configuration<a name="line.1306"></a>
+<span class="sourceLineNo">1307</span>          .getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);<a name="line.1307"></a>
+<span class="sourceLineNo">1308</span>      ConnectStringParser parser =<a name="line.1308"></a>
+<span class="sourceLineNo">1309</span>          new ConnectStringParser(ZKConfig.getZKQuorumServersString(configuration));<a name="line.1309"></a>
+<span class="sourceLineNo">1310</span>      hosts = Lists.newArrayList();<a name="line.1310"></a>
+<span class="sourceLineNo">1311</span>      for (InetSocketAddress server : parser.getServerAddresses()) {<a name="line.1311"></a>
+<span class="sourceLineNo">1312</span>        hosts.add(server.toString());<a name="line.1312"></a>
+<span class="sourceLineNo">1313</span>      }<a name="line.1313"></a>
+<span class="sourceLineNo">1314</span>    }<a name="line.1314"></a>
+<span class="sourceLineNo">1315</span><a name="line.1315"></a>
+<span class="sourceLineNo">1316</span>    @Override public void run() {<a name="line.1316"></a>
+<span class="sourceLineNo">1317</span>      List&lt;ZookeeperTask&gt; tasks = Lists.newArrayList();<a name="line.1317"></a>
+<span class="sourceLineNo">1318</span>      for (final String host : hosts) {<a name="line.1318"></a>
+<span class="sourceLineNo">1319</span>        tasks.add(new ZookeeperTask(connection, host, znode, timeout, getSink()));<a name="line.1319"></a>
+<span class="sourceLineNo">1320</span>      }<a name="line.1320"></a>
+<span class="sourceLineNo">1321</span>      try {<a name="line.1321"></a>
+<span class="sourceLineNo">1322</span>        for (Future&lt;Void&gt; future : this.executor.invokeAll(tasks)) {<a name="line.1322"></a>
+<span class="sourceLineNo">1323</span>          try {<a name="line.1323"></a>
+<span class="sourceLineNo">1324</span>            future.get();<a name="line.1324"></a>
+<span class="sourceLineNo">1325</span>          } catch (ExecutionException e) {<a name="line.1325"></a>
+<span class="sourceLineNo">1326</span>            LOG.error("Sniff zookeeper failed!", e);<a name="line.1326"></a>
+<span class="sourceLineNo">1327</span>            this.errorCode = ERROR_EXIT_CODE;<a name="line.1327"></a>
+<span class="sourceLineNo">1328</span>          }<a name="line.1328"></a>
+<span class="sourceLineNo">1329</span>        }<a name="line.1329"></a>
+<span class="sourceLineNo">1330</span>      } catch (InterruptedException e) {<a name="line.1330"></a>
+<span class="sourceLineNo">1331</span>        this.errorCode = ERROR_EXIT_CODE;<a name="line.1331"></a>
+<span class="sourceLineNo">1332</span>        Thread.currentThread().interrupt();<a name="line.1332"></a>
+<span class="sourceLineNo">1333</span>        LOG.error("Sniff zookeeper interrupted!", e);<a name="line.1333"></a>
+<span class="sourceLineNo">1334</span>      }<a name="line.1334"></a>
+<span class="sourceLineNo">1335</span>      this.done = true;<a name="line.1335"></a>
+<span class="sourceLineNo">1336</span>    }<a name="line.1336"></a>
 <span class="sourceLineNo">1337</span><a name="line.1337"></a>
-<span class="sourceLineNo">1338</span>    private ZookeeperStdOutSink getSink() {<a name="line.1338"></a>
-<span class="sourceLineNo">1339</span>      if (!(sink instanceof ZookeeperStdOutSink)) {<a name="line.1339"></a>
-<span class="sourceLineNo">1340</span>        throw new RuntimeException("Can only write to zookeeper sink");<a name="line.1340"></a>
-<span class="sourceLineNo">1341</span>      }<a name="line.1341"></a>
-<span class="sourceLineNo">1342</span>      return ((ZookeeperStdOutSink) sink);<a name="line.1342"></a>
-<span class="sourceLineNo">1343</span>    }<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">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">1346</span><a name="line.1346"></a>
-<span class="sourceLineNo">1347</span>  // a monitor for regionserver mode<a name="line.1347"></a>
-<span class="sourceLineNo">1348</span>  private static class RegionServerMonitor extends Monitor {<a name="line.1348"></a>
-<span class="sourceLineNo">1349</span><a name="line.1349"></a>
-<span class="sourceLineNo">1350</span>    private boolean allRegions;<a name="line.1350"></a>
-<span class="sourceLineNo">1351</span><a name="line.1351"></a>
-<span class="sourceLineNo">1352</span>    public RegionServerMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,<a name="line.1352"></a>
-<span class="sourceLineNo">1353</span>        ExtendedSink sink, ExecutorService executor, boolean allRegions,<a name="line.1353"></a>
-<span class="sourceLineNo">1354</span>        boolean treatFailureAsError) {<a name="line.1354"></a>
-<span class="sourceLineNo">1355</span>      super(connection, monitorTargets, useRegExp, sink, executor, treatFailureAsError);<a name="line.1355"></a>
-<span class="sourceLineNo">1356</span>      this.allRegions = allRegions;<a name="line.1356"></a>
-<span class="sourceLineNo">1357</span>    }<a name="line.1357"></a>
-<span class="sourceLineNo">1358</span><a name="line.1358"></a>
-<span class="sourceLineNo">1359</span>    private ExtendedSink getSink() {<a name="line.1359"></a>
-<span class="sourceLineNo">1360</span>      return (ExtendedSink) this.sink;<a name="line.1360"></a>
-<span class="sourceLineNo">1361</span>    }<a name="line.1361"></a>
-<span class="sourceLineNo">1362</span><a name="line.1362"></a>
-<span class="sourceLineNo">1363</span>    @Override<a name="line.1363"></a>
-<span class="sourceLineNo">1364</span>    public void run() {<a name="line.1364"></a>
-<span class="sourceLineNo">1365</span>      if (this.initAdmin() &amp;&amp; this.checkNoTableNames()) {<a name="line.1365"></a>
-<span class="sourceLineNo">1366</span>        Map&lt;String, List&lt;HRegionInfo&gt;&gt; rsAndRMap = this.filterRegionServerByName();<a name="line.1366"></a>
-<span class="sourceLineNo">1367</span>        this.initialized = true;<a name="line.1367"></a>
-<span class="sourceLineNo">1368</span>        this.monitorRegionServers(rsAndRMap);<a name="line.1368"></a>
-<span class="sourceLineNo">1369</span>      }<a name="line.1369"></a>
-<span class="sourceLineNo">1370</span>      this.done = true;<a name="line.1370"></a>
-<span class="sourceLineNo">1371</span>    }<a name="line.1371"></a>
-<span class="sourceLineNo">1372</span><a name="line.1372"></a>
-<span class="sourceLineNo">1373</span>    private boolean checkNoTableNames() {<a name="line.1373"></a>
-<span class="sourceLineNo">1374</span>      List&lt;String&gt; foundTableNames = new ArrayList&lt;&gt;();<a name="line.1374"></a>
-<span class="sourceLineNo">1375</span>      TableName[] tableNames = null;<a name="line.1375"></a>
-<span class="sourceLineNo">1376</span><a name="line.1376"></a>
-<span class="sourceLineNo">1377</span>      if (LOG.isDebugEnabled()) {<a name="line.1377"></a>
-<span class="sourceLineNo">1378</span>        LOG.debug(String.format("reading list of tables"));<a name="line.1378"></a>
-<span class="sourceLineNo">1379</span>      }<a name="line.1379"></a>
-<span class="sourceLineNo">1380</span>      try {<a name="line.1380"></a>
-<span class="sourceLineNo">1381</span>        tableNames = this.admin.listTableNames();<a name="line.1381"></a>
-<span class="sourceLineNo">1382</span>      } catch (IOException e) {<a name="line.1382"></a>
-<span class="sourceLineNo">1383</span>        LOG.error("Get listTableNames failed", e);<a name="line.1383"></a>
-<span class="sourceLineNo">1384</span>        this.errorCode = INIT_ERROR_EXIT_CODE;<a name="line.1384"></a>
-<span class="sourceLineNo">1385</span>        return false;<a name="line.1385"></a>
-<span class="sourceLineNo">1386</span>      }<a name="line.1386"></a>
-<span class="sourceLineNo">1387</span><a name="line.1387"></a>
-<span class="sourceLineNo">1388</span>      if (this.targets == null || this.targets.length == 0) return true;<a name="line.1388"></a>
-<span class="sourceLineNo">1389</span><a name="line.1389"></a>
-<span class="sourceLineNo">1390</span>      for (String target : this.targets) {<a name="line.1390"></a>
-<span class="sourceLineNo">1391</span>        for (TableName tableName : tableNames) {<a name="line.1391"></a>
-<span class="sourceLineNo">1392</span>          if (target.equals(tableName.getNameAsString())) {<a name="line.1392"></a>
-<span class="sourceLineNo">1393</span>            foundTableNames.add(target);<a name="line.1393"></a>
-<span class="sourceLineNo">1394</span>          }<a name="line.1394"></a>
-<span class="sourceLineNo">1395</span>        }<a name="line.1395"></a>
-<span class="sourceLineNo">1396</span>      }<a name="line.1396"></a>
-<span class="sourceLineNo">1397</span><a name="line.1397"></a>
-<span class="sourceLineNo">1398</span>      if (foundTableNames.size() &gt; 0) {<a name="line.1398"></a>
-<span class="sourceLineNo">1399</span>        System.err.println("Cannot pass a tablename when using the -regionserver " +<a name="line.1399"></a>
-<span class="sourceLineNo">1400</span>            "option, tablenames:" + foundTableNames.toString());<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>        this.errorCode = USAGE_EXIT_CODE;<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span>      }<a name="line.1402"></a>
-<span class="sourceLineNo">1403</span>      return foundTableNames.isEmpty();<a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>    }<a name="line.1404"></a>
-<span class="sourceLineNo">1405</span><a name="line.1405"></a>
-<span class="sourceLineNo">1406</span>    private void monitorRegionServers(Map&lt;String, List&lt;HRegionInfo&gt;&gt; rsAndRMap) {<a name="line.1406"></a>
-<span class="sourceLineNo">1407</span>      List&lt;RegionServerTask&gt; tasks = new ArrayList&lt;&gt;();<a name="line.1407"></a>
-<span class="sourceLineNo">1408</span>      Map&lt;String, AtomicLong&gt; successMap = new HashMap&lt;&gt;();<a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>      Random rand = new Random();<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span>      for (Map.Entry&lt;String, List&lt;HRegionInfo&gt;&gt; entry : rsAndRMap.entrySet()) {<a name="line.1410"></a>
-<span class="sourceLineNo">1411</span>        String serverName = entry.getKey();<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span>        AtomicLong successes = new AtomicLong(0);<a name="line.1412"></a>
-<span class="sourceLineNo">1413</span>        successMap.put(serverName, successes);<a name="line.1413"></a>
-<span class="sourceLineNo">1414</span>        if (entry.getValue().isEmpty()) {<a name="line.1414"></a>
-<span class="sourceLineNo">1415</span>          LOG.error(String.format("Regionserver not serving any regions - %s", serverName));<a name="line.1415"></a>
-<span class="sourceLineNo">1416</span>        } else if (this.allRegions) {<a name="line.1416"></a>
-<span class="sourceLineNo">1417</span>          for (HRegionInfo region : entry.getValue()) {<a name="line.1417"></a>
-<span class="sourceLineNo">1418</span>            tasks.add(new RegionServerTask(this.connection,<a name="line.1418"></a>
-<span class="sourceLineNo">1419</span>                serverName,<a name="line.1419"></a>
-<span class="sourceLineNo">1420</span>                region,<a name="line.1420"></a>
-<span class="sourceLineNo">1421</span>                getSink(),<a name="line.1421"></a>
-<span class="sourceLineNo">1422</span>                successes));<a name="line.1422"></a>
-<span class="sourceLineNo">1423</span>          }<a name="line.1423"></a>
-<span class="sourceLineNo">1424</span>        } else {<a name="line.1424"></a>
-<span class="sourceLineNo">1425</span>          // random select a region if flag not set<a name="line.1425"></a>
-<span class="sourceLineNo">1426</span>          HRegionInfo region = entry.getValue().get(rand.nextInt(entry.getValue().size()));<a name="line.1426"></a>
-<span class="sourceLineNo">1427</span>          tasks.add(new RegionServerTask(this.connection,<a name="line.1427"></a>
-<span class="sourceLineNo">1428</span>              serverName,<a name="line.1428"></a>
-<span class="sourceLineNo">1429</span>              region,<a name="line.1429"></a>
-<span class="sourceLineNo">1430</span>              getSink(),<a name="line.1430"></a>
-<span class="sourceLineNo">1431</span>              successes));<a name="line.1431"></a>
-<span class="sourceLineNo">1432</span>        }<a name="line.1432"></a>
-<span class="sourceLineNo">1433</span>      }<a name="line.1433"></a>
-<span class="sourceLineNo">1434</span>      try {<a name="line.1434"></a>
-<span class="sourceLineNo">1435</span>        for (Future&lt;Void&gt; future : this.executor.invokeAll(tasks)) {<a name="line.1435"></a>
-<span class="sourceLineNo">1436</span>          try {<a name="line.1436"></a>
-<span class="sourceLineNo">1437</span>            future.get();<a name="line.1437"></a>
-<span class="sourceLineNo">1438</span>          } catch (ExecutionException e) {<a name="line.1438"></a>
-<span class="sourceLineNo">1439</span>            LOG.error("Sniff regionserver failed!", e);<a name="line.1439"></a>
-<span class="sourceLineNo">1440</span>            this.errorCode = ERROR_EXIT_CODE;<a name="line.1440"></a>
-<span class="sourceLineNo">1441</span>          }<a name="line.1441"></a>
-<span class="sourceLineNo">1442</span>        }<a name="line.1442"></a>
-<span class="sourceLineNo">1443</span>        if (this.allRegions) {<a name="line.1443"></a>
-<span class="sourceLineNo">1444</span>          for (Map.Entry&lt;String, List&lt;HRegionInfo&gt;&gt; entry : rsAndRMap.entrySet()) {<a name="line.1444"></a>
-<span class="sourceLineNo">1445</span>            String serverName = entry.getKey();<a name="line.1445"></a>
-<span class="sourceLineNo">1446</span>            LOG.info("Successfully read " + successMap.get(serverName) + " regions out of "<a name="line.1446"></a>
-<span class="sourceLineNo">1447</span>                    + entry.getValue().size() + " on regionserver:" + serverName);<a name="line.1447"></a>
-<span class="sourceLineNo">1448</span>          }<a name="line.1448"></a>
-<span class="sourceLineNo">1449</span>        }<a name="line.1449"></a>
-<span class="sourceLineNo">1450</span>      } catch (InterruptedException e) {<a name="line.1450"></a>
-<span class="sourceLineNo">1451</span>        this.errorCode = ERROR_EXIT_CODE;<a name="line.1451"></a>
-<span class="sourceLineNo">1452</span>        LOG.error("Sniff regionserver interrupted!", e);<a name="line.1452"></a>
-<span class="sourceLineNo">1453</span>      }<a name="line.1453"></a>
-<span class="sourceLineNo">1454</span>    }<a name="line.1454"></a>
-<span class="sourceLineNo">1455</span><a name="line.1455"></a>
-<span class="sourceLineNo">1456</span>    private Map&lt;String, List&lt;HRegionInfo&gt;&gt; filterRegionServerByName() {<a name="line.1456"></a>
-<span class="sourceLineNo">1457</span>      Map&lt;String, List&lt;HRegionInfo&gt;&gt; regionServerAndRegionsMap = this.getAllRegionServerByName();<a name="line.1457"></a>
-<span class="sourceLineNo">1458</span>      regionServerAndRegionsMap = this.doFilterRegionServerByName(regionServerAndRegionsMap);<a name="line.1458"></a>
-<span class="sourceLineNo">1459</span>      return regionServerAndRegionsMap;<a name="line.1459"></a>
-<span class="sourceLineNo">1460</span>    }<a name="line.1460"></a>
-<span class="sourceLineNo">1461</span><a name="line.1461"></a>
-<span class="sourceLineNo">1462</span>    private Map&lt;String, List&lt;HRegionInfo&gt;&gt; getAllRegionServerByName() {<a name="line.1462"></a>
-<span class="sourceLineNo">1463</span>      Map&lt;String, List&lt;HRegionInfo&gt;&gt; rsAndRMap = new HashMap&lt;&gt;();<a name="line.1463"></a>
-<span class="sourceLineNo">1464</span>      Table table = null;<a name="line.1464"></a>
-<span class="sourceLineNo">1465</span>      RegionLocator regionLocator = null;<a name="line.1465"></a>
-<span class="sourceLineNo">1466</span>      try {<a name="line.1466"></a>
-<span class="sourceLineNo">1467</span>        if (LOG.isDebugEnabled()) {<a name="line.1467"></a>
-<span class="sourceLineNo">1468</span>          LOG.debug(String.format("reading list of tables and locations"));<a name="line.1468"></a>
-<span class="sourceLineNo">1469</span>        }<a name="line.1469"></a>
-<span class="sourceLineNo">1470</span>        HTableDescriptor[] tableDescs = this.admin.listTables();<a name="line.1470"></a>
-<span class="sourceLineNo">1471</span>        List&lt;HRegionInfo&gt; regions = null;<a name="line.1471"></a>
-<span class="sourceLineNo">1472</span>        for (HTableDescriptor tableDesc : tableDescs) {<a name="line.1472"></a>
-<span class="sourceLineNo">1473</span>          table = this.admin.getConnection().getTable(tableDesc.getTableName());<a name="line.1473"></a>
-<span class="sourceLineNo">1474</span>          regionLocator = this.admin.getConnection().getRegionLocator(tableDesc.getTableName());<a name="line.1474"></a>
-<span class="sourceLineNo">1475</span><a name="line.1475"></a>
-<span class="sourceLineNo">1476</span>          for (HRegionLocation location : regionLocator.getAllRegionLocations()) {<a name="line.1476"></a>
-<span class="sourceLineNo">1477</span>            ServerName rs = location.getServerName();<a name="line.1477"></a>
-<span class="sourceLineNo">1478</span>            String rsName = rs.getHostname();<a name="line.1478"></a>
-<span class="sourceLineNo">1479</span>            HRegionInfo r = location.getRegionInfo();<a name="line.1479"></a>
-<span class="sourceLineNo">1480</span><a name="line.1480"></a>
-<span class="sourceLineNo">1481</span>            if (rsAndRMap.containsKey(rsName)) {<a name="line.1481"></a>
-<span class="sourceLineNo">1482</span>              regions = rsAndRMap.get(rsName);<a name="line.1482"></a>
-<span class="sourceLineNo">1483</span>            } else {<a name="line.1483"></a>
-<span class="sourceLineNo">1484</span>              regions = new ArrayList&lt;&gt;();<a name="line.1484"></a>
-<span class="sourceLineNo">1485</span>              rsAndRMap.put(rsName, regions);<a name="line.1485"></a>
-<span class="sourceLineNo">1486</span>            }<a name="line.1486"></a>
-<span class="sourceLineNo">1487</span>            regions.add(r);<a name="line.1487"></a>
-<span class="sourceLineNo">1488</span>          }<a name="line.1488"></a>
-<span class="sourceLineNo">1489</span>          table.close();<a name="line.1489"></a>
-<span class="sourceLineNo">1490</span>        }<a name="line.1490"></a>
-<span class="sourceLineNo">1491</span><a name="line.1491"></a>
-<span class="sourceLineNo">1492</span>        //get any live regionservers not serving any regions<a name="line.1492"></a>
-<span class="sourceLineNo">1493</span>        for (ServerName rs : this.admin.getClusterStatus().getServers()) {<a name="line.1493"></a>
-<span class="sourceLineNo">1494</span>          String rsName = rs.getHostname();<a name="line.1494"></a>
-<span class="sourceLineNo">1495</span>          if (!rsAndRMap.containsKey(rsName)) {<a name="line.1495"></a>
-<span class="sourceLineNo">1496</span>            rsAndRMap.put(rsName, Collections.&lt;HRegionInfo&gt;emptyList());<a name="line.1496"></a>
-<span class="sourceLineNo">1497</span>          }<a name="line.1497"></a>
-<span class="sourceLineNo">1498</span>        }<a name="line.1498"></a>
-<span class="sourceLineNo">1499</span>      } catch (IOException e) {<a name="line.1499"></a>
-<span class="sourceLineNo">1500</span>        String msg = "Get HTables info failed";<a name="line.1500"></a>
-<span class="sourceLineNo">1501</span>        LOG.error(msg, e);<a name="line.1501"></a>
-<span class="sourceLineNo">1502</span>        this.errorCode = INIT_ERROR_EXIT_CODE;<a name="line.1502"></a>
-<span class="sourceLineNo">1503</span>      } finally {<a name="line.1503"></a>
-<span class="sourceLineNo">1504</span>        if (table != null) {<a name="line.1504"></a>
-<span class="sourceLineNo">1505</span>          try {<a name="line.1505"></a>
-<span class="sourceLineNo">1506</span>            table.close();<a name="line.1506"></a>
-<span class="sourceLineNo">1507</span>          } catch (IOException e) {<a name="line.1507"></a>
-<span class="sourceLineNo">1508</span>            LOG.warn("Close table failed", e);<a name="line.1508"></a>
-<span class="sourceLineNo">1509</span>          }<a name="line.1509"></a>
-<span class="sourceLineNo">1510</span>        }<a name="line.1510"></a>
-<span class="sourceLineNo">1511</span>      }<a name="line.1511"></a>
-<span class="sourceLineNo">1512</span><a name="line.1512"></a>
-<span class="sourceLineNo">1513</span>      return rsAndRMap;<a name="line.1513"></a>
-<span class="sourceLineNo">1514</span>    }<a name="line.1514"></a>
-<span class="sourceLineNo">1515</span><a name="line.1515"></a>
-<span class="sourceLineNo">1516</span>    private Map&lt;String, List&lt;HRegionInfo&gt;&gt; doFilterRegionServerByName(<a name="line.1516"></a>
-<span class="sourceLineNo">1517</span>        Map&lt;String, List&lt;HRegionInfo&gt;&gt; fullRsAndRMap) {<a name="line.1517"></a>
-<span class="sourceLineNo">1518</span><a name="line.1518"></a>
-<span class="sourceLineNo">1519</span>      Map&lt;String, List&lt;HRegionInfo&gt;&gt; filteredRsAndRMap = null;<a name="line.1519"></a>
-<span class="sourceLineNo">1520</span><a name="line.1520"></a>
-<span class="sourceLineNo">1521</span>      if (this.targets != null &amp;&amp; this.targets.length &gt; 0) {<a name="line.1521"></a>
-<span class="sourceLineNo">1522</span>        filteredRsAndRMap = new HashMap&lt;&gt;();<a name="line.1522"></a>
-<span class="sourceLineNo">1523</span>        Pattern pattern = null;<a name="line.1523"></a>
-<span class="sourceLineNo">1524</span>        Matcher matcher = null;<a name="line.1524"></a>
-<span class="sourceLineNo">1525</span>        boolean regExpFound = false;<a name="line.1525"></a>
-<span class="sourceLineNo">1526</span>        for (String rsName : this.targets) {<a name="line.1526"></a>
-<span class="sourceLineNo">1527</span>          if (this.useRegExp) {<a name="line.1527"></a>
-<span class="sourceLineNo">1528</span>            regExpFound = false;<a name="line.1528"></a>
-<span class="sourceLineNo">1529</span>            pattern = Pattern.compile(rsName);<a name="line.1529"></a>
-<span class="sourceLineNo">1530</span>            for (Map.Entry&lt;String, List&lt;HRegionInfo&gt;&gt; entry : fullRsAndRMap.entrySet()) {<a name="line.1530"></a>
-<span class="sourceLineNo">1531</span>              matcher = pattern.matcher(entry.getKey());<a name="line.1531"></a>
-<span class="sourceLineNo">1532</span>              if (matcher.matches()) {<a name="line.1532"></a>
-<span class="sourceLineNo">1533</span>                filteredRsAndRMap.put(entry.getKey(), entry.getValue());<a name="line.1533"></a>
-<span class="sourceLineNo">1534</span>                regExpFound = true;<a name="line.1534"></a>
-<span class="sourceLineNo">1535</span>              }<a name="line.1535"></a>
-<span class="sourceLineNo">1536</span>            }<a name="line.1536"></a>
-<span class="sourceLineNo">1537</span>            if (!regExpFound) {<a name="line.1537"></a>
-<span class="sourceLineNo">1538</span>              LOG.info("No RegionServerInfo found, regionServerPattern:" + rsName);<a name="line.1538"></a>
-<span class="sourceLineNo">1539</span>            }<a name="line.1539"></a>
-<span class="sourceLineNo">1540</span>          } else {<a name="line.1540"></a>
-<span class="sourceLineNo">1541</span>            if (fullRsAndRMap.containsKey(rsName)) {<a name="line.1541"></a>
-<span class="sourceLineNo">1542</span>              filteredRsAndRMap.put(rsName, fullRsAndRMap.get(rsName));<a name="line.1542"></a>
-<span class="sourceLineNo">1543</span>            } else {<a name="line.1543"></a>
-<span class="sourceLineNo">1544</span>              LOG.info("No RegionServerInfo found, regionServerName:" + rsName);<a name="line.1544"></a>
-<span class="sourceLineNo">1545</span>            }<a name="line.1545"></a>
-<span class="sourceLineNo">1546</span>          }<a name="line.1546"></a>
-<span class="sourceLineNo">1547</span>        }<a name="line.1547"></a>
-<span class="sourceLineNo">1548</span>      } else {<a name="line.1548"></a>
-<span class="sourceLineNo">1549</span>        filteredRsAndRMap = fullRsAndRMap;<a name="line.1549"></a>
-<span class="sourceLineNo">1550</span>      }<a name="line.1550"></a>
-<span class="sourceLineNo">1551</span>      return filteredRsAndRMap;<a name="line.1551"></a>
-<span class="sourceLineNo">1552</span>    }<a name="line.1552"></a>
-<span class="sourceLineNo">1553</span>  }<a name="line.1553"></a>
-<span class="sourceLineNo">1554</span><a name="line.1554"></a>
-<span class="sourceLineNo">1555</span>  public static void main(String[] args) throws Exception {<a name="line.1555"></a>
-<span class="sourceLineNo">1556</span>    final Configuration conf = HBaseConfiguration.create();<a name="line.1556"></a>
-<span class="sourceLineNo">1557</span><a name="line.1557"></a>
-<span class="sourceLineNo">1558</span>    // loading the generic options to conf<a name="line.1558"></a>
-<span class="sourceLineNo">1559</span>    new GenericOptionsParser(conf, args);<a name="line.1559"></a>
-<span class="sourceLineNo">1560</span><a name="line.1560"></a>
-<span class="sourceLineNo">1561</span>    int numThreads = conf.getInt("hbase.canary.threads.num", MAX_THREADS_NUM);<a name="line.1561"></a>
-<span class="sourceLineNo">1562</span>    LOG.info("Number of execution threads " + numThreads);<a name="line.1562"></a>
-<span class="sourceLineNo">1563</span><a name="line.1563"></a>
-<span class="sourceLineNo">1564</span>    ExecutorService executor = new ScheduledThreadPoolExecutor(numThreads);<a name="line.1564"></a>
-<span class="sourceLineNo">1565</span><a name="line.1565"></a>
-<span class="sourceLineNo">1566</span>    Class&lt;? extends Sink&gt; sinkClass =<a name="line.1566"></a>
-<span class="sourceLineNo">1567</span>        conf.getClass("hbase.canary.sink.class", RegionServerStdOutSink.class, Sink.class);<a name="line.1567"></a>
-<span class="sourceLineNo">1568</span>    Sink sink = ReflectionUtils.newInstance(sinkClass);<a name="line.1568"></a>
-<span class="sourceLineNo">1569</span><a name="line.1569"></a>
-<span class="sourceLineNo">1570</span>    int exitCode = ToolRunner.run(conf, new Canary(executor, sink), args);<a name="line.1570"></a>
-<span class="sourceLineNo">1571</span>    executor.shutdown();<a name="line.1571"></a>
-<span class="sourceLineNo">1572</span>    System.exit(exitCode);<a name="line.1572"></a>
-<span class="sourceLineNo">1573</span>  }<a name="line.1573"></a>
-<span class="sourceLineNo">1574</span>}<a name="line.1574"></a>
+<span class="sourceLineNo">1347</span><a name="line.1347"></a>
+<span class="sourceLineNo">1348</span>  // a monitor for regionserver mode<a name="line.1348"></a>
+<span class="sourceLineNo">1349</span>  private static class RegionServerMonitor extends Monitor {<a name="line.1349"></a>
+<span class="sourceLineNo">1350</span><a name="line.1350"></a>
+<span class="sourceLineNo">1351</span>    private boolean allRegions;<a name="line.1351"></a>
+<span class="sourceLineNo">1352</span><a name="line.1352"></a>
+<span class="sourceLineNo">1353</span>    public RegionServerMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,<a name="line.1353"></a>
+<span class="sourceLineNo">1354</span>        ExtendedSink sink, ExecutorService executor, boolean allRegions,<a name="line.1354"></a>
+<span class="sourceLineNo">1355</span>        boolean treatFailureAsError) {<a name="line.1355"></a>
+<span class="sourceLineNo">1356</span>      super(connection, monitorTargets, useRegExp, sink, executor, treatFailureAsError);<a name="line.1356"></a>
+<span class="sourceLineNo">1357</span>      this.allRegions = allRegions;<a name="line.1357"></a>
+<span class="sourceLineNo">1358</span>    }<a name="line.1358"></a>
+<span class="sourceLineNo">1359</span><a name="line.1359"></a>
+<span class="sourceLineNo">1360</span>    private ExtendedSink getSink() {<a name="line.1360"></a>
+<span class="sourceLineNo">1361</span>      return (ExtendedSink) this.sink;<a name="line.1361"></a>
+<span class="sourceLineNo">1362</span>    }<a name="line.1362"></a>
+<span class="sourceLineNo">1363</span><a name="line.1363"></a>
+<span class="sourceLineNo">1364</span>    @Override<a name="line.1364"></a>
+<span class="sourceLineNo">1365</span>    public void run() {<a name="line.1365"></a>
+<span class="sourceLineNo">1366</span>      if (this.initAdmin() &amp;&amp; this.checkNoTableNames()) {<a name="line.1366"></a>
+<span class="sourceLineNo">1367</span>        Map&lt;String, List&lt;HRegionInfo&gt;&gt; rsAndRMap = this.filterRegionServerByName();<a name="line.1367"></a>
+<span class="sourceLineNo">1368</span>        this.initialized = true;<a name="line.1368"></a>
+<span class="sourceLineNo">1369</span>        this.monitorRegionServers(rsAndRMap);<a name="line.1369"></a>
+<span class="sourceLineNo">1370</span>      }<a name="line.1370"></a>
+<span class="sourceLineNo">1371</span>      this.done = true;<a name="line.1371"></a>
+<span class="sourceLineNo">1372</span>    }<a name="line.1372"></a>
+<span class="sourceLineNo">1373</span><a name="line.1373"></a>
+<span class="sourceLineNo">1374</span>    private boolean checkNoTableNames() {<a name="line.1374"></a>
+<span class="sourceLineNo">1375</span>      List&lt;String&gt; foundTableNames = new ArrayList&lt;&gt;();<a name="line.1375"></a>
+<span class="sourceLineNo">1376</span>      TableName[] tableNames = null;<a name="line.1376"></a>
+<span class="sourceLineNo">1377</span><a name="line.1377"></a>
+<span class="sourceLineNo">1378</span>      if (LOG.isDebugEnabled()) {<a name="line.1378"></a>
+<span class="sourceLineNo">1379</span>        LOG.debug(String.format("reading list of tables"));<a name="line.1379"></a>
+<span class="sourceLineNo">1380</span>      }<a name="line.1380"></a>
+<span class="sourceLineNo">1381</span>      try {<a name="line.1381"></a>
+<span class="sourceLineNo">1382</span>        tableNames = this.admin.listTableNames();<a name="line.1382"></a>
+<span class="sourceLineNo">1383</span>      } catch (IOException e) {<a name="line.1383"></a>
+<span class="sourceLineNo">1384</span>        LOG.error("Get listTableNames failed", e);<a name="line.1384"></a>
+<span class="sourceLineNo">1385</span>        this.errorCode = INIT_ERROR_EXIT_CODE;<a name="line.1385"></a>
+<span class="sourceLineNo">1386</span>        return false;<a name="line.1386"></a>
+<span class="sourceLineNo">1387</span>      }<a name="line.1387"></a>
+<span class="sourceLineNo">1388</span><a name="line.1388"></a>
+<span class="sourceLineNo">1389</span>      if (this.targets == null || this.targets.length == 0) return true;<a name="line.1389"></a>
+<span class="sourceLineNo">1390</span><a name="line.1390"></a>
+<span class="sourceLineNo">1391</span>      for (String target : this.targets) {<a name="line.1391"></a>
+<span class="sourceLineNo">1392</span>        for (TableName tableName : tableNames) {<a name="line.1392"></a>
+<span class="sourceLineNo">1393</span>          if (target.equals(tableName.getNameAsString())) {<a name="line.1393"></a>
+<span class="sourceLineNo">1394</span>            foundTableNames.add(target);<a name="line.1394"></a>
+<span class="sourceLineNo">1395</span>          }<a name="line.1395"></a>
+<span class="sourceLineNo">1396</span>        }<a name="line.1396"></a>
+<span class="sourceLineNo">1397</span>      }<a name="line.1397"></a>
+<span class="sourceLineNo">1398</span><a name="line.1398"></a>
+<span class="sourceLineNo">1399</span>      if (foundTableNames.size() &gt; 0) {<a name="line.1399"></a>
+<span class="sourceLineNo">1400</span>        System.err.println("Cannot pass a tablename when using the -regionserver " +<a name="line.1400"></a>
+<span class="sourceLineNo">1401</span>            "option, tablenames:" + foundTableNames.toString());<a name="line.1401"></a>
+<span class="sourceLineNo">1402</span>        this.errorCode = USAGE_EXIT_CODE;<a name="line.1402"></a>
+<span class="sourceLineNo">1403</span>      }<a name="line.1403"></a>
+<span class="sourceLineNo">1404</span>      return foundTableNames.isEmpty();<a name="line.1404"></a>
+<span class="sourceLineNo">1405</span>    }<a name="line.1405"></a>
+<span class="sourceLineNo">1406</span><a name="line.1406"></a>
+<span class="sourceLineNo">1407</span>    private void monitorRegionServers(Map&lt;String, List&lt;HRegionInfo&gt;&gt; rsAndRMap) {<a name="line.1407"></a>
+<span class="sourceLineNo">1408</span>      List&lt;RegionServerTask&gt; tasks = new ArrayList&lt;&gt;();<a name="line.1408"></a>
+<span class="sourceLineNo">1409</span>      Map&lt;String, AtomicLong&gt; successMap = new HashMap&lt;&gt;();<a name="line.1409"></a>
+<span class="sourceLineNo">1410</span>      Random rand = new Random();<a name="line.1410"></a>
+<span class="sourceLineNo">1411</span>      for (Map.Entry&lt;String, List&lt;HRegionInfo&gt;&gt; entry : rsAndRMap.entrySet()) {<a name="line.1411"></a>
+<span class="sourceLineNo">1412</span>        String serverName = entry.getKey();<a name="line.1412"></a>
+<span class="sourceLineNo">1413</span>        AtomicLong successes = new AtomicLong(0);<a name="line.1413"></a>
+<span class="sourceLineNo">1414</span>        successMap.put(serverName, successes);<a name="line.1414"></a>
+<span class="sourceLineNo">1415</span>        if (entry.getValue().isEmpty()) {<a name="line.1415"></a>
+<span class="sourceLineNo">1416</span>          LOG.error(String.format("Regionserver not serving any regions - %s", serverName));<a name="line.1416"></a>
+<span class="sourceLineNo">1417</span>        } else if (this.allRegions) {<a name="line.1417"></a>
+<span class="sourceLineNo">1418</span>          for (HRegionInfo region : entry.getValue()) {<a name="line.1418"></a>
+<span class="sourceLineNo">1419</span>            tasks.add(new RegionServerTask(this.connection,<a name="line.1419"></a>
+<span class="sourceLineNo">1420</span>                serverName,<a name="line.1420"></a>
+<span class="sourceLineNo">1421</span>                region,<a name="line.1421"></a>
+<span class="sourceLineNo">1422</span>                getSink(),<a name="line.1422"></a>
+<span class="sourceLineNo">1423</span>                successes));<a name="line.1423"></a>
+<span class="sourceLineNo">1424</span>          }<a name="line.1424"></a>
+<span class="sourceLineNo">1425</span>        } else {<a name="line.1425"></a>
+<span class="sourceLineNo">1426</span>          // random select a region if flag not set<a name="line.1426"></a>
+<span class="sourceLineNo">1427</span>          HRegionInfo region = entry.getValue().get(rand.nextInt(entry.getValue().size()));<a name="line.1427"></a>
+<span class="sourceLineNo">1428</span>          tasks.add(new RegionServerTask(this.connection,<a name="line.1428"></a>
+<span class="sourceLineNo">1429</span>              serverName,<a name="line.1429"></a>
+<span class="sourceLineNo">1430</span>              region,<a name="line.1430"></a>
+<span class="sourceLineNo">1431</span>              getSink(),<a name="line.1431"></a>
+<span class="sourceLineNo">1432</span>              successes));<a name="line.1432"></a>
+<span class="sourceLineNo">1433</span>        }<a name="line.1433"></a>
+<span class="sourceLineNo">1434</span>      }<a name="line.1434"></a>
+<span class="sourceLineNo">1435</span>      try {<a name="line.1435"></a>
+<span class="sourceLineNo">1436</span>        for (Future&lt;Void&gt; future : this.executor.invokeAll(tasks)) {<a name="line.1436"></a>
+<span class="sourceLineNo">1437</span>          try {<a name="line.1437"></a>
+<span class="sourceLineNo">1438</span>            future.get();<a name="line.1438"></a>
+<span class="sourceLineNo">1439</span>          } catch (ExecutionException e) {<a name="line.1439"></a>
+<span class="sourceLineNo">1440</span>            LOG.error("Sniff regionserver failed!", e);<a name="line.1440"></a>
+<span class="sourceLineNo">1441</span>            this.errorCode = ERROR_EXIT_CODE;<a name="line.1441"></a>
+<span class="sourceLineNo">1442</span>          }<a name="line.1442"></a>
+<span class="sourceLineNo">1443</span>        }<a name="line.1443"></a>
+<span class="sourceLineNo">1444</span>        if (this.allRegions) {<a name="line.1444"></a>
+<span class="sourceLineNo">1445</span>          for (Map.Entry&lt;String, List&lt;HRegionInfo&gt;&gt; entry : rsAndRMap.entrySet()) {<a name="line.1445"></a>
+<span class="sourceLineNo">1446</span>            String serverName = entry.getKey();<a name="line.1446"></a>
+<span class="sourceLineNo">1447</span>            LOG.info("Successfully read " + successMap.get(serverName) + " regions out of "<a name="line.1447"></a>
+<span class="sourceLineNo">1448</span>                    + entry.getValue().size() + " on regionserver:" + serverName);<a name="line.1448"></a>
+<span class="sourceLineNo">1449</span>          }<a name="line.1449"></a>
+<span class="sourceLineNo">1450</span>        }<a name="line.1450"></a>
+<span class="sourceLineNo">1451</span>      } catch (InterruptedException e) {<a name="line.1451"></a>
+<span class="sourceLineNo">1452</span>        this.errorCode = ERROR_EXIT_CODE;<a name="line.1452"></a>
+<span class="sourceLineNo">1453</span>        LOG.error("Sniff regionserver interrupted!", e);<a name="line.1453"></a>
+<span class="sourceLineNo">1454</span>      }<a name="line.1454"></a>
+<span class="sourceLineNo">1455</span>    }<a name="line.1455"></a>
+<span class="sourceLineNo">1456</span><a name="line.1456"></a>
+<span class="sourceLineNo">1457</span>    private Map&lt;String, List&lt;HRegionInfo&gt;&gt; filterRegionServerByName() {<a name="line.1457"></a>
+<span class="sourceLineNo">1458</span>      Map&lt;String, List&lt;HRegionInfo&gt;&gt; regionServerAndRegionsMap = this.getAllRegionServerByName();<a name="line.1458"></a>
+<span class="sourceLineNo">1459</span>      regionServerAndRegionsMap = this.doFilterRegionServerByName(regionServerAndRegionsMap);<a name="line.1459"></a>
+<span class="sourceLineNo">1460</span>      return regionServerAndRegionsMap;<a name="line.1460"></a>
+<span class="sourceLineNo">1461</span>    }<a name="line.1461"></

<TRUNCATED>

Mime
View raw message