hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [19/51] [partial] hbase-site git commit: Published site at 021f66d11d2cbb7308308093e29e69d6e7661ee9.
Date Sat, 12 May 2018 14:48:03 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/92a26cfb/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html
index 4a879bb..7d27402 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html
@@ -300,7 +300,7 @@
 <span class="sourceLineNo">292</span>  private Map&lt;String, com.google.protobuf.Service&gt; coprocessorServiceHandlers = Maps.newHashMap();<a name="line.292"></a>
 <span class="sourceLineNo">293</span><a name="line.293"></a>
 <span class="sourceLineNo">294</span>  // Track data size in all memstores<a name="line.294"></a>
-<span class="sourceLineNo">295</span>  private final MemStoreSizing memStoreSize = new MemStoreSizing();<a name="line.295"></a>
+<span class="sourceLineNo">295</span>  private final MemStoreSizing memStoreSizing = new ThreadSafeMemStoreSizing();<a name="line.295"></a>
 <span class="sourceLineNo">296</span>  private final RegionServicesForStores regionServicesForStores = new RegionServicesForStores(this);<a name="line.296"></a>
 <span class="sourceLineNo">297</span><a name="line.297"></a>
 <span class="sourceLineNo">298</span>  // Debug possible data loss due to WAL off<a name="line.298"></a>
@@ -1218,7389 +1218,7399 @@
 <span class="sourceLineNo">1210</span>   * Increase the size of mem store in this region and the size of global mem<a name="line.1210"></a>
 <span class="sourceLineNo">1211</span>   * store<a name="line.1211"></a>
 <span class="sourceLineNo">1212</span>   */<a name="line.1212"></a>
-<span class="sourceLineNo">1213</span>  public void incMemStoreSize(MemStoreSize memStoreSize) {<a name="line.1213"></a>
-<span class="sourceLineNo">1214</span>    if (this.rsAccounting != null) {<a name="line.1214"></a>
-<span class="sourceLineNo">1215</span>      rsAccounting.incGlobalMemStoreSize(memStoreSize);<a name="line.1215"></a>
-<span class="sourceLineNo">1216</span>    }<a name="line.1216"></a>
-<span class="sourceLineNo">1217</span>    long dataSize;<a name="line.1217"></a>
-<span class="sourceLineNo">1218</span>    synchronized (this.memStoreSize) {<a name="line.1218"></a>
-<span class="sourceLineNo">1219</span>      this.memStoreSize.incMemStoreSize(memStoreSize);<a name="line.1219"></a>
-<span class="sourceLineNo">1220</span>      dataSize = this.memStoreSize.getDataSize();<a name="line.1220"></a>
-<span class="sourceLineNo">1221</span>    }<a name="line.1221"></a>
-<span class="sourceLineNo">1222</span>    checkNegativeMemStoreDataSize(dataSize, memStoreSize.getDataSize());<a name="line.1222"></a>
-<span class="sourceLineNo">1223</span>  }<a name="line.1223"></a>
-<span class="sourceLineNo">1224</span><a name="line.1224"></a>
-<span class="sourceLineNo">1225</span>  public void decrMemStoreSize(MemStoreSize memStoreSize) {<a name="line.1225"></a>
-<span class="sourceLineNo">1226</span>    if (this.rsAccounting != null) {<a name="line.1226"></a>
-<span class="sourceLineNo">1227</span>      rsAccounting.decGlobalMemStoreSize(memStoreSize);<a name="line.1227"></a>
-<span class="sourceLineNo">1228</span>    }<a name="line.1228"></a>
-<span class="sourceLineNo">1229</span>    long size;<a name="line.1229"></a>
-<span class="sourceLineNo">1230</span>    synchronized (this.memStoreSize) {<a name="line.1230"></a>
-<span class="sourceLineNo">1231</span>      this.memStoreSize.decMemStoreSize(memStoreSize);<a name="line.1231"></a>
-<span class="sourceLineNo">1232</span>      size = this.memStoreSize.getDataSize();<a name="line.1232"></a>
+<span class="sourceLineNo">1213</span>  void incMemStoreSize(MemStoreSize mss) {<a name="line.1213"></a>
+<span class="sourceLineNo">1214</span>    incMemStoreSize(mss.getDataSize(), mss.getHeapSize(), mss.getOffHeapSize());<a name="line.1214"></a>
+<span class="sourceLineNo">1215</span>  }<a name="line.1215"></a>
+<span class="sourceLineNo">1216</span><a name="line.1216"></a>
+<span class="sourceLineNo">1217</span>  void incMemStoreSize(long dataSizeDelta, long heapSizeDelta, long offHeapSizeDelta) {<a name="line.1217"></a>
+<span class="sourceLineNo">1218</span>    if (this.rsAccounting != null) {<a name="line.1218"></a>
+<span class="sourceLineNo">1219</span>      rsAccounting.incGlobalMemStoreSize(dataSizeDelta, heapSizeDelta, offHeapSizeDelta);<a name="line.1219"></a>
+<span class="sourceLineNo">1220</span>    }<a name="line.1220"></a>
+<span class="sourceLineNo">1221</span>    long dataSize =<a name="line.1221"></a>
+<span class="sourceLineNo">1222</span>        this.memStoreSizing.incMemStoreSize(dataSizeDelta, heapSizeDelta, offHeapSizeDelta);<a name="line.1222"></a>
+<span class="sourceLineNo">1223</span>    checkNegativeMemStoreDataSize(dataSize, dataSizeDelta);<a name="line.1223"></a>
+<span class="sourceLineNo">1224</span>  }<a name="line.1224"></a>
+<span class="sourceLineNo">1225</span><a name="line.1225"></a>
+<span class="sourceLineNo">1226</span>  void decrMemStoreSize(MemStoreSize mss) {<a name="line.1226"></a>
+<span class="sourceLineNo">1227</span>    decrMemStoreSize(mss.getDataSize(), mss.getHeapSize(), mss.getOffHeapSize());<a name="line.1227"></a>
+<span class="sourceLineNo">1228</span>  }<a name="line.1228"></a>
+<span class="sourceLineNo">1229</span><a name="line.1229"></a>
+<span class="sourceLineNo">1230</span>  void decrMemStoreSize(long dataSizeDelta, long heapSizeDelta, long offHeapSizeDelta) {<a name="line.1230"></a>
+<span class="sourceLineNo">1231</span>    if (this.rsAccounting != null) {<a name="line.1231"></a>
+<span class="sourceLineNo">1232</span>      rsAccounting.decGlobalMemStoreSize(dataSizeDelta, heapSizeDelta, offHeapSizeDelta);<a name="line.1232"></a>
 <span class="sourceLineNo">1233</span>    }<a name="line.1233"></a>
-<span class="sourceLineNo">1234</span>    checkNegativeMemStoreDataSize(size, -memStoreSize.getDataSize());<a name="line.1234"></a>
-<span class="sourceLineNo">1235</span>  }<a name="line.1235"></a>
-<span class="sourceLineNo">1236</span><a name="line.1236"></a>
-<span class="sourceLineNo">1237</span>  private void checkNegativeMemStoreDataSize(long memStoreDataSize, long delta) {<a name="line.1237"></a>
-<span class="sourceLineNo">1238</span>    // This is extremely bad if we make memStoreSize negative. Log as much info on the offending<a name="line.1238"></a>
-<span class="sourceLineNo">1239</span>    // caller as possible. (memStoreSize might be a negative value already -- freeing memory)<a name="line.1239"></a>
-<span class="sourceLineNo">1240</span>    if (memStoreDataSize &lt; 0) {<a name="line.1240"></a>
-<span class="sourceLineNo">1241</span>      LOG.error("Asked to modify this region's (" + this.toString()<a name="line.1241"></a>
-<span class="sourceLineNo">1242</span>          + ") memStoreSize to a negative value which is incorrect. Current memStoreSize="<a name="line.1242"></a>
-<span class="sourceLineNo">1243</span>          + (memStoreDataSize - delta) + ", delta=" + delta, new Exception());<a name="line.1243"></a>
-<span class="sourceLineNo">1244</span>    }<a name="line.1244"></a>
-<span class="sourceLineNo">1245</span>  }<a name="line.1245"></a>
-<span class="sourceLineNo">1246</span><a name="line.1246"></a>
-<span class="sourceLineNo">1247</span>  @Override<a name="line.1247"></a>
-<span class="sourceLineNo">1248</span>  public RegionInfo getRegionInfo() {<a name="line.1248"></a>
-<span class="sourceLineNo">1249</span>    return this.fs.getRegionInfo();<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>   * @return Instance of {@link RegionServerServices} used by this HRegion.<a name="line.1253"></a>
-<span class="sourceLineNo">1254</span>   * Can be null.<a name="line.1254"></a>
-<span class="sourceLineNo">1255</span>   */<a name="line.1255"></a>
-<span class="sourceLineNo">1256</span>  RegionServerServices getRegionServerServices() {<a name="line.1256"></a>
-<span class="sourceLineNo">1257</span>    return this.rsServices;<a name="line.1257"></a>
-<span class="sourceLineNo">1258</span>  }<a name="line.1258"></a>
-<span class="sourceLineNo">1259</span><a name="line.1259"></a>
-<span class="sourceLineNo">1260</span>  @Override<a name="line.1260"></a>
-<span class="sourceLineNo">1261</span>  public long getReadRequestsCount() {<a name="line.1261"></a>
-<span class="sourceLineNo">1262</span>    return readRequestsCount.sum();<a name="line.1262"></a>
-<span class="sourceLineNo">1263</span>  }<a name="line.1263"></a>
-<span class="sourceLineNo">1264</span><a name="line.1264"></a>
-<span class="sourceLineNo">1265</span>  @Override<a name="line.1265"></a>
-<span class="sourceLineNo">1266</span>  public long getFilteredReadRequestsCount() {<a name="line.1266"></a>
-<span class="sourceLineNo">1267</span>    return filteredReadRequestsCount.sum();<a name="line.1267"></a>
-<span class="sourceLineNo">1268</span>  }<a name="line.1268"></a>
-<span class="sourceLineNo">1269</span><a name="line.1269"></a>
-<span class="sourceLineNo">1270</span>  @Override<a name="line.1270"></a>
-<span class="sourceLineNo">1271</span>  public long getWriteRequestsCount() {<a name="line.1271"></a>
-<span class="sourceLineNo">1272</span>    return writeRequestsCount.sum();<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>  @Override<a name="line.1275"></a>
-<span class="sourceLineNo">1276</span>  public long getMemStoreDataSize() {<a name="line.1276"></a>
-<span class="sourceLineNo">1277</span>    return memStoreSize.getDataSize();<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>  }<a name="line.1278"></a>
-<span class="sourceLineNo">1279</span><a name="line.1279"></a>
-<span class="sourceLineNo">1280</span>  @Override<a name="line.1280"></a>
-<span class="sourceLineNo">1281</span>  public long getMemStoreHeapSize() {<a name="line.1281"></a>
-<span class="sourceLineNo">1282</span>    return memStoreSize.getHeapSize();<a name="line.1282"></a>
-<span class="sourceLineNo">1283</span>  }<a name="line.1283"></a>
-<span class="sourceLineNo">1284</span><a name="line.1284"></a>
-<span class="sourceLineNo">1285</span>  @Override<a name="line.1285"></a>
-<span class="sourceLineNo">1286</span>  public long getMemStoreOffHeapSize() {<a name="line.1286"></a>
-<span class="sourceLineNo">1287</span>    return memStoreSize.getOffHeapSize();<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 store services for this region, to access services required by store level needs */<a name="line.1290"></a>
-<span class="sourceLineNo">1291</span>  public RegionServicesForStores getRegionServicesForStores() {<a name="line.1291"></a>
-<span class="sourceLineNo">1292</span>    return regionServicesForStores;<a name="line.1292"></a>
-<span class="sourceLineNo">1293</span>  }<a name="line.1293"></a>
-<span class="sourceLineNo">1294</span><a name="line.1294"></a>
-<span class="sourceLineNo">1295</span>  @Override<a name="line.1295"></a>
-<span class="sourceLineNo">1296</span>  public long getNumMutationsWithoutWAL() {<a name="line.1296"></a>
-<span class="sourceLineNo">1297</span>    return numMutationsWithoutWAL.sum();<a name="line.1297"></a>
-<span class="sourceLineNo">1298</span>  }<a name="line.1298"></a>
-<span class="sourceLineNo">1299</span><a name="line.1299"></a>
-<span class="sourceLineNo">1300</span>  @Override<a name="line.1300"></a>
-<span class="sourceLineNo">1301</span>  public long getDataInMemoryWithoutWAL() {<a name="line.1301"></a>
-<span class="sourceLineNo">1302</span>    return dataInMemoryWithoutWAL.sum();<a name="line.1302"></a>
-<span class="sourceLineNo">1303</span>  }<a name="line.1303"></a>
-<span class="sourceLineNo">1304</span><a name="line.1304"></a>
-<span class="sourceLineNo">1305</span>  @Override<a name="line.1305"></a>
-<span class="sourceLineNo">1306</span>  public long getBlockedRequestsCount() {<a name="line.1306"></a>
-<span class="sourceLineNo">1307</span>    return blockedRequestsCount.sum();<a name="line.1307"></a>
-<span class="sourceLineNo">1308</span>  }<a name="line.1308"></a>
-<span class="sourceLineNo">1309</span><a name="line.1309"></a>
-<span class="sourceLineNo">1310</span>  @Override<a name="line.1310"></a>
-<span class="sourceLineNo">1311</span>  public long getCheckAndMutateChecksPassed() {<a name="line.1311"></a>
-<span class="sourceLineNo">1312</span>    return checkAndMutateChecksPassed.sum();<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<a name="line.1315"></a>
-<span class="sourceLineNo">1316</span>  public long getCheckAndMutateChecksFailed() {<a name="line.1316"></a>
-<span class="sourceLineNo">1317</span>    return checkAndMutateChecksFailed.sum();<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>  // TODO Needs to check whether we should expose our metrics system to CPs. If CPs themselves doing<a name="line.1320"></a>
-<span class="sourceLineNo">1321</span>  // the op and bypassing the core, this might be needed? Should be stop supporting the bypass<a name="line.1321"></a>
-<span class="sourceLineNo">1322</span>  // feature?<a name="line.1322"></a>
-<span class="sourceLineNo">1323</span>  public MetricsRegion getMetrics() {<a name="line.1323"></a>
-<span class="sourceLineNo">1324</span>    return metricsRegion;<a name="line.1324"></a>
-<span class="sourceLineNo">1325</span>  }<a name="line.1325"></a>
-<span class="sourceLineNo">1326</span><a name="line.1326"></a>
-<span class="sourceLineNo">1327</span>  @Override<a name="line.1327"></a>
-<span class="sourceLineNo">1328</span>  public boolean isClosed() {<a name="line.1328"></a>
-<span class="sourceLineNo">1329</span>    return this.closed.get();<a name="line.1329"></a>
-<span class="sourceLineNo">1330</span>  }<a name="line.1330"></a>
-<span class="sourceLineNo">1331</span><a name="line.1331"></a>
-<span class="sourceLineNo">1332</span>  @Override<a name="line.1332"></a>
-<span class="sourceLineNo">1333</span>  public boolean isClosing() {<a name="line.1333"></a>
-<span class="sourceLineNo">1334</span>    return this.closing.get();<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">1337</span>  @Override<a name="line.1337"></a>
-<span class="sourceLineNo">1338</span>  public boolean isReadOnly() {<a name="line.1338"></a>
-<span class="sourceLineNo">1339</span>    return this.writestate.isReadOnly();<a name="line.1339"></a>
-<span class="sourceLineNo">1340</span>  }<a name="line.1340"></a>
-<span class="sourceLineNo">1341</span><a name="line.1341"></a>
-<span class="sourceLineNo">1342</span>  @Override<a name="line.1342"></a>
-<span class="sourceLineNo">1343</span>  public boolean isAvailable() {<a name="line.1343"></a>
-<span class="sourceLineNo">1344</span>    return !isClosed() &amp;&amp; !isClosing();<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>  @Override<a name="line.1347"></a>
-<span class="sourceLineNo">1348</span>  public boolean isSplittable() {<a name="line.1348"></a>
-<span class="sourceLineNo">1349</span>    return isAvailable() &amp;&amp; !hasReferences();<a name="line.1349"></a>
-<span class="sourceLineNo">1350</span>  }<a name="line.1350"></a>
-<span class="sourceLineNo">1351</span><a name="line.1351"></a>
-<span class="sourceLineNo">1352</span>  @Override<a name="line.1352"></a>
-<span class="sourceLineNo">1353</span>  public boolean isMergeable() {<a name="line.1353"></a>
-<span class="sourceLineNo">1354</span>    if (!isAvailable()) {<a name="line.1354"></a>
-<span class="sourceLineNo">1355</span>      LOG.debug("Region " + this<a name="line.1355"></a>
-<span class="sourceLineNo">1356</span>          + " is not mergeable because it is closing or closed");<a name="line.1356"></a>
-<span class="sourceLineNo">1357</span>      return false;<a name="line.1357"></a>
-<span class="sourceLineNo">1358</span>    }<a name="line.1358"></a>
-<span class="sourceLineNo">1359</span>    if (hasReferences()) {<a name="line.1359"></a>
-<span class="sourceLineNo">1360</span>      LOG.debug("Region " + this<a name="line.1360"></a>
-<span class="sourceLineNo">1361</span>          + " is not mergeable because it has references");<a name="line.1361"></a>
-<span class="sourceLineNo">1362</span>      return false;<a name="line.1362"></a>
-<span class="sourceLineNo">1363</span>    }<a name="line.1363"></a>
-<span class="sourceLineNo">1364</span><a name="line.1364"></a>
-<span class="sourceLineNo">1365</span>    return true;<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>  public boolean areWritesEnabled() {<a name="line.1368"></a>
-<span class="sourceLineNo">1369</span>    synchronized(this.writestate) {<a name="line.1369"></a>
-<span class="sourceLineNo">1370</span>      return this.writestate.writesEnabled;<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><a name="line.1373"></a>
-<span class="sourceLineNo">1374</span>  @VisibleForTesting<a name="line.1374"></a>
-<span class="sourceLineNo">1375</span>  public MultiVersionConcurrencyControl getMVCC() {<a name="line.1375"></a>
-<span class="sourceLineNo">1376</span>    return mvcc;<a name="line.1376"></a>
-<span class="sourceLineNo">1377</span>  }<a name="line.1377"></a>
-<span class="sourceLineNo">1378</span><a name="line.1378"></a>
-<span class="sourceLineNo">1379</span>  @Override<a name="line.1379"></a>
-<span class="sourceLineNo">1380</span>  public long getMaxFlushedSeqId() {<a name="line.1380"></a>
-<span class="sourceLineNo">1381</span>    return maxFlushedSeqId;<a name="line.1381"></a>
-<span class="sourceLineNo">1382</span>  }<a name="line.1382"></a>
-<span class="sourceLineNo">1383</span><a name="line.1383"></a>
-<span class="sourceLineNo">1384</span>  /**<a name="line.1384"></a>
-<span class="sourceLineNo">1385</span>   * @return readpoint considering given IsolationLevel. Pass {@code null} for default<a name="line.1385"></a>
-<span class="sourceLineNo">1386</span>   */<a name="line.1386"></a>
-<span class="sourceLineNo">1387</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1387"></a>
-<span class="sourceLineNo">1388</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1388"></a>
-<span class="sourceLineNo">1389</span>      // This scan can read even uncommitted transactions<a name="line.1389"></a>
-<span class="sourceLineNo">1390</span>      return Long.MAX_VALUE;<a name="line.1390"></a>
-<span class="sourceLineNo">1391</span>    }<a name="line.1391"></a>
-<span class="sourceLineNo">1392</span>    return mvcc.getReadPoint();<a name="line.1392"></a>
-<span class="sourceLineNo">1393</span>  }<a name="line.1393"></a>
-<span class="sourceLineNo">1394</span><a name="line.1394"></a>
-<span class="sourceLineNo">1395</span>  public boolean isLoadingCfsOnDemandDefault() {<a name="line.1395"></a>
-<span class="sourceLineNo">1396</span>    return this.isLoadingCfsOnDemandDefault;<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>  /**<a name="line.1399"></a>
-<span class="sourceLineNo">1400</span>   * Close down this HRegion.  Flush the cache, shut down each HStore, don't<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>   * service any more calls.<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span>   *<a name="line.1402"></a>
-<span class="sourceLineNo">1403</span>   * &lt;p&gt;This method could take some time to execute, so don't call it from a<a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>   * time-sensitive thread.<a name="line.1404"></a>
-<span class="sourceLineNo">1405</span>   *<a name="line.1405"></a>
-<span class="sourceLineNo">1406</span>   * @return Vector of all the storage files that the HRegion's component<a name="line.1406"></a>
-<span class="sourceLineNo">1407</span>   * HStores make use of.  It's a list of all StoreFile objects. Returns empty<a name="line.1407"></a>
-<span class="sourceLineNo">1408</span>   * vector if already closed and null if judged that it should not close.<a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>   *<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span>   * @throws IOException e<a name="line.1410"></a>
-<span class="sourceLineNo">1411</span>   * @throws DroppedSnapshotException Thrown when replay of wal is required<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span>   * because a Snapshot was not properly persisted. The region is put in closing mode, and the<a name="line.1412"></a>
-<span class="sourceLineNo">1413</span>   * caller MUST abort after this.<a name="line.1413"></a>
-<span class="sourceLineNo">1414</span>   */<a name="line.1414"></a>
-<span class="sourceLineNo">1415</span>  public Map&lt;byte[], List&lt;HStoreFile&gt;&gt; close() throws IOException {<a name="line.1415"></a>
-<span class="sourceLineNo">1416</span>    return close(false);<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>  private final Object closeLock = new Object();<a name="line.1419"></a>
+<span class="sourceLineNo">1234</span>    long dataSize =<a name="line.1234"></a>
+<span class="sourceLineNo">1235</span>        this.memStoreSizing.decMemStoreSize(dataSizeDelta, heapSizeDelta, offHeapSizeDelta);<a name="line.1235"></a>
+<span class="sourceLineNo">1236</span>    checkNegativeMemStoreDataSize(dataSize, -dataSizeDelta);<a name="line.1236"></a>
+<span class="sourceLineNo">1237</span>  }<a name="line.1237"></a>
+<span class="sourceLineNo">1238</span><a name="line.1238"></a>
+<span class="sourceLineNo">1239</span>  private void checkNegativeMemStoreDataSize(long memStoreDataSize, long delta) {<a name="line.1239"></a>
+<span class="sourceLineNo">1240</span>    // This is extremely bad if we make memStoreSizing negative. Log as much info on the offending<a name="line.1240"></a>
+<span class="sourceLineNo">1241</span>    // caller as possible. (memStoreSizing might be a negative value already -- freeing memory)<a name="line.1241"></a>
+<span class="sourceLineNo">1242</span>    if (memStoreDataSize &lt; 0) {<a name="line.1242"></a>
+<span class="sourceLineNo">1243</span>      LOG.error("Asked to modify this region's (" + this.toString()<a name="line.1243"></a>
+<span class="sourceLineNo">1244</span>          + ") memStoreSizing to a negative value which is incorrect. Current memStoreSizing="<a name="line.1244"></a>
+<span class="sourceLineNo">1245</span>          + (memStoreDataSize - delta) + ", delta=" + delta, new Exception());<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>  @Override<a name="line.1249"></a>
+<span class="sourceLineNo">1250</span>  public RegionInfo getRegionInfo() {<a name="line.1250"></a>
+<span class="sourceLineNo">1251</span>    return this.fs.getRegionInfo();<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>   * @return Instance of {@link RegionServerServices} used by this HRegion.<a name="line.1255"></a>
+<span class="sourceLineNo">1256</span>   * Can be null.<a name="line.1256"></a>
+<span class="sourceLineNo">1257</span>   */<a name="line.1257"></a>
+<span class="sourceLineNo">1258</span>  RegionServerServices getRegionServerServices() {<a name="line.1258"></a>
+<span class="sourceLineNo">1259</span>    return this.rsServices;<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>  @Override<a name="line.1262"></a>
+<span class="sourceLineNo">1263</span>  public long getReadRequestsCount() {<a name="line.1263"></a>
+<span class="sourceLineNo">1264</span>    return readRequestsCount.sum();<a name="line.1264"></a>
+<span class="sourceLineNo">1265</span>  }<a name="line.1265"></a>
+<span class="sourceLineNo">1266</span><a name="line.1266"></a>
+<span class="sourceLineNo">1267</span>  @Override<a name="line.1267"></a>
+<span class="sourceLineNo">1268</span>  public long getFilteredReadRequestsCount() {<a name="line.1268"></a>
+<span class="sourceLineNo">1269</span>    return filteredReadRequestsCount.sum();<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>  @Override<a name="line.1272"></a>
+<span class="sourceLineNo">1273</span>  public long getWriteRequestsCount() {<a name="line.1273"></a>
+<span class="sourceLineNo">1274</span>    return writeRequestsCount.sum();<a name="line.1274"></a>
+<span class="sourceLineNo">1275</span>  }<a name="line.1275"></a>
+<span class="sourceLineNo">1276</span><a name="line.1276"></a>
+<span class="sourceLineNo">1277</span>  @Override<a name="line.1277"></a>
+<span class="sourceLineNo">1278</span>  public long getMemStoreDataSize() {<a name="line.1278"></a>
+<span class="sourceLineNo">1279</span>    return memStoreSizing.getDataSize();<a name="line.1279"></a>
+<span class="sourceLineNo">1280</span>  }<a name="line.1280"></a>
+<span class="sourceLineNo">1281</span><a name="line.1281"></a>
+<span class="sourceLineNo">1282</span>  @Override<a name="line.1282"></a>
+<span class="sourceLineNo">1283</span>  public long getMemStoreHeapSize() {<a name="line.1283"></a>
+<span class="sourceLineNo">1284</span>    return memStoreSizing.getHeapSize();<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>  @Override<a name="line.1287"></a>
+<span class="sourceLineNo">1288</span>  public long getMemStoreOffHeapSize() {<a name="line.1288"></a>
+<span class="sourceLineNo">1289</span>    return memStoreSizing.getOffHeapSize();<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>  /** @return store services for this region, to access services required by store level needs */<a name="line.1292"></a>
+<span class="sourceLineNo">1293</span>  public RegionServicesForStores getRegionServicesForStores() {<a name="line.1293"></a>
+<span class="sourceLineNo">1294</span>    return regionServicesForStores;<a name="line.1294"></a>
+<span class="sourceLineNo">1295</span>  }<a name="line.1295"></a>
+<span class="sourceLineNo">1296</span><a name="line.1296"></a>
+<span class="sourceLineNo">1297</span>  @Override<a name="line.1297"></a>
+<span class="sourceLineNo">1298</span>  public long getNumMutationsWithoutWAL() {<a name="line.1298"></a>
+<span class="sourceLineNo">1299</span>    return numMutationsWithoutWAL.sum();<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>  @Override<a name="line.1302"></a>
+<span class="sourceLineNo">1303</span>  public long getDataInMemoryWithoutWAL() {<a name="line.1303"></a>
+<span class="sourceLineNo">1304</span>    return dataInMemoryWithoutWAL.sum();<a name="line.1304"></a>
+<span class="sourceLineNo">1305</span>  }<a name="line.1305"></a>
+<span class="sourceLineNo">1306</span><a name="line.1306"></a>
+<span class="sourceLineNo">1307</span>  @Override<a name="line.1307"></a>
+<span class="sourceLineNo">1308</span>  public long getBlockedRequestsCount() {<a name="line.1308"></a>
+<span class="sourceLineNo">1309</span>    return blockedRequestsCount.sum();<a name="line.1309"></a>
+<span class="sourceLineNo">1310</span>  }<a name="line.1310"></a>
+<span class="sourceLineNo">1311</span><a name="line.1311"></a>
+<span class="sourceLineNo">1312</span>  @Override<a name="line.1312"></a>
+<span class="sourceLineNo">1313</span>  public long getCheckAndMutateChecksPassed() {<a name="line.1313"></a>
+<span class="sourceLineNo">1314</span>    return checkAndMutateChecksPassed.sum();<a name="line.1314"></a>
+<span class="sourceLineNo">1315</span>  }<a name="line.1315"></a>
+<span class="sourceLineNo">1316</span><a name="line.1316"></a>
+<span class="sourceLineNo">1317</span>  @Override<a name="line.1317"></a>
+<span class="sourceLineNo">1318</span>  public long getCheckAndMutateChecksFailed() {<a name="line.1318"></a>
+<span class="sourceLineNo">1319</span>    return checkAndMutateChecksFailed.sum();<a name="line.1319"></a>
+<span class="sourceLineNo">1320</span>  }<a name="line.1320"></a>
+<span class="sourceLineNo">1321</span><a name="line.1321"></a>
+<span class="sourceLineNo">1322</span>  // TODO Needs to check whether we should expose our metrics system to CPs. If CPs themselves doing<a name="line.1322"></a>
+<span class="sourceLineNo">1323</span>  // the op and bypassing the core, this might be needed? Should be stop supporting the bypass<a name="line.1323"></a>
+<span class="sourceLineNo">1324</span>  // feature?<a name="line.1324"></a>
+<span class="sourceLineNo">1325</span>  public MetricsRegion getMetrics() {<a name="line.1325"></a>
+<span class="sourceLineNo">1326</span>    return metricsRegion;<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>  @Override<a name="line.1329"></a>
+<span class="sourceLineNo">1330</span>  public boolean isClosed() {<a name="line.1330"></a>
+<span class="sourceLineNo">1331</span>    return this.closed.get();<a name="line.1331"></a>
+<span class="sourceLineNo">1332</span>  }<a name="line.1332"></a>
+<span class="sourceLineNo">1333</span><a name="line.1333"></a>
+<span class="sourceLineNo">1334</span>  @Override<a name="line.1334"></a>
+<span class="sourceLineNo">1335</span>  public boolean isClosing() {<a name="line.1335"></a>
+<span class="sourceLineNo">1336</span>    return this.closing.get();<a name="line.1336"></a>
+<span class="sourceLineNo">1337</span>  }<a name="line.1337"></a>
+<span class="sourceLineNo">1338</span><a name="line.1338"></a>
+<span class="sourceLineNo">1339</span>  @Override<a name="line.1339"></a>
+<span class="sourceLineNo">1340</span>  public boolean isReadOnly() {<a name="line.1340"></a>
+<span class="sourceLineNo">1341</span>    return this.writestate.isReadOnly();<a name="line.1341"></a>
+<span class="sourceLineNo">1342</span>  }<a name="line.1342"></a>
+<span class="sourceLineNo">1343</span><a name="line.1343"></a>
+<span class="sourceLineNo">1344</span>  @Override<a name="line.1344"></a>
+<span class="sourceLineNo">1345</span>  public boolean isAvailable() {<a name="line.1345"></a>
+<span class="sourceLineNo">1346</span>    return !isClosed() &amp;&amp; !isClosing();<a name="line.1346"></a>
+<span class="sourceLineNo">1347</span>  }<a name="line.1347"></a>
+<span class="sourceLineNo">1348</span><a name="line.1348"></a>
+<span class="sourceLineNo">1349</span>  @Override<a name="line.1349"></a>
+<span class="sourceLineNo">1350</span>  public boolean isSplittable() {<a name="line.1350"></a>
+<span class="sourceLineNo">1351</span>    return isAvailable() &amp;&amp; !hasReferences();<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>  @Override<a name="line.1354"></a>
+<span class="sourceLineNo">1355</span>  public boolean isMergeable() {<a name="line.1355"></a>
+<span class="sourceLineNo">1356</span>    if (!isAvailable()) {<a name="line.1356"></a>
+<span class="sourceLineNo">1357</span>      LOG.debug("Region " + this<a name="line.1357"></a>
+<span class="sourceLineNo">1358</span>          + " is not mergeable because it is closing or closed");<a name="line.1358"></a>
+<span class="sourceLineNo">1359</span>      return false;<a name="line.1359"></a>
+<span class="sourceLineNo">1360</span>    }<a name="line.1360"></a>
+<span class="sourceLineNo">1361</span>    if (hasReferences()) {<a name="line.1361"></a>
+<span class="sourceLineNo">1362</span>      LOG.debug("Region " + this<a name="line.1362"></a>
+<span class="sourceLineNo">1363</span>          + " is not mergeable because it has references");<a name="line.1363"></a>
+<span class="sourceLineNo">1364</span>      return false;<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>    return true;<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>  public boolean areWritesEnabled() {<a name="line.1370"></a>
+<span class="sourceLineNo">1371</span>    synchronized(this.writestate) {<a name="line.1371"></a>
+<span class="sourceLineNo">1372</span>      return this.writestate.writesEnabled;<a name="line.1372"></a>
+<span class="sourceLineNo">1373</span>    }<a name="line.1373"></a>
+<span class="sourceLineNo">1374</span>  }<a name="line.1374"></a>
+<span class="sourceLineNo">1375</span><a name="line.1375"></a>
+<span class="sourceLineNo">1376</span>  @VisibleForTesting<a name="line.1376"></a>
+<span class="sourceLineNo">1377</span>  public MultiVersionConcurrencyControl getMVCC() {<a name="line.1377"></a>
+<span class="sourceLineNo">1378</span>    return mvcc;<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>  @Override<a name="line.1381"></a>
+<span class="sourceLineNo">1382</span>  public long getMaxFlushedSeqId() {<a name="line.1382"></a>
+<span class="sourceLineNo">1383</span>    return maxFlushedSeqId;<a name="line.1383"></a>
+<span class="sourceLineNo">1384</span>  }<a name="line.1384"></a>
+<span class="sourceLineNo">1385</span><a name="line.1385"></a>
+<span class="sourceLineNo">1386</span>  /**<a name="line.1386"></a>
+<span class="sourceLineNo">1387</span>   * @return readpoint considering given IsolationLevel. Pass {@code null} for default<a name="line.1387"></a>
+<span class="sourceLineNo">1388</span>   */<a name="line.1388"></a>
+<span class="sourceLineNo">1389</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1389"></a>
+<span class="sourceLineNo">1390</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1390"></a>
+<span class="sourceLineNo">1391</span>      // This scan can read even uncommitted transactions<a name="line.1391"></a>
+<span class="sourceLineNo">1392</span>      return Long.MAX_VALUE;<a name="line.1392"></a>
+<span class="sourceLineNo">1393</span>    }<a name="line.1393"></a>
+<span class="sourceLineNo">1394</span>    return mvcc.getReadPoint();<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>  public boolean isLoadingCfsOnDemandDefault() {<a name="line.1397"></a>
+<span class="sourceLineNo">1398</span>    return this.isLoadingCfsOnDemandDefault;<a name="line.1398"></a>
+<span class="sourceLineNo">1399</span>  }<a name="line.1399"></a>
+<span class="sourceLineNo">1400</span><a name="line.1400"></a>
+<span class="sourceLineNo">1401</span>  /**<a name="line.1401"></a>
+<span class="sourceLineNo">1402</span>   * Close down this HRegion.  Flush the cache, shut down each HStore, don't<a name="line.1402"></a>
+<span class="sourceLineNo">1403</span>   * service any more calls.<a name="line.1403"></a>
+<span class="sourceLineNo">1404</span>   *<a name="line.1404"></a>
+<span class="sourceLineNo">1405</span>   * &lt;p&gt;This method could take some time to execute, so don't call it from a<a name="line.1405"></a>
+<span class="sourceLineNo">1406</span>   * time-sensitive thread.<a name="line.1406"></a>
+<span class="sourceLineNo">1407</span>   *<a name="line.1407"></a>
+<span class="sourceLineNo">1408</span>   * @return Vector of all the storage files that the HRegion's component<a name="line.1408"></a>
+<span class="sourceLineNo">1409</span>   * HStores make use of.  It's a list of all StoreFile objects. Returns empty<a name="line.1409"></a>
+<span class="sourceLineNo">1410</span>   * vector if already closed and null if judged that it should not close.<a name="line.1410"></a>
+<span class="sourceLineNo">1411</span>   *<a name="line.1411"></a>
+<span class="sourceLineNo">1412</span>   * @throws IOException e<a name="line.1412"></a>
+<span class="sourceLineNo">1413</span>   * @throws DroppedSnapshotException Thrown when replay of wal is required<a name="line.1413"></a>
+<span class="sourceLineNo">1414</span>   * because a Snapshot was not properly persisted. The region is put in closing mode, and the<a name="line.1414"></a>
+<span class="sourceLineNo">1415</span>   * caller MUST abort after this.<a name="line.1415"></a>
+<span class="sourceLineNo">1416</span>   */<a name="line.1416"></a>
+<span class="sourceLineNo">1417</span>  public Map&lt;byte[], List&lt;HStoreFile&gt;&gt; close() throws IOException {<a name="line.1417"></a>
+<span class="sourceLineNo">1418</span>    return close(false);<a name="line.1418"></a>
+<span class="sourceLineNo">1419</span>  }<a name="line.1419"></a>
 <span class="sourceLineNo">1420</span><a name="line.1420"></a>
-<span class="sourceLineNo">1421</span>  /** Conf key for the periodic flush interval */<a name="line.1421"></a>
-<span class="sourceLineNo">1422</span>  public static final String MEMSTORE_PERIODIC_FLUSH_INTERVAL =<a name="line.1422"></a>
-<span class="sourceLineNo">1423</span>      "hbase.regionserver.optionalcacheflushinterval";<a name="line.1423"></a>
-<span class="sourceLineNo">1424</span>  /** Default interval for the memstore flush */<a name="line.1424"></a>
-<span class="sourceLineNo">1425</span>  public static final int DEFAULT_CACHE_FLUSH_INTERVAL = 3600000;<a name="line.1425"></a>
-<span class="sourceLineNo">1426</span>  /** Default interval for System tables memstore flush */<a name="line.1426"></a>
-<span class="sourceLineNo">1427</span>  public static final int SYSTEM_CACHE_FLUSH_INTERVAL = 300000; // 5 minutes<a name="line.1427"></a>
-<span class="sourceLineNo">1428</span><a name="line.1428"></a>
-<span class="sourceLineNo">1429</span>  /** Conf key to force a flush if there are already enough changes for one region in memstore */<a name="line.1429"></a>
-<span class="sourceLineNo">1430</span>  public static final String MEMSTORE_FLUSH_PER_CHANGES =<a name="line.1430"></a>
-<span class="sourceLineNo">1431</span>      "hbase.regionserver.flush.per.changes";<a name="line.1431"></a>
-<span class="sourceLineNo">1432</span>  public static final long DEFAULT_FLUSH_PER_CHANGES = 30000000; // 30 millions<a name="line.1432"></a>
-<span class="sourceLineNo">1433</span>  /**<a name="line.1433"></a>
-<span class="sourceLineNo">1434</span>   * The following MAX_FLUSH_PER_CHANGES is large enough because each KeyValue has 20+ bytes<a name="line.1434"></a>
-<span class="sourceLineNo">1435</span>   * overhead. Therefore, even 1G empty KVs occupy at least 20GB memstore size for a single region<a name="line.1435"></a>
-<span class="sourceLineNo">1436</span>   */<a name="line.1436"></a>
-<span class="sourceLineNo">1437</span>  public static final long MAX_FLUSH_PER_CHANGES = 1000000000; // 1G<a name="line.1437"></a>
-<span class="sourceLineNo">1438</span><a name="line.1438"></a>
-<span class="sourceLineNo">1439</span>  /**<a name="line.1439"></a>
-<span class="sourceLineNo">1440</span>   * Close down this HRegion.  Flush the cache unless abort parameter is true,<a name="line.1440"></a>
-<span class="sourceLineNo">1441</span>   * Shut down each HStore, don't service any more calls.<a name="line.1441"></a>
-<span class="sourceLineNo">1442</span>   *<a name="line.1442"></a>
-<span class="sourceLineNo">1443</span>   * This method could take some time to execute, so don't call it from a<a name="line.1443"></a>
-<span class="sourceLineNo">1444</span>   * time-sensitive thread.<a name="line.1444"></a>
-<span class="sourceLineNo">1445</span>   *<a name="line.1445"></a>
-<span class="sourceLineNo">1446</span>   * @param abort true if server is aborting (only during testing)<a name="line.1446"></a>
-<span class="sourceLineNo">1447</span>   * @return Vector of all the storage files that the HRegion's component<a name="line.1447"></a>
-<span class="sourceLineNo">1448</span>   * HStores make use of.  It's a list of StoreFile objects.  Can be null if<a name="line.1448"></a>
-<span class="sourceLineNo">1449</span>   * we are not to close at this time or we are already closed.<a name="line.1449"></a>
-<span class="sourceLineNo">1450</span>   *<a name="line.1450"></a>
-<span class="sourceLineNo">1451</span>   * @throws IOException e<a name="line.1451"></a>
-<span class="sourceLineNo">1452</span>   * @throws DroppedSnapshotException Thrown when replay of wal is required<a name="line.1452"></a>
-<span class="sourceLineNo">1453</span>   * because a Snapshot was not properly persisted. The region is put in closing mode, and the<a name="line.1453"></a>
-<span class="sourceLineNo">1454</span>   * caller MUST abort after this.<a name="line.1454"></a>
-<span class="sourceLineNo">1455</span>   */<a name="line.1455"></a>
-<span class="sourceLineNo">1456</span>  public Map&lt;byte[], List&lt;HStoreFile&gt;&gt; close(boolean abort) throws IOException {<a name="line.1456"></a>
-<span class="sourceLineNo">1457</span>    // Only allow one thread to close at a time. Serialize them so dual<a name="line.1457"></a>
-<span class="sourceLineNo">1458</span>    // threads attempting to close will run up against each other.<a name="line.1458"></a>
-<span class="sourceLineNo">1459</span>    MonitoredTask status = TaskMonitor.get().createStatus(<a name="line.1459"></a>
-<span class="sourceLineNo">1460</span>        "Closing region " + this.getRegionInfo().getEncodedName() +<a name="line.1460"></a>
-<span class="sourceLineNo">1461</span>        (abort ? " due to abort" : ""));<a name="line.1461"></a>
-<span class="sourceLineNo">1462</span><a name="line.1462"></a>
-<span class="sourceLineNo">1463</span>    status.setStatus("Waiting for close lock");<a name="line.1463"></a>
-<span class="sourceLineNo">1464</span>    try {<a name="line.1464"></a>
-<span class="sourceLineNo">1465</span>      synchronized (closeLock) {<a name="line.1465"></a>
-<span class="sourceLineNo">1466</span>        return doClose(abort, status);<a name="line.1466"></a>
-<span class="sourceLineNo">1467</span>      }<a name="line.1467"></a>
-<span class="sourceLineNo">1468</span>    } finally {<a name="line.1468"></a>
-<span class="sourceLineNo">1469</span>      status.cleanup();<a name="line.1469"></a>
-<span class="sourceLineNo">1470</span>    }<a name="line.1470"></a>
-<span class="sourceLineNo">1471</span>  }<a name="line.1471"></a>
-<span class="sourceLineNo">1472</span><a name="line.1472"></a>
-<span class="sourceLineNo">1473</span>  /**<a name="line.1473"></a>
-<span class="sourceLineNo">1474</span>   * Exposed for some very specific unit tests.<a name="line.1474"></a>
-<span class="sourceLineNo">1475</span>   */<a name="line.1475"></a>
-<span class="sourceLineNo">1476</span>  @VisibleForTesting<a name="line.1476"></a>
-<span class="sourceLineNo">1477</span>  public void setClosing(boolean closing) {<a name="line.1477"></a>
-<span class="sourceLineNo">1478</span>    this.closing.set(closing);<a name="line.1478"></a>
-<span class="sourceLineNo">1479</span>  }<a name="line.1479"></a>
-<span class="sourceLineNo">1480</span><a name="line.1480"></a>
-<span class="sourceLineNo">1481</span>  /**<a name="line.1481"></a>
-<span class="sourceLineNo">1482</span>   * The {@link HRegion#doClose} will block forever if someone tries proving the dead lock via the unit test.<a name="line.1482"></a>
-<span class="sourceLineNo">1483</span>   * Instead of blocking, the {@link HRegion#doClose} will throw exception if you set the timeout.<a name="line.1483"></a>
-<span class="sourceLineNo">1484</span>   * @param timeoutForWriteLock the second time to wait for the write lock in {@link HRegion#doClose}<a name="line.1484"></a>
-<span class="sourceLineNo">1485</span>   */<a name="line.1485"></a>
-<span class="sourceLineNo">1486</span>  @VisibleForTesting<a name="line.1486"></a>
-<span class="sourceLineNo">1487</span>  public void setTimeoutForWriteLock(long timeoutForWriteLock) {<a name="line.1487"></a>
-<span class="sourceLineNo">1488</span>    assert timeoutForWriteLock &gt;= 0;<a name="line.1488"></a>
-<span class="sourceLineNo">1489</span>    this.timeoutForWriteLock = timeoutForWriteLock;<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>  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="UL_UNRELEASED_LOCK_EXCEPTION_PATH",<a name="line.1492"></a>
-<span class="sourceLineNo">1493</span>      justification="I think FindBugs is confused")<a name="line.1493"></a>
-<span class="sourceLineNo">1494</span>  private Map&lt;byte[], List&lt;HStoreFile&gt;&gt; doClose(boolean abort, MonitoredTask status)<a name="line.1494"></a>
-<span class="sourceLineNo">1495</span>      throws IOException {<a name="line.1495"></a>
-<span class="sourceLineNo">1496</span>    if (isClosed()) {<a name="line.1496"></a>
-<span class="sourceLineNo">1497</span>      LOG.warn("Region " + this + " already closed");<a name="line.1497"></a>
-<span class="sourceLineNo">1498</span>      return null;<a name="line.1498"></a>
-<span class="sourceLineNo">1499</span>    }<a name="line.1499"></a>
-<span class="sourceLineNo">1500</span><a name="line.1500"></a>
-<span class="sourceLineNo">1501</span>    if (coprocessorHost != null) {<a name="line.1501"></a>
-<span class="sourceLineNo">1502</span>      status.setStatus("Running coprocessor pre-close hooks");<a name="line.1502"></a>
-<span class="sourceLineNo">1503</span>      this.coprocessorHost.preClose(abort);<a name="line.1503"></a>
-<span class="sourceLineNo">1504</span>    }<a name="line.1504"></a>
-<span class="sourceLineNo">1505</span>    status.setStatus("Disabling compacts and flushes for region");<a name="line.1505"></a>
-<span class="sourceLineNo">1506</span>    boolean canFlush = true;<a name="line.1506"></a>
-<span class="sourceLineNo">1507</span>    synchronized (writestate) {<a name="line.1507"></a>
-<span class="sourceLineNo">1508</span>      // Disable compacting and flushing by background threads for this<a name="line.1508"></a>
-<span class="sourceLineNo">1509</span>      // region.<a name="line.1509"></a>
-<span class="sourceLineNo">1510</span>      canFlush = !writestate.readOnly;<a name="line.1510"></a>
-<span class="sourceLineNo">1511</span>      writestate.writesEnabled = false;<a name="line.1511"></a>
-<span class="sourceLineNo">1512</span>      LOG.debug("Closing {}, disabling compactions &amp; flushes",<a name="line.1512"></a>
-<span class="sourceLineNo">1513</span>          this.getRegionInfo().getEncodedName());<a name="line.1513"></a>
-<span class="sourceLineNo">1514</span>      waitForFlushesAndCompactions();<a name="line.1514"></a>
-<span class="sourceLineNo">1515</span>    }<a name="line.1515"></a>
-<span class="sourceLineNo">1516</span>    // If we were not just flushing, is it worth doing a preflush...one<a name="line.1516"></a>
-<span class="sourceLineNo">1517</span>    // that will clear out of the bulk of the memstore before we put up<a name="line.1517"></a>
-<span class="sourceLineNo">1518</span>    // the close flag?<a name="line.1518"></a>
-<span class="sourceLineNo">1519</span>    if (!abort &amp;&amp; worthPreFlushing() &amp;&amp; canFlush) {<a name="line.1519"></a>
-<span class="sourceLineNo">1520</span>      status.setStatus("Pre-flushing region before close");<a name="line.1520"></a>
-<span class="sourceLineNo">1521</span>      LOG.info("Running close preflush of {}" + this.getRegionInfo().getEncodedName());<a name="line.1521"></a>
-<span class="sourceLineNo">1522</span>      try {<a name="line.1522"></a>
-<span class="sourceLineNo">1523</span>        internalFlushcache(status);<a name="line.1523"></a>
-<span class="sourceLineNo">1524</span>      } catch (IOException ioe) {<a name="line.1524"></a>
-<span class="sourceLineNo">1525</span>        // Failed to flush the region. Keep going.<a name="line.1525"></a>
-<span class="sourceLineNo">1526</span>        status.setStatus("Failed pre-flush " + this + "; " + ioe.getMessage());<a name="line.1526"></a>
-<span class="sourceLineNo">1527</span>      }<a name="line.1527"></a>
-<span class="sourceLineNo">1528</span>    }<a name="line.1528"></a>
-<span class="sourceLineNo">1529</span><a name="line.1529"></a>
-<span class="sourceLineNo">1530</span>    if (timeoutForWriteLock == null<a name="line.1530"></a>
-<span class="sourceLineNo">1531</span>        || timeoutForWriteLock == Long.MAX_VALUE) {<a name="line.1531"></a>
-<span class="sourceLineNo">1532</span>      // block waiting for the lock for closing<a name="line.1532"></a>
-<span class="sourceLineNo">1533</span>      lock.writeLock().lock(); // FindBugs: Complains UL_UNRELEASED_LOCK_EXCEPTION_PATH but seems fine<a name="line.1533"></a>
-<span class="sourceLineNo">1534</span>    } else {<a name="line.1534"></a>
-<span class="sourceLineNo">1535</span>      try {<a name="line.1535"></a>
-<span class="sourceLineNo">1536</span>        boolean succeed = lock.writeLock().tryLock(timeoutForWriteLock, TimeUnit.SECONDS);<a name="line.1536"></a>
-<span class="sourceLineNo">1537</span>        if (!succeed) {<a name="line.1537"></a>
-<span class="sourceLineNo">1538</span>          throw new IOException("Failed to get write lock when closing region");<a name="line.1538"></a>
-<span class="sourceLineNo">1539</span>        }<a name="line.1539"></a>
-<span class="sourceLineNo">1540</span>      } catch (InterruptedException e) {<a name="line.1540"></a>
-<span class="sourceLineNo">1541</span>        throw (InterruptedIOException) new InterruptedIOException().initCause(e);<a name="line.1541"></a>
-<span class="sourceLineNo">1542</span>      }<a name="line.1542"></a>
-<span class="sourceLineNo">1543</span>    }<a name="line.1543"></a>
-<span class="sourceLineNo">1544</span>    this.closing.set(true);<a name="line.1544"></a>
-<span class="sourceLineNo">1545</span>    status.setStatus("Disabling writes for close");<a name="line.1545"></a>
-<span class="sourceLineNo">1546</span>    try {<a name="line.1546"></a>
-<span class="sourceLineNo">1547</span>      if (this.isClosed()) {<a name="line.1547"></a>
-<span class="sourceLineNo">1548</span>        status.abort("Already got closed by another process");<a name="line.1548"></a>
-<span class="sourceLineNo">1549</span>        // SplitTransaction handles the null<a name="line.1549"></a>
-<span class="sourceLineNo">1550</span>        return null;<a name="line.1550"></a>
-<span class="sourceLineNo">1551</span>      }<a name="line.1551"></a>
-<span class="sourceLineNo">1552</span>      LOG.debug("Updates disabled for region " + this);<a name="line.1552"></a>
-<span class="sourceLineNo">1553</span>      // Don't flush the cache if we are aborting<a name="line.1553"></a>
-<span class="sourceLineNo">1554</span>      if (!abort &amp;&amp; canFlush) {<a name="line.1554"></a>
-<span class="sourceLineNo">1555</span>        int failedfFlushCount = 0;<a name="line.1555"></a>
-<span class="sourceLineNo">1556</span>        int flushCount = 0;<a name="line.1556"></a>
-<span class="sourceLineNo">1557</span>        long tmp = 0;<a name="line.1557"></a>
-<span class="sourceLineNo">1558</span>        long remainingSize = this.memStoreSize.getDataSize();<a name="line.1558"></a>
-<span class="sourceLineNo">1559</span>        while (remainingSize &gt; 0) {<a name="line.1559"></a>
-<span class="sourceLineNo">1560</span>          try {<a name="line.1560"></a>
-<span class="sourceLineNo">1561</span>            internalFlushcache(status);<a name="line.1561"></a>
-<span class="sourceLineNo">1562</span>            if(flushCount &gt;0) {<a name="line.1562"></a>
-<span class="sourceLineNo">1563</span>              LOG.info("Running extra flush, " + flushCount +<a name="line.1563"></a>
-<span class="sourceLineNo">1564</span>                  " (carrying snapshot?) " + this);<a name="line.1564"></a>
-<span class="sourceLineNo">1565</span>            }<a name="line.1565"></a>
-<span class="sourceLineNo">1566</span>            flushCount++;<a name="line.1566"></a>
-<span class="sourceLineNo">1567</span>            tmp = this.memStoreSize.getDataSize();<a name="line.1567"></a>
-<span class="sourceLineNo">1568</span>            if (tmp &gt;= remainingSize) {<a name="line.1568"></a>
-<span class="sourceLineNo">1569</span>              failedfFlushCount++;<a name="line.1569"></a>
-<span class="sourceLineNo">1570</span>            }<a name="line.1570"></a>
-<span class="sourceLineNo">1571</span>            remainingSize = tmp;<a name="line.1571"></a>
-<span class="sourceLineNo">1572</span>            if (failedfFlushCount &gt; 5) {<a name="line.1572"></a>
-<span class="sourceLineNo">1573</span>              // If we failed 5 times and are unable to clear memory, abort<a name="line.1573"></a>
-<span class="sourceLineNo">1574</span>              // so we do not lose data<a name="line.1574"></a>
-<span class="sourceLineNo">1575</span>              throw new DroppedSnapshotException("Failed clearing memory after " +<a name="line.1575"></a>
-<span class="sourceLineNo">1576</span>                  flushCount + " attempts on region: " +<a name="line.1576"></a>
-<span class="sourceLineNo">1577</span>                  Bytes.toStringBinary(getRegionInfo().getRegionName()));<a name="line.1577"></a>
-<span class="sourceLineNo">1578</span>            }<a name="line.1578"></a>
-<span class="sourceLineNo">1579</span>          } catch (IOException ioe) {<a name="line.1579"></a>
-<span class="sourceLineNo">1580</span>            status.setStatus("Failed flush " + this + ", putting online again");<a name="line.1580"></a>
-<span class="sourceLineNo">1581</span>            synchronized (writestate) {<a name="line.1581"></a>
-<span class="sourceLineNo">1582</span>              writestate.writesEnabled = true;<a name="line.1582"></a>
-<span class="sourceLineNo">1583</span>            }<a name="line.1583"></a>
-<span class="sourceLineNo">1584</span>            // Have to throw to upper layers.  I can't abort server from here.<a name="line.1584"></a>
-<span class="sourceLineNo">1585</span>            throw ioe;<a name="line.1585"></a>
-<span class="sourceLineNo">1586</span>          }<a name="line.1586"></a>
-<span class="sourceLineNo">1587</span>        }<a name="line.1587"></a>
-<span class="sourceLineNo">1588</span>      }<a name="line.1588"></a>
-<span class="sourceLineNo">1589</span><a name="line.1589"></a>
-<span class="sourceLineNo">1590</span>      Map&lt;byte[], List&lt;HStoreFile&gt;&gt; result = new TreeMap&lt;&gt;(Bytes.BYTES_COMPARATOR);<a name="line.1590"></a>
-<span class="sourceLineNo">1591</span>      if (!stores.isEmpty()) {<a name="line.1591"></a>
-<span class="sourceLineNo">1592</span>        // initialize the thread pool for closing stores in parallel.<a name="line.1592"></a>
-<span class="sourceLineNo">1593</span>        ThreadPoolExecutor storeCloserThreadPool =<a name="line.1593"></a>
-<span class="sourceLineNo">1594</span>          getStoreOpenAndCloseThreadPool("StoreCloserThread-" +<a name="line.1594"></a>
-<span class="sourceLineNo">1595</span>            getRegionInfo().getRegionNameAsString());<a name="line.1595"></a>
-<span class="sourceLineNo">1596</span>        CompletionService&lt;Pair&lt;byte[], Collection&lt;HStoreFile&gt;&gt;&gt; completionService =<a name="line.1596"></a>
-<span class="sourceLineNo">1597</span>          new ExecutorCompletionService&lt;&gt;(storeCloserThreadPool);<a name="line.1597"></a>
-<span class="sourceLineNo">1598</span><a name="line.1598"></a>
-<span class="sourceLineNo">1599</span>        // close each store in parallel<a name="line.1599"></a>
-<span class="sourceLineNo">1600</span>        for (HStore store : stores.values()) {<a name="line.1600"></a>
-<span class="sourceLineNo">1601</span>          MemStoreSize flushableSize = store.getFlushableSize();<a name="line.1601"></a>
-<span class="sourceLineNo">1602</span>          if (!(abort || flushableSize.getDataSize() == 0 || writestate.readOnly)) {<a name="line.1602"></a>
-<span class="sourceLineNo">1603</span>            if (getRegionServerServices() != null) {<a name="line.1603"></a>
-<span class="sourceLineNo">1604</span>              getRegionServerServices().abort("Assertion failed while closing store "<a name="line.1604"></a>
-<span class="sourceLineNo">1605</span>                + getRegionInfo().getRegionNameAsString() + " " + store<a name="line.1605"></a>
-<span class="sourceLineNo">1606</span>                + ". flushableSize expected=0, actual= " + flushableSize<a name="line.1606"></a>
-<span class="sourceLineNo">1607</span>                + ". Current memStoreSize=" + getMemStoreDataSize() + ". Maybe a coprocessor "<a name="line.1607"></a>
-<span class="sourceLineNo">1608</span>                + "operation failed and left the memstore in a partially updated state.", null);<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>          completionService<a name="line.1611"></a>
-<span class="sourceLineNo">1612</span>              .submit(new Callable&lt;Pair&lt;byte[], Collection&lt;HStoreFile&gt;&gt;&gt;() {<a name="line.1612"></a>
-<span class="sourceLineNo">1613</span>                @Override<a name="line.1613"></a>
-<span class="sourceLineNo">1614</span>                public Pair&lt;byte[], Collection&lt;HStoreFile&gt;&gt; call() throws IOException {<a name="line.1614"></a>
-<span class="sourceLineNo">1615</span>                  return new Pair&lt;&gt;(store.getColumnFamilyDescriptor().getName(), store.close());<a name="line.1615"></a>
-<span class="sourceLineNo">1616</span>                }<a name="line.1616"></a>
-<span class="sourceLineNo">1617</span>              });<a name="line.1617"></a>
-<span class="sourceLineNo">1618</span>        }<a name="line.1618"></a>
-<span class="sourceLineNo">1619</span>        try {<a name="line.1619"></a>
-<span class="sourceLineNo">1620</span>          for (int i = 0; i &lt; stores.size(); i++) {<a name="line.1620"></a>
-<span class="sourceLineNo">1621</span>            Future&lt;Pair&lt;byte[], Collection&lt;HStoreFile&gt;&gt;&gt; future = completionService.take();<a name="line.1621"></a>
-<span class="sourceLineNo">1622</span>            Pair&lt;byte[], Collection&lt;HStoreFile&gt;&gt; storeFiles = future.get();<a name="line.1622"></a>
-<span class="sourceLineNo">1623</span>            List&lt;HStoreFile&gt; familyFiles = result.get(storeFiles.getFirst());<a name="line.1623"></a>
-<span class="sourceLineNo">1624</span>            if (familyFiles == null) {<a name="line.1624"></a>
-<span class="sourceLineNo">1625</span>              familyFiles = new ArrayList&lt;&gt;();<a name="line.1625"></a>
-<span class="sourceLineNo">1626</span>              result.put(storeFiles.getFirst(), familyFiles);<a name="line.1626"></a>
-<span class="sourceLineNo">1627</span>            }<a name="line.1627"></a>
-<span class="sourceLineNo">1628</span>            familyFiles.addAll(storeFiles.getSecond());<a name="line.1628"></a>
-<span class="sourceLineNo">1629</span>          }<a name="line.1629"></a>
-<span class="sourceLineNo">1630</span>        } catch (InterruptedException e) {<a name="line.1630"></a>
-<span class="sourceLineNo">1631</span>          throw (InterruptedIOException)new InterruptedIOException().initCause(e);<a name="line.1631"></a>
-<span class="sourceLineNo">1632</span>        } catch (ExecutionException e) {<a name="line.1632"></a>
-<span class="sourceLineNo">1633</span>          Throwable cause = e.getCause();<a name="line.1633"></a>
-<span class="sourceLineNo">1634</span>          if (cause instanceof IOException) {<a name="line.1634"></a>
-<span class="sourceLineNo">1635</span>            throw (IOException) cause;<a name="line.1635"></a>
-<span class="sourceLineNo">1636</span>          }<a name="line.1636"></a>
-<span class="sourceLineNo">1637</span>          throw new IOException(cause);<a name="line.1637"></a>
-<span class="sourceLineNo">1638</span>        } finally {<a name="line.1638"></a>
-<span class="sourceLineNo">1639</span>          storeCloserThreadPool.shutdownNow();<a name="line.1639"></a>
-<span class="sourceLineNo">1640</span>        }<a name="line.1640"></a>
-<span class="sourceLineNo">1641</span>      }<a name="line.1641"></a>
-<span class="sourceLineNo">1642</span><a name="line.1642"></a>
-<span class="sourceLineNo">1643</span>      status.setStatus("Writing region close event to WAL");<a name="line.1643"></a>
-<span class="sourceLineNo">1644</span>      if (!abort &amp;&amp; wal != null &amp;&amp; getRegionServerServices() != null &amp;&amp; !writestate.readOnly) {<a name="line.1644"></a>
-<span class="sourceLineNo">1645</span>        writeRegionCloseMarker(wal);<a name="line.1645"></a>
-<span class="sourceLineNo">1646</span>      }<a name="line.1646"></a>
-<span class="sourceLineNo">1647</span><a name="line.1647"></a>
-<span class="sourceLineNo">1648</span>      this.closed.set(true);<a name="line.1648"></a>
-<span class="sourceLineNo">1649</span>      if (!canFlush) {<a name="line.1649"></a>
-<span class="sourceLineNo">1650</span>        this.decrMemStoreSize(new MemStoreSize(memStoreSize));<a name="line.1650"></a>
-<span class="sourceLineNo">1651</span>      } else if (memStoreSize.getDataSize() != 0) {<a name="line.1651"></a>
-<span class="sourceLineNo">1652</span>        LOG.error("Memstore data size is " + memStoreSize.getDataSize());<a name="line.1652"></a>
-<span class="sourceLineNo">1653</span>      }<a name="line.1653"></a>
-<span class="sourceLineNo">1654</span>      if (coprocessorHost != null) {<a name="line.1654"></a>
-<span class="sourceLineNo">1655</span>        status.setStatus("Running coprocessor post-close hooks");<a name="line.1655"></a>
-<span class="sourceLineNo">1656</span>        this.coprocessorHost.postClose(abort);<a name="line.1656"></a>
-<span class="sourceLineNo">1657</span>      }<a name="line.1657"></a>
-<span class="sourceLineNo">1658</span>      if (this.metricsRegion != null) {<a name="line.1658"></a>
-<span class="sourceLineNo">1659</span>        this.metricsRegion.close();<a name="line.1659"></a>
+<span class="sourceLineNo">1421</span>  private final Object closeLock = new Object();<a name="line.1421"></a>
+<span class="sourceLineNo">1422</span><a name="line.1422"></a>
+<span class="sourceLineNo">1423</span>  /** Conf key for the periodic flush interval */<a name="line.1423"></a>
+<span class="sourceLineNo">1424</span>  public static final String MEMSTORE_PERIODIC_FLUSH_INTERVAL =<a name="line.1424"></a>
+<span class="sourceLineNo">1425</span>      "hbase.regionserver.optionalcacheflushinterval";<a name="line.1425"></a>
+<span class="sourceLineNo">1426</span>  /** Default interval for the memstore flush */<a name="line.1426"></a>
+<span class="sourceLineNo">1427</span>  public static final int DEFAULT_CACHE_FLUSH_INTERVAL = 3600000;<a name="line.1427"></a>
+<span class="sourceLineNo">1428</span>  /** Default interval for System tables memstore flush */<a name="line.1428"></a>
+<span class="sourceLineNo">1429</span>  public static final int SYSTEM_CACHE_FLUSH_INTERVAL = 300000; // 5 minutes<a name="line.1429"></a>
+<span class="sourceLineNo">1430</span><a name="line.1430"></a>
+<span class="sourceLineNo">1431</span>  /** Conf key to force a flush if there are already enough changes for one region in memstore */<a name="line.1431"></a>
+<span class="sourceLineNo">1432</span>  public static final String MEMSTORE_FLUSH_PER_CHANGES =<a name="line.1432"></a>
+<span class="sourceLineNo">1433</span>      "hbase.regionserver.flush.per.changes";<a name="line.1433"></a>
+<span class="sourceLineNo">1434</span>  public static final long DEFAULT_FLUSH_PER_CHANGES = 30000000; // 30 millions<a name="line.1434"></a>
+<span class="sourceLineNo">1435</span>  /**<a name="line.1435"></a>
+<span class="sourceLineNo">1436</span>   * The following MAX_FLUSH_PER_CHANGES is large enough because each KeyValue has 20+ bytes<a name="line.1436"></a>
+<span class="sourceLineNo">1437</span>   * overhead. Therefore, even 1G empty KVs occupy at least 20GB memstore size for a single region<a name="line.1437"></a>
+<span class="sourceLineNo">1438</span>   */<a name="line.1438"></a>
+<span class="sourceLineNo">1439</span>  public static final long MAX_FLUSH_PER_CHANGES = 1000000000; // 1G<a name="line.1439"></a>
+<span class="sourceLineNo">1440</span><a name="line.1440"></a>
+<span class="sourceLineNo">1441</span>  /**<a name="line.1441"></a>
+<span class="sourceLineNo">1442</span>   * Close down this HRegion.  Flush the cache unless abort parameter is true,<a name="line.1442"></a>
+<span class="sourceLineNo">1443</span>   * Shut down each HStore, don't service any more calls.<a name="line.1443"></a>
+<span class="sourceLineNo">1444</span>   *<a name="line.1444"></a>
+<span class="sourceLineNo">1445</span>   * This method could take some time to execute, so don't call it from a<a name="line.1445"></a>
+<span class="sourceLineNo">1446</span>   * time-sensitive thread.<a name="line.1446"></a>
+<span class="sourceLineNo">1447</span>   *<a name="line.1447"></a>
+<span class="sourceLineNo">1448</span>   * @param abort true if server is aborting (only during testing)<a name="line.1448"></a>
+<span class="sourceLineNo">1449</span>   * @return Vector of all the storage files that the HRegion's component<a name="line.1449"></a>
+<span class="sourceLineNo">1450</span>   * HStores make use of.  It's a list of StoreFile objects.  Can be null if<a name="line.1450"></a>
+<span class="sourceLineNo">1451</span>   * we are not to close at this time or we are already closed.<a name="line.1451"></a>
+<span class="sourceLineNo">1452</span>   *<a name="line.1452"></a>
+<span class="sourceLineNo">1453</span>   * @throws IOException e<a name="line.1453"></a>
+<span class="sourceLineNo">1454</span>   * @throws DroppedSnapshotException Thrown when replay of wal is required<a name="line.1454"></a>
+<span class="sourceLineNo">1455</span>   * because a Snapshot was not properly persisted. The region is put in closing mode, and the<a name="line.1455"></a>
+<span class="sourceLineNo">1456</span>   * caller MUST abort after this.<a name="line.1456"></a>
+<span class="sourceLineNo">1457</span>   */<a name="line.1457"></a>
+<span class="sourceLineNo">1458</span>  public Map&lt;byte[], List&lt;HStoreFile&gt;&gt; close(boolean abort) throws IOException {<a name="line.1458"></a>
+<span class="sourceLineNo">1459</span>    // Only allow one thread to close at a time. Serialize them so dual<a name="line.1459"></a>
+<span class="sourceLineNo">1460</span>    // threads attempting to close will run up against each other.<a name="line.1460"></a>
+<span class="sourceLineNo">1461</span>    MonitoredTask status = TaskMonitor.get().createStatus(<a name="line.1461"></a>
+<span class="sourceLineNo">1462</span>        "Closing region " + this.getRegionInfo().getEncodedName() +<a name="line.1462"></a>
+<span class="sourceLineNo">1463</span>        (abort ? " due to abort" : ""));<a name="line.1463"></a>
+<span class="sourceLineNo">1464</span><a name="line.1464"></a>
+<span class="sourceLineNo">1465</span>    status.setStatus("Waiting for close lock");<a name="line.1465"></a>
+<span class="sourceLineNo">1466</span>    try {<a name="line.1466"></a>
+<span class="sourceLineNo">1467</span>      synchronized (closeLock) {<a name="line.1467"></a>
+<span class="sourceLineNo">1468</span>        return doClose(abort, status);<a name="line.1468"></a>
+<span class="sourceLineNo">1469</span>      }<a name="line.1469"></a>
+<span class="sourceLineNo">1470</span>    } finally {<a name="line.1470"></a>
+<span class="sourceLineNo">1471</span>      status.cleanup();<a name="line.1471"></a>
+<span class="sourceLineNo">1472</span>    }<a name="line.1472"></a>
+<span class="sourceLineNo">1473</span>  }<a name="line.1473"></a>
+<span class="sourceLineNo">1474</span><a name="line.1474"></a>
+<span class="sourceLineNo">1475</span>  /**<a name="line.1475"></a>
+<span class="sourceLineNo">1476</span>   * Exposed for some very specific unit tests.<a name="line.1476"></a>
+<span class="sourceLineNo">1477</span>   */<a name="line.1477"></a>
+<span class="sourceLineNo">1478</span>  @VisibleForTesting<a name="line.1478"></a>
+<span class="sourceLineNo">1479</span>  public void setClosing(boolean closing) {<a name="line.1479"></a>
+<span class="sourceLineNo">1480</span>    this.closing.set(closing);<a name="line.1480"></a>
+<span class="sourceLineNo">1481</span>  }<a name="line.1481"></a>
+<span class="sourceLineNo">1482</span><a name="line.1482"></a>
+<span class="sourceLineNo">1483</span>  /**<a name="line.1483"></a>
+<span class="sourceLineNo">1484</span>   * The {@link HRegion#doClose} will block forever if someone tries proving the dead lock via the unit test.<a name="line.1484"></a>
+<span class="sourceLineNo">1485</span>   * Instead of blocking, the {@link HRegion#doClose} will throw exception if you set the timeout.<a name="line.1485"></a>
+<span class="sourceLineNo">1486</span>   * @param timeoutForWriteLock the second time to wait for the write lock in {@link HRegion#doClose}<a name="line.1486"></a>
+<span class="sourceLineNo">1487</span>   */<a name="line.1487"></a>
+<span class="sourceLineNo">1488</span>  @VisibleForTesting<a name="line.1488"></a>
+<span class="sourceLineNo">1489</span>  public void setTimeoutForWriteLock(long timeoutForWriteLock) {<a name="line.1489"></a>
+<span class="sourceLineNo">1490</span>    assert timeoutForWriteLock &gt;= 0;<a name="line.1490"></a>
+<span class="sourceLineNo">1491</span>    this.timeoutForWriteLock = timeoutForWriteLock;<a name="line.1491"></a>
+<span class="sourceLineNo">1492</span>  }<a name="line.1492"></a>
+<span class="sourceLineNo">1493</span><a name="line.1493"></a>
+<span class="sourceLineNo">1494</span>  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="UL_UNRELEASED_LOCK_EXCEPTION_PATH",<a name="line.1494"></a>
+<span class="sourceLineNo">1495</span>      justification="I think FindBugs is confused")<a name="line.1495"></a>
+<span class="sourceLineNo">1496</span>  private Map&lt;byte[], List&lt;HStoreFile&gt;&gt; doClose(boolean abort, MonitoredTask status)<a name="line.1496"></a>
+<span class="sourceLineNo">1497</span>      throws IOException {<a name="line.1497"></a>
+<span class="sourceLineNo">1498</span>    if (isClosed()) {<a name="line.1498"></a>
+<span class="sourceLineNo">1499</span>      LOG.warn("Region " + this + " already closed");<a name="line.1499"></a>
+<span class="sourceLineNo">1500</span>      return null;<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>    if (coprocessorHost != null) {<a name="line.1503"></a>
+<span class="sourceLineNo">1504</span>      status.setStatus("Running coprocessor pre-close hooks");<a name="line.1504"></a>
+<span class="sourceLineNo">1505</span>      this.coprocessorHost.preClose(abort);<a name="line.1505"></a>
+<span class="sourceLineNo">1506</span>    }<a name="line.1506"></a>
+<span class="sourceLineNo">1507</span>    status.setStatus("Disabling compacts and flushes for region");<a name="line.1507"></a>
+<span class="sourceLineNo">1508</span>    boolean canFlush = true;<a name="line.1508"></a>
+<span class="sourceLineNo">1509</span>    synchronized (writestate) {<a name="line.1509"></a>
+<span class="sourceLineNo">1510</span>      // Disable compacting and flushing by background threads for this<a name="line.1510"></a>
+<span class="sourceLineNo">1511</span>      // region.<a name="line.1511"></a>
+<span class="sourceLineNo">1512</span>      canFlush = !writestate.readOnly;<a name="line.1512"></a>
+<span class="sourceLineNo">1513</span>      writestate.writesEnabled = false;<a name="line.1513"></a>
+<span class="sourceLineNo">1514</span>      LOG.debug("Closing {}, disabling compactions &amp; flushes",<a name="line.1514"></a>
+<span class="sourceLineNo">1515</span>          this.getRegionInfo().getEncodedName());<a name="line.1515"></a>
+<span class="sourceLineNo">1516</span>      waitForFlushesAndCompactions();<a name="line.1516"></a>
+<span class="sourceLineNo">1517</span>    }<a name="line.1517"></a>
+<span class="sourceLineNo">1518</span>    // If we were not just flushing, is it worth doing a preflush...one<a name="line.1518"></a>
+<span class="sourceLineNo">1519</span>    // that will clear out of the bulk of the memstore before we put up<a name="line.1519"></a>
+<span class="sourceLineNo">1520</span>    // the close flag?<a name="line.1520"></a>
+<span class="sourceLineNo">1521</span>    if (!abort &amp;&amp; worthPreFlushing() &amp;&amp; canFlush) {<a name="line.1521"></a>
+<span class="sourceLineNo">1522</span>      status.setStatus("Pre-flushing region before close");<a name="line.1522"></a>
+<span class="sourceLineNo">1523</span>      LOG.info("Running close preflush of {}" + this.getRegionInfo().getEncodedName());<a name="line.1523"></a>
+<span class="sourceLineNo">1524</span>      try {<a name="line.1524"></a>
+<span class="sourceLineNo">1525</span>        internalFlushcache(status);<a name="line.1525"></a>
+<span class="sourceLineNo">1526</span>      } catch (IOException ioe) {<a name="line.1526"></a>
+<span class="sourceLineNo">1527</span>        // Failed to flush the region. Keep going.<a name="line.1527"></a>
+<span class="sourceLineNo">1528</span>        status.setStatus("Failed pre-flush " + this + "; " + ioe.getMessage());<a name="line.1528"></a>
+<span class="sourceLineNo">1529</span>      }<a name="line.1529"></a>
+<span class="sourceLineNo">1530</span>    }<a name="line.1530"></a>
+<span class="sourceLineNo">1531</span><a name="line.1531"></a>
+<span class="sourceLineNo">1532</span>    if (timeoutForWriteLock == null<a name="line.1532"></a>
+<span class="sourceLineNo">1533</span>        || timeoutForWriteLock == Long.MAX_VALUE) {<a name="line.1533"></a>
+<span class="sourceLineNo">1534</span>      // block waiting for the lock for closing<a name="line.1534"></a>
+<span class="sourceLineNo">1535</span>      lock.writeLock().lock(); // FindBugs: Complains UL_UNRELEASED_LOCK_EXCEPTION_PATH but seems fine<a name="line.1535"></a>
+<span class="sourceLineNo">1536</span>    } else {<a name="line.1536"></a>
+<span class="sourceLineNo">1537</span>      try {<a name="line.1537"></a>
+<span class="sourceLineNo">1538</span>        boolean succeed = lock.writeLock().tryLock(timeoutForWriteLock, TimeUnit.SECONDS);<a name="line.1538"></a>
+<span class="sourceLineNo">1539</span>        if (!succeed) {<a name="line.1539"></a>
+<span class="sourceLineNo">1540</span>          throw new IOException("Failed to get write lock when closing region");<a name="line.1540"></a>
+<span class="sourceLineNo">1541</span>        }<a name="line.1541"></a>
+<span class="sourceLineNo">1542</span>      } catch (InterruptedException e) {<a name="line.1542"></a>
+<span class="sourceLineNo">1543</span>        throw (InterruptedIOException) new InterruptedIOException().initCause(e);<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>    this.closing.set(true);<a name="line.1546"></a>
+<span class="sourceLineNo">1547</span>    status.setStatus("Disabling writes for close");<a name="line.1547"></a>
+<span class="sourceLineNo">1548</span>    try {<a name="line.1548"></a>
+<span class="sourceLineNo">1549</span>      if (this.isClosed()) {<a name="line.1549"></a>
+<span class="sourceLineNo">1550</span>        status.abort("Already got closed by another process");<a name="line.1550"></a>
+<span class="sourceLineNo">1551</span>        // SplitTransaction handles the null<a name="line.1551"></a>
+<span class="sourceLineNo">1552</span>        return null;<a name="line.1552"></a>
+<span class="sourceLineNo">1553</span>      }<a name="line.1553"></a>
+<span class="sourceLineNo">1554</span>      LOG.debug("Updates disabled for region " + this);<a name="line.1554"></a>
+<span class="sourceLineNo">1555</span>      // Don't flush the cache if we are aborting<a name="line.1555"></a>
+<span class="sourceLineNo">1556</span>      if (!abort &amp;&amp; canFlush) {<a name="line.1556"></a>
+<span class="sourceLineNo">1557</span>        int failedfFlushCount = 0;<a name="line.1557"></a>
+<span class="sourceLineNo">1558</span>        int flushCount = 0;<a name="line.1558"></a>
+<span class="sourceLineNo">1559</span>        long tmp = 0;<a name="line.1559"></a>
+<span class="sourceLineNo">1560</span>        long remainingSize = this.memStoreSizing.getDataSize();<a name="line.1560"></a>
+<span class="sourceLineNo">1561</span>        while (remainingSize &gt; 0) {<a name="line.1561"></a>
+<span class="sourceLineNo">1562</span>          try {<a name="line.1562"></a>
+<span class="sourceLineNo">1563</span>            internalFlushcache(status);<a name="line.1563"></a>
+<span class="sourceLineNo">1564</span>            if(flushCount &gt;0) {<a name="line.1564"></a>
+<span class="sourceLineNo">1565</span>              LOG.info("Running extra flush, " + flushCount +<a name="line.1565"></a>
+<span class="sourceLineNo">1566</span>                  " (carrying snapshot?) " + this);<a name="line.1566"></a>
+<span class="sourceLineNo">1567</span>            }<a name="line.1567"></a>
+<span class="sourceLineNo">1568</span>            flushCount++;<a name="line.1568"></a>
+<span class="sourceLineNo">1569</span>            tmp = this.memStoreSizing.getDataSize();<a name="line.1569"></a>
+<span class="sourceLineNo">1570</span>            if (tmp &gt;= remainingSize) {<a name="line.1570"></a>
+<span class="sourceLineNo">1571</span>              failedfFlushCount++;<a name="line.1571"></a>
+<span class="sourceLineNo">1572</span>            }<a name="line.1572"></a>
+<span class="sourceLineNo">1573</span>            remainingSize = tmp;<a name="line.1573"></a>
+<span class="sourceLineNo">1574</span>            if (failedfFlushCount &gt; 5) {<a name="line.1574"></a>
+<span class="sourceLineNo">1575</span>              // If we failed 5 times and are unable to clear memory, abort<a name="line.1575"></a>
+<span class="sourceLineNo">1576</span>              // so we do not lose data<a name="line.1576"></a>
+<span class="sourceLineNo">1577</span>              throw new DroppedSnapshotException("Failed clearing memory after " +<a name="line.1577"></a>
+<span class="sourceLineNo">1578</span>                  flushCount + " attempts on region: " +<a name="line.1578"></a>
+<span class="sourceLineNo">1579</span>                  Bytes.toStringBinary(getRegionInfo().getRegionName()));<a name="line.1579"></a>
+<span class="sourceLineNo">1580</span>            }<a name="line.1580"></a>
+<span class="sourceLineNo">1581</span>          } catch (IOException ioe) {<a name="line.1581"></a>
+<span class="sourceLineNo">1582</span>            status.setStatus("Failed flush " + this + ", putting online again");<a name="line.1582"></a>
+<span class="sourceLineNo">1583</span>            synchronized (writestate) {<a name="line.1583"></a>
+<span class="sourceLineNo">1584</span>              writestate.writesEnabled = true;<a name="line.1584"></a>
+<span class="sourceLineNo">1585</span>            }<a name="line.1585"></a>
+<span class="sourceLineNo">1586</span>            // Have to throw to upper layers.  I can't abort server from here.<a name="line.1586"></a>
+<span class="sourceLineNo">1587</span>            throw ioe;<a name="line.1587"></a>
+<span class="sourceLineNo">1588</span>          }<a name="line.1588"></a>
+<span class="sourceLineNo">1589</span>        }<a name="line.1589"></a>
+<span class="sourceLineNo">1590</span>      }<a name="line.1590"></a>
+<span class="sourceLineNo">1591</span><a name="line.1591"></a>
+<span class="sourceLineNo">1592</span>      Map&lt;byte[], List&lt;HStoreFile&gt;&gt; result = new TreeMap&lt;&gt;(Bytes.BYTES_COMPARATOR);<a name="line.1592"></a>
+<span class="sourceLineNo">1593</span>      if (!stores.isEmpty()) {<a name="line.1593"></a>
+<span class="sourceLineNo">1594</span>        // initialize the thread pool for closing stores in parallel.<a name="line.1594"></a>
+<span class="sourceLineNo">1595</span>        ThreadPoolExecutor storeCloserThreadPool =<a name="line.1595"></a>
+<span class="sourceLineNo">1596</span>          getStoreOpenAndCloseThreadPool("StoreCloserThread-" +<a name="line.1596"></a>
+<span class="sourceLineNo">1597</span>            getRegionInfo().getRegionNameAsString());<a name="line.1597"></a>
+<span class="sourceLineNo">1598</span>        CompletionService&lt;Pair&lt;byte[], Collection&lt;HStoreFile&gt;&gt;&gt; completionService =<a name="line.1598"></a>
+<span class="sourceLineNo">1599</span>          new ExecutorCompletionService&lt;&gt;(storeCloserThreadPool);<a name="line.1599"></a>
+<span class="sourceLineNo">1600</span><a name="line.1600"></a>
+<span class="sourceLineNo">1601</span>        // close each store in parallel<a name="line.1601"></a>
+<span class="sourceLineNo">1602</span>        for (HStore store : stores.values()) {<a name="line.1602"></a>
+<span class="sourceLineNo">1603</span>          MemStoreSize mss = store.getFlushableSize();<a name="line.1603"></a>
+<span class="sourceLineNo">1604</span>          if (!(abort || mss.getDataSize() == 0 || writestate.readOnly)) {<a name="line.1604"></a>
+<span class="sourceLineNo">1605</span>            if (getRegionServerServices() != null) {<a name="line.1605"></a>
+<span class="sourceLineNo">1606</span>              getRegionServerServices().abort("Assertion failed while closing store "<a name="line.1606"></a>
+<span class="sourceLineNo">1607</span>                + getRegionInfo().getRegionNameAsString() + " " + store<a name="line.1607"></a>
+<span class="sourceLineNo">1608</span>                + ". flushableSize expected=0, actual={" + mss<a name="line.1608"></a>
+<span class="sourceLineNo">1609</span>                + "}. Current memStoreSize=" + this.memStoreSizing.getMemStoreSize() +<a name="line.1609"></a>
+<span class="sourceLineNo">1610</span>                  ". Maybe a coprocessor "<a name="line.1610"></a>
+<span class="sourceLineNo">1611</span>                + "operation failed and left the memstore in a partially updated state.", null);<a name="line.1611"></a>
+<span class="sourceLineNo">1612</span>            }<a name="line.1612"></a>
+<span class="sourceLineNo">1613</span>          }<a name="line.1613"></a>
+<span class="sourceLineNo">1614</span>          completionService<a name="line.1614"></a>
+<span class="sourceLineNo">1615</span>              .submit(new Callable&lt;Pair&lt;byte[], Collection&lt;HStoreFile&gt;&gt;&gt;() {<a name="line.1615"></a>
+<span class="sourceLineNo">1616</span>                @Override<a name="line.1616"></a>
+<span class="sourceLineNo">1617</span>                public Pair&lt;byte[], Collection&lt;HStoreFile&gt;&gt; call() throws IOException {<a name="line.1617"></a>
+<span class="sourceLineNo">1618</span>                  return new Pair&lt;&gt;(store.getColumnFamilyDescriptor().getName(), store.close());<a name="line.1618"></a>
+<span class="sourceLineNo">1619</span>                }<a name="line.1619"></a>
+<span class="sourceLineNo">1620</span>              });<a name="line.1620"></a>
+<span class="sourceLineNo">1621</span>        }<a name="line.1621"></a>
+<span class="sourceLineNo">1622</span>        try {<a name="line.1622"></a>
+<span class="sourceLineNo">1623</span>          for (int i = 0; i &lt; stores.size(); i++) {<a name="line.1623"></a>
+<span class="sourceLineNo">1624</span>            Future&lt;Pair&lt;byte[], Collection&lt;HStoreFile&gt;&gt;&gt; future = completionService.take();<a name="line.1624"></a>
+<span class="sourceLineNo">1625</span>            Pair&lt;byte[], Collection&lt;HStoreFile&gt;&gt; storeFiles = future.get();<a name="line.1625"></a>
+<span class="sourceLineNo">1626</span>            List&lt;HStoreFile&gt; familyFiles = result.get(storeFiles.getFirst());<a name="line.1626"></a>
+<span class="sourceLineNo">1627</span>            if (familyFiles == null) {<a name="line.1627"></a>
+<span class="sourceLineNo">1628</span>              familyFiles = new ArrayList&lt;&gt;();<a name="line.1628"></a>
+<span class="sourceLineNo">1629</span>              result.put(storeFiles.getFirst(), familyFiles);<a name="line.1629"></a>
+<span class="sourceLineNo">1630</span>            }<a name="line.1630"></a>
+<span class="sourceLineNo">1631</span>            familyFiles.addAll(storeFiles.getSecond());<a name="line.1631"></a>
+<span class="sourceLineNo">1632</span>          }<a name="line.1632"></a>
+<span class="sourceLineNo">1633</span>        } catch (InterruptedException e) {<a name="line.1633"></a>
+<span class="sourceLineNo">1634</span>          throw (InterruptedIOException)new InterruptedIOException().initCause(e);<a name="line.1634"></a>
+<span class="sourceLineNo">1635</span>        } catch (ExecutionException e) {<a name="line.1635"></a>
+<span class="sourceLineNo">1636</span>          Throwable cause = e.getCause();<a name="line.1636"></a>
+<span class="sourceLineNo">1637</span>          if (cause instanceof IOException) {<a name="line.1637"></a>
+<span class="sourceLineNo">1638</span>            throw (IOException) cause;<a name="line.1638"></a>
+<span class="sourceLineNo">1639</span>          }<a name="line.1639"></a>
+<span class="sourceLineNo">1640</span>          throw new IOException(cause);<a name="line.1640"></a>
+<span class="sourceLineNo">1641</span>        } finally {<a name="line.1641"></a>
+<span class="sourceLineNo">1642</span>          storeCloserThreadPool.shutdownNow();<a name="line.1642"></a>
+<span class="sourceLineNo">1643</span>        }<a name="line.1643"></a>
+<span class="sourceLineNo">1644</span>      }<a name="line.1644"></a>
+<span class="sourceLineNo">1645</span><a name="line.1645"></a>
+<span class="sourceLineNo">1646</span>      status.setStatus("Writing region close event to WAL");<a name="line.1646"></a>
+<span class="sourceLineNo">1647</span>      if (!abort &amp;&amp; wal != null &amp;&amp; getRegionServerServices() != null &amp;&amp; !writestate.readOnly) {<a name="line.1647"></a>
+<span class="sourceLineNo">1648</span>        writeRegionCloseMarker(wal);<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

<TRUNCATED>

Mime
View raw message