hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [08/25] hbase-site git commit: Published site at 2ab8122a24eb8444c2804b7f980bf008f395933d.
Date Tue, 11 Sep 2018 14:54:12 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/dcc97e01/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestHRegion.GetTillDoneOrException.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestHRegion.GetTillDoneOrException.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestHRegion.GetTillDoneOrException.html
index f2a9072..d2de828 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestHRegion.GetTillDoneOrException.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestHRegion.GetTillDoneOrException.html
@@ -274,7 +274,7 @@
 <span class="sourceLineNo">266</span>    assertEquals(HConstants.NO_SEQNUM, region.getMaxFlushedSeqId());<a name="line.266"></a>
 <span class="sourceLineNo">267</span>    // Weird. This returns 0 if no store files or no edits. Afraid to change it.<a name="line.267"></a>
 <span class="sourceLineNo">268</span>    assertEquals(0, (long)region.getMaxStoreSeqId().get(COLUMN_FAMILY_BYTES));<a name="line.268"></a>
-<span class="sourceLineNo">269</span>    region.close();<a name="line.269"></a>
+<span class="sourceLineNo">269</span>    HBaseTestingUtility.closeRegionAndWAL(this.region);<a name="line.269"></a>
 <span class="sourceLineNo">270</span>    assertEquals(HConstants.NO_SEQNUM, region.getMaxFlushedSeqId());<a name="line.270"></a>
 <span class="sourceLineNo">271</span>    assertEquals(0, (long)region.getMaxStoreSeqId().get(COLUMN_FAMILY_BYTES));<a name="line.271"></a>
 <span class="sourceLineNo">272</span>    // Open region again.<a name="line.272"></a>
@@ -289,6035 +289,6038 @@
 <span class="sourceLineNo">281</span>    assertEquals(0, (long)region.getMaxStoreSeqId().get(COLUMN_FAMILY_BYTES));<a name="line.281"></a>
 <span class="sourceLineNo">282</span>    region.flush(true);<a name="line.282"></a>
 <span class="sourceLineNo">283</span>    long max = region.getMaxFlushedSeqId();<a name="line.283"></a>
-<span class="sourceLineNo">284</span>    region.close();<a name="line.284"></a>
+<span class="sourceLineNo">284</span>    HBaseTestingUtility.closeRegionAndWAL(this.region);<a name="line.284"></a>
 <span class="sourceLineNo">285</span>    assertEquals(max, region.getMaxFlushedSeqId());<a name="line.285"></a>
-<span class="sourceLineNo">286</span>  }<a name="line.286"></a>
-<span class="sourceLineNo">287</span><a name="line.287"></a>
-<span class="sourceLineNo">288</span>  /**<a name="line.288"></a>
-<span class="sourceLineNo">289</span>   * Test for Bug 2 of HBASE-10466.<a name="line.289"></a>
-<span class="sourceLineNo">290</span>   * "Bug 2: Conditions for the first flush of region close (so-called pre-flush) If memstoreSize<a name="line.290"></a>
-<span class="sourceLineNo">291</span>   * is smaller than a certain value, or when region close starts a flush is ongoing, the first<a name="line.291"></a>
-<span class="sourceLineNo">292</span>   * flush is skipped and only the second flush takes place. However, two flushes are required in<a name="line.292"></a>
-<span class="sourceLineNo">293</span>   * case previous flush fails and leaves some data in snapshot. The bug could cause loss of data<a name="line.293"></a>
-<span class="sourceLineNo">294</span>   * in current memstore. The fix is removing all conditions except abort check so we ensure 2<a name="line.294"></a>
-<span class="sourceLineNo">295</span>   * flushes for region close."<a name="line.295"></a>
-<span class="sourceLineNo">296</span>   * @throws IOException<a name="line.296"></a>
-<span class="sourceLineNo">297</span>   */<a name="line.297"></a>
-<span class="sourceLineNo">298</span>  @Test<a name="line.298"></a>
-<span class="sourceLineNo">299</span>  public void testCloseCarryingSnapshot() throws IOException {<a name="line.299"></a>
-<span class="sourceLineNo">300</span>    region = initHRegion(tableName, method, CONF, COLUMN_FAMILY_BYTES);<a name="line.300"></a>
-<span class="sourceLineNo">301</span>    HStore store = region.getStore(COLUMN_FAMILY_BYTES);<a name="line.301"></a>
-<span class="sourceLineNo">302</span>    // Get some random bytes.<a name="line.302"></a>
-<span class="sourceLineNo">303</span>    byte [] value = Bytes.toBytes(method);<a name="line.303"></a>
-<span class="sourceLineNo">304</span>    // Make a random put against our cf.<a name="line.304"></a>
-<span class="sourceLineNo">305</span>    Put put = new Put(value);<a name="line.305"></a>
-<span class="sourceLineNo">306</span>    put.addColumn(COLUMN_FAMILY_BYTES, null, value);<a name="line.306"></a>
-<span class="sourceLineNo">307</span>    // First put something in current memstore, which will be in snapshot after flusher.prepare()<a name="line.307"></a>
-<span class="sourceLineNo">308</span>    region.put(put);<a name="line.308"></a>
-<span class="sourceLineNo">309</span>    StoreFlushContext storeFlushCtx = store.createFlushContext(12345, FlushLifeCycleTracker.DUMMY);<a name="line.309"></a>
-<span class="sourceLineNo">310</span>    storeFlushCtx.prepare();<a name="line.310"></a>
-<span class="sourceLineNo">311</span>    // Second put something in current memstore<a name="line.311"></a>
-<span class="sourceLineNo">312</span>    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("abc"), value);<a name="line.312"></a>
-<span class="sourceLineNo">313</span>    region.put(put);<a name="line.313"></a>
-<span class="sourceLineNo">314</span>    // Close with something in memstore and something in the snapshot.  Make sure all is cleared.<a name="line.314"></a>
-<span class="sourceLineNo">315</span>    region.close();<a name="line.315"></a>
-<span class="sourceLineNo">316</span>    assertEquals(0, region.getMemStoreDataSize());<a name="line.316"></a>
-<span class="sourceLineNo">317</span>    HBaseTestingUtility.closeRegionAndWAL(region);<a name="line.317"></a>
-<span class="sourceLineNo">318</span>  }<a name="line.318"></a>
-<span class="sourceLineNo">319</span><a name="line.319"></a>
-<span class="sourceLineNo">320</span>  /*<a name="line.320"></a>
-<span class="sourceLineNo">321</span>   * This test is for verifying memstore snapshot size is correctly updated in case of rollback<a name="line.321"></a>
-<span class="sourceLineNo">322</span>   * See HBASE-10845<a name="line.322"></a>
-<span class="sourceLineNo">323</span>   */<a name="line.323"></a>
-<span class="sourceLineNo">324</span>  @Test<a name="line.324"></a>
-<span class="sourceLineNo">325</span>  public void testMemstoreSnapshotSize() throws IOException {<a name="line.325"></a>
-<span class="sourceLineNo">326</span>    class MyFaultyFSLog extends FaultyFSLog {<a name="line.326"></a>
-<span class="sourceLineNo">327</span>      StoreFlushContext storeFlushCtx;<a name="line.327"></a>
-<span class="sourceLineNo">328</span>      public MyFaultyFSLog(FileSystem fs, Path rootDir, String logName, Configuration conf)<a name="line.328"></a>
-<span class="sourceLineNo">329</span>          throws IOException {<a name="line.329"></a>
-<span class="sourceLineNo">330</span>        super(fs, rootDir, logName, conf);<a name="line.330"></a>
-<span class="sourceLineNo">331</span>      }<a name="line.331"></a>
-<span class="sourceLineNo">332</span><a name="line.332"></a>
-<span class="sourceLineNo">333</span>      void setStoreFlushCtx(StoreFlushContext storeFlushCtx) {<a name="line.333"></a>
-<span class="sourceLineNo">334</span>        this.storeFlushCtx = storeFlushCtx;<a name="line.334"></a>
-<span class="sourceLineNo">335</span>      }<a name="line.335"></a>
-<span class="sourceLineNo">336</span><a name="line.336"></a>
-<span class="sourceLineNo">337</span>      @Override<a name="line.337"></a>
-<span class="sourceLineNo">338</span>      public void sync(long txid) throws IOException {<a name="line.338"></a>
-<span class="sourceLineNo">339</span>        storeFlushCtx.prepare();<a name="line.339"></a>
-<span class="sourceLineNo">340</span>        super.sync(txid);<a name="line.340"></a>
-<span class="sourceLineNo">341</span>      }<a name="line.341"></a>
-<span class="sourceLineNo">342</span>    }<a name="line.342"></a>
-<span class="sourceLineNo">343</span><a name="line.343"></a>
-<span class="sourceLineNo">344</span>    FileSystem fs = FileSystem.get(CONF);<a name="line.344"></a>
-<span class="sourceLineNo">345</span>    Path rootDir = new Path(dir + "testMemstoreSnapshotSize");<a name="line.345"></a>
-<span class="sourceLineNo">346</span>    MyFaultyFSLog faultyLog = new MyFaultyFSLog(fs, rootDir, "testMemstoreSnapshotSize", CONF);<a name="line.346"></a>
-<span class="sourceLineNo">347</span>    faultyLog.init();<a name="line.347"></a>
-<span class="sourceLineNo">348</span>    region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, faultyLog,<a name="line.348"></a>
-<span class="sourceLineNo">349</span>        COLUMN_FAMILY_BYTES);<a name="line.349"></a>
-<span class="sourceLineNo">350</span><a name="line.350"></a>
-<span class="sourceLineNo">351</span>    HStore store = region.getStore(COLUMN_FAMILY_BYTES);<a name="line.351"></a>
-<span class="sourceLineNo">352</span>    // Get some random bytes.<a name="line.352"></a>
-<span class="sourceLineNo">353</span>    byte [] value = Bytes.toBytes(method);<a name="line.353"></a>
-<span class="sourceLineNo">354</span>    faultyLog.setStoreFlushCtx(store.createFlushContext(12345, FlushLifeCycleTracker.DUMMY));<a name="line.354"></a>
-<span class="sourceLineNo">355</span><a name="line.355"></a>
-<span class="sourceLineNo">356</span>    Put put = new Put(value);<a name="line.356"></a>
-<span class="sourceLineNo">357</span>    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("abc"), value);<a name="line.357"></a>
-<span class="sourceLineNo">358</span>    faultyLog.setFailureType(FaultyFSLog.FailureType.SYNC);<a name="line.358"></a>
-<span class="sourceLineNo">359</span>    boolean threwIOE = false;<a name="line.359"></a>
-<span class="sourceLineNo">360</span>    try {<a name="line.360"></a>
-<span class="sourceLineNo">361</span>      region.put(put);<a name="line.361"></a>
-<span class="sourceLineNo">362</span>    } catch (IOException ioe) {<a name="line.362"></a>
-<span class="sourceLineNo">363</span>      threwIOE = true;<a name="line.363"></a>
-<span class="sourceLineNo">364</span>    } finally {<a name="line.364"></a>
-<span class="sourceLineNo">365</span>      assertTrue("The regionserver should have thrown an exception", threwIOE);<a name="line.365"></a>
-<span class="sourceLineNo">366</span>    }<a name="line.366"></a>
-<span class="sourceLineNo">367</span>    MemStoreSize mss = store.getFlushableSize();<a name="line.367"></a>
-<span class="sourceLineNo">368</span>    assertTrue("flushable size should be zero, but it is " + mss,<a name="line.368"></a>
-<span class="sourceLineNo">369</span>        mss.getDataSize() == 0);<a name="line.369"></a>
-<span class="sourceLineNo">370</span>  }<a name="line.370"></a>
-<span class="sourceLineNo">371</span><a name="line.371"></a>
-<span class="sourceLineNo">372</span>  /**<a name="line.372"></a>
-<span class="sourceLineNo">373</span>   * Create a WAL outside of the usual helper in<a name="line.373"></a>
-<span class="sourceLineNo">374</span>   * {@link HBaseTestingUtility#createWal(Configuration, Path, RegionInfo)} because that method<a name="line.374"></a>
-<span class="sourceLineNo">375</span>   * doesn't play nicely with FaultyFileSystem. Call this method before overriding<a name="line.375"></a>
-<span class="sourceLineNo">376</span>   * {@code fs.file.impl}.<a name="line.376"></a>
-<span class="sourceLineNo">377</span>   * @param callingMethod a unique component for the path, probably the name of the test method.<a name="line.377"></a>
-<span class="sourceLineNo">378</span>   */<a name="line.378"></a>
-<span class="sourceLineNo">379</span>  private static WAL createWALCompatibleWithFaultyFileSystem(String callingMethod,<a name="line.379"></a>
-<span class="sourceLineNo">380</span>      Configuration conf, TableName tableName) throws IOException {<a name="line.380"></a>
-<span class="sourceLineNo">381</span>    final Path logDir = TEST_UTIL.getDataTestDirOnTestFS(callingMethod + ".log");<a name="line.381"></a>
-<span class="sourceLineNo">382</span>    final Configuration walConf = new Configuration(conf);<a name="line.382"></a>
-<span class="sourceLineNo">383</span>    FSUtils.setRootDir(walConf, logDir);<a name="line.383"></a>
-<span class="sourceLineNo">384</span>    return new WALFactory(walConf, callingMethod)<a name="line.384"></a>
-<span class="sourceLineNo">385</span>        .getWAL(RegionInfoBuilder.newBuilder(tableName).build());<a name="line.385"></a>
-<span class="sourceLineNo">386</span>  }<a name="line.386"></a>
-<span class="sourceLineNo">387</span><a name="line.387"></a>
-<span class="sourceLineNo">388</span>  @Test<a name="line.388"></a>
-<span class="sourceLineNo">389</span>  public void testMemstoreSizeAccountingWithFailedPostBatchMutate() throws IOException {<a name="line.389"></a>
-<span class="sourceLineNo">390</span>    String testName = "testMemstoreSizeAccountingWithFailedPostBatchMutate";<a name="line.390"></a>
-<span class="sourceLineNo">391</span>    FileSystem fs = FileSystem.get(CONF);<a name="line.391"></a>
-<span class="sourceLineNo">392</span>    Path rootDir = new Path(dir + testName);<a name="line.392"></a>
-<span class="sourceLineNo">393</span>    FSHLog hLog = new FSHLog(fs, rootDir, testName, CONF);<a name="line.393"></a>
-<span class="sourceLineNo">394</span>    hLog.init();<a name="line.394"></a>
-<span class="sourceLineNo">395</span>    region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, hLog,<a name="line.395"></a>
-<span class="sourceLineNo">396</span>        COLUMN_FAMILY_BYTES);<a name="line.396"></a>
-<span class="sourceLineNo">397</span>    HStore store = region.getStore(COLUMN_FAMILY_BYTES);<a name="line.397"></a>
-<span class="sourceLineNo">398</span>    assertEquals(0, region.getMemStoreDataSize());<a name="line.398"></a>
-<span class="sourceLineNo">399</span><a name="line.399"></a>
-<span class="sourceLineNo">400</span>    // Put one value<a name="line.400"></a>
-<span class="sourceLineNo">401</span>    byte [] value = Bytes.toBytes(method);<a name="line.401"></a>
-<span class="sourceLineNo">402</span>    Put put = new Put(value);<a name="line.402"></a>
-<span class="sourceLineNo">403</span>    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("abc"), value);<a name="line.403"></a>
-<span class="sourceLineNo">404</span>    region.put(put);<a name="line.404"></a>
-<span class="sourceLineNo">405</span>    long onePutSize = region.getMemStoreDataSize();<a name="line.405"></a>
-<span class="sourceLineNo">406</span>    assertTrue(onePutSize &gt; 0);<a name="line.406"></a>
-<span class="sourceLineNo">407</span><a name="line.407"></a>
-<span class="sourceLineNo">408</span>    RegionCoprocessorHost mockedCPHost = Mockito.mock(RegionCoprocessorHost.class);<a name="line.408"></a>
-<span class="sourceLineNo">409</span>    doThrow(new IOException())<a name="line.409"></a>
-<span class="sourceLineNo">410</span>       .when(mockedCPHost).postBatchMutate(Mockito.&lt;MiniBatchOperationInProgress&lt;Mutation&gt;&gt;any());<a name="line.410"></a>
-<span class="sourceLineNo">411</span>    region.setCoprocessorHost(mockedCPHost);<a name="line.411"></a>
-<span class="sourceLineNo">412</span><a name="line.412"></a>
-<span class="sourceLineNo">413</span>    put = new Put(value);<a name="line.413"></a>
-<span class="sourceLineNo">414</span>    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("dfg"), value);<a name="line.414"></a>
-<span class="sourceLineNo">415</span>    try {<a name="line.415"></a>
-<span class="sourceLineNo">416</span>      region.put(put);<a name="line.416"></a>
-<span class="sourceLineNo">417</span>      fail("Should have failed with IOException");<a name="line.417"></a>
-<span class="sourceLineNo">418</span>    } catch (IOException expected) {<a name="line.418"></a>
-<span class="sourceLineNo">419</span>    }<a name="line.419"></a>
-<span class="sourceLineNo">420</span>    long expectedSize = onePutSize * 2;<a name="line.420"></a>
-<span class="sourceLineNo">421</span>    assertEquals("memstoreSize should be incremented",<a name="line.421"></a>
-<span class="sourceLineNo">422</span>        expectedSize, region.getMemStoreDataSize());<a name="line.422"></a>
-<span class="sourceLineNo">423</span>    assertEquals("flushable size should be incremented",<a name="line.423"></a>
-<span class="sourceLineNo">424</span>        expectedSize, store.getFlushableSize().getDataSize());<a name="line.424"></a>
-<span class="sourceLineNo">425</span><a name="line.425"></a>
-<span class="sourceLineNo">426</span>    region.setCoprocessorHost(null);<a name="line.426"></a>
-<span class="sourceLineNo">427</span>  }<a name="line.427"></a>
-<span class="sourceLineNo">428</span><a name="line.428"></a>
-<span class="sourceLineNo">429</span>  /**<a name="line.429"></a>
-<span class="sourceLineNo">430</span>   * A test case of HBASE-21041<a name="line.430"></a>
-<span class="sourceLineNo">431</span>   * @throws Exception Exception<a name="line.431"></a>
-<span class="sourceLineNo">432</span>   */<a name="line.432"></a>
-<span class="sourceLineNo">433</span>  @Test<a name="line.433"></a>
-<span class="sourceLineNo">434</span>  public void testFlushAndMemstoreSizeCounting() throws Exception {<a name="line.434"></a>
-<span class="sourceLineNo">435</span>    byte[] family = Bytes.toBytes("family");<a name="line.435"></a>
-<span class="sourceLineNo">436</span>    this.region = initHRegion(tableName, method, CONF, family);<a name="line.436"></a>
-<span class="sourceLineNo">437</span>    final WALFactory wals = new WALFactory(CONF, method);<a name="line.437"></a>
-<span class="sourceLineNo">438</span>    try {<a name="line.438"></a>
-<span class="sourceLineNo">439</span>      for (byte[] row : HBaseTestingUtility.ROWS) {<a name="line.439"></a>
-<span class="sourceLineNo">440</span>        Put put = new Put(row);<a name="line.440"></a>
-<span class="sourceLineNo">441</span>        put.addColumn(family, family, row);<a name="line.441"></a>
-<span class="sourceLineNo">442</span>        region.put(put);<a name="line.442"></a>
-<span class="sourceLineNo">443</span>      }<a name="line.443"></a>
-<span class="sourceLineNo">444</span>      region.flush(true);<a name="line.444"></a>
-<span class="sourceLineNo">445</span>      // After flush, data size should be zero<a name="line.445"></a>
-<span class="sourceLineNo">446</span>      assertEquals(0, region.getMemStoreDataSize());<a name="line.446"></a>
-<span class="sourceLineNo">447</span>      // After flush, a new active mutable segment is created, so the heap size<a name="line.447"></a>
-<span class="sourceLineNo">448</span>      // should equal to MutableSegment.DEEP_OVERHEAD<a name="line.448"></a>
-<span class="sourceLineNo">449</span>      assertEquals(MutableSegment.DEEP_OVERHEAD, region.getMemStoreHeapSize());<a name="line.449"></a>
-<span class="sourceLineNo">450</span>      // After flush, offheap should be zero<a name="line.450"></a>
-<span class="sourceLineNo">451</span>      assertEquals(0, region.getMemStoreOffHeapSize());<a name="line.451"></a>
-<span class="sourceLineNo">452</span>    } finally {<a name="line.452"></a>
-<span class="sourceLineNo">453</span>      HBaseTestingUtility.closeRegionAndWAL(this.region);<a name="line.453"></a>
-<span class="sourceLineNo">454</span>      this.region = null;<a name="line.454"></a>
-<span class="sourceLineNo">455</span>      wals.close();<a name="line.455"></a>
-<span class="sourceLineNo">456</span>    }<a name="line.456"></a>
-<span class="sourceLineNo">457</span>  }<a name="line.457"></a>
-<span class="sourceLineNo">458</span><a name="line.458"></a>
-<span class="sourceLineNo">459</span>  /**<a name="line.459"></a>
-<span class="sourceLineNo">460</span>   * Test we do not lose data if we fail a flush and then close.<a name="line.460"></a>
-<span class="sourceLineNo">461</span>   * Part of HBase-10466.  Tests the following from the issue description:<a name="line.461"></a>
-<span class="sourceLineNo">462</span>   * "Bug 1: Wrong calculation of HRegion.memstoreSize: When a flush fails, data to be flushed is<a name="line.462"></a>
-<span class="sourceLineNo">463</span>   * kept in each MemStore's snapshot and wait for next flush attempt to continue on it. But when<a name="line.463"></a>
-<span class="sourceLineNo">464</span>   * the next flush succeeds, the counter of total memstore size in HRegion is always deduced by<a name="line.464"></a>
-<span class="sourceLineNo">465</span>   * the sum of current memstore sizes instead of snapshots left from previous failed flush. This<a name="line.465"></a>
-<span class="sourceLineNo">466</span>   * calculation is problematic that almost every time there is failed flush, HRegion.memstoreSize<a name="line.466"></a>
-<span class="sourceLineNo">467</span>   * gets reduced by a wrong value. If region flush could not proceed for a couple cycles, the size<a name="line.467"></a>
-<span class="sourceLineNo">468</span>   * in current memstore could be much larger than the snapshot. It's likely to drift memstoreSize<a name="line.468"></a>
-<span class="sourceLineNo">469</span>   * much smaller than expected. In extreme case, if the error accumulates to even bigger than<a name="line.469"></a>
-<span class="sourceLineNo">470</span>   * HRegion's memstore size limit, any further flush is skipped because flush does not do anything<a name="line.470"></a>
-<span class="sourceLineNo">471</span>   * if memstoreSize is not larger than 0."<a name="line.471"></a>
-<span class="sourceLineNo">472</span>   * @throws Exception<a name="line.472"></a>
-<span class="sourceLineNo">473</span>   */<a name="line.473"></a>
-<span class="sourceLineNo">474</span>  @Test<a name="line.474"></a>
-<span class="sourceLineNo">475</span>  public void testFlushSizeAccounting() throws Exception {<a name="line.475"></a>
-<span class="sourceLineNo">476</span>    final Configuration conf = HBaseConfiguration.create(CONF);<a name="line.476"></a>
-<span class="sourceLineNo">477</span>    final WAL wal = createWALCompatibleWithFaultyFileSystem(method, conf, tableName);<a name="line.477"></a>
-<span class="sourceLineNo">478</span>    // Only retry once.<a name="line.478"></a>
-<span class="sourceLineNo">479</span>    conf.setInt("hbase.hstore.flush.retries.number", 1);<a name="line.479"></a>
-<span class="sourceLineNo">480</span>    final User user =<a name="line.480"></a>
-<span class="sourceLineNo">481</span>      User.createUserForTesting(conf, method, new String[]{"foo"});<a name="line.481"></a>
-<span class="sourceLineNo">482</span>    // Inject our faulty LocalFileSystem<a name="line.482"></a>
-<span class="sourceLineNo">483</span>    conf.setClass("fs.file.impl", FaultyFileSystem.class, FileSystem.class);<a name="line.483"></a>
-<span class="sourceLineNo">484</span>    user.runAs(new PrivilegedExceptionAction&lt;Object&gt;() {<a name="line.484"></a>
-<span class="sourceLineNo">485</span>      @Override<a name="line.485"></a>
-<span class="sourceLineNo">486</span>      public Object run() throws Exception {<a name="line.486"></a>
-<span class="sourceLineNo">487</span>        // Make sure it worked (above is sensitive to caching details in hadoop core)<a name="line.487"></a>
-<span class="sourceLineNo">488</span>        FileSystem fs = FileSystem.get(conf);<a name="line.488"></a>
-<span class="sourceLineNo">489</span>        Assert.assertEquals(FaultyFileSystem.class, fs.getClass());<a name="line.489"></a>
-<span class="sourceLineNo">490</span>        FaultyFileSystem ffs = (FaultyFileSystem)fs;<a name="line.490"></a>
-<span class="sourceLineNo">491</span>        HRegion region = null;<a name="line.491"></a>
-<span class="sourceLineNo">492</span>        try {<a name="line.492"></a>
-<span class="sourceLineNo">493</span>          // Initialize region<a name="line.493"></a>
-<span class="sourceLineNo">494</span>          region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, wal,<a name="line.494"></a>
-<span class="sourceLineNo">495</span>              COLUMN_FAMILY_BYTES);<a name="line.495"></a>
-<span class="sourceLineNo">496</span>          long size = region.getMemStoreDataSize();<a name="line.496"></a>
-<span class="sourceLineNo">497</span>          Assert.assertEquals(0, size);<a name="line.497"></a>
-<span class="sourceLineNo">498</span>          // Put one item into memstore.  Measure the size of one item in memstore.<a name="line.498"></a>
-<span class="sourceLineNo">499</span>          Put p1 = new Put(row);<a name="line.499"></a>
-<span class="sourceLineNo">500</span>          p1.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual1, 1, (byte[]) null));<a name="line.500"></a>
-<span class="sourceLineNo">501</span>          region.put(p1);<a name="line.501"></a>
-<span class="sourceLineNo">502</span>          final long sizeOfOnePut = region.getMemStoreDataSize();<a name="line.502"></a>
-<span class="sourceLineNo">503</span>          // Fail a flush which means the current memstore will hang out as memstore 'snapshot'.<a name="line.503"></a>
-<span class="sourceLineNo">504</span>          try {<a name="line.504"></a>
-<span class="sourceLineNo">505</span>            LOG.info("Flushing");<a name="line.505"></a>
-<span class="sourceLineNo">506</span>            region.flush(true);<a name="line.506"></a>
-<span class="sourceLineNo">507</span>            Assert.fail("Didn't bubble up IOE!");<a name="line.507"></a>
-<span class="sourceLineNo">508</span>          } catch (DroppedSnapshotException dse) {<a name="line.508"></a>
-<span class="sourceLineNo">509</span>            // What we are expecting<a name="line.509"></a>
-<span class="sourceLineNo">510</span>            region.closing.set(false); // this is needed for the rest of the test to work<a name="line.510"></a>
-<span class="sourceLineNo">511</span>          }<a name="line.511"></a>
-<span class="sourceLineNo">512</span>          // Make it so all writes succeed from here on out<a name="line.512"></a>
-<span class="sourceLineNo">513</span>          ffs.fault.set(false);<a name="line.513"></a>
-<span class="sourceLineNo">514</span>          // Check sizes.  Should still be the one entry.<a name="line.514"></a>
-<span class="sourceLineNo">515</span>          Assert.assertEquals(sizeOfOnePut, region.getMemStoreDataSize());<a name="line.515"></a>
-<span class="sourceLineNo">516</span>          // Now add two entries so that on this next flush that fails, we can see if we<a name="line.516"></a>
-<span class="sourceLineNo">517</span>          // subtract the right amount, the snapshot size only.<a name="line.517"></a>
-<span class="sourceLineNo">518</span>          Put p2 = new Put(row);<a name="line.518"></a>
-<span class="sourceLineNo">519</span>          p2.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual2, 2, (byte[])null));<a name="line.519"></a>
-<span class="sourceLineNo">520</span>          p2.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual3, 3, (byte[])null));<a name="line.520"></a>
-<span class="sourceLineNo">521</span>          region.put(p2);<a name="line.521"></a>
-<span class="sourceLineNo">522</span>          long expectedSize = sizeOfOnePut * 3;<a name="line.522"></a>
-<span class="sourceLineNo">523</span>          Assert.assertEquals(expectedSize, region.getMemStoreDataSize());<a name="line.523"></a>
-<span class="sourceLineNo">524</span>          // Do a successful flush.  It will clear the snapshot only.  Thats how flushes work.<a name="line.524"></a>
-<span class="sourceLineNo">525</span>          // If already a snapshot, we clear it else we move the memstore to be snapshot and flush<a name="line.525"></a>
-<span class="sourceLineNo">526</span>          // it<a name="line.526"></a>
-<span class="sourceLineNo">527</span>          region.flush(true);<a name="line.527"></a>
-<span class="sourceLineNo">528</span>          // Make sure our memory accounting is right.<a name="line.528"></a>
-<span class="sourceLineNo">529</span>          Assert.assertEquals(sizeOfOnePut * 2, region.getMemStoreDataSize());<a name="line.529"></a>
-<span class="sourceLineNo">530</span>        } finally {<a name="line.530"></a>
-<span class="sourceLineNo">531</span>          HBaseTestingUtility.closeRegionAndWAL(region);<a name="line.531"></a>
-<span class="sourceLineNo">532</span>        }<a name="line.532"></a>
-<span class="sourceLineNo">533</span>        return null;<a name="line.533"></a>
-<span class="sourceLineNo">534</span>      }<a name="line.534"></a>
-<span class="sourceLineNo">535</span>    });<a name="line.535"></a>
-<span class="sourceLineNo">536</span>    FileSystem.closeAllForUGI(user.getUGI());<a name="line.536"></a>
-<span class="sourceLineNo">537</span>  }<a name="line.537"></a>
-<span class="sourceLineNo">538</span><a name="line.538"></a>
-<span class="sourceLineNo">539</span>  @Test<a name="line.539"></a>
-<span class="sourceLineNo">540</span>  public void testCloseWithFailingFlush() throws Exception {<a name="line.540"></a>
-<span class="sourceLineNo">541</span>    final Configuration conf = HBaseConfiguration.create(CONF);<a name="line.541"></a>
-<span class="sourceLineNo">542</span>    final WAL wal = createWALCompatibleWithFaultyFileSystem(method, conf, tableName);<a name="line.542"></a>
-<span class="sourceLineNo">543</span>    // Only retry once.<a name="line.543"></a>
-<span class="sourceLineNo">544</span>    conf.setInt("hbase.hstore.flush.retries.number", 1);<a name="line.544"></a>
-<span class="sourceLineNo">545</span>    final User user =<a name="line.545"></a>
-<span class="sourceLineNo">546</span>      User.createUserForTesting(conf, this.method, new String[]{"foo"});<a name="line.546"></a>
-<span class="sourceLineNo">547</span>    // Inject our faulty LocalFileSystem<a name="line.547"></a>
-<span class="sourceLineNo">548</span>    conf.setClass("fs.file.impl", FaultyFileSystem.class, FileSystem.class);<a name="line.548"></a>
-<span class="sourceLineNo">549</span>    user.runAs(new PrivilegedExceptionAction&lt;Object&gt;() {<a name="line.549"></a>
-<span class="sourceLineNo">550</span>      @Override<a name="line.550"></a>
-<span class="sourceLineNo">551</span>      public Object run() throws Exception {<a name="line.551"></a>
-<span class="sourceLineNo">552</span>        // Make sure it worked (above is sensitive to caching details in hadoop core)<a name="line.552"></a>
-<span class="sourceLineNo">553</span>        FileSystem fs = FileSystem.get(conf);<a name="line.553"></a>
-<span class="sourceLineNo">554</span>        Assert.assertEquals(FaultyFileSystem.class, fs.getClass());<a name="line.554"></a>
-<span class="sourceLineNo">555</span>        FaultyFileSystem ffs = (FaultyFileSystem)fs;<a name="line.555"></a>
-<span class="sourceLineNo">556</span>        HRegion region = null;<a name="line.556"></a>
-<span class="sourceLineNo">557</span>        try {<a name="line.557"></a>
-<span class="sourceLineNo">558</span>          // Initialize region<a name="line.558"></a>
-<span class="sourceLineNo">559</span>          region = initHRegion(tableName, null, null, false,<a name="line.559"></a>
-<span class="sourceLineNo">560</span>              Durability.SYNC_WAL, wal, COLUMN_FAMILY_BYTES);<a name="line.560"></a>
-<span class="sourceLineNo">561</span>          long size = region.getMemStoreDataSize();<a name="line.561"></a>
-<span class="sourceLineNo">562</span>          Assert.assertEquals(0, size);<a name="line.562"></a>
-<span class="sourceLineNo">563</span>          // Put one item into memstore.  Measure the size of one item in memstore.<a name="line.563"></a>
-<span class="sourceLineNo">564</span>          Put p1 = new Put(row);<a name="line.564"></a>
-<span class="sourceLineNo">565</span>          p1.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual1, 1, (byte[])null));<a name="line.565"></a>
-<span class="sourceLineNo">566</span>          region.put(p1);<a name="line.566"></a>
-<span class="sourceLineNo">567</span>          // Manufacture an outstanding snapshot -- fake a failed flush by doing prepare step only.<a name="line.567"></a>
-<span class="sourceLineNo">568</span>          HStore store = region.getStore(COLUMN_FAMILY_BYTES);<a name="line.568"></a>
-<span class="sourceLineNo">569</span>          StoreFlushContext storeFlushCtx =<a name="line.569"></a>
-<span class="sourceLineNo">570</span>              store.createFlushContext(12345, FlushLifeCycleTracker.DUMMY);<a name="line.570"></a>
-<span class="sourceLineNo">571</span>          storeFlushCtx.prepare();<a name="line.571"></a>
-<span class="sourceLineNo">572</span>          // Now add two entries to the foreground memstore.<a name="line.572"></a>
-<span class="sourceLineNo">573</span>          Put p2 = new Put(row);<a name="line.573"></a>
-<span class="sourceLineNo">574</span>          p2.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual2, 2, (byte[])null));<a name="line.574"></a>
-<span class="sourceLineNo">575</span>          p2.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual3, 3, (byte[])null));<a name="line.575"></a>
-<span class="sourceLineNo">576</span>          region.put(p2);<a name="line.576"></a>
-<span class="sourceLineNo">577</span>          // Now try close on top of a failing flush.<a name="line.577"></a>
-<span class="sourceLineNo">578</span>          region.close();<a name="line.578"></a>
-<span class="sourceLineNo">579</span>          fail();<a name="line.579"></a>
-<span class="sourceLineNo">580</span>        } catch (DroppedSnapshotException dse) {<a name="line.580"></a>
-<span class="sourceLineNo">581</span>          // Expected<a name="line.581"></a>
-<span class="sourceLineNo">582</span>          LOG.info("Expected DroppedSnapshotException");<a name="line.582"></a>
-<span class="sourceLineNo">583</span>        } finally {<a name="line.583"></a>
-<span class="sourceLineNo">584</span>          // Make it so all writes succeed from here on out so can close clean<a name="line.584"></a>
-<span class="sourceLineNo">585</span>          ffs.fault.set(false);<a name="line.585"></a>
-<span class="sourceLineNo">586</span>          HBaseTestingUtility.closeRegionAndWAL(region);<a name="line.586"></a>
-<span class="sourceLineNo">587</span>        }<a name="line.587"></a>
-<span class="sourceLineNo">588</span>        return null;<a name="line.588"></a>
-<span class="sourceLineNo">589</span>      }<a name="line.589"></a>
-<span class="sourceLineNo">590</span>    });<a name="line.590"></a>
-<span class="sourceLineNo">591</span>    FileSystem.closeAllForUGI(user.getUGI());<a name="line.591"></a>
-<span class="sourceLineNo">592</span>  }<a name="line.592"></a>
-<span class="sourceLineNo">593</span><a name="line.593"></a>
-<span class="sourceLineNo">594</span>  @Test<a name="line.594"></a>
-<span class="sourceLineNo">595</span>  public void testCompactionAffectedByScanners() throws Exception {<a name="line.595"></a>
-<span class="sourceLineNo">596</span>    byte[] family = Bytes.toBytes("family");<a name="line.596"></a>
-<span class="sourceLineNo">597</span>    this.region = initHRegion(tableName, method, CONF, family);<a name="line.597"></a>
-<span class="sourceLineNo">598</span><a name="line.598"></a>
-<span class="sourceLineNo">599</span>    Put put = new Put(Bytes.toBytes("r1"));<a name="line.599"></a>
-<span class="sourceLineNo">600</span>    put.addColumn(family, Bytes.toBytes("q1"), Bytes.toBytes("v1"));<a name="line.600"></a>
-<span class="sourceLineNo">601</span>    region.put(put);<a name="line.601"></a>
-<span class="sourceLineNo">602</span>    region.flush(true);<a name="line.602"></a>
-<span class="sourceLineNo">603</span><a name="line.603"></a>
-<span class="sourceLineNo">604</span>    Scan scan = new Scan();<a name="line.604"></a>
-<span class="sourceLineNo">605</span>    scan.setMaxVersions(3);<a name="line.605"></a>
-<span class="sourceLineNo">606</span>    // open the first scanner<a name="line.606"></a>
-<span class="sourceLineNo">607</span>    RegionScanner scanner1 = region.getScanner(scan);<a name="line.607"></a>
-<span class="sourceLineNo">608</span><a name="line.608"></a>
-<span class="sourceLineNo">609</span>    Delete delete = new Delete(Bytes.toBytes("r1"));<a name="line.609"></a>
-<span class="sourceLineNo">610</span>    region.delete(delete);<a name="line.610"></a>
-<span class="sourceLineNo">611</span>    region.flush(true);<a name="line.611"></a>
-<span class="sourceLineNo">612</span><a name="line.612"></a>
-<span class="sourceLineNo">613</span>    // open the second scanner<a name="line.613"></a>
-<span class="sourceLineNo">614</span>    RegionScanner scanner2 = region.getScanner(scan);<a name="line.614"></a>
-<span class="sourceLineNo">615</span><a name="line.615"></a>
-<span class="sourceLineNo">616</span>    List&lt;Cell&gt; results = new ArrayList&lt;&gt;();<a name="line.616"></a>
+<span class="sourceLineNo">286</span>    this.region = null;<a name="line.286"></a>
+<span class="sourceLineNo">287</span>  }<a name="line.287"></a>
+<span class="sourceLineNo">288</span><a name="line.288"></a>
+<span class="sourceLineNo">289</span>  /**<a name="line.289"></a>
+<span class="sourceLineNo">290</span>   * Test for Bug 2 of HBASE-10466.<a name="line.290"></a>
+<span class="sourceLineNo">291</span>   * "Bug 2: Conditions for the first flush of region close (so-called pre-flush) If memstoreSize<a name="line.291"></a>
+<span class="sourceLineNo">292</span>   * is smaller than a certain value, or when region close starts a flush is ongoing, the first<a name="line.292"></a>
+<span class="sourceLineNo">293</span>   * flush is skipped and only the second flush takes place. However, two flushes are required in<a name="line.293"></a>
+<span class="sourceLineNo">294</span>   * case previous flush fails and leaves some data in snapshot. The bug could cause loss of data<a name="line.294"></a>
+<span class="sourceLineNo">295</span>   * in current memstore. The fix is removing all conditions except abort check so we ensure 2<a name="line.295"></a>
+<span class="sourceLineNo">296</span>   * flushes for region close."<a name="line.296"></a>
+<span class="sourceLineNo">297</span>   * @throws IOException<a name="line.297"></a>
+<span class="sourceLineNo">298</span>   */<a name="line.298"></a>
+<span class="sourceLineNo">299</span>  @Test<a name="line.299"></a>
+<span class="sourceLineNo">300</span>  public void testCloseCarryingSnapshot() throws IOException {<a name="line.300"></a>
+<span class="sourceLineNo">301</span>    region = initHRegion(tableName, method, CONF, COLUMN_FAMILY_BYTES);<a name="line.301"></a>
+<span class="sourceLineNo">302</span>    HStore store = region.getStore(COLUMN_FAMILY_BYTES);<a name="line.302"></a>
+<span class="sourceLineNo">303</span>    // Get some random bytes.<a name="line.303"></a>
+<span class="sourceLineNo">304</span>    byte [] value = Bytes.toBytes(method);<a name="line.304"></a>
+<span class="sourceLineNo">305</span>    // Make a random put against our cf.<a name="line.305"></a>
+<span class="sourceLineNo">306</span>    Put put = new Put(value);<a name="line.306"></a>
+<span class="sourceLineNo">307</span>    put.addColumn(COLUMN_FAMILY_BYTES, null, value);<a name="line.307"></a>
+<span class="sourceLineNo">308</span>    // First put something in current memstore, which will be in snapshot after flusher.prepare()<a name="line.308"></a>
+<span class="sourceLineNo">309</span>    region.put(put);<a name="line.309"></a>
+<span class="sourceLineNo">310</span>    StoreFlushContext storeFlushCtx = store.createFlushContext(12345, FlushLifeCycleTracker.DUMMY);<a name="line.310"></a>
+<span class="sourceLineNo">311</span>    storeFlushCtx.prepare();<a name="line.311"></a>
+<span class="sourceLineNo">312</span>    // Second put something in current memstore<a name="line.312"></a>
+<span class="sourceLineNo">313</span>    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("abc"), value);<a name="line.313"></a>
+<span class="sourceLineNo">314</span>    region.put(put);<a name="line.314"></a>
+<span class="sourceLineNo">315</span>    // Close with something in memstore and something in the snapshot.  Make sure all is cleared.<a name="line.315"></a>
+<span class="sourceLineNo">316</span>    HBaseTestingUtility.closeRegionAndWAL(region);<a name="line.316"></a>
+<span class="sourceLineNo">317</span>    assertEquals(0, region.getMemStoreDataSize());<a name="line.317"></a>
+<span class="sourceLineNo">318</span>    region = null;<a name="line.318"></a>
+<span class="sourceLineNo">319</span>  }<a name="line.319"></a>
+<span class="sourceLineNo">320</span><a name="line.320"></a>
+<span class="sourceLineNo">321</span>  /*<a name="line.321"></a>
+<span class="sourceLineNo">322</span>   * This test is for verifying memstore snapshot size is correctly updated in case of rollback<a name="line.322"></a>
+<span class="sourceLineNo">323</span>   * See HBASE-10845<a name="line.323"></a>
+<span class="sourceLineNo">324</span>   */<a name="line.324"></a>
+<span class="sourceLineNo">325</span>  @Test<a name="line.325"></a>
+<span class="sourceLineNo">326</span>  public void testMemstoreSnapshotSize() throws IOException {<a name="line.326"></a>
+<span class="sourceLineNo">327</span>    class MyFaultyFSLog extends FaultyFSLog {<a name="line.327"></a>
+<span class="sourceLineNo">328</span>      StoreFlushContext storeFlushCtx;<a name="line.328"></a>
+<span class="sourceLineNo">329</span>      public MyFaultyFSLog(FileSystem fs, Path rootDir, String logName, Configuration conf)<a name="line.329"></a>
+<span class="sourceLineNo">330</span>          throws IOException {<a name="line.330"></a>
+<span class="sourceLineNo">331</span>        super(fs, rootDir, logName, conf);<a name="line.331"></a>
+<span class="sourceLineNo">332</span>      }<a name="line.332"></a>
+<span class="sourceLineNo">333</span><a name="line.333"></a>
+<span class="sourceLineNo">334</span>      void setStoreFlushCtx(StoreFlushContext storeFlushCtx) {<a name="line.334"></a>
+<span class="sourceLineNo">335</span>        this.storeFlushCtx = storeFlushCtx;<a name="line.335"></a>
+<span class="sourceLineNo">336</span>      }<a name="line.336"></a>
+<span class="sourceLineNo">337</span><a name="line.337"></a>
+<span class="sourceLineNo">338</span>      @Override<a name="line.338"></a>
+<span class="sourceLineNo">339</span>      public void sync(long txid) throws IOException {<a name="line.339"></a>
+<span class="sourceLineNo">340</span>        storeFlushCtx.prepare();<a name="line.340"></a>
+<span class="sourceLineNo">341</span>        super.sync(txid);<a name="line.341"></a>
+<span class="sourceLineNo">342</span>      }<a name="line.342"></a>
+<span class="sourceLineNo">343</span>    }<a name="line.343"></a>
+<span class="sourceLineNo">344</span><a name="line.344"></a>
+<span class="sourceLineNo">345</span>    FileSystem fs = FileSystem.get(CONF);<a name="line.345"></a>
+<span class="sourceLineNo">346</span>    Path rootDir = new Path(dir + "testMemstoreSnapshotSize");<a name="line.346"></a>
+<span class="sourceLineNo">347</span>    MyFaultyFSLog faultyLog = new MyFaultyFSLog(fs, rootDir, "testMemstoreSnapshotSize", CONF);<a name="line.347"></a>
+<span class="sourceLineNo">348</span>    faultyLog.init();<a name="line.348"></a>
+<span class="sourceLineNo">349</span>    region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, faultyLog,<a name="line.349"></a>
+<span class="sourceLineNo">350</span>        COLUMN_FAMILY_BYTES);<a name="line.350"></a>
+<span class="sourceLineNo">351</span><a name="line.351"></a>
+<span class="sourceLineNo">352</span>    HStore store = region.getStore(COLUMN_FAMILY_BYTES);<a name="line.352"></a>
+<span class="sourceLineNo">353</span>    // Get some random bytes.<a name="line.353"></a>
+<span class="sourceLineNo">354</span>    byte [] value = Bytes.toBytes(method);<a name="line.354"></a>
+<span class="sourceLineNo">355</span>    faultyLog.setStoreFlushCtx(store.createFlushContext(12345, FlushLifeCycleTracker.DUMMY));<a name="line.355"></a>
+<span class="sourceLineNo">356</span><a name="line.356"></a>
+<span class="sourceLineNo">357</span>    Put put = new Put(value);<a name="line.357"></a>
+<span class="sourceLineNo">358</span>    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("abc"), value);<a name="line.358"></a>
+<span class="sourceLineNo">359</span>    faultyLog.setFailureType(FaultyFSLog.FailureType.SYNC);<a name="line.359"></a>
+<span class="sourceLineNo">360</span>    boolean threwIOE = false;<a name="line.360"></a>
+<span class="sourceLineNo">361</span>    try {<a name="line.361"></a>
+<span class="sourceLineNo">362</span>      region.put(put);<a name="line.362"></a>
+<span class="sourceLineNo">363</span>    } catch (IOException ioe) {<a name="line.363"></a>
+<span class="sourceLineNo">364</span>      threwIOE = true;<a name="line.364"></a>
+<span class="sourceLineNo">365</span>    } finally {<a name="line.365"></a>
+<span class="sourceLineNo">366</span>      assertTrue("The regionserver should have thrown an exception", threwIOE);<a name="line.366"></a>
+<span class="sourceLineNo">367</span>    }<a name="line.367"></a>
+<span class="sourceLineNo">368</span>    MemStoreSize mss = store.getFlushableSize();<a name="line.368"></a>
+<span class="sourceLineNo">369</span>    assertTrue("flushable size should be zero, but it is " + mss,<a name="line.369"></a>
+<span class="sourceLineNo">370</span>        mss.getDataSize() == 0);<a name="line.370"></a>
+<span class="sourceLineNo">371</span>  }<a name="line.371"></a>
+<span class="sourceLineNo">372</span><a name="line.372"></a>
+<span class="sourceLineNo">373</span>  /**<a name="line.373"></a>
+<span class="sourceLineNo">374</span>   * Create a WAL outside of the usual helper in<a name="line.374"></a>
+<span class="sourceLineNo">375</span>   * {@link HBaseTestingUtility#createWal(Configuration, Path, RegionInfo)} because that method<a name="line.375"></a>
+<span class="sourceLineNo">376</span>   * doesn't play nicely with FaultyFileSystem. Call this method before overriding<a name="line.376"></a>
+<span class="sourceLineNo">377</span>   * {@code fs.file.impl}.<a name="line.377"></a>
+<span class="sourceLineNo">378</span>   * @param callingMethod a unique component for the path, probably the name of the test method.<a name="line.378"></a>
+<span class="sourceLineNo">379</span>   */<a name="line.379"></a>
+<span class="sourceLineNo">380</span>  private static WAL createWALCompatibleWithFaultyFileSystem(String callingMethod,<a name="line.380"></a>
+<span class="sourceLineNo">381</span>      Configuration conf, TableName tableName) throws IOException {<a name="line.381"></a>
+<span class="sourceLineNo">382</span>    final Path logDir = TEST_UTIL.getDataTestDirOnTestFS(callingMethod + ".log");<a name="line.382"></a>
+<span class="sourceLineNo">383</span>    final Configuration walConf = new Configuration(conf);<a name="line.383"></a>
+<span class="sourceLineNo">384</span>    FSUtils.setRootDir(walConf, logDir);<a name="line.384"></a>
+<span class="sourceLineNo">385</span>    return new WALFactory(walConf, callingMethod)<a name="line.385"></a>
+<span class="sourceLineNo">386</span>        .getWAL(RegionInfoBuilder.newBuilder(tableName).build());<a name="line.386"></a>
+<span class="sourceLineNo">387</span>  }<a name="line.387"></a>
+<span class="sourceLineNo">388</span><a name="line.388"></a>
+<span class="sourceLineNo">389</span>  @Test<a name="line.389"></a>
+<span class="sourceLineNo">390</span>  public void testMemstoreSizeAccountingWithFailedPostBatchMutate() throws IOException {<a name="line.390"></a>
+<span class="sourceLineNo">391</span>    String testName = "testMemstoreSizeAccountingWithFailedPostBatchMutate";<a name="line.391"></a>
+<span class="sourceLineNo">392</span>    FileSystem fs = FileSystem.get(CONF);<a name="line.392"></a>
+<span class="sourceLineNo">393</span>    Path rootDir = new Path(dir + testName);<a name="line.393"></a>
+<span class="sourceLineNo">394</span>    FSHLog hLog = new FSHLog(fs, rootDir, testName, CONF);<a name="line.394"></a>
+<span class="sourceLineNo">395</span>    hLog.init();<a name="line.395"></a>
+<span class="sourceLineNo">396</span>    region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, hLog,<a name="line.396"></a>
+<span class="sourceLineNo">397</span>        COLUMN_FAMILY_BYTES);<a name="line.397"></a>
+<span class="sourceLineNo">398</span>    HStore store = region.getStore(COLUMN_FAMILY_BYTES);<a name="line.398"></a>
+<span class="sourceLineNo">399</span>    assertEquals(0, region.getMemStoreDataSize());<a name="line.399"></a>
+<span class="sourceLineNo">400</span><a name="line.400"></a>
+<span class="sourceLineNo">401</span>    // Put one value<a name="line.401"></a>
+<span class="sourceLineNo">402</span>    byte [] value = Bytes.toBytes(method);<a name="line.402"></a>
+<span class="sourceLineNo">403</span>    Put put = new Put(value);<a name="line.403"></a>
+<span class="sourceLineNo">404</span>    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("abc"), value);<a name="line.404"></a>
+<span class="sourceLineNo">405</span>    region.put(put);<a name="line.405"></a>
+<span class="sourceLineNo">406</span>    long onePutSize = region.getMemStoreDataSize();<a name="line.406"></a>
+<span class="sourceLineNo">407</span>    assertTrue(onePutSize &gt; 0);<a name="line.407"></a>
+<span class="sourceLineNo">408</span><a name="line.408"></a>
+<span class="sourceLineNo">409</span>    RegionCoprocessorHost mockedCPHost = Mockito.mock(RegionCoprocessorHost.class);<a name="line.409"></a>
+<span class="sourceLineNo">410</span>    doThrow(new IOException())<a name="line.410"></a>
+<span class="sourceLineNo">411</span>       .when(mockedCPHost).postBatchMutate(Mockito.&lt;MiniBatchOperationInProgress&lt;Mutation&gt;&gt;any());<a name="line.411"></a>
+<span class="sourceLineNo">412</span>    region.setCoprocessorHost(mockedCPHost);<a name="line.412"></a>
+<span class="sourceLineNo">413</span><a name="line.413"></a>
+<span class="sourceLineNo">414</span>    put = new Put(value);<a name="line.414"></a>
+<span class="sourceLineNo">415</span>    put.addColumn(COLUMN_FAMILY_BYTES, Bytes.toBytes("dfg"), value);<a name="line.415"></a>
+<span class="sourceLineNo">416</span>    try {<a name="line.416"></a>
+<span class="sourceLineNo">417</span>      region.put(put);<a name="line.417"></a>
+<span class="sourceLineNo">418</span>      fail("Should have failed with IOException");<a name="line.418"></a>
+<span class="sourceLineNo">419</span>    } catch (IOException expected) {<a name="line.419"></a>
+<span class="sourceLineNo">420</span>    }<a name="line.420"></a>
+<span class="sourceLineNo">421</span>    long expectedSize = onePutSize * 2;<a name="line.421"></a>
+<span class="sourceLineNo">422</span>    assertEquals("memstoreSize should be incremented",<a name="line.422"></a>
+<span class="sourceLineNo">423</span>        expectedSize, region.getMemStoreDataSize());<a name="line.423"></a>
+<span class="sourceLineNo">424</span>    assertEquals("flushable size should be incremented",<a name="line.424"></a>
+<span class="sourceLineNo">425</span>        expectedSize, store.getFlushableSize().getDataSize());<a name="line.425"></a>
+<span class="sourceLineNo">426</span><a name="line.426"></a>
+<span class="sourceLineNo">427</span>    region.setCoprocessorHost(null);<a name="line.427"></a>
+<span class="sourceLineNo">428</span>  }<a name="line.428"></a>
+<span class="sourceLineNo">429</span><a name="line.429"></a>
+<span class="sourceLineNo">430</span>  /**<a name="line.430"></a>
+<span class="sourceLineNo">431</span>   * A test case of HBASE-21041<a name="line.431"></a>
+<span class="sourceLineNo">432</span>   * @throws Exception Exception<a name="line.432"></a>
+<span class="sourceLineNo">433</span>   */<a name="line.433"></a>
+<span class="sourceLineNo">434</span>  @Test<a name="line.434"></a>
+<span class="sourceLineNo">435</span>  public void testFlushAndMemstoreSizeCounting() throws Exception {<a name="line.435"></a>
+<span class="sourceLineNo">436</span>    byte[] family = Bytes.toBytes("family");<a name="line.436"></a>
+<span class="sourceLineNo">437</span>    this.region = initHRegion(tableName, method, CONF, family);<a name="line.437"></a>
+<span class="sourceLineNo">438</span>    final WALFactory wals = new WALFactory(CONF, method);<a name="line.438"></a>
+<span class="sourceLineNo">439</span>    try {<a name="line.439"></a>
+<span class="sourceLineNo">440</span>      for (byte[] row : HBaseTestingUtility.ROWS) {<a name="line.440"></a>
+<span class="sourceLineNo">441</span>        Put put = new Put(row);<a name="line.441"></a>
+<span class="sourceLineNo">442</span>        put.addColumn(family, family, row);<a name="line.442"></a>
+<span class="sourceLineNo">443</span>        region.put(put);<a name="line.443"></a>
+<span class="sourceLineNo">444</span>      }<a name="line.444"></a>
+<span class="sourceLineNo">445</span>      region.flush(true);<a name="line.445"></a>
+<span class="sourceLineNo">446</span>      // After flush, data size should be zero<a name="line.446"></a>
+<span class="sourceLineNo">447</span>      assertEquals(0, region.getMemStoreDataSize());<a name="line.447"></a>
+<span class="sourceLineNo">448</span>      // After flush, a new active mutable segment is created, so the heap size<a name="line.448"></a>
+<span class="sourceLineNo">449</span>      // should equal to MutableSegment.DEEP_OVERHEAD<a name="line.449"></a>
+<span class="sourceLineNo">450</span>      assertEquals(MutableSegment.DEEP_OVERHEAD, region.getMemStoreHeapSize());<a name="line.450"></a>
+<span class="sourceLineNo">451</span>      // After flush, offheap should be zero<a name="line.451"></a>
+<span class="sourceLineNo">452</span>      assertEquals(0, region.getMemStoreOffHeapSize());<a name="line.452"></a>
+<span class="sourceLineNo">453</span>    } finally {<a name="line.453"></a>
+<span class="sourceLineNo">454</span>      HBaseTestingUtility.closeRegionAndWAL(this.region);<a name="line.454"></a>
+<span class="sourceLineNo">455</span>      this.region = null;<a name="line.455"></a>
+<span class="sourceLineNo">456</span>      wals.close();<a name="line.456"></a>
+<span class="sourceLineNo">457</span>    }<a name="line.457"></a>
+<span class="sourceLineNo">458</span>  }<a name="line.458"></a>
+<span class="sourceLineNo">459</span><a name="line.459"></a>
+<span class="sourceLineNo">460</span>  /**<a name="line.460"></a>
+<span class="sourceLineNo">461</span>   * Test we do not lose data if we fail a flush and then close.<a name="line.461"></a>
+<span class="sourceLineNo">462</span>   * Part of HBase-10466.  Tests the following from the issue description:<a name="line.462"></a>
+<span class="sourceLineNo">463</span>   * "Bug 1: Wrong calculation of HRegion.memstoreSize: When a flush fails, data to be flushed is<a name="line.463"></a>
+<span class="sourceLineNo">464</span>   * kept in each MemStore's snapshot and wait for next flush attempt to continue on it. But when<a name="line.464"></a>
+<span class="sourceLineNo">465</span>   * the next flush succeeds, the counter of total memstore size in HRegion is always deduced by<a name="line.465"></a>
+<span class="sourceLineNo">466</span>   * the sum of current memstore sizes instead of snapshots left from previous failed flush. This<a name="line.466"></a>
+<span class="sourceLineNo">467</span>   * calculation is problematic that almost every time there is failed flush, HRegion.memstoreSize<a name="line.467"></a>
+<span class="sourceLineNo">468</span>   * gets reduced by a wrong value. If region flush could not proceed for a couple cycles, the size<a name="line.468"></a>
+<span class="sourceLineNo">469</span>   * in current memstore could be much larger than the snapshot. It's likely to drift memstoreSize<a name="line.469"></a>
+<span class="sourceLineNo">470</span>   * much smaller than expected. In extreme case, if the error accumulates to even bigger than<a name="line.470"></a>
+<span class="sourceLineNo">471</span>   * HRegion's memstore size limit, any further flush is skipped because flush does not do anything<a name="line.471"></a>
+<span class="sourceLineNo">472</span>   * if memstoreSize is not larger than 0."<a name="line.472"></a>
+<span class="sourceLineNo">473</span>   * @throws Exception<a name="line.473"></a>
+<span class="sourceLineNo">474</span>   */<a name="line.474"></a>
+<span class="sourceLineNo">475</span>  @Test<a name="line.475"></a>
+<span class="sourceLineNo">476</span>  public void testFlushSizeAccounting() throws Exception {<a name="line.476"></a>
+<span class="sourceLineNo">477</span>    final Configuration conf = HBaseConfiguration.create(CONF);<a name="line.477"></a>
+<span class="sourceLineNo">478</span>    final WAL wal = createWALCompatibleWithFaultyFileSystem(method, conf, tableName);<a name="line.478"></a>
+<span class="sourceLineNo">479</span>    // Only retry once.<a name="line.479"></a>
+<span class="sourceLineNo">480</span>    conf.setInt("hbase.hstore.flush.retries.number", 1);<a name="line.480"></a>
+<span class="sourceLineNo">481</span>    final User user =<a name="line.481"></a>
+<span class="sourceLineNo">482</span>      User.createUserForTesting(conf, method, new String[]{"foo"});<a name="line.482"></a>
+<span class="sourceLineNo">483</span>    // Inject our faulty LocalFileSystem<a name="line.483"></a>
+<span class="sourceLineNo">484</span>    conf.setClass("fs.file.impl", FaultyFileSystem.class, FileSystem.class);<a name="line.484"></a>
+<span class="sourceLineNo">485</span>    user.runAs(new PrivilegedExceptionAction&lt;Object&gt;() {<a name="line.485"></a>
+<span class="sourceLineNo">486</span>      @Override<a name="line.486"></a>
+<span class="sourceLineNo">487</span>      public Object run() throws Exception {<a name="line.487"></a>
+<span class="sourceLineNo">488</span>        // Make sure it worked (above is sensitive to caching details in hadoop core)<a name="line.488"></a>
+<span class="sourceLineNo">489</span>        FileSystem fs = FileSystem.get(conf);<a name="line.489"></a>
+<span class="sourceLineNo">490</span>        Assert.assertEquals(FaultyFileSystem.class, fs.getClass());<a name="line.490"></a>
+<span class="sourceLineNo">491</span>        FaultyFileSystem ffs = (FaultyFileSystem)fs;<a name="line.491"></a>
+<span class="sourceLineNo">492</span>        HRegion region = null;<a name="line.492"></a>
+<span class="sourceLineNo">493</span>        try {<a name="line.493"></a>
+<span class="sourceLineNo">494</span>          // Initialize region<a name="line.494"></a>
+<span class="sourceLineNo">495</span>          region = initHRegion(tableName, null, null, false, Durability.SYNC_WAL, wal,<a name="line.495"></a>
+<span class="sourceLineNo">496</span>              COLUMN_FAMILY_BYTES);<a name="line.496"></a>
+<span class="sourceLineNo">497</span>          long size = region.getMemStoreDataSize();<a name="line.497"></a>
+<span class="sourceLineNo">498</span>          Assert.assertEquals(0, size);<a name="line.498"></a>
+<span class="sourceLineNo">499</span>          // Put one item into memstore.  Measure the size of one item in memstore.<a name="line.499"></a>
+<span class="sourceLineNo">500</span>          Put p1 = new Put(row);<a name="line.500"></a>
+<span class="sourceLineNo">501</span>          p1.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual1, 1, (byte[]) null));<a name="line.501"></a>
+<span class="sourceLineNo">502</span>          region.put(p1);<a name="line.502"></a>
+<span class="sourceLineNo">503</span>          final long sizeOfOnePut = region.getMemStoreDataSize();<a name="line.503"></a>
+<span class="sourceLineNo">504</span>          // Fail a flush which means the current memstore will hang out as memstore 'snapshot'.<a name="line.504"></a>
+<span class="sourceLineNo">505</span>          try {<a name="line.505"></a>
+<span class="sourceLineNo">506</span>            LOG.info("Flushing");<a name="line.506"></a>
+<span class="sourceLineNo">507</span>            region.flush(true);<a name="line.507"></a>
+<span class="sourceLineNo">508</span>            Assert.fail("Didn't bubble up IOE!");<a name="line.508"></a>
+<span class="sourceLineNo">509</span>          } catch (DroppedSnapshotException dse) {<a name="line.509"></a>
+<span class="sourceLineNo">510</span>            // What we are expecting<a name="line.510"></a>
+<span class="sourceLineNo">511</span>            region.closing.set(false); // this is needed for the rest of the test to work<a name="line.511"></a>
+<span class="sourceLineNo">512</span>          }<a name="line.512"></a>
+<span class="sourceLineNo">513</span>          // Make it so all writes succeed from here on out<a name="line.513"></a>
+<span class="sourceLineNo">514</span>          ffs.fault.set(false);<a name="line.514"></a>
+<span class="sourceLineNo">515</span>          // Check sizes.  Should still be the one entry.<a name="line.515"></a>
+<span class="sourceLineNo">516</span>          Assert.assertEquals(sizeOfOnePut, region.getMemStoreDataSize());<a name="line.516"></a>
+<span class="sourceLineNo">517</span>          // Now add two entries so that on this next flush that fails, we can see if we<a name="line.517"></a>
+<span class="sourceLineNo">518</span>          // subtract the right amount, the snapshot size only.<a name="line.518"></a>
+<span class="sourceLineNo">519</span>          Put p2 = new Put(row);<a name="line.519"></a>
+<span class="sourceLineNo">520</span>          p2.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual2, 2, (byte[])null));<a name="line.520"></a>
+<span class="sourceLineNo">521</span>          p2.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual3, 3, (byte[])null));<a name="line.521"></a>
+<span class="sourceLineNo">522</span>          region.put(p2);<a name="line.522"></a>
+<span class="sourceLineNo">523</span>          long expectedSize = sizeOfOnePut * 3;<a name="line.523"></a>
+<span class="sourceLineNo">524</span>          Assert.assertEquals(expectedSize, region.getMemStoreDataSize());<a name="line.524"></a>
+<span class="sourceLineNo">525</span>          // Do a successful flush.  It will clear the snapshot only.  Thats how flushes work.<a name="line.525"></a>
+<span class="sourceLineNo">526</span>          // If already a snapshot, we clear it else we move the memstore to be snapshot and flush<a name="line.526"></a>
+<span class="sourceLineNo">527</span>          // it<a name="line.527"></a>
+<span class="sourceLineNo">528</span>          region.flush(true);<a name="line.528"></a>
+<span class="sourceLineNo">529</span>          // Make sure our memory accounting is right.<a name="line.529"></a>
+<span class="sourceLineNo">530</span>          Assert.assertEquals(sizeOfOnePut * 2, region.getMemStoreDataSize());<a name="line.530"></a>
+<span class="sourceLineNo">531</span>        } finally {<a name="line.531"></a>
+<span class="sourceLineNo">532</span>          HBaseTestingUtility.closeRegionAndWAL(region);<a name="line.532"></a>
+<span class="sourceLineNo">533</span>        }<a name="line.533"></a>
+<span class="sourceLineNo">534</span>        return null;<a name="line.534"></a>
+<span class="sourceLineNo">535</span>      }<a name="line.535"></a>
+<span class="sourceLineNo">536</span>    });<a name="line.536"></a>
+<span class="sourceLineNo">537</span>    FileSystem.closeAllForUGI(user.getUGI());<a name="line.537"></a>
+<span class="sourceLineNo">538</span>  }<a name="line.538"></a>
+<span class="sourceLineNo">539</span><a name="line.539"></a>
+<span class="sourceLineNo">540</span>  @Test<a name="line.540"></a>
+<span class="sourceLineNo">541</span>  public void testCloseWithFailingFlush() throws Exception {<a name="line.541"></a>
+<span class="sourceLineNo">542</span>    final Configuration conf = HBaseConfiguration.create(CONF);<a name="line.542"></a>
+<span class="sourceLineNo">543</span>    final WAL wal = createWALCompatibleWithFaultyFileSystem(method, conf, tableName);<a name="line.543"></a>
+<span class="sourceLineNo">544</span>    // Only retry once.<a name="line.544"></a>
+<span class="sourceLineNo">545</span>    conf.setInt("hbase.hstore.flush.retries.number", 1);<a name="line.545"></a>
+<span class="sourceLineNo">546</span>    final User user =<a name="line.546"></a>
+<span class="sourceLineNo">547</span>      User.createUserForTesting(conf, this.method, new String[]{"foo"});<a name="line.547"></a>
+<span class="sourceLineNo">548</span>    // Inject our faulty LocalFileSystem<a name="line.548"></a>
+<span class="sourceLineNo">549</span>    conf.setClass("fs.file.impl", FaultyFileSystem.class, FileSystem.class);<a name="line.549"></a>
+<span class="sourceLineNo">550</span>    user.runAs(new PrivilegedExceptionAction&lt;Object&gt;() {<a name="line.550"></a>
+<span class="sourceLineNo">551</span>      @Override<a name="line.551"></a>
+<span class="sourceLineNo">552</span>      public Object run() throws Exception {<a name="line.552"></a>
+<span class="sourceLineNo">553</span>        // Make sure it worked (above is sensitive to caching details in hadoop core)<a name="line.553"></a>
+<span class="sourceLineNo">554</span>        FileSystem fs = FileSystem.get(conf);<a name="line.554"></a>
+<span class="sourceLineNo">555</span>        Assert.assertEquals(FaultyFileSystem.class, fs.getClass());<a name="line.555"></a>
+<span class="sourceLineNo">556</span>        FaultyFileSystem ffs = (FaultyFileSystem)fs;<a name="line.556"></a>
+<span class="sourceLineNo">557</span>        HRegion region = null;<a name="line.557"></a>
+<span class="sourceLineNo">558</span>        try {<a name="line.558"></a>
+<span class="sourceLineNo">559</span>          // Initialize region<a name="line.559"></a>
+<span class="sourceLineNo">560</span>          region = initHRegion(tableName, null, null, false,<a name="line.560"></a>
+<span class="sourceLineNo">561</span>              Durability.SYNC_WAL, wal, COLUMN_FAMILY_BYTES);<a name="line.561"></a>
+<span class="sourceLineNo">562</span>          long size = region.getMemStoreDataSize();<a name="line.562"></a>
+<span class="sourceLineNo">563</span>          Assert.assertEquals(0, size);<a name="line.563"></a>
+<span class="sourceLineNo">564</span>          // Put one item into memstore.  Measure the size of one item in memstore.<a name="line.564"></a>
+<span class="sourceLineNo">565</span>          Put p1 = new Put(row);<a name="line.565"></a>
+<span class="sourceLineNo">566</span>          p1.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual1, 1, (byte[])null));<a name="line.566"></a>
+<span class="sourceLineNo">567</span>          region.put(p1);<a name="line.567"></a>
+<span class="sourceLineNo">568</span>          // Manufacture an outstanding snapshot -- fake a failed flush by doing prepare step only.<a name="line.568"></a>
+<span class="sourceLineNo">569</span>          HStore store = region.getStore(COLUMN_FAMILY_BYTES);<a name="line.569"></a>
+<span class="sourceLineNo">570</span>          StoreFlushContext storeFlushCtx =<a name="line.570"></a>
+<span class="sourceLineNo">571</span>              store.createFlushContext(12345, FlushLifeCycleTracker.DUMMY);<a name="line.571"></a>
+<span class="sourceLineNo">572</span>          storeFlushCtx.prepare();<a name="line.572"></a>
+<span class="sourceLineNo">573</span>          // Now add two entries to the foreground memstore.<a name="line.573"></a>
+<span class="sourceLineNo">574</span>          Put p2 = new Put(row);<a name="line.574"></a>
+<span class="sourceLineNo">575</span>          p2.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual2, 2, (byte[])null));<a name="line.575"></a>
+<span class="sourceLineNo">576</span>          p2.add(new KeyValue(row, COLUMN_FAMILY_BYTES, qual3, 3, (byte[])null));<a name="line.576"></a>
+<span class="sourceLineNo">577</span>          region.put(p2);<a name="line.577"></a>
+<span class="sourceLineNo">578</span>          // Now try close on top of a failing flush.<a name="line.578"></a>
+<span class="sourceLineNo">579</span>          HBaseTestingUtility.closeRegionAndWAL(region);<a name="line.579"></a>
+<span class="sourceLineNo">580</span>          region = null;<a name="line.580"></a>
+<span class="sourceLineNo">581</span>          fail();<a name="line.581"></a>
+<span class="sourceLineNo">582</span>        } catch (DroppedSnapshotException dse) {<a name="line.582"></a>
+<span class="sourceLineNo">583</span>          // Expected<a name="line.583"></a>
+<span class="sourceLineNo">584</span>          LOG.info("Expected DroppedSnapshotException");<a name="line.584"></a>
+<span class="sourceLineNo">585</span>        } finally {<a name="line.585"></a>
+<span class="sourceLineNo">586</span>          // Make it so all writes succeed from here on out so can close clean<a name="line.586"></a>
+<span class="sourceLineNo">587</span>          ffs.fault.set(false);<a name="line.587"></a>
+<span class="sourceLineNo">588</span>          HBaseTestingUtility.closeRegionAndWAL(region);<a name="line.588"></a>
+<span class="sourceLineNo">589</span>        }<a name="line.589"></a>
+<span class="sourceLineNo">590</span>        return null;<a name="line.590"></a>
+<span class="sourceLineNo">591</span>      }<a name="line.591"></a>
+<span class="sourceLineNo">592</span>    });<a name="line.592"></a>
+<span class="sourceLineNo">593</span>    FileSystem.closeAllForUGI(user.getUGI());<a name="line.593"></a>
+<span class="sourceLineNo">594</span>  }<a name="line.594"></a>
+<span class="sourceLineNo">595</span><a name="line.595"></a>
+<span class="sourceLineNo">596</span>  @Test<a name="line.596"></a>
+<span class="sourceLineNo">597</span>  public void testCompactionAffectedByScanners() throws Exception {<a name="line.597"></a>
+<span class="sourceLineNo">598</span>    byte[] family = Bytes.toBytes("family");<a name="line.598"></a>
+<span class="sourceLineNo">599</span>    this.region = initHRegion(tableName, method, CONF, family);<a name="line.599"></a>
+<span class="sourceLineNo">600</span><a name="line.600"></a>
+<span class="sourceLineNo">601</span>    Put put = new Put(Bytes.toBytes("r1"));<a name="line.601"></a>
+<span class="sourceLineNo">602</span>    put.addColumn(family, Bytes.toBytes("q1"), Bytes.toBytes("v1"));<a name="line.602"></a>
+<span class="sourceLineNo">603</span>    region.put(put);<a name="line.603"></a>
+<span class="sourceLineNo">604</span>    region.flush(true);<a name="line.604"></a>
+<span class="sourceLineNo">605</span><a name="line.605"></a>
+<span class="sourceLineNo">606</span>    Scan scan = new Scan();<a name="line.606"></a>
+<span class="sourceLineNo">607</span>    scan.setMaxVersions(3);<a name="line.607"></a>
+<span class="sourceLineNo">608</span>    // open the first scanner<a name="line.608"></a>
+<span class="sourceLineNo">609</span>    RegionScanner scanner1 = region.getScanner(scan);<a name="line.609"></a>
+<span class="sourceLineNo">610</span><a name="line.610"></a>
+<span class="sourceLineNo">611</span>    Delete delete = new Delete(Bytes.toBytes("r1"));<a name="line.611"></a>
+<span class="sourceLineNo">612</span>    region.delete(delete);<a name="line.612"></a>
+<span class="sourceLineNo">613</span>    region.flush(true);<a name="line.613"></a>
+<span class="sourceLineNo">614</span><a name="line.614"></a>
+<span class="sourceLineNo">615</span>    // open the second scanner<a name="line.615"></a>
+<span class="sourceLineNo">616</span>    RegionScanner scanner2 = region.getScanner(scan);<a name="line.616"></a>
 <span class="sourceLineNo">617</span><a name="line.617"></a>
-<span class="sourceLineNo">618</span>    System.out.println("Smallest read point:" + region.getSmallestReadPoint());<a name="line.618"></a>
+<span class="sourceLineNo">618</span>    List&lt;Cell&gt; results = new ArrayList&lt;&gt;();<a name="line.618"></a>
 <span class="sourceLineNo">619</span><a name="line.619"></a>
-<span class="sourceLineNo">620</span>    // make a major compaction<a name="line.620"></a>
-<span class="sourceLineNo">621</span>    region.compact(true);<a name="line.621"></a>
-<span class="sourceLineNo">622</span><a name="line.622"></a>
-<span class="sourceLineNo">623</span>    // open the third scanner<a name="line.623"></a>
-<span class="sourceLineNo">624</span>    RegionScanner scanner3 = region.getScanner(scan);<a name="line.624"></a>
-<span class="sourceLineNo">625</span><a name="line.625"></a>
-<span class="sourceLineNo">626</span>    // get data from scanner 1, 2, 3 after major compaction<a name="line.626"></a>
-<span class="sourceLineNo">627</span>    scanner1.next(results);<a name="line.627"></a>
-<span class="sourceLineNo">628</span>    System.out.println(results);<a name="line.628"></a>
-<span class="sourceLineNo">629</span>    assertEquals(1, results.size());<a name="line.629"></a>
-<span class="sourceLineNo">630</span><a name="line.630"></a>
-<span class="sourceLineNo">631</span>    results.clear();<a name="line.631"></a>
-<span class="sourceLineNo">632</span>    scanner2.next(results);<a name="line.632"></a>
-<span class="sourceLineNo">633</span>    System.out.println(results);<a name="line.633"></a>
-<span class="sourceLineNo">634</span>    assertEquals(0, results.size());<a name="line.634"></a>
-<span class="sourceLineNo">635</span><a name="line.635"></a>
-<span class="sourceLineNo">636</span>    results.clear();<a name="line.636"></a>
-<span class="sourceLineNo">637</span>    scanner3.next(results);<a name="line.637"></a>
-<span class="sourceLineNo">638</span>    System.out.println(results);<a name="line.638"></a>
-<span class="sourceLineNo">639</span>    assertEquals(0, results.size());<a name="line.639"></a>
-<span class="sourceLineNo">640</span>  }<a name="line.640"></a>
-<span class="sourceLineNo">641</span><a name="line.641"></a>
-<span class="sourceLineNo">642</span>  @Test<a name="line.642"></a>
-<span class="sourceLineNo">643</span>  public void testToShowNPEOnRegionScannerReseek() throws Exception {<a name="line.643"></a>
-<span class="sourceLineNo">644</span>    byte[] family = Bytes.toBytes("family");<a name="line.644"></a>
-<span class="sourceLineNo">645</span>    this.region = initHRegion(tableName, method, CONF, family);<a name="line.645"></a>
-<span class="sourceLineNo">646</span><a name="line.646"></a>
-<span class="sourceLineNo">647</span>    Put put = new Put(Bytes.toBytes("r1"));<a name="line.647"></a>
-<span class="sourceLineNo">648</span>    put.addColumn(family, Bytes.toBytes("q1"), Bytes.toBytes("v1"));<a name="line.648"></a>
-<span class="sourceLineNo">649</span>    region.put(put);<a name="line.649"></a>
-<span class="sourceLineNo">650</span>    put = new Put(Bytes.toBytes("r2"));<a name="line.650"></a>
-<span class="sourceLineNo">651</span>    put.addColumn(family, Bytes.toBytes("q1"), Bytes.toBytes("v1"));<a name="line.651"></a>
-<span class="sourceLineNo">652</span>    region.put(put);<a name="line.652"></a>
-<span class="sourceLineNo">653</span>    region.flush(true);<a name="line.653"></a>
-<span class="sourceLineNo">654</span><a name="line.654"></a>
-<span class="sourceLineNo">655</span>    Scan scan = new Scan();<a name="line.655"></a>
-<span class="sourceLineNo">656</span>    scan.setMaxVersions(3);<a name="line.656"></a>
-<span class="sourceLineNo">657</span>    // open the first scanner<a name="line.657"></a>
-<span class="sourceLineNo">658</span>    RegionScanner scanner1 = region.getScanner(scan);<a name="line.658"></a>
-<span class="sourceLineNo">659</span><a name="line.659"></a>
-<span class="sourceLineNo">660</span>    System.out.println("Smallest read point:" + region.getSmallestReadPoint());<a name="line.660"></a>
+<span class="sourceLineNo">620</span>    System.out.println("Smallest read point:" + region.getSmallestReadPoint());<a name="line.620"></a>
+<span class="sourceLineNo">621</span><a name="line.621"></a>
+<span class="sourceLineNo">622</span>    // make a major compaction<a name="line.622"></a>
+<span class="sourceLineNo">623</span>    region.compact(true);<a name="line.623"></a>
+<span class="sourceLineNo">624</span><a name="line.624"></a>
+<span class="sourceLineNo">625</span>    // open the third scanner<a name="line.625"></a>
+<span class="sourceLineNo">626</span>    RegionScanner scanner3 = region.getScanner(scan);<a name="line.626"></a>
+<span class="sourceLineNo">627</span><a name="line.627"></a>
+<span class="sourceLineNo">628</span>    // get data from scanner 1, 2, 3 after major compaction<a name="line.628"></a>
+<span class="sourceLineNo">629</span>    scanner1.next(results);<a name="line.629"></a>
+<span class="sourceLineNo">630</span>    System.out.println(results);<a name="line.630"></a>
+<span class="sourceLineNo">631</span>    assertEquals(1, results.size());<a name="line.631"></a>
+<span class="sourceLineNo">632</span><a name="line.632"></a>
+<span class="sourceLineNo">633</span>    results.clear();<a name="line.633"></a>
+<span class="sourceLineNo">634</span>    scanner2.next(results);<a name="line.634"></a>
+<span class="sourceLineNo">635</span>    System.out.println(results);<a name="line.635"></a>
+<span class="sourceLineNo">636</span>    assertEquals(0, results.size());<a name="line.636"></a>
+<span class="sourceLineNo">637</span><a name="line.637"></a>
+<span class="sourceLineNo">638</span>    results.clear();<a name="line.638"></a>
+<span class="sourceLineNo">639</span>    scanner3.next(results);<a name="line.639"></a>
+<span class="sourceLineNo">640</span>    System.out.println(results);<a name="line.640"></a>
+<span class="sourceLineNo">641</span>    assertEquals(0, results.size());<a name="line.641"></a>
+<span class="sourceLineNo">642</span>  }<a name="line.642"></a>
+<span class="sourceLineNo">643</span><a name="line.643"></a>
+<span class="sourceLineNo">644</span>  @Test<a name="line.644"></a>
+<span class="sourceLineNo">645</span>  public void testToShowNPEOnRegionScannerReseek() throws Exception {<a name="line.645"></a>
+<span class="sourceLineNo">646</span>    byte[] family = Bytes.toBytes("family");<a name="line.646"></a>
+<span class="sourceLineNo">647</span>    this.region = initHRegion(tableName, method, CONF, family);<a name="line.647"></a>
+<span class="sourceLineNo">648</span><a name="line.648"></a>
+<span class="sourceLineNo">649</span>    Put put = new Put(Bytes.toBytes("r1"));<a name="line.649"></a>
+<span class="sourceLineNo">650</span>    put.addColumn(family, Bytes.toBytes("q1"), Bytes.toBytes("v1"));<a name="line.650"></a>
+<span class="sourceLineNo">651</span>    region.put(put);<a name="line.651"></a>
+<span class="sourceLineNo">652</span>    put = new Put(Bytes.toBytes("r2"));<a name="line.652"></a>
+<span class="sourceLineNo">653</span>    put.addColumn(family, Bytes.toBytes("q1"), Bytes.toBytes("v1"));<a name="line.653"></a>
+<span class="sourceLineNo">654</span>    region.put(put);<a name="line.654"></a>
+<span class="sourceLineNo">655</span>    region.flush(true);<a name="line.655"></a>
+<span class="sourceLineNo">656</span><a name="line.656"></a>
+<span class="sourceLineNo">657</span>    Scan scan = new Scan();<a name="line.657"></a>
+<span class="sourceLineNo">658</span>    scan.setMaxVersions(3);<a name="line.658"></a>
+<span class="sourceLineNo">659</span>    // open the first scanner<a name="line.659"></a>
+<span class="sourceLineNo">660</span>    RegionScanner scanner1 = region.getScanner(scan);<a name="line.660"></a>
 <span class="sourceLineNo">661</span><a name="line.661"></a>
-<span class="sourceLineNo">662</span>    region.compact(true);<a name="line.662"></a>
+<span class="sourceLineNo">662</span>    System.out.println("Smallest read point:" + region.getSmallestReadPoint());<a name="line.662"></a>
 <span class="sourceLineNo">663</span><a name="line.663"></a>
-<span class="sourceLineNo">664</span>    scanner1.reseek(Bytes.toBytes("r2"));<a name="line.664"></a>
-<span class="sourceLineNo">665</span>    List&lt;Cell&gt; results = new ArrayList&lt;&gt;();<a name="line.665"></a>
-<span class="sourceLineNo">666</span>    scanner1.next(results);<a name="line.666"></a>
-<span class="sourceLineNo">667</span>    Cell keyValue = results.get(0);<a name="line.667"></a>
-<span class="sourceLineNo">668</span>    Assert.assertTrue(Bytes.compareTo(CellUtil.cloneRow(keyValue), Bytes.toBytes("r2")) == 0);<a name="line.668"></a>
-<span class="sourceLineNo">669</span>    scanner1.close();<a name="line.669"></a>
-<span class="sourceLineNo">670</span>  }<a name="line.670"></a>
-<span class="sourceLineNo">671</span><a name="line.671"></a>
-<span class="sourceLineNo">672</span>  @Test<a name="line.672"></a>
-<span class="sourceLineNo">673</span>  public void testSkipRecoveredEditsReplay() throws Exception {<a name="line.673"></a>
-<span class="sourceLineNo">674</span>    byte[] family = Bytes.toBytes("family");<a name="line.674"></a>
-<span class="sourceLineNo">675</span>    this.region = initHRegion(tableName, method, CONF, family);<a name="line.675"></a>
-<span class="sourceLineNo">676</span>    final WALFactory wals = new WALFactory(CONF, method);<a name="line.676"></a>
-<span class="sourceLineNo">677</span>    try {<a name="line.677"></a>
-<span class="sourceLineNo">678</span>      Path regiondir = region.getRegionFileSystem().getRegionDir();<a name="line.678"></a>
-<span class="sourceLineNo">679</span>      FileSystem fs = region.getRegionFileSystem().getFileSystem();<a name="line.679"></a>
-<span class="sourceLineNo">680</span>      byte[] regionName = region.getRegionInfo().getEncodedNameAsBytes();<a name="line.680"></a>
-<span class="sourceLineNo">681</span><a name="line.681"></a>
-<span class="sourceLineNo">682</span>      Path recoveredEditsDir = WALSplitter.getRegionDirRecoveredEditsDir(regiondir);<a name="line.682"></a>
+<span class="sourceLineNo">664</span>    region.compact(true);<a name="line.664"></a>
+<span class="sourceLineNo">665</span><a name="line.665"></a>
+<span class="sourceLineNo">666</span>    scanner1.reseek(Bytes.toBytes("r2"));<a name="line.666"></a>
+<span class="sourceLineNo">667</span>    List&lt;Cell&gt; results = new ArrayList&lt;&gt;();<a name="line.667"></a>
+<span class="sourceLineNo">668</span>    scanner1.next(results);<a name="line.668"></a>
+<span class="sourceLineNo">669</span>    Cell keyValue = results.get(0);<a name="line.669"></a>
+<span class="sourceLineNo">670</span>    Assert.assertTrue(Bytes.compareTo(CellUtil.cloneRow(keyValue), Bytes.toBytes("r2")) == 0);<a name="line.670"></a>
+<span class="sourceLineNo">671</span>    scanner1.close();<a name="line.671"></a>
+<span class="sourceLineNo">672</span>  }<a name="line.672"></a>
+<span class="sourceLineNo">673</span><a name="line.673"></a>
+<span class="sourceLineNo">674</span>  @Test<a name="line.674"></a>
+<span class="sourceLineNo">675</span>  public void testSkipRecoveredEditsReplay() throws Exception {<a name="line.675"></a>
+<span class="sourceLineNo">676</span>    byte[] family = Bytes.toBytes("family");<a name="line.676"></a>
+<span class="sourceLineNo">677</span>    this.region = initHRegion(tableName, method, CONF, family);<a name="line.677"></a>
+<span class="sourceLineNo">678</span>    final WALFactory wals = new WALFactory(CONF, method);<a name="line.678"></a>
+<span class="sourceLineNo">679</span>    try {<a name="line.679"></a>
+<span class="sourceLineNo">680</span>      Path regiondir = region.getRegionFileSystem().getRegionDir();<a name="line.680"></a>
+<span class="sourceLineNo">681</span>      FileSystem fs = region.getRegionFileSystem().getFileSystem();<a name="line.681"></a>
+<span class="sourceLineNo">682</span>      byte[] regionName = region.getRegionInfo().getEncodedNameAsBytes();<a name="line.682"></a>
 <span class="sourceLineNo">683</span><a name="line.683"></a>
-<span class="sourceLineNo">684</span>      long maxSeqId = 1050;<a name="line.684"></a>
-<span class="sourceLineNo">685</span>      long minSeqId = 1000;<a name="line.685"></a>
-<span class="sourceLineNo">686</span><a name="line.686"></a>
-<span class="sourceLineNo">687</span>      for (long i = minSeqId; i &lt;= maxSeqId; i += 10) {<a name="line.687"></a>
-<span class="sourceLineNo">688</span>        Path recoveredEdits = new Path(recoveredEditsDir, String.format("%019d", i));<a name="line.688"></a>
-<span class="sourceLineNo">689</span>        fs.create(recoveredEdits);<a name="line.689"></a>
-<span class="sourceLineNo">690</span>        WALProvider.Writer writer = wals.createRecoveredEditsWriter(fs, recoveredEdits);<a name="line.690"></a>
-<span class="sourceLineNo">691</span><a name="line.691"></a>
-<span class="sourceLineNo">692</span>        long time = System.nanoTime();<a name="line.692"></a>
-<span class="sourceLineNo">693</span>        WALEdit edit = new WALEdit();<a name="line.693"></a>
-<span class="sourceLineNo">694</span>        edit.add(new KeyValue(row, family, Bytes.toBytes(i), time, KeyValue.Type.Put, Bytes<a name="line.694"></a>
-<span class="sourceLineNo">695</span>            .toBytes(i)));<a name="line.695"></a>
-<span class="sourceLineNo">696</span>        writer.append(new WAL.Entry(new WALKeyImpl(regionName, tableName, i, time,<a name="line.696"></a>
-<span class="sourceLineNo">697</span>            HConstants.DEFAULT_CLUSTER_ID), edit));<a name="line.697"></a>
-<span class="sourceLineNo">698</span><a name="line.698"></a>
-<span class="sourceLineNo">699</span>        writer.close();<a name="line.699"></a>
-<span class="sourceLineNo">700</span>      }<a name="line.700"></a>
-<span class="sourceLineNo">701</span>      MonitoredTask status = TaskMonitor.get().createStatus(method);<a name="line.701"></a>
-<span class="sourceLineNo">702</span>      Map&lt;byte[], Long&gt; maxSeqIdInStores = new TreeMap&lt;&gt;(Bytes.BYTES_COMPARATOR);<a name="line.702"></a>
-<span class="sourceLineNo">703</span>      for (HStore store : region.getStores()) {<a name="line.703"></a>
-<span class="sourceLineNo">704</span>        maxSeqIdInStores.put(Bytes.toBytes(store.getColumnFamilyName()), minSeqId - 1);<a name="line.704"></a>
-<span class="sourceLineNo">705</span>      }<a name="line.705"></a>
-<span class="sourceLineNo">706</span>      long seqId = region.replayRecoveredEditsIfAny(regiondir, maxSeqIdInStores, null, status);<a name="line.706"></a>
-<span class="sourceLineNo">707</span>      assertEquals(maxSeqId, seqId);<a name="line.707"></a>
-<span class="sourceLineNo">708</span>      region.getMVCC().advanceTo(seqId);<a name="line.708"></a>
-<span class="sourceLineNo">709</span>      Get get = new Get(row);<a name="line.709"></a>
-<span class="sourceLineNo">710</span>      Result result = region.get(get);<a name="line.710"></a>
-<span class="sourceLineNo">711</span>      for (long i = minSeqId; i &lt;= maxSeqId; i += 10) {<a name="line.711"></a>
-<span class="sourceLineNo">712</span>        List&lt;Cell&gt; kvs = result.getColumnCells(family, Bytes.toBytes(i));<a name="line.712"></a>
-<span class="sourceLineNo">713</span>        assertEquals(1, kvs.size());<a name="line.713"></a>
-<span class="sourceLineNo">714</span>        assertArrayEquals(Bytes.toBytes(i), CellUtil.cloneValue(kvs.get(0)));<a name="line.714"></a>
-<span class="sourceLineNo">715</span>      }<a name="line.715"></a>
-<span class="sourceLineNo">716</span>    } finally {<a name="line.716"></a>
-<span class="sourceLineNo">717</span>      HBaseTestingUtility.closeRegionAndWAL(this.region);<a name="line.717"></a>
-<span class="sourceLineNo">718</span>      this.region = null;<a name="line.718"></a>
-<span class="sourceLineNo">719</span>      wals.close();<a name="line.719"></a>
-<span class="sourceLineNo">720</span>    }<a name="line.720"></a>
-<span class="sourceLineNo">721</span>  }<a name="line.721"></a>
-<span class="sourceLineNo">722</span><a name="line.722"></a>
-<span class="sourceLineNo">723</span>  @Test<a name="line.723"></a>
-<span class="sourceLineNo">724</span>  public void testSkipRecoveredEditsReplaySomeIgnored() throws Exception {<a name="line.724"></a>
-<span class="sourceLineNo">725</span>    byte[] family = Bytes.toBytes("family");<a name="line.725"></a>
-<span class="sourceLineNo">726</span>    this.region = initHRegion(tableName, method, CONF, family);<a name="line.726"></a>
-<span class="sourceLineNo">727</span>    final WALFactory wals = new WALFactory(CONF, method);<a name="line.727"></a>
-<span class="sourceLineNo">728</span>    try {<a name="line.728"></a>
-<span class="sourceLineNo">729</span>      Path regiondir = region.getRegionFileSystem().getRegionDir();<a name="line.729"></a>
-<span class="sourceLineNo">730</span>      FileSystem fs = region.getRegionFileSystem().getFileSystem();<a name="line.730"></a>
-<span class="sourceLineNo">731</span>      byte[] regionName = region.getRegionInfo().getEncodedNameAsBytes();<a name="line.731"></a>
-<span class="sourceLineNo">732</span><a name="line.732"></a>
-<span class="sourceLineNo">733</span>      Path recoveredEditsDir = WALSplitter.getRegionDirRecoveredEditsDir(regiondir);<a name="line.733"></a>
+<span class="sourceLineNo">684</span>      Path recoveredEditsDir = WALSplitter.getRegionDirRecoveredEditsDir(regiondir);<a name="line.684"></a>
+<span class="sourceLineNo">685</span><a name="line.685"></a>
+<span class="sourceLineNo">686</span>      long maxSeqId = 1050;<a name="line.686"></a>
+<span class="sourceLineNo">687</span>      long minSeqId = 1000;<a name="line.687"></a>
+<sp

<TRUNCATED>

Mime
View raw message