http://git-wip-us.apache.org/repos/asf/hbase-site/blob/883dde2f/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.MovedRegionsCleaner.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.MovedRegionsCleaner.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.MovedRegionsCleaner.html index 9644187..b979909 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.MovedRegionsCleaner.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.MovedRegionsCleaner.html @@ -1199,2602 +1199,2599 @@ <span class="sourceLineNo">1191</span> ClusterStatusProtos.ServerLoad sl = buildServerLoad(reportStartTime, reportEndTime);<a name="line.1191"></a> <span class="sourceLineNo">1192</span> try {<a name="line.1192"></a> <span class="sourceLineNo">1193</span> RegionServerReportRequest.Builder request = RegionServerReportRequest.newBuilder();<a name="line.1193"></a> -<span class="sourceLineNo">1194</span> ServerName sn = ServerName.parseVersionedServerName(this.serverName.getVersionedBytes());<a name="line.1194"></a> -<span class="sourceLineNo">1195</span> request.setServer(ProtobufUtil.toServerName(sn));<a name="line.1195"></a> -<span class="sourceLineNo">1196</span> request.setLoad(sl);<a name="line.1196"></a> -<span class="sourceLineNo">1197</span> rss.regionServerReport(null, request.build());<a name="line.1197"></a> -<span class="sourceLineNo">1198</span> } catch (ServiceException se) {<a name="line.1198"></a> -<span class="sourceLineNo">1199</span> IOException ioe = ProtobufUtil.getRemoteException(se);<a name="line.1199"></a> -<span class="sourceLineNo">1200</span> if (ioe instanceof YouAreDeadException) {<a name="line.1200"></a> -<span class="sourceLineNo">1201</span> // This will be caught and handled as a fatal error in run()<a name="line.1201"></a> -<span class="sourceLineNo">1202</span> throw ioe;<a name="line.1202"></a> -<span class="sourceLineNo">1203</span> }<a name="line.1203"></a> -<span class="sourceLineNo">1204</span> if (rssStub == rss) {<a name="line.1204"></a> -<span class="sourceLineNo">1205</span> rssStub = null;<a name="line.1205"></a> -<span class="sourceLineNo">1206</span> }<a name="line.1206"></a> -<span class="sourceLineNo">1207</span> // Couldn't connect to the master, get location from zk and reconnect<a name="line.1207"></a> -<span class="sourceLineNo">1208</span> // Method blocks until new master is found or we are stopped<a name="line.1208"></a> -<span class="sourceLineNo">1209</span> createRegionServerStatusStub(true);<a name="line.1209"></a> -<span class="sourceLineNo">1210</span> }<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> * Reports the given map of Regions and their size on the filesystem to the active Master.<a name="line.1214"></a> -<span class="sourceLineNo">1215</span> *<a name="line.1215"></a> -<span class="sourceLineNo">1216</span> * @param regionSizeStore The store containing region sizes<a name="line.1216"></a> -<span class="sourceLineNo">1217</span> * @return false if FileSystemUtilizationChore should pause reporting to master. true otherwise<a name="line.1217"></a> -<span class="sourceLineNo">1218</span> */<a name="line.1218"></a> -<span class="sourceLineNo">1219</span> public boolean reportRegionSizesForQuotas(RegionSizeStore regionSizeStore) {<a name="line.1219"></a> -<span class="sourceLineNo">1220</span> RegionServerStatusService.BlockingInterface rss = rssStub;<a name="line.1220"></a> -<span class="sourceLineNo">1221</span> if (rss == null) {<a name="line.1221"></a> -<span class="sourceLineNo">1222</span> // the current server could be stopping.<a name="line.1222"></a> -<span class="sourceLineNo">1223</span> LOG.trace("Skipping Region size report to HMaster as stub is null");<a name="line.1223"></a> -<span class="sourceLineNo">1224</span> return true;<a name="line.1224"></a> -<span class="sourceLineNo">1225</span> }<a name="line.1225"></a> -<span class="sourceLineNo">1226</span> try {<a name="line.1226"></a> -<span class="sourceLineNo">1227</span> buildReportAndSend(rss, regionSizeStore);<a name="line.1227"></a> -<span class="sourceLineNo">1228</span> } catch (ServiceException se) {<a name="line.1228"></a> -<span class="sourceLineNo">1229</span> IOException ioe = ProtobufUtil.getRemoteException(se);<a name="line.1229"></a> -<span class="sourceLineNo">1230</span> if (ioe instanceof PleaseHoldException) {<a name="line.1230"></a> -<span class="sourceLineNo">1231</span> LOG.trace("Failed to report region sizes to Master because it is initializing."<a name="line.1231"></a> -<span class="sourceLineNo">1232</span> + " This will be retried.", ioe);<a name="line.1232"></a> -<span class="sourceLineNo">1233</span> // The Master is coming up. Will retry the report later. Avoid re-creating the stub.<a name="line.1233"></a> -<span class="sourceLineNo">1234</span> return true;<a name="line.1234"></a> -<span class="sourceLineNo">1235</span> }<a name="line.1235"></a> -<span class="sourceLineNo">1236</span> if (rssStub == rss) {<a name="line.1236"></a> -<span class="sourceLineNo">1237</span> rssStub = null;<a name="line.1237"></a> -<span class="sourceLineNo">1238</span> }<a name="line.1238"></a> -<span class="sourceLineNo">1239</span> createRegionServerStatusStub(true);<a name="line.1239"></a> -<span class="sourceLineNo">1240</span> if (ioe instanceof DoNotRetryIOException) {<a name="line.1240"></a> -<span class="sourceLineNo">1241</span> DoNotRetryIOException doNotRetryEx = (DoNotRetryIOException) ioe;<a name="line.1241"></a> -<span class="sourceLineNo">1242</span> if (doNotRetryEx.getCause() != null) {<a name="line.1242"></a> -<span class="sourceLineNo">1243</span> Throwable t = doNotRetryEx.getCause();<a name="line.1243"></a> -<span class="sourceLineNo">1244</span> if (t instanceof UnsupportedOperationException) {<a name="line.1244"></a> -<span class="sourceLineNo">1245</span> LOG.debug("master doesn't support ReportRegionSpaceUse, pause before retrying");<a name="line.1245"></a> -<span class="sourceLineNo">1246</span> return false;<a name="line.1246"></a> -<span class="sourceLineNo">1247</span> }<a name="line.1247"></a> -<span class="sourceLineNo">1248</span> }<a name="line.1248"></a> -<span class="sourceLineNo">1249</span> }<a name="line.1249"></a> -<span class="sourceLineNo">1250</span> LOG.debug("Failed to report region sizes to Master. This will be retried.", ioe);<a name="line.1250"></a> -<span class="sourceLineNo">1251</span> }<a name="line.1251"></a> -<span class="sourceLineNo">1252</span> return true;<a name="line.1252"></a> -<span class="sourceLineNo">1253</span> }<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> * Builds the region size report and sends it to the master. Upon successful sending of the<a name="line.1256"></a> -<span class="sourceLineNo">1257</span> * report, the region sizes that were sent are marked as sent.<a name="line.1257"></a> -<span class="sourceLineNo">1258</span> *<a name="line.1258"></a> -<span class="sourceLineNo">1259</span> * @param rss The stub to send to the Master<a name="line.1259"></a> -<span class="sourceLineNo">1260</span> * @param regionSizeStore The store containing region sizes<a name="line.1260"></a> -<span class="sourceLineNo">1261</span> */<a name="line.1261"></a> -<span class="sourceLineNo">1262</span> void buildReportAndSend(RegionServerStatusService.BlockingInterface rss,<a name="line.1262"></a> -<span class="sourceLineNo">1263</span> RegionSizeStore regionSizeStore) throws ServiceException {<a name="line.1263"></a> -<span class="sourceLineNo">1264</span> RegionSpaceUseReportRequest request =<a name="line.1264"></a> -<span class="sourceLineNo">1265</span> buildRegionSpaceUseReportRequest(Objects.requireNonNull(regionSizeStore));<a name="line.1265"></a> -<span class="sourceLineNo">1266</span> rss.reportRegionSpaceUse(null, request);<a name="line.1266"></a> -<span class="sourceLineNo">1267</span> // Record the number of size reports sent<a name="line.1267"></a> -<span class="sourceLineNo">1268</span> if (metricsRegionServer != null) {<a name="line.1268"></a> -<span class="sourceLineNo">1269</span> metricsRegionServer.incrementNumRegionSizeReportsSent(regionSizeStore.size());<a name="line.1269"></a> -<span class="sourceLineNo">1270</span> }<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> * Builds a {@link RegionSpaceUseReportRequest} protobuf message from the region size map.<a name="line.1274"></a> -<span class="sourceLineNo">1275</span> *<a name="line.1275"></a> -<span class="sourceLineNo">1276</span> * @param regionSizeStore The size in bytes of regions<a name="line.1276"></a> -<span class="sourceLineNo">1277</span> * @return The corresponding protocol buffer message.<a name="line.1277"></a> -<span class="sourceLineNo">1278</span> */<a name="line.1278"></a> -<span class="sourceLineNo">1279</span> RegionSpaceUseReportRequest buildRegionSpaceUseReportRequest(RegionSizeStore regionSizes) {<a name="line.1279"></a> -<span class="sourceLineNo">1280</span> RegionSpaceUseReportRequest.Builder request = RegionSpaceUseReportRequest.newBuilder();<a name="line.1280"></a> -<span class="sourceLineNo">1281</span> for (Entry<RegionInfo, RegionSize> entry : regionSizes) {<a name="line.1281"></a> -<span class="sourceLineNo">1282</span> request.addSpaceUse(convertRegionSize(entry.getKey(), entry.getValue().getSize()));<a name="line.1282"></a> -<span class="sourceLineNo">1283</span> }<a name="line.1283"></a> -<span class="sourceLineNo">1284</span> return request.build();<a name="line.1284"></a> -<span class="sourceLineNo">1285</span> }<a name="line.1285"></a> -<span class="sourceLineNo">1286</span><a name="line.1286"></a> -<span class="sourceLineNo">1287</span> /**<a name="line.1287"></a> -<span class="sourceLineNo">1288</span> * Converts a pair of {@link RegionInfo} and {@code long} into a {@link RegionSpaceUse}<a name="line.1288"></a> -<span class="sourceLineNo">1289</span> * protobuf message.<a name="line.1289"></a> -<span class="sourceLineNo">1290</span> *<a name="line.1290"></a> -<span class="sourceLineNo">1291</span> * @param regionInfo The RegionInfo<a name="line.1291"></a> -<span class="sourceLineNo">1292</span> * @param sizeInBytes The size in bytes of the Region<a name="line.1292"></a> -<span class="sourceLineNo">1293</span> * @return The protocol buffer<a name="line.1293"></a> -<span class="sourceLineNo">1294</span> */<a name="line.1294"></a> -<span class="sourceLineNo">1295</span> RegionSpaceUse convertRegionSize(RegionInfo regionInfo, Long sizeInBytes) {<a name="line.1295"></a> -<span class="sourceLineNo">1296</span> return RegionSpaceUse.newBuilder()<a name="line.1296"></a> -<span class="sourceLineNo">1297</span> .setRegionInfo(ProtobufUtil.toRegionInfo(Objects.requireNonNull(regionInfo)))<a name="line.1297"></a> -<span class="sourceLineNo">1298</span> .setRegionSize(Objects.requireNonNull(sizeInBytes))<a name="line.1298"></a> -<span class="sourceLineNo">1299</span> .build();<a name="line.1299"></a> -<span class="sourceLineNo">1300</span> }<a name="line.1300"></a> -<span class="sourceLineNo">1301</span><a name="line.1301"></a> -<span class="sourceLineNo">1302</span> ClusterStatusProtos.ServerLoad buildServerLoad(long reportStartTime, long reportEndTime)<a name="line.1302"></a> -<span class="sourceLineNo">1303</span> throws IOException {<a name="line.1303"></a> -<span class="sourceLineNo">1304</span> // We're getting the MetricsRegionServerWrapper here because the wrapper computes requests<a name="line.1304"></a> -<span class="sourceLineNo">1305</span> // per second, and other metrics As long as metrics are part of ServerLoad it's best to use<a name="line.1305"></a> -<span class="sourceLineNo">1306</span> // the wrapper to compute those numbers in one place.<a name="line.1306"></a> -<span class="sourceLineNo">1307</span> // In the long term most of these should be moved off of ServerLoad and the heart beat.<a name="line.1307"></a> -<span class="sourceLineNo">1308</span> // Instead they should be stored in an HBase table so that external visibility into HBase is<a name="line.1308"></a> -<span class="sourceLineNo">1309</span> // improved; Additionally the load balancer will be able to take advantage of a more complete<a name="line.1309"></a> -<span class="sourceLineNo">1310</span> // history.<a name="line.1310"></a> -<span class="sourceLineNo">1311</span> MetricsRegionServerWrapper regionServerWrapper = metricsRegionServer.getRegionServerWrapper();<a name="line.1311"></a> -<span class="sourceLineNo">1312</span> Collection<HRegion> regions = getOnlineRegionsLocalContext();<a name="line.1312"></a> -<span class="sourceLineNo">1313</span> long usedMemory = -1L;<a name="line.1313"></a> -<span class="sourceLineNo">1314</span> long maxMemory = -1L;<a name="line.1314"></a> -<span class="sourceLineNo">1315</span> final MemoryUsage usage = MemorySizeUtil.safeGetHeapMemoryUsage();<a name="line.1315"></a> -<span class="sourceLineNo">1316</span> if (usage != null) {<a name="line.1316"></a> -<span class="sourceLineNo">1317</span> usedMemory = usage.getUsed();<a name="line.1317"></a> -<span class="sourceLineNo">1318</span> maxMemory = usage.getMax();<a name="line.1318"></a> -<span class="sourceLineNo">1319</span> }<a name="line.1319"></a> -<span class="sourceLineNo">1320</span><a name="line.1320"></a> -<span class="sourceLineNo">1321</span> ClusterStatusProtos.ServerLoad.Builder serverLoad = ClusterStatusProtos.ServerLoad.newBuilder();<a name="line.1321"></a> -<span class="sourceLineNo">1322</span> serverLoad.setNumberOfRequests((int) regionServerWrapper.getRequestsPerSecond());<a name="line.1322"></a> -<span class="sourceLineNo">1323</span> serverLoad.setTotalNumberOfRequests(regionServerWrapper.getTotalRequestCount());<a name="line.1323"></a> -<span class="sourceLineNo">1324</span> serverLoad.setUsedHeapMB((int)(usedMemory / 1024 / 1024));<a name="line.1324"></a> -<span class="sourceLineNo">1325</span> serverLoad.setMaxHeapMB((int) (maxMemory / 1024 / 1024));<a name="line.1325"></a> -<span class="sourceLineNo">1326</span> Set<String> coprocessors = getWAL(null).getCoprocessorHost().getCoprocessors();<a name="line.1326"></a> -<span class="sourceLineNo">1327</span> Builder coprocessorBuilder = Coprocessor.newBuilder();<a name="line.1327"></a> -<span class="sourceLineNo">1328</span> for (String coprocessor : coprocessors) {<a name="line.1328"></a> -<span class="sourceLineNo">1329</span> serverLoad.addCoprocessors(coprocessorBuilder.setName(coprocessor).build());<a name="line.1329"></a> -<span class="sourceLineNo">1330</span> }<a name="line.1330"></a> -<span class="sourceLineNo">1331</span> RegionLoad.Builder regionLoadBldr = RegionLoad.newBuilder();<a name="line.1331"></a> -<span class="sourceLineNo">1332</span> RegionSpecifier.Builder regionSpecifier = RegionSpecifier.newBuilder();<a name="line.1332"></a> -<span class="sourceLineNo">1333</span> for (HRegion region : regions) {<a name="line.1333"></a> -<span class="sourceLineNo">1334</span> if (region.getCoprocessorHost() != null) {<a name="line.1334"></a> -<span class="sourceLineNo">1335</span> Set<String> regionCoprocessors = region.getCoprocessorHost().getCoprocessors();<a name="line.1335"></a> -<span class="sourceLineNo">1336</span> Iterator<String> iterator = regionCoprocessors.iterator();<a name="line.1336"></a> -<span class="sourceLineNo">1337</span> while (iterator.hasNext()) {<a name="line.1337"></a> -<span class="sourceLineNo">1338</span> serverLoad.addCoprocessors(coprocessorBuilder.setName(iterator.next()).build());<a name="line.1338"></a> -<span class="sourceLineNo">1339</span> }<a name="line.1339"></a> -<span class="sourceLineNo">1340</span> }<a name="line.1340"></a> -<span class="sourceLineNo">1341</span> serverLoad.addRegionLoads(createRegionLoad(region, regionLoadBldr, regionSpecifier));<a name="line.1341"></a> -<span class="sourceLineNo">1342</span> for (String coprocessor : getWAL(region.getRegionInfo()).getCoprocessorHost()<a name="line.1342"></a> -<span class="sourceLineNo">1343</span> .getCoprocessors()) {<a name="line.1343"></a> -<span class="sourceLineNo">1344</span> serverLoad.addCoprocessors(coprocessorBuilder.setName(coprocessor).build());<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> serverLoad.setReportStartTime(reportStartTime);<a name="line.1347"></a> -<span class="sourceLineNo">1348</span> serverLoad.setReportEndTime(reportEndTime);<a name="line.1348"></a> -<span class="sourceLineNo">1349</span> if (this.infoServer != null) {<a name="line.1349"></a> -<span class="sourceLineNo">1350</span> serverLoad.setInfoServerPort(this.infoServer.getPort());<a name="line.1350"></a> -<span class="sourceLineNo">1351</span> } else {<a name="line.1351"></a> -<span class="sourceLineNo">1352</span> serverLoad.setInfoServerPort(-1);<a name="line.1352"></a> -<span class="sourceLineNo">1353</span> }<a name="line.1353"></a> -<span class="sourceLineNo">1354</span><a name="line.1354"></a> -<span class="sourceLineNo">1355</span> // for the replicationLoad purpose. Only need to get from one executorService<a name="line.1355"></a> -<span class="sourceLineNo">1356</span> // either source or sink will get the same info<a name="line.1356"></a> -<span class="sourceLineNo">1357</span> ReplicationSourceService rsources = getReplicationSourceService();<a name="line.1357"></a> -<span class="sourceLineNo">1358</span><a name="line.1358"></a> -<span class="sourceLineNo">1359</span> if (rsources != null) {<a name="line.1359"></a> -<span class="sourceLineNo">1360</span> // always refresh first to get the latest value<a name="line.1360"></a> -<span class="sourceLineNo">1361</span> ReplicationLoad rLoad = rsources.refreshAndGetReplicationLoad();<a name="line.1361"></a> -<span class="sourceLineNo">1362</span> if (rLoad != null) {<a name="line.1362"></a> -<span class="sourceLineNo">1363</span> serverLoad.setReplLoadSink(rLoad.getReplicationLoadSink());<a name="line.1363"></a> -<span class="sourceLineNo">1364</span> for (ClusterStatusProtos.ReplicationLoadSource rLS : rLoad.getReplicationLoadSourceList()) {<a name="line.1364"></a> -<span class="sourceLineNo">1365</span> serverLoad.addReplLoadSource(rLS);<a name="line.1365"></a> -<span class="sourceLineNo">1366</span> }<a name="line.1366"></a> -<span class="sourceLineNo">1367</span> }<a name="line.1367"></a> -<span class="sourceLineNo">1368</span> }<a name="line.1368"></a> -<span class="sourceLineNo">1369</span><a name="line.1369"></a> -<span class="sourceLineNo">1370</span> return serverLoad.build();<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> String getOnlineRegionsAsPrintableString() {<a name="line.1373"></a> -<span class="sourceLineNo">1374</span> StringBuilder sb = new StringBuilder();<a name="line.1374"></a> -<span class="sourceLineNo">1375</span> for (Region r: this.onlineRegions.values()) {<a name="line.1375"></a> -<span class="sourceLineNo">1376</span> if (sb.length() > 0) sb.append(", ");<a name="line.1376"></a> -<span class="sourceLineNo">1377</span> sb.append(r.getRegionInfo().getEncodedName());<a name="line.1377"></a> -<span class="sourceLineNo">1378</span> }<a name="line.1378"></a> -<span class="sourceLineNo">1379</span> return sb.toString();<a name="line.1379"></a> -<span class="sourceLineNo">1380</span> }<a name="line.1380"></a> -<span class="sourceLineNo">1381</span><a name="line.1381"></a> -<span class="sourceLineNo">1382</span> /**<a name="line.1382"></a> -<span class="sourceLineNo">1383</span> * Wait on regions close.<a name="line.1383"></a> -<span class="sourceLineNo">1384</span> */<a name="line.1384"></a> -<span class="sourceLineNo">1385</span> private void waitOnAllRegionsToClose(final boolean abort) {<a name="line.1385"></a> -<span class="sourceLineNo">1386</span> // Wait till all regions are closed before going out.<a name="line.1386"></a> -<span class="sourceLineNo">1387</span> int lastCount = -1;<a name="line.1387"></a> -<span class="sourceLineNo">1388</span> long previousLogTime = 0;<a name="line.1388"></a> -<span class="sourceLineNo">1389</span> Set<String> closedRegions = new HashSet<>();<a name="line.1389"></a> -<span class="sourceLineNo">1390</span> boolean interrupted = false;<a name="line.1390"></a> -<span class="sourceLineNo">1391</span> try {<a name="line.1391"></a> -<span class="sourceLineNo">1392</span> while (!isOnlineRegionsEmpty()) {<a name="line.1392"></a> -<span class="sourceLineNo">1393</span> int count = getNumberOfOnlineRegions();<a name="line.1393"></a> -<span class="sourceLineNo">1394</span> // Only print a message if the count of regions has changed.<a name="line.1394"></a> -<span class="sourceLineNo">1395</span> if (count != lastCount) {<a name="line.1395"></a> -<span class="sourceLineNo">1396</span> // Log every second at most<a name="line.1396"></a> -<span class="sourceLineNo">1397</span> if (System.currentTimeMillis() > (previousLogTime + 1000)) {<a name="line.1397"></a> -<span class="sourceLineNo">1398</span> previousLogTime = System.currentTimeMillis();<a name="line.1398"></a> -<span class="sourceLineNo">1399</span> lastCount = count;<a name="line.1399"></a> -<span class="sourceLineNo">1400</span> LOG.info("Waiting on " + count + " regions to close");<a name="line.1400"></a> -<span class="sourceLineNo">1401</span> // Only print out regions still closing if a small number else will<a name="line.1401"></a> -<span class="sourceLineNo">1402</span> // swamp the log.<a name="line.1402"></a> -<span class="sourceLineNo">1403</span> if (count < 10 && LOG.isDebugEnabled()) {<a name="line.1403"></a> -<span class="sourceLineNo">1404</span> LOG.debug("Online Regions=" + this.onlineRegions);<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> }<a name="line.1407"></a> -<span class="sourceLineNo">1408</span> // Ensure all user regions have been sent a close. Use this to<a name="line.1408"></a> -<span class="sourceLineNo">1409</span> // protect against the case where an open comes in after we start the<a name="line.1409"></a> -<span class="sourceLineNo">1410</span> // iterator of onlineRegions to close all user regions.<a name="line.1410"></a> -<span class="sourceLineNo">1411</span> for (Map.Entry<String, HRegion> e : this.onlineRegions.entrySet()) {<a name="line.1411"></a> -<span class="sourceLineNo">1412</span> RegionInfo hri = e.getValue().getRegionInfo();<a name="line.1412"></a> -<span class="sourceLineNo">1413</span> if (!this.regionsInTransitionInRS.containsKey(hri.getEncodedNameAsBytes()) &&<a name="line.1413"></a> -<span class="sourceLineNo">1414</span> !closedRegions.contains(hri.getEncodedName())) {<a name="line.1414"></a> -<span class="sourceLineNo">1415</span> closedRegions.add(hri.getEncodedName());<a name="line.1415"></a> -<span class="sourceLineNo">1416</span> // Don't update zk with this close transition; pass false.<a name="line.1416"></a> -<span class="sourceLineNo">1417</span> closeRegionIgnoreErrors(hri, abort);<a name="line.1417"></a> -<span class="sourceLineNo">1418</span> }<a name="line.1418"></a> -<span class="sourceLineNo">1419</span> }<a name="line.1419"></a> -<span class="sourceLineNo">1420</span> // No regions in RIT, we could stop waiting now.<a name="line.1420"></a> -<span class="sourceLineNo">1421</span> if (this.regionsInTransitionInRS.isEmpty()) {<a name="line.1421"></a> -<span class="sourceLineNo">1422</span> if (!isOnlineRegionsEmpty()) {<a name="line.1422"></a> -<span class="sourceLineNo">1423</span> LOG.info("We were exiting though online regions are not empty," +<a name="line.1423"></a> -<span class="sourceLineNo">1424</span> " because some regions failed closing");<a name="line.1424"></a> -<span class="sourceLineNo">1425</span> }<a name="line.1425"></a> -<span class="sourceLineNo">1426</span> break;<a name="line.1426"></a> -<span class="sourceLineNo">1427</span> }<a name="line.1427"></a> -<span class="sourceLineNo">1428</span> if (sleep(200)) {<a name="line.1428"></a> -<span class="sourceLineNo">1429</span> interrupted = true;<a name="line.1429"></a> -<span class="sourceLineNo">1430</span> }<a name="line.1430"></a> -<span class="sourceLineNo">1431</span> }<a name="line.1431"></a> -<span class="sourceLineNo">1432</span> } finally {<a name="line.1432"></a> -<span class="sourceLineNo">1433</span> if (interrupted) {<a name="line.1433"></a> -<span class="sourceLineNo">1434</span> Thread.currentThread().interrupt();<a name="line.1434"></a> -<span class="sourceLineNo">1435</span> }<a name="line.1435"></a> -<span class="sourceLineNo">1436</span> }<a name="line.1436"></a> -<span class="sourceLineNo">1437</span> }<a name="line.1437"></a> -<span class="sourceLineNo">1438</span><a name="line.1438"></a> -<span class="sourceLineNo">1439</span> private boolean sleep(long millis) {<a name="line.1439"></a> -<span class="sourceLineNo">1440</span> boolean interrupted = false;<a name="line.1440"></a> -<span class="sourceLineNo">1441</span> try {<a name="line.1441"></a> -<span class="sourceLineNo">1442</span> Thread.sleep(millis);<a name="line.1442"></a> -<span class="sourceLineNo">1443</span> } catch (InterruptedException e) {<a name="line.1443"></a> -<span class="sourceLineNo">1444</span> LOG.warn("Interrupted while sleeping");<a name="line.1444"></a> -<span class="sourceLineNo">1445</span> interrupted = true;<a name="line.1445"></a> -<span class="sourceLineNo">1446</span> }<a name="line.1446"></a> -<span class="sourceLineNo">1447</span> return interrupted;<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> private void shutdownWAL(final boolean close) {<a name="line.1450"></a> -<span class="sourceLineNo">1451</span> if (this.walFactory != null) {<a name="line.1451"></a> -<span class="sourceLineNo">1452</span> try {<a name="line.1452"></a> -<span class="sourceLineNo">1453</span> if (close) {<a name="line.1453"></a> -<span class="sourceLineNo">1454</span> walFactory.close();<a name="line.1454"></a> -<span class="sourceLineNo">1455</span> } else {<a name="line.1455"></a> -<span class="sourceLineNo">1456</span> walFactory.shutdown();<a name="line.1456"></a> -<span class="sourceLineNo">1457</span> }<a name="line.1457"></a> -<span class="sourceLineNo">1458</span> } catch (Throwable e) {<a name="line.1458"></a> -<span class="sourceLineNo">1459</span> e = e instanceof RemoteException ? ((RemoteException) e).unwrapRemoteException() : e;<a name="line.1459"></a> -<span class="sourceLineNo">1460</span> LOG.error("Shutdown / close of WAL failed: " + e);<a name="line.1460"></a> -<span class="sourceLineNo">1461</span> LOG.debug("Shutdown / close exception details:", e);<a name="line.1461"></a> -<span class="sourceLineNo">1462</span> }<a name="line.1462"></a> -<span class="sourceLineNo">1463</span> }<a name="line.1463"></a> -<span class="sourceLineNo">1464</span> }<a name="line.1464"></a> -<span class="sourceLineNo">1465</span><a name="line.1465"></a> -<span class="sourceLineNo">1466</span> /*<a name="line.1466"></a> -<span class="sourceLineNo">1467</span> * Run init. Sets up wal and starts up all server threads.<a name="line.1467"></a> -<span class="sourceLineNo">1468</span> *<a name="line.1468"></a> -<span class="sourceLineNo">1469</span> * @param c Extra configuration.<a name="line.1469"></a> -<span class="sourceLineNo">1470</span> */<a name="line.1470"></a> -<span class="sourceLineNo">1471</span> protected void handleReportForDutyResponse(final RegionServerStartupResponse c)<a name="line.1471"></a> -<span class="sourceLineNo">1472</span> throws IOException {<a name="line.1472"></a> -<span class="sourceLineNo">1473</span> try {<a name="line.1473"></a> -<span class="sourceLineNo">1474</span> boolean updateRootDir = false;<a name="line.1474"></a> -<span class="sourceLineNo">1475</span> for (NameStringPair e : c.getMapEntriesList()) {<a name="line.1475"></a> -<span class="sourceLineNo">1476</span> String key = e.getName();<a name="line.1476"></a> -<span class="sourceLineNo">1477</span> // The hostname the master sees us as.<a name="line.1477"></a> -<span class="sourceLineNo">1478</span> if (key.equals(HConstants.KEY_FOR_HOSTNAME_SEEN_BY_MASTER)) {<a name="line.1478"></a> -<span class="sourceLineNo">1479</span> String hostnameFromMasterPOV = e.getValue();<a name="line.1479"></a> -<span class="sourceLineNo">1480</span> this.serverName = ServerName.valueOf(hostnameFromMasterPOV, rpcServices.isa.getPort(),<a name="line.1480"></a> -<span class="sourceLineNo">1481</span> this.startcode);<a name="line.1481"></a> -<span class="sourceLineNo">1482</span> if (!StringUtils.isBlank(useThisHostnameInstead) &&<a name="line.1482"></a> -<span class="sourceLineNo">1483</span> !hostnameFromMasterPOV.equals(useThisHostnameInstead)) {<a name="line.1483"></a> -<span class="sourceLineNo">1484</span> String msg = "Master passed us a different hostname to use; was=" +<a name="line.1484"></a> -<span class="sourceLineNo">1485</span> this.useThisHostnameInstead + ", but now=" + hostnameFromMasterPOV;<a name="line.1485"></a> -<span class="sourceLineNo">1486</span> LOG.error(msg);<a name="line.1486"></a> -<span class="sourceLineNo">1487</span> throw new IOException(msg);<a name="line.1487"></a> -<span class="sourceLineNo">1488</span> }<a name="line.1488"></a> -<span class="sourceLineNo">1489</span> if (StringUtils.isBlank(useThisHostnameInstead) &&<a name="line.1489"></a> -<span class="sourceLineNo">1490</span> !hostnameFromMasterPOV.equals(rpcServices.isa.getHostName())) {<a name="line.1490"></a> -<span class="sourceLineNo">1491</span> String msg = "Master passed us a different hostname to use; was=" +<a name="line.1491"></a> -<span class="sourceLineNo">1492</span> rpcServices.isa.getHostName() + ", but now=" + hostnameFromMasterPOV;<a name="line.1492"></a> -<span class="sourceLineNo">1493</span> LOG.error(msg);<a name="line.1493"></a> -<span class="sourceLineNo">1494</span> }<a name="line.1494"></a> -<span class="sourceLineNo">1495</span> continue;<a name="line.1495"></a> -<span class="sourceLineNo">1496</span> }<a name="line.1496"></a> -<span class="sourceLineNo">1497</span><a name="line.1497"></a> -<span class="sourceLineNo">1498</span> String value = e.getValue();<a name="line.1498"></a> -<span class="sourceLineNo">1499</span> if (key.equals(HConstants.HBASE_DIR)) {<a name="line.1499"></a> -<span class="sourceLineNo">1500</span> if (value != null && !value.equals(conf.get(HConstants.HBASE_DIR))) {<a name="line.1500"></a> -<span class="sourceLineNo">1501</span> updateRootDir = true;<a name="line.1501"></a> -<span class="sourceLineNo">1502</span> }<a name="line.1502"></a> -<span class="sourceLineNo">1503</span> }<a name="line.1503"></a> -<span class="sourceLineNo">1504</span><a name="line.1504"></a> -<span class="sourceLineNo">1505</span> if (LOG.isDebugEnabled()) {<a name="line.1505"></a> -<span class="sourceLineNo">1506</span> LOG.debug("Config from master: " + key + "=" + value);<a name="line.1506"></a> -<span class="sourceLineNo">1507</span> }<a name="line.1507"></a> -<span class="sourceLineNo">1508</span> this.conf.set(key, value);<a name="line.1508"></a> -<span class="sourceLineNo">1509</span> }<a name="line.1509"></a> -<span class="sourceLineNo">1510</span> // Set our ephemeral znode up in zookeeper now we have a name.<a name="line.1510"></a> -<span class="sourceLineNo">1511</span> createMyEphemeralNode();<a name="line.1511"></a> -<span class="sourceLineNo">1512</span><a name="line.1512"></a> -<span class="sourceLineNo">1513</span> if (updateRootDir) {<a name="line.1513"></a> -<span class="sourceLineNo">1514</span> // initialize file system by the config fs.defaultFS and hbase.rootdir from master<a name="line.1514"></a> -<span class="sourceLineNo">1515</span> initializeFileSystem();<a name="line.1515"></a> -<span class="sourceLineNo">1516</span> }<a name="line.1516"></a> -<span class="sourceLineNo">1517</span><a name="line.1517"></a> -<span class="sourceLineNo">1518</span> // hack! Maps DFSClient => RegionServer for logs. HDFS made this<a name="line.1518"></a> -<span class="sourceLineNo">1519</span> // config param for task trackers, but we can piggyback off of it.<a name="line.1519"></a> -<span class="sourceLineNo">1520</span> if (this.conf.get("mapreduce.task.attempt.id") == null) {<a name="line.1520"></a> -<span class="sourceLineNo">1521</span> this.conf.set("mapreduce.task.attempt.id", "hb_rs_" + this.serverName.toString());<a name="line.1521"></a> -<span class="sourceLineNo">1522</span> }<a name="line.1522"></a> -<span class="sourceLineNo">1523</span><a name="line.1523"></a> -<span class="sourceLineNo">1524</span> // Save it in a file, this will allow to see if we crash<a name="line.1524"></a> -<span class="sourceLineNo">1525</span> ZNodeClearer.writeMyEphemeralNodeOnDisk(getMyEphemeralNodePath());<a name="line.1525"></a> -<span class="sourceLineNo">1526</span><a name="line.1526"></a> -<span class="sourceLineNo">1527</span> // This call sets up an initialized replication and WAL. Later we start it up.<a name="line.1527"></a> -<span class="sourceLineNo">1528</span> setupWALAndReplication();<a name="line.1528"></a> -<span class="sourceLineNo">1529</span> // Init in here rather than in constructor after thread name has been set<a name="line.1529"></a> -<span class="sourceLineNo">1530</span> this.metricsRegionServer = new MetricsRegionServer(<a name="line.1530"></a> -<span class="sourceLineNo">1531</span> new MetricsRegionServerWrapperImpl(this), conf);<a name="line.1531"></a> -<span class="sourceLineNo">1532</span> this.metricsTable = new MetricsTable(new MetricsTableWrapperAggregateImpl(this));<a name="line.1532"></a> -<span class="sourceLineNo">1533</span> // Now that we have a metrics source, start the pause monitor<a name="line.1533"></a> -<span class="sourceLineNo">1534</span> this.pauseMonitor = new JvmPauseMonitor(conf, getMetrics().getMetricsSource());<a name="line.1534"></a> -<span class="sourceLineNo">1535</span> pauseMonitor.start();<a name="line.1535"></a> -<span class="sourceLineNo">1536</span><a name="line.1536"></a> -<span class="sourceLineNo">1537</span> // There is a rare case where we do NOT want services to start. Check config.<a name="line.1537"></a> -<span class="sourceLineNo">1538</span> if (getConfiguration().getBoolean("hbase.regionserver.workers", true)) {<a name="line.1538"></a> -<span class="sourceLineNo">1539</span> startServices();<a name="line.1539"></a> -<span class="sourceLineNo">1540</span> }<a name="line.1540"></a> -<span class="sourceLineNo">1541</span> // In here we start up the replication Service. Above we initialized it. TODO. Reconcile.<a name="line.1541"></a> -<span class="sourceLineNo">1542</span> // or make sense of it.<a name="line.1542"></a> -<span class="sourceLineNo">1543</span> startReplicationService();<a name="line.1543"></a> +<span class="sourceLineNo">1194</span> request.setServer(ProtobufUtil.toServerName(this.serverName));<a name="line.1194"></a> +<span class="sourceLineNo">1195</span> request.setLoad(sl);<a name="line.1195"></a> +<span class="sourceLineNo">1196</span> rss.regionServerReport(null, request.build());<a name="line.1196"></a> +<span class="sourceLineNo">1197</span> } catch (ServiceException se) {<a name="line.1197"></a> +<span class="sourceLineNo">1198</span> IOException ioe = ProtobufUtil.getRemoteException(se);<a name="line.1198"></a> +<span class="sourceLineNo">1199</span> if (ioe instanceof YouAreDeadException) {<a name="line.1199"></a> +<span class="sourceLineNo">1200</span> // This will be caught and handled as a fatal error in run()<a name="line.1200"></a> +<span class="sourceLineNo">1201</span> throw ioe;<a name="line.1201"></a> +<span class="sourceLineNo">1202</span> }<a name="line.1202"></a> +<span class="sourceLineNo">1203</span> if (rssStub == rss) {<a name="line.1203"></a> +<span class="sourceLineNo">1204</span> rssStub = null;<a name="line.1204"></a> +<span class="sourceLineNo">1205</span> }<a name="line.1205"></a> +<span class="sourceLineNo">1206</span> // Couldn't connect to the master, get location from zk and reconnect<a name="line.1206"></a> +<span class="sourceLineNo">1207</span> // Method blocks until new master is found or we are stopped<a name="line.1207"></a> +<span class="sourceLineNo">1208</span> createRegionServerStatusStub(true);<a name="line.1208"></a> +<span class="sourceLineNo">1209</span> }<a name="line.1209"></a> +<span class="sourceLineNo">1210</span> }<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> * Reports the given map of Regions and their size on the filesystem to the active Master.<a name="line.1213"></a> +<span class="sourceLineNo">1214</span> *<a name="line.1214"></a> +<span class="sourceLineNo">1215</span> * @param regionSizeStore The store containing region sizes<a name="line.1215"></a> +<span class="sourceLineNo">1216</span> * @return false if FileSystemUtilizationChore should pause reporting to master. true otherwise<a name="line.1216"></a> +<span class="sourceLineNo">1217</span> */<a name="line.1217"></a> +<span class="sourceLineNo">1218</span> public boolean reportRegionSizesForQuotas(RegionSizeStore regionSizeStore) {<a name="line.1218"></a> +<span class="sourceLineNo">1219</span> RegionServerStatusService.BlockingInterface rss = rssStub;<a name="line.1219"></a> +<span class="sourceLineNo">1220</span> if (rss == null) {<a name="line.1220"></a> +<span class="sourceLineNo">1221</span> // the current server could be stopping.<a name="line.1221"></a> +<span class="sourceLineNo">1222</span> LOG.trace("Skipping Region size report to HMaster as stub is null");<a name="line.1222"></a> +<span class="sourceLineNo">1223</span> return true;<a name="line.1223"></a> +<span class="sourceLineNo">1224</span> }<a name="line.1224"></a> +<span class="sourceLineNo">1225</span> try {<a name="line.1225"></a> +<span class="sourceLineNo">1226</span> buildReportAndSend(rss, regionSizeStore);<a name="line.1226"></a> +<span class="sourceLineNo">1227</span> } catch (ServiceException se) {<a name="line.1227"></a> +<span class="sourceLineNo">1228</span> IOException ioe = ProtobufUtil.getRemoteException(se);<a name="line.1228"></a> +<span class="sourceLineNo">1229</span> if (ioe instanceof PleaseHoldException) {<a name="line.1229"></a> +<span class="sourceLineNo">1230</span> LOG.trace("Failed to report region sizes to Master because it is initializing."<a name="line.1230"></a> +<span class="sourceLineNo">1231</span> + " This will be retried.", ioe);<a name="line.1231"></a> +<span class="sourceLineNo">1232</span> // The Master is coming up. Will retry the report later. Avoid re-creating the stub.<a name="line.1232"></a> +<span class="sourceLineNo">1233</span> return true;<a name="line.1233"></a> +<span class="sourceLineNo">1234</span> }<a name="line.1234"></a> +<span class="sourceLineNo">1235</span> if (rssStub == rss) {<a name="line.1235"></a> +<span class="sourceLineNo">1236</span> rssStub = null;<a name="line.1236"></a> +<span class="sourceLineNo">1237</span> }<a name="line.1237"></a> +<span class="sourceLineNo">1238</span> createRegionServerStatusStub(true);<a name="line.1238"></a> +<span class="sourceLineNo">1239</span> if (ioe instanceof DoNotRetryIOException) {<a name="line.1239"></a> +<span class="sourceLineNo">1240</span> DoNotRetryIOException doNotRetryEx = (DoNotRetryIOException) ioe;<a name="line.1240"></a> +<span class="sourceLineNo">1241</span> if (doNotRetryEx.getCause() != null) {<a name="line.1241"></a> +<span class="sourceLineNo">1242</span> Throwable t = doNotRetryEx.getCause();<a name="line.1242"></a> +<span class="sourceLineNo">1243</span> if (t instanceof UnsupportedOperationException) {<a name="line.1243"></a> +<span class="sourceLineNo">1244</span> LOG.debug("master doesn't support ReportRegionSpaceUse, pause before retrying");<a name="line.1244"></a> +<span class="sourceLineNo">1245</span> return false;<a name="line.1245"></a> +<span class="sourceLineNo">1246</span> }<a name="line.1246"></a> +<span class="sourceLineNo">1247</span> }<a name="line.1247"></a> +<span class="sourceLineNo">1248</span> }<a name="line.1248"></a> +<span class="sourceLineNo">1249</span> LOG.debug("Failed to report region sizes to Master. This will be retried.", ioe);<a name="line.1249"></a> +<span class="sourceLineNo">1250</span> }<a name="line.1250"></a> +<span class="sourceLineNo">1251</span> return true;<a name="line.1251"></a> +<span class="sourceLineNo">1252</span> }<a name="line.1252"></a> +<span class="sourceLineNo">1253</span><a name="line.1253"></a> +<span class="sourceLineNo">1254</span> /**<a name="line.1254"></a> +<span class="sourceLineNo">1255</span> * Builds the region size report and sends it to the master. Upon successful sending of the<a name="line.1255"></a> +<span class="sourceLineNo">1256</span> * report, the region sizes that were sent are marked as sent.<a name="line.1256"></a> +<span class="sourceLineNo">1257</span> *<a name="line.1257"></a> +<span class="sourceLineNo">1258</span> * @param rss The stub to send to the Master<a name="line.1258"></a> +<span class="sourceLineNo">1259</span> * @param regionSizeStore The store containing region sizes<a name="line.1259"></a> +<span class="sourceLineNo">1260</span> */<a name="line.1260"></a> +<span class="sourceLineNo">1261</span> void buildReportAndSend(RegionServerStatusService.BlockingInterface rss,<a name="line.1261"></a> +<span class="sourceLineNo">1262</span> RegionSizeStore regionSizeStore) throws ServiceException {<a name="line.1262"></a> +<span class="sourceLineNo">1263</span> RegionSpaceUseReportRequest request =<a name="line.1263"></a> +<span class="sourceLineNo">1264</span> buildRegionSpaceUseReportRequest(Objects.requireNonNull(regionSizeStore));<a name="line.1264"></a> +<span class="sourceLineNo">1265</span> rss.reportRegionSpaceUse(null, request);<a name="line.1265"></a> +<span class="sourceLineNo">1266</span> // Record the number of size reports sent<a name="line.1266"></a> +<span class="sourceLineNo">1267</span> if (metricsRegionServer != null) {<a name="line.1267"></a> +<span class="sourceLineNo">1268</span> metricsRegionServer.incrementNumRegionSizeReportsSent(regionSizeStore.size());<a name="line.1268"></a> +<span class="sourceLineNo">1269</span> }<a name="line.1269"></a> +<span class="sourceLineNo">1270</span> }<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> * Builds a {@link RegionSpaceUseReportRequest} protobuf message from the region size map.<a name="line.1273"></a> +<span class="sourceLineNo">1274</span> *<a name="line.1274"></a> +<span class="sourceLineNo">1275</span> * @param regionSizeStore The size in bytes of regions<a name="line.1275"></a> +<span class="sourceLineNo">1276</span> * @return The corresponding protocol buffer message.<a name="line.1276"></a> +<span class="sourceLineNo">1277</span> */<a name="line.1277"></a> +<span class="sourceLineNo">1278</span> RegionSpaceUseReportRequest buildRegionSpaceUseReportRequest(RegionSizeStore regionSizes) {<a name="line.1278"></a> +<span class="sourceLineNo">1279</span> RegionSpaceUseReportRequest.Builder request = RegionSpaceUseReportRequest.newBuilder();<a name="line.1279"></a> +<span class="sourceLineNo">1280</span> for (Entry<RegionInfo, RegionSize> entry : regionSizes) {<a name="line.1280"></a> +<span class="sourceLineNo">1281</span> request.addSpaceUse(convertRegionSize(entry.getKey(), entry.getValue().getSize()));<a name="line.1281"></a> +<span class="sourceLineNo">1282</span> }<a name="line.1282"></a> +<span class="sourceLineNo">1283</span> return request.build();<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> /**<a name="line.1286"></a> +<span class="sourceLineNo">1287</span> * Converts a pair of {@link RegionInfo} and {@code long} into a {@link RegionSpaceUse}<a name="line.1287"></a> +<span class="sourceLineNo">1288</span> * protobuf message.<a name="line.1288"></a> +<span class="sourceLineNo">1289</span> *<a name="line.1289"></a> +<span class="sourceLineNo">1290</span> * @param regionInfo The RegionInfo<a name="line.1290"></a> +<span class="sourceLineNo">1291</span> * @param sizeInBytes The size in bytes of the Region<a name="line.1291"></a> +<span class="sourceLineNo">1292</span> * @return The protocol buffer<a name="line.1292"></a> +<span class="sourceLineNo">1293</span> */<a name="line.1293"></a> +<span class="sourceLineNo">1294</span> RegionSpaceUse convertRegionSize(RegionInfo regionInfo, Long sizeInBytes) {<a name="line.1294"></a> +<span class="sourceLineNo">1295</span> return RegionSpaceUse.newBuilder()<a name="line.1295"></a> +<span class="sourceLineNo">1296</span> .setRegionInfo(ProtobufUtil.toRegionInfo(Objects.requireNonNull(regionInfo)))<a name="line.1296"></a> +<span class="sourceLineNo">1297</span> .setRegionSize(Objects.requireNonNull(sizeInBytes))<a name="line.1297"></a> +<span class="sourceLineNo">1298</span> .build();<a name="line.1298"></a> +<span class="sourceLineNo">1299</span> }<a name="line.1299"></a> +<span class="sourceLineNo">1300</span><a name="line.1300"></a> +<span class="sourceLineNo">1301</span> ClusterStatusProtos.ServerLoad buildServerLoad(long reportStartTime, long reportEndTime)<a name="line.1301"></a> +<span class="sourceLineNo">1302</span> throws IOException {<a name="line.1302"></a> +<span class="sourceLineNo">1303</span> // We're getting the MetricsRegionServerWrapper here because the wrapper computes requests<a name="line.1303"></a> +<span class="sourceLineNo">1304</span> // per second, and other metrics As long as metrics are part of ServerLoad it's best to use<a name="line.1304"></a> +<span class="sourceLineNo">1305</span> // the wrapper to compute those numbers in one place.<a name="line.1305"></a> +<span class="sourceLineNo">1306</span> // In the long term most of these should be moved off of ServerLoad and the heart beat.<a name="line.1306"></a> +<span class="sourceLineNo">1307</span> // Instead they should be stored in an HBase table so that external visibility into HBase is<a name="line.1307"></a> +<span class="sourceLineNo">1308</span> // improved; Additionally the load balancer will be able to take advantage of a more complete<a name="line.1308"></a> +<span class="sourceLineNo">1309</span> // history.<a name="line.1309"></a> +<span class="sourceLineNo">1310</span> MetricsRegionServerWrapper regionServerWrapper = metricsRegionServer.getRegionServerWrapper();<a name="line.1310"></a> +<span class="sourceLineNo">1311</span> Collection<HRegion> regions = getOnlineRegionsLocalContext();<a name="line.1311"></a> +<span class="sourceLineNo">1312</span> long usedMemory = -1L;<a name="line.1312"></a> +<span class="sourceLineNo">1313</span> long maxMemory = -1L;<a name="line.1313"></a> +<span class="sourceLineNo">1314</span> final MemoryUsage usage = MemorySizeUtil.safeGetHeapMemoryUsage();<a name="line.1314"></a> +<span class="sourceLineNo">1315</span> if (usage != null) {<a name="line.1315"></a> +<span class="sourceLineNo">1316</span> usedMemory = usage.getUsed();<a name="line.1316"></a> +<span class="sourceLineNo">1317</span> maxMemory = usage.getMax();<a name="line.1317"></a> +<span class="sourceLineNo">1318</span> }<a name="line.1318"></a> +<span class="sourceLineNo">1319</span><a name="line.1319"></a> +<span class="sourceLineNo">1320</span> ClusterStatusProtos.ServerLoad.Builder serverLoad = ClusterStatusProtos.ServerLoad.newBuilder();<a name="line.1320"></a> +<span class="sourceLineNo">1321</span> serverLoad.setNumberOfRequests((int) regionServerWrapper.getRequestsPerSecond());<a name="line.1321"></a> +<span class="sourceLineNo">1322</span> serverLoad.setTotalNumberOfRequests(regionServerWrapper.getTotalRequestCount());<a name="line.1322"></a> +<span class="sourceLineNo">1323</span> serverLoad.setUsedHeapMB((int)(usedMemory / 1024 / 1024));<a name="line.1323"></a> +<span class="sourceLineNo">1324</span> serverLoad.setMaxHeapMB((int) (maxMemory / 1024 / 1024));<a name="line.1324"></a> +<span class="sourceLineNo">1325</span> Set<String> coprocessors = getWAL(null).getCoprocessorHost().getCoprocessors();<a name="line.1325"></a> +<span class="sourceLineNo">1326</span> Builder coprocessorBuilder = Coprocessor.newBuilder();<a name="line.1326"></a> +<span class="sourceLineNo">1327</span> for (String coprocessor : coprocessors) {<a name="line.1327"></a> +<span class="sourceLineNo">1328</span> serverLoad.addCoprocessors(coprocessorBuilder.setName(coprocessor).build());<a name="line.1328"></a> +<span class="sourceLineNo">1329</span> }<a name="line.1329"></a> +<span class="sourceLineNo">1330</span> RegionLoad.Builder regionLoadBldr = RegionLoad.newBuilder();<a name="line.1330"></a> +<span class="sourceLineNo">1331</span> RegionSpecifier.Builder regionSpecifier = RegionSpecifier.newBuilder();<a name="line.1331"></a> +<span class="sourceLineNo">1332</span> for (HRegion region : regions) {<a name="line.1332"></a> +<span class="sourceLineNo">1333</span> if (region.getCoprocessorHost() != null) {<a name="line.1333"></a> +<span class="sourceLineNo">1334</span> Set<String> regionCoprocessors = region.getCoprocessorHost().getCoprocessors();<a name="line.1334"></a> +<span class="sourceLineNo">1335</span> Iterator<String> iterator = regionCoprocessors.iterator();<a name="line.1335"></a> +<span class="sourceLineNo">1336</span> while (iterator.hasNext()) {<a name="line.1336"></a> +<span class="sourceLineNo">1337</span> serverLoad.addCoprocessors(coprocessorBuilder.setName(iterator.next()).build());<a name="line.1337"></a> +<span class="sourceLineNo">1338</span> }<a name="line.1338"></a> +<span class="sourceLineNo">1339</span> }<a name="line.1339"></a> +<span class="sourceLineNo">1340</span> serverLoad.addRegionLoads(createRegionLoad(region, regionLoadBldr, regionSpecifier));<a name="line.1340"></a> +<span class="sourceLineNo">1341</span> for (String coprocessor : getWAL(region.getRegionInfo()).getCoprocessorHost()<a name="line.1341"></a> +<span class="sourceLineNo">1342</span> .getCoprocessors()) {<a name="line.1342"></a> +<span class="sourceLineNo">1343</span> serverLoad.addCoprocessors(coprocessorBuilder.setName(coprocessor).build());<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> serverLoad.setReportStartTime(reportStartTime);<a name="line.1346"></a> +<span class="sourceLineNo">1347</span> serverLoad.setReportEndTime(reportEndTime);<a name="line.1347"></a> +<span class="sourceLineNo">1348</span> if (this.infoServer != null) {<a name="line.1348"></a> +<span class="sourceLineNo">1349</span> serverLoad.setInfoServerPort(this.infoServer.getPort());<a name="line.1349"></a> +<span class="sourceLineNo">1350</span> } else {<a name="line.1350"></a> +<span class="sourceLineNo">1351</span> serverLoad.setInfoServerPort(-1);<a name="line.1351"></a> +<span class="sourceLineNo">1352</span> }<a name="line.1352"></a> +<span class="sourceLineNo">1353</span><a name="line.1353"></a> +<span class="sourceLineNo">1354</span> // for the replicationLoad purpose. Only need to get from one executorService<a name="line.1354"></a> +<span class="sourceLineNo">1355</span> // either source or sink will get the same info<a name="line.1355"></a> +<span class="sourceLineNo">1356</span> ReplicationSourceService rsources = getReplicationSourceService();<a name="line.1356"></a> +<span class="sourceLineNo">1357</span><a name="line.1357"></a> +<span class="sourceLineNo">1358</span> if (rsources != null) {<a name="line.1358"></a> +<span class="sourceLineNo">1359</span> // always refresh first to get the latest value<a name="line.1359"></a> +<span class="sourceLineNo">1360</span> ReplicationLoad rLoad = rsources.refreshAndGetReplicationLoad();<a name="line.1360"></a> +<span class="sourceLineNo">1361</span> if (rLoad != null) {<a name="line.1361"></a> +<span class="sourceLineNo">1362</span> serverLoad.setReplLoadSink(rLoad.getReplicationLoadSink());<a name="line.1362"></a> +<span class="sourceLineNo">1363</span> for (ClusterStatusProtos.ReplicationLoadSource rLS : rLoad.getReplicationLoadSourceList()) {<a name="line.1363"></a> +<span class="sourceLineNo">1364</span> serverLoad.addReplLoadSource(rLS);<a name="line.1364"></a> +<span class="sourceLineNo">1365</span> }<a name="line.1365"></a> +<span class="sourceLineNo">1366</span> }<a name="line.1366"></a> +<span class="sourceLineNo">1367</span> }<a name="line.1367"></a> +<span class="sourceLineNo">1368</span><a name="line.1368"></a> +<span class="sourceLineNo">1369</span> return serverLoad.build();<a name="line.1369"></a> +<span class="sourceLineNo">1370</span> }<a name="line.1370"></a> +<span class="sourceLineNo">1371</span><a name="line.1371"></a> +<span class="sourceLineNo">1372</span> String getOnlineRegionsAsPrintableString() {<a name="line.1372"></a> +<span class="sourceLineNo">1373</span> StringBuilder sb = new StringBuilder();<a name="line.1373"></a> +<span class="sourceLineNo">1374</span> for (Region r: this.onlineRegions.values()) {<a name="line.1374"></a> +<span class="sourceLineNo">1375</span> if (sb.length() > 0) sb.append(", ");<a name="line.1375"></a> +<span class="sourceLineNo">1376</span> sb.append(r.getRegionInfo().getEncodedName());<a name="line.1376"></a> +<span class="sourceLineNo">1377</span> }<a name="line.1377"></a> +<span class="sourceLineNo">1378</span> return sb.toString();<a name="line.1378"></a> +<span class="sourceLineNo">1379</span> }<a name="line.1379"></a> +<span class="sourceLineNo">1380</span><a name="line.1380"></a> +<span class="sourceLineNo">1381</span> /**<a name="line.1381"></a> +<span class="sourceLineNo">1382</span> * Wait on regions close.<a name="line.1382"></a> +<span class="sourceLineNo">1383</span> */<a name="line.1383"></a> +<span class="sourceLineNo">1384</span> private void waitOnAllRegionsToClose(final boolean abort) {<a name="line.1384"></a> +<span class="sourceLineNo">1385</span> // Wait till all regions are closed before going out.<a name="line.1385"></a> +<span class="sourceLineNo">1386</span> int lastCount = -1;<a name="line.1386"></a> +<span class="sourceLineNo">1387</span> long previousLogTime = 0;<a name="line.1387"></a> +<span class="sourceLineNo">1388</span> Set<String> closedRegions = new HashSet<>();<a name="line.1388"></a> +<span class="sourceLineNo">1389</span> boolean interrupted = false;<a name="line.1389"></a> +<span class="sourceLineNo">1390</span> try {<a name="line.1390"></a> +<span class="sourceLineNo">1391</span> while (!isOnlineRegionsEmpty()) {<a name="line.1391"></a> +<span class="sourceLineNo">1392</span> int count = getNumberOfOnlineRegions();<a name="line.1392"></a> +<span class="sourceLineNo">1393</span> // Only print a message if the count of regions has changed.<a name="line.1393"></a> +<span class="sourceLineNo">1394</span> if (count != lastCount) {<a name="line.1394"></a> +<span class="sourceLineNo">1395</span> // Log every second at most<a name="line.1395"></a> +<span class="sourceLineNo">1396</span> if (System.currentTimeMillis() > (previousLogTime + 1000)) {<a name="line.1396"></a> +<span class="sourceLineNo">1397</span> previousLogTime = System.currentTimeMillis();<a name="line.1397"></a> +<span class="sourceLineNo">1398</span> lastCount = count;<a name="line.1398"></a> +<span class="sourceLineNo">1399</span> LOG.info("Waiting on " + count + " regions to close");<a name="line.1399"></a> +<span class="sourceLineNo">1400</span> // Only print out regions still closing if a small number else will<a name="line.1400"></a> +<span class="sourceLineNo">1401</span> // swamp the log.<a name="line.1401"></a> +<span class="sourceLineNo">1402</span> if (count < 10 && LOG.isDebugEnabled()) {<a name="line.1402"></a> +<span class="sourceLineNo">1403</span> LOG.debug("Online Regions=" + this.onlineRegions);<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> }<a name="line.1406"></a> +<span class="sourceLineNo">1407</span> // Ensure all user regions have been sent a close. Use this to<a name="line.1407"></a> +<span class="sourceLineNo">1408</span> // protect against the case where an open comes in after we start the<a name="line.1408"></a> +<span class="sourceLineNo">1409</span> // iterator of onlineRegions to close all user regions.<a name="line.1409"></a> +<span class="sourceLineNo">1410</span> for (Map.Entry<String, HRegion> e : this.onlineRegions.entrySet()) {<a name="line.1410"></a> +<span class="sourceLineNo">1411</span> RegionInfo hri = e.getValue().getRegionInfo();<a name="line.1411"></a> +<span class="sourceLineNo">1412</span> if (!this.regionsInTransitionInRS.containsKey(hri.getEncodedNameAsBytes()) &&<a name="line.1412"></a> +<span class="sourceLineNo">1413</span> !closedRegions.contains(hri.getEncodedName())) {<a name="line.1413"></a> +<span class="sourceLineNo">1414</span> closedRegions.add(hri.getEncodedName());<a name="line.1414"></a> +<span class="sourceLineNo">1415</span> // Don't update zk with this close transition; pass false.<a name="line.1415"></a> +<span class="sourceLineNo">1416</span> closeRegionIgnoreErrors(hri, abort);<a name="line.1416"></a> +<span class="sourceLineNo">1417</span> }<a name="line.1417"></a> +<span class="sourceLineNo">1418</span> }<a name="line.1418"></a> +<span class="sourceLineNo">1419</span> // No regions in RIT, we could stop waiting now.<a name="line.1419"></a> +<span class="sourceLineNo">1420</span> if (this.regionsInTransitionInRS.isEmpty()) {<a name="line.1420"></a> +<span class="sourceLineNo">1421</span> if (!isOnlineRegionsEmpty()) {<a name="line.1421"></a> +<span class="sourceLineNo">1422</span> LOG.info("We were exiting though online regions are not empty," +<a name="line.1422"></a> +<span class="sourceLineNo">1423</span> " because some regions failed closing");<a name="line.1423"></a> +<span class="sourceLineNo">1424</span> }<a name="line.1424"></a> +<span class="sourceLineNo">1425</span> break;<a name="line.1425"></a> +<span class="sourceLineNo">1426</span> }<a name="line.1426"></a> +<span class="sourceLineNo">1427</span> if (sleep(200)) {<a name="line.1427"></a> +<span class="sourceLineNo">1428</span> interrupted = true;<a name="line.1428"></a> +<span class="sourceLineNo">1429</span> }<a name="line.1429"></a> +<span class="sourceLineNo">1430</span> }<a name="line.1430"></a> +<span class="sourceLineNo">1431</span> } finally {<a name="line.1431"></a> +<span class="sourceLineNo">1432</span> if (interrupted) {<a name="line.1432"></a> +<span class="sourceLineNo">1433</span> Thread.currentThread().interrupt();<a name="line.1433"></a> +<span class="sourceLineNo">1434</span> }<a name="line.1434"></a> +<span class="sourceLineNo">1435</span> }<a name="line.1435"></a> +<span class="sourceLineNo">1436</span> }<a name="line.1436"></a> +<span class="sourceLineNo">1437</span><a name="line.1437"></a> +<span class="sourceLineNo">1438</span> private boolean sleep(long millis) {<a name="line.1438"></a> +<span class="sourceLineNo">1439</span> boolean interrupted = false;<a name="line.1439"></a> +<span class="sourceLineNo">1440</span> try {<a name="line.1440"></a> +<span class="sourceLineNo">1441</span> Thread.sleep(millis);<a name="line.1441"></a> +<span class="sourceLineNo">1442</span> } catch (InterruptedException e) {<a name="line.1442"></a> +<span class="sourceLineNo">1443</span> LOG.warn("Interrupted while sleeping");<a name="line.1443"></a> +<span class="sourceLineNo">1444</span> interrupted = true;<a name="line.1444"></a> +<span class="sourceLineNo">1445</span> }<a name="line.1445"></a> +<span class="sourceLineNo">1446</span> return interrupted;<a name="line.1446"></a> +<span class="sourceLineNo">1447</span> }<a name="line.1447"></a> +<span class="sourceLineNo">1448</span><a name="line.1448"></a> +<span class="sourceLineNo">1449</span> private void shutdownWAL(final boolean close) {<a name="line.1449"></a> +<span class="sourceLineNo">1450</span> if (this.walFactory != null) {<a name="line.1450"></a> +<span class="sourceLineNo">1451</span> try {<a name="line.1451"></a> +<span class="sourceLineNo">1452</span> if (close) {<a name="line.1452"></a> +<span class="sourceLineNo">1453</span> walFactory.close();<a name="line.1453"></a> +<span class="sourceLineNo">1454</span> } else {<a name="line.1454"></a> +<span class="sourceLineNo">1455</span> walFactory.shutdown();<a name="line.1455"></a> +<span class="sourceLineNo">1456</span> }<a name="line.1456"></a> +<span class="sourceLineNo">1457</span> } catch (Throwable e) {<a name="line.1457"></a> +<span class="sourceLineNo">1458</span> e = e instanceof RemoteException ? ((RemoteException) e).unwrapRemoteException() : e;<a name="line.1458"></a> +<span class="sourceLineNo">1459</span> LOG.error("Shutdown / close of WAL failed: " + e);<a name="line.1459"></a> +<span class="sourceLineNo">1460</span> LOG.debug("Shutdown / close exception details:", e);<a name="line.1460"></a> +<span class="sourceLineNo">1461</span> }<a name="line.1461"></a> +<span class="sourceLineNo">1462</span> }<a name="line.1462"></a> +<span class="sourceLineNo">1463</span> }<a name="line.1463"></a> +<span class="sourceLineNo">1464</span><a name="line.1464"></a> +<span class="sourceLineNo">1465</span> /*<a name="line.1465"></a> +<span class="sourceLineNo">1466</span> * Run init. Sets up wal and starts up all server threads.<a name="line.1466"></a> +<span class="sourceLineNo">1467</span> *<a name="line.1467"></a> +<span class="sourceLineNo">1468</span> * @param c Extra configuration.<a name="line.1468"></a> +<span class="sourceLineNo">1469</span> */<a name="line.1469"></a> +<span class="sourceLineNo">1470</span> protected void handleReportForDutyResponse(final RegionServerStartupResponse c)<a name="line.1470"></a> +<span class="sourceLineNo">1471</span> throws IOException {<a name="line.1471"></a> +<span class="sourceLineNo">1472</span> try {<a name="line.1472"></a> +<span class="sourceLineNo">1473</span> boolean updateRootDir = false;<a name="line.1473"></a> +<span class="sourceLineNo">1474</span> for (NameStringPair e : c.getMapEntriesList()) {<a name="line.1474"></a> +<span class="sourceLineNo">1475</span> String key = e.getName();<a name="line.1475"></a> +<span class="sourceLineNo">1476</span> // The hostname the master sees us as.<a name="line.1476"></a> +<span class="sourceLineNo">1477</span> if (key.equals(HConstants.KEY_FOR_HOSTNAME_SEEN_BY_MASTER)) {<a name="line.1477"></a> +<span class="sourceLineNo">1478</span> String hostnameFromMasterPOV = e.getValue();<a name="line.1478"></a> +<span class="sourceLineNo">1479</span> this.serverName = ServerName.valueOf(hostnameFromMasterPOV, rpcServices.isa.getPort(),<a name="line.1479"></a> +<span class="sourceLineNo">1480</span> this.startcode);<a name="line.1480"></a> +<span class="sourceLineNo">1481</span> if (!StringUtils.isBlank(useThisHostnameInstead) &&<a name="line.1481"></a> +<span class="sourceLineNo">1482</span> !hostnameFromMasterPOV.equals(useThisHostnameInstead)) {<a name="line.1482"></a> +<span class="sourceLineNo">1483</span> String msg = "Master passed us a different hostname to use; was=" +<a name="line.1483"></a> +<span class="sourceLineNo">1484</span> this.useThisHostnameInstead + ", but now=" + hostnameFromMasterPOV;<a name="line.1484"></a> +<span class="sourceLineNo">1485</span> LOG.error(msg);<a name="line.1485"></a> +<span class="sourceLineNo">1486</span> throw new IOException(msg);<a name="line.1486"></a> +<span class="sourceLineNo">1487</span> }<a name="line.1487"></a> +<span class="sourceLineNo">1488</span> if (StringUtils.isBlank(useThisHostnameInstead) &&<a name="line.1488"></a> +<span class="sourceLineNo">1489</span> !hostnameFromMasterPOV.equals(rpcServices.isa.getHostName())) {<a name="line.1489"></a> +<span class="sourceLineNo">1490</span> String msg = "Master passed us a different hostname to use; was=" +<a name="line.1490"></a> +<span class="sourceLineNo">1491</span> rpcServices.isa.getHostName() + ", but now=" + hostnameFromMasterPOV;<a name="line.1491"></a> +<span class="sourceLineNo">1492</span> LOG.error(msg);<a name="line.1492"></a> +<span class="sourceLineNo">1493</span> }<a name="line.1493"></a> +<span class="sourceLineNo">1494</span> continue;<a name="line.1494"></a> +<span class="sourceLineNo">1495</span> }<a name="line.1495"></a> +<span class="sourceLineNo">1496</span><a name="line.1496"></a> +<span class="sourceLineNo">1497</span> String value = e.getValue();<a name="line.1497"></a> +<span class="sourceLineNo">1498</span> if (key.equals(HConstants.HBASE_DIR)) {<a name="line.1498"></a> +<span class="sourceLineNo">1499</span> if (value != null && !value.equals(conf.get(HConstants.HBASE_DIR))) {<a name="line.1499"></a> +<span class="sourceLineNo">1500</span> updateRootDir = true;<a name="line.1500"></a> +<span class="sourceLineNo">1501</span> }<a name="line.1501"></a> +<span class="sourceLineNo">1502</span> }<a name="line.1502"></a> +<span class="sourceLineNo">1503</span><a name="line.1503"></a> +<span class="sourceLineNo">1504</span> if (LOG.isDebugEnabled()) {<a name="line.1504"></a> +<span class="sourceLineNo">1505</span> LOG.debug("Config from master: " + key + "=" + value);<a name="line.1505"></a> +<span class="sourceLineNo">1506</span> }<a name="line.1506"></a> +<span class="sourceLineNo">1507</span> this.conf.set(key, value);<a name="line.1507"></a> +<span class="sourceLineNo">1508</span> }<a name="line.1508"></a> +<span class="sourceLineNo">1509</span> // Set our ephemeral znode up in zookeeper now we have a name.<a name="line.1509"></a> +<span class="sourceLineNo">1510</span> createMyEphemeralNode();<a name="line.1510"></a> +<span class="sourceLineNo">1511</span><a name="line.1511"></a> +<span class="sourceLineNo">1512</span> if (updateRootDir) {<a name="line.1512"></a> +<span class="sourceLineNo">1513</span> // initialize file system by the config fs.defaultFS and hbase.rootdir from master<a name="line.1513"></a> +<span class="sourceLineNo">1514</span> initializeFileSystem();<a name="line.1514"></a> +<span class="sourceLineNo">1515</span> }<a name="line.1515"></a> +<span class="sourceLineNo">1516</span><a name="line.1516"></a> +<span class="sourceLineNo">1517</span> // hack! Maps DFSClient => RegionServer for logs. HDFS made this<a name="line.1517"></a> +<span class="sourceLineNo">1518</span> // config param for task trackers, but we can piggyback off of it.<a name="line.1518"></a> +<span class="sourceLineNo">1519</span> if (this.conf.get("mapreduce.task.attempt.id") == null) {<a name="line.1519"></a> +<span class="sourceLineNo">1520</span> this.conf.set("mapreduce.task.attempt.id", "hb_rs_" + this.serverName.toString());<a name="line.1520"></a> +<span class="sourceLineNo">1521</span> }<a name="line.1521"></a> +<span class="sourceLineNo">1522</span><a name="line.1522"></a> +<span class="sourceLineNo">1523</span> // Save it in a file, this will allow to see if we crash<a name="line.1523"></a> +<span class="sourceLineNo">1524</span> ZNodeClearer.writeMyEphemeralNodeOnDisk(getMyEphemeralNodePath());<a name="line.1524"></a> +<span class="sourceLineNo">1525</span><a name="line.1525"></a> +<span class="sourceLineNo">1526</span> // This call sets up an initialized replication and WAL. Later we start it up.<a name="line.1526"></a> +<span class="sourceLineNo">1527</span> setupWALAndReplication();<a name="line.1527"></a> +<span class="sourceLineNo">1528</span> // Init in here rather than in constructor after thread name has been set<a name="line.1528"></a> +<span class="sourceLineNo">1529</span> this.metricsRegionServer = new MetricsRegionServer(<a name="line.1529"></a> +<span class="sourceLineNo">1530</span> new MetricsRegionServerWrapperImpl(this), conf);<a name="line.1530"></a> +<span class="sourceLineNo">1531</span> this.metricsTable = new MetricsTable(new MetricsTableWrapperAggregateImpl(this));<a name="line.1531"></a> +<span class="sourceLineNo">1532</span> // Now that we have a metrics source, start the pause monitor<a name="line.1532"></a> +<span class="sourceLineNo">1533</span> this.pauseMonitor = new JvmPauseMonitor(conf, getMetrics().getMetricsSource());<a name="line.1533"></a> +<span class="sourceLineNo">1534</span> pauseMonitor.start();<a name="line.1534"></a> +<span class="sourceLineNo">1535</span><a name="line.1535"></a> +<span class="sourceLineNo">1536</span> // There is a rare case where we do NOT want services to start. Check config.<a name="line.1536"></a> +<span class="sourceLineNo">1537</span> if (getConfiguration().getBoolean("hbase.regionserver.workers", true)) {<a name="line.1537"></a> +<span class="sourceLineNo">1538</span> startServices();<a name="line.1538"></a> +<span class="sourceLineNo">1539</span> }<a name="line.1539"></a> +<span class="sourceLineNo">1540</span> // In here we start up the replication Service. Above we initialized it. TODO. Reconcile.<a name="line.1540"></a> +<span class="sourceLineNo">1541</span> // or make sense of it.<a name="line.1541"></a> +<span class="sourceLineNo">1542</span> startReplicationService();<a name="line.1542"></a> +<span class="sourceLineNo">1543</span><a name="line.1543"></a> <span class="sourceLineNo">1544</span><a name="line.1544"></a> -<span class="sourceLineNo">1545</span><a name="line.1545"></a> -<span class="sourceLineNo">1546</span> // Set up ZK<a name="line.1546"></a> -<span class="sourceLineNo">1547</span> LOG.info("Serving as " + this.serverName + ", RpcServer on " + rpcServices.isa +<a name="line.1547"></a> -<span class="sourceLineNo">1548</span> ", sessionid=0x" +<a name="line.1548"></a> -<span class="sourceLineNo">1549</span> Long.toHexString(this.zooKeeper.getRecoverableZooKeeper().getSessionId()));<a name="line.1549"></a> -<span class="sourceLineNo">1550</span><a name="line.1550"></a> -<span class="sourceLineNo">1551</span> // Wake up anyone waiting for this server to online<a name="line.1551"></a> -<span class="sourceLineNo">1552</span> synchronized (online) {<a name="line.1552"></a> -<span class="sourceLineNo">1553</span> online.set(true);<a name="line.1553"></a> -<span class="sourceLineNo">1554</span> online.notifyAll();<a name="line.1554"></a> -<span class="sourceLineNo">1555</span> }<a name="line.1555"></a> -<span class="sourceLineNo">1556</span> } catch (Throwable e) {<a name="line.1556"></a> -<span class="sourceLineNo">1557</span> stop("Failed initialization");<a name="line.1557"></a> -<span class="sourceLineNo">1558</span> throw convertThrowableToIOE(cleanup(e, "Failed init"),<a name="line.1558"></a> -<span class="sourceLineNo">1559</span> "Region server startup failed");<a name="line.1559"></a> -<span class="sourceLineNo">1560</span> } finally {<a name="line.1560"></a> -<span class="sourceLineNo">1561</span> sleeper.skipSleepCycle();<a name="line.1561"></a> -<span class="sourceLineNo">1562</span> }<a name="line.1562"></a> -<span class="sourceLineNo">1563</span> }<a name="line.1563"></a> -<span class="sourceLineNo">1564</span><a name="line.1564"></a> -<span class="sourceLineNo">1565</span> protected void initializeMemStoreChunkCreator() {<a name="line.1565"></a> -<span class="sourceLineNo">1566</span> if (MemStoreLAB.isEnabled(conf)) {<a name="line.1566"></a> -<span class="sourceLineNo">1567</span> // MSLAB is enabled. So initialize MemStoreChunkPool<a name="line.1567"></a> -<span class="sourceLineNo">1568</span> // By this time, the MemstoreFlusher is already initialized. We can get the global limits from<a name="line.1568"></a> -<span class="sourceLineNo">1569</span> // it.<a name="line.1569"></a> -<span class="sourceLineNo">1570</span> Pair<Long, MemoryType> pair = MemorySizeUtil.getGlobalMemStoreSize(conf);<a name="line.1570"></a> -<span class="sourceLineNo">1571</span> long globalMemStoreSize = pair.getFirst();<a name="line.1571"></a> -<span class="sourceLineNo">1572</span> boolean offheap = this.regionServerAccounting.isOffheap();<a name="line.1572"></a> -<span class="sourceLineNo">1573</span> // When off heap memstore in use, take full area for chunk pool.<a name="line.1573"></a> -<span class="sourceLineNo">1574</span> float poolSizePercentage = offheap? 1.0F:<a name="line.1574"></a> -<span class="sourceLineNo">1575</span> conf.getFloat(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, MemStoreLAB.POOL_MAX_SIZE_DEFAULT);<a name="line.1575"></a> -<span class="sourceLineNo">1576</span> float initialCountPercentage = conf.getFloat(MemStoreLAB.CHUNK_POOL_INITIALSIZE_KEY,<a name="line.1576"></a> -<span class="sourceLineNo">1577</span> MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT);<a name="line.1577"></a> -<span class="sourceLineNo">1578</span> int chunkSize = conf.getInt(MemStoreLAB.CHUNK_SIZE_KEY, MemStoreLAB.CHUNK_SIZE_DEFAULT);<a name="line.1578"></a> -<span class="sourceLineNo">1579</span> // init the chunkCreator<a name="line.1579"></a> -<span class="sourceLineNo">1580</span> ChunkCreator chunkCreator =<a name="line.1580"></a> -<span class="sourceLineNo">1581</span> ChunkCreator.initialize(chunkSize, offheap, globalMemStoreSize, poolSizePercentage,<a name="line.1581"></a> -<span class="sourceLineNo">1582</span> initialCountPercentage, this.hMemManager);<a name="line.1582"></a> -<span class="sourceLineNo">1583</span> }<a name="line.1583"></a> -<span class="sourceLineNo">1584</span> }<a name="line.1584"></a> -<span class="sourceLineNo">1585</span><a name="line.1585"></a> -<span class="sourceLineNo">1586</span> private void startHeapMemoryManager() {<a name="line.1586"></a> -<span class="sourceLineNo">1587</span> this.hMemManager = HeapMemoryManager.create(this.conf, this.cacheFlusher, this,<a name="line.1587"></a> -<span class="sourceLineNo">1588</span> this.regionServerAccounting);<a name="line.1588"></a> -<span class="sourceLineNo">1589</span> if (this.hMemManager != null) {<a name="line.1589"></a> -<span class="sourceLineNo">1590</span> this.hMemManager.start(getChoreService());<a name="line.1590"></a> -<span class="sourceLineNo">1591</span> }<a name="line.1591"></a> -<span class="sourceLineNo">1592</span> }<a name="line.1592"></a> -<span class="sourceLineNo">1593</span><a name="line.1593"></a> -<span class="sourceLineNo">1594</span> private void createMyEphemeralNode() throws KeeperException, IOException {<a name="line.1594"></a> -<span class="sourceLineNo">1595</span> RegionServerInfo.Builder rsInfo = RegionServerInfo.newBuilder();<a name="line.1595"></a> -<span class="sourceLineNo">1596</span> rsInfo.setInfoPort(infoServer != null ? infoServer.getPort() : -1);<a name="line.1596"></a> -<span class="sourceLineNo">1597</span> rsInfo.setVersionInfo(ProtobufUtil.getVersionInfo());<a name="line.1597"></a> -<span class="sourceLineNo">1598</span> byte[] data = ProtobufUtil.prependPBMagic(rsInfo.build().toByteArray());<a name="line.1598"></a> -<span class="sourceLineNo">1599</span> ZKUtil.createEphemeralNodeAndWatch(this.zooKeeper, getMyEphemeralNodePath(), data);<a name="line.1599"></a> -<span class="sourceLineNo">1600</span> }<a name="line.1600"></a> -<span class="sourceLineNo">1601</span><a name="line.1601"></a> -<span class="sourceLineNo">1602</span> private void deleteMyEphemeralNode() throws KeeperException {<a name="line.1602"></a> -<span class="sourceLineNo">1603</span> ZKUtil.deleteNode(this.zooKeeper, getMyEphemeralNodePath());<a name="line.1603"></a> -<span class="sourceLineNo">1604</span> }<a name="line.1604"></a> -<span class="sourceLineNo">1605</span><a name="line.1605"></a> -<span class="sourceLineNo">1606</span> @Override<a name="line.1606"></a> -<span class="sourceLineNo">1607</span> public RegionServerAccounting getRegionServerAccounting() {<a name="line.1607"></a> -<span class="sourceLineNo">1608</span> return regionServerAccounting;<a name="line.1608"></a> -<span class="sourceLineNo">1609</span> }<a name="line.1609"></a> -<span class="sourceLineNo">1610</span><a name="line.1610"></a> -<span class="sourceLineNo">1611</span> /*<a name="line.1611"></a> -<span class="sourceLineNo">1612</span> * @param r Region to get RegionLoad for.<a name="line.1612"></a> -<span class="sourceLineNo">1613</span> * @param regionLoadBldr the RegionLoad.Builder, can be null<a name="line.1613"></a> -<span class="sourceLineNo">1614</span> * @param regionSpecifier the RegionSpecifier.Builder, can be null<a name="line.1614"></a> -<span class="sourceLineNo">1615</span> * @return RegionLoad instance.<a name="line.1615"></a> -<span class="sourceLineNo">1616</span> *<a name="line.1616"></a> -<span class="sourceLineNo">1617</span> * @throws IOException<a name="line.1617"></a> -<span class="sourceLineNo">1618</span> */<a name="line.1618"></a> -<span class="sourceLineNo">1619</span> RegionLoad createRegionLoad(final HRegion r, RegionLoad.Builder regionLoadBldr,<a name="line.1619"></a> -<span class="sourceLineNo">1620</span> RegionSpecifier.Builder regionSpecifier) throws IOException {<a name="line.1620"></a> -<span class="sourceLineNo">1621</span> byte[] name = r.getRegionInfo().getRegionName();<a name="line.1621"></a> -<span class="sourceLineNo">1622</span> int stores = 0;<a name="line.1622"></a> -<span class="sourceLineNo">1623</span> int storefiles = 0;<a name="line.1623"></a> -<span class="sourceLineNo">1624</span> int storeUncompressedSizeMB = 0;<a name="line.1624"></a> -<span class="sourceLineNo">1625</span> int storefileSizeMB = 0;<a name="line.1625"></a> -<span class="sourceLineNo">1626</span> int memstoreSizeMB = (int) (r.getMemStoreDataSize() / 1024 / 1024);<a name="line.1626"></a> -<span class="sourceLineNo">1627</span> long storefileIndexSizeKB = 0;<a name="line.1627"></a> -<span class="sourceLineNo">1628</span> int rootLevelIndexSizeKB = 0;<a name="line.1628"></a> -<span class="sourceLineNo">1629</span> int totalStaticIndexSizeKB = 0;<a name="line.1629"></a> -<span class="sourceLineNo">1630</span> int totalStaticBloomSizeKB = 0;<a name="line.1630"></a> -<span class="sourceLineNo">1631</span> long totalCompactingKVs = 0;<a name="line.1631"></a> -<span class="sourceLineNo">1632</span> long currentCompactedKVs = 0;<a name="line.1632"></a> -<span class="sourceLineNo">1633</span> List<HStore> storeList = r.getStores();<a name="line.1633"></a> -<span class="sourceLineNo">1634</span> stores += storeList.size();<a name="line.1634"></a> -<span class="sourceLineNo">1635</span> for (HStore store : storeList) {<a name="line.1635"></a> -<span class="sourceLineNo">1636</span> storefiles += store.getStorefilesCount();<a name="line.1636"></a> -<span class="sourceLineNo">1637</span> storeUncompressedSizeMB += (int) (store.getStoreSizeUncompressed() / 1024 / 1024);<a name="line.1637"></a> -<span class="sourceLineNo">1638</span> storefileSizeMB += (int) (store.getStorefilesSize() / 1024 / 1024);<a name="line.1638"></a> -<span class="sourceLineNo">1639</span> //TODO: storefileIndexSizeKB is same with rootLevelIndexSizeKB?<a name="line.1639"></a> -<span class="sourceLineNo">1640</span> storefileIndexSizeKB += store.getStorefilesRootLevelIndexSize() / 1024;<a name="line.1640"></a> -<span class="sourceLineNo">1641</span> CompactionProgress progress = store.getCompactionProgress();<a name="line.1641"></a> -<span class="sourceLineNo">1642</span> if (progress != null) {<a name="line.1642"></a> -<span class="sourceLineNo">1643</span> totalCompactingKVs += progress.getTotalCompactingKVs();<a name="line.1643"></a> -<span class="sourceLineNo">1644</span> currentCompactedKVs += progress.currentCompactedKVs;<a name="line.1644"></a> -<span class="sourceLineNo">1645</span> }<a name="line.1645"></a> -<span class="sourceLineNo">1646</span> rootLevelIndexSizeKB += (int) (store.getStorefilesRootLevelIndexSize() / 1024);<a name="line.1646"></a> -<span class="sourceLineNo">1647</span> totalStaticIndexSizeKB += (int) (store.getTotalStaticIndexSize() / 1024);<a name="line.1647"></a> -<span class="sourceLineNo">1648</span> totalStaticBloomSizeKB += (int) (store.getTotalStaticBloomSize() / 1024);<a name="line.1648"></a> -<span class="sourceLineNo">1649</span> }<a name="line.1649"></a> -<span class="sourceLineNo">1650</span><a name="line.1650"></a> -<span class="sourceLineNo">1651</span> float dataLocality =<a name="line.1651"></a> -<span class="sourceLineNo">1652</span> r.getHDFSBlocksDistribution().getBlockLocalityIndex(serverName.getHostname());<a name="line.1652"></a> -<span class="sourceLineNo">1653</span> if (regionLoadBldr == null) {<a name="line.1653"></a> -<span class="sourceLineNo">1654</span> regionLoadBldr = RegionLoad.newBuilder();<a name="line.1654"></a> -<span class="sourceLineNo">1655</span> }<a name="line.1655"></a> -<span class="sourceLineNo">1656</span> if (regionSpecifier == null) {<a name="line.1656"></a> -<span class="sourceLineNo">1657</span> regionSpecifier = RegionSpecifier.newBuilder();<a name="line.1657"></a> -<span class="sourceLineNo">1658</span> }<a name="line.1658"></a> -<span class="sourceLineNo">1659</span> regionSpecifier.setType(RegionSpecifierType.REGION_NAME);<a name="line.1659"></a> -<span class="sourceLineNo">1660</span> regionSpecifier.setValue(UnsafeByteOperations.unsafeWrap(name));<a name="line.1660"></a> -<span class="sourceLineNo">1661</span> regionLoadBldr.setRegionSpecifier(regionSpecifier.build())<a name="line.1661"></a> -<span class="sourceLineNo">1662</span> .setStores(stores)<a name="line.1662"></a> -<span class="sourceLineNo">1663</span> .setStorefiles(storefiles)<a name="line.1663"></a> -<span class="sourceLineNo">1664</span> .setStoreUncompressedSizeMB(storeUncompressedSizeMB)<a name="line.1664"></a> -<span class="sourceLineNo">1665</span> .setStorefileSizeMB(storefileSizeMB)<a name="line.1665"></a> -<span class="sourceLineNo">1666</span> .setMemStoreSizeMB(memstoreSizeMB)<a name="line.1666"></a> -<span class="sourceLineNo">1667</span> .setStorefileIndexSizeKB(storefileIndexSizeKB)<a name="line.1667"></a> -<span class="sourceLineNo">1668</span> .setRootIndexSizeKB(rootLevelIndexSizeKB)<a name="line.1668"></a> -<span class="sourceLineNo">1669</span> .setTotalStaticIndexSizeKB(totalStaticIndexSizeKB)<a name="line.1669"></a> -<span class="sourceLineNo">1670</span> .setTotalStaticBloomSizeKB(totalStaticBloomSizeKB)<a name="line.1670"></a> -<span class="sourceLineNo">1671</span> .setReadRequestsCount(r.getReadRequestsCount())<a name="line.1671"></a> -<span class="sourceLineNo">1672</span> .setFilteredReadRequestsCount(r.getFilteredReadRequestsCount())<a name="line.1672"></a> -<span class="sourceLineNo">1673</span> .setWriteRequestsCount(r.getWriteRequestsCount())<a name="line.1673"></a> -<span class="sourceLineNo">1674</span> .setTotalCompactingKVs(totalCompactingKVs)<a name="line.1674"></a> -<span class="sourceLineNo">1675</span> .setCurrentCompactedKVs(currentCompactedKVs)<a name="line.1675"></a> -<span class="sourceLineNo">1676</span> .setDataLocality(dataLocality)<a name="line.1676"></a> -<span class="sourceLineNo">1677</span> .setLastMajorCompactionTs(r.getOldestHfileTs(true));<a name="line.1677"></a> -<span class="sourceLineNo">1678</span> r.setCompleteSequenceId(regionLoadBldr);<a name="line.1678"></a> -<span class="sourceLineNo">1679</span><a name="line.1679"></a> -<span class="sourceLineNo">1680</span> return regionLoadBldr.build();<a name="line.1680"></a> -<span class="sourceLineNo">1681</span> }<a name="line.1681"></a> -<span class="sourceLineNo">1682</span><a name="line.1682"></a> -<span class="sourceLineNo">1683</span> /**<a name="line.1683"></a> -<span class="sourceLineNo">1684</span> * @param encodedRegionName<a name="line.1684"></a> -<span class="sourceLineNo">1685</span> * @return An instance of RegionLoad.<a name="line.1685"></a> -<span class="sourceLineNo">1686</span> */<a name="line.1686"></a> -<span class="sourceLineNo">1687</span> public RegionLoad createRegionLoad(final String encodedRegionName) throws IOException {<a name="line.1687"></a> -<span class="sourceLineNo">1688</span> HRegion r = onlineRegions.get(encodedRegionName);<a name="line.1688"></a> -<span
<TRUNCATED>