hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [20/45] hbase-site git commit: Published site at 04622254f7209c5cfeadcfa137a97fbed161075a.
Date Mon, 14 Dec 2015 16:38:31 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/736088b3/testdevapidocs/src-html/org/apache/hadoop/hbase/client/TestBlockEvictionFromClient.CustomInnerRegionObserver.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/client/TestBlockEvictionFromClient.CustomInnerRegionObserver.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/client/TestBlockEvictionFromClient.CustomInnerRegionObserver.html
index 9640466..93346d6 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/client/TestBlockEvictionFromClient.CustomInnerRegionObserver.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/client/TestBlockEvictionFromClient.CustomInnerRegionObserver.html
@@ -929,524 +929,656 @@
 <span class="sourceLineNo">921</span>  }<a name="line.921"></a>
 <span class="sourceLineNo">922</span><a name="line.922"></a>
 <span class="sourceLineNo">923</span>  @Test<a name="line.923"></a>
-<span class="sourceLineNo">924</span>  public void testScanWithException() throws IOException, InterruptedException {<a name="line.924"></a>
-<span class="sourceLineNo">925</span>    HTable table = null;<a name="line.925"></a>
-<span class="sourceLineNo">926</span>    try {<a name="line.926"></a>
-<span class="sourceLineNo">927</span>      latch = new CountDownLatch(1);<a name="line.927"></a>
-<span class="sourceLineNo">928</span>      exceptionLatch = new CountDownLatch(1);<a name="line.928"></a>
-<span class="sourceLineNo">929</span>      TableName tableName = TableName.valueOf("testScanWithException");<a name="line.929"></a>
-<span class="sourceLineNo">930</span>      // Create KV that will give you two blocks<a name="line.930"></a>
-<span class="sourceLineNo">931</span>      // Create a table with block size as 1024<a name="line.931"></a>
-<span class="sourceLineNo">932</span>      table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,<a name="line.932"></a>
-<span class="sourceLineNo">933</span>          CustomInnerRegionObserverWrapper.class.getName());<a name="line.933"></a>
-<span class="sourceLineNo">934</span>      // get the block cache and region<a name="line.934"></a>
-<span class="sourceLineNo">935</span>      RegionLocator locator = table.getRegionLocator();<a name="line.935"></a>
-<span class="sourceLineNo">936</span>      String regionName = locator.getAllRegionLocations().get(0).getRegionInfo().getEncodedName();<a name="line.936"></a>
-<span class="sourceLineNo">937</span>      Region region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getFromOnlineRegions(<a name="line.937"></a>
-<span class="sourceLineNo">938</span>          regionName);<a name="line.938"></a>
-<span class="sourceLineNo">939</span>      Store store = region.getStores().iterator().next();<a name="line.939"></a>
-<span class="sourceLineNo">940</span>      CacheConfig cacheConf = store.getCacheConfig();<a name="line.940"></a>
-<span class="sourceLineNo">941</span>      cacheConf.setCacheDataOnWrite(true);<a name="line.941"></a>
-<span class="sourceLineNo">942</span>      cacheConf.setEvictOnClose(true);<a name="line.942"></a>
-<span class="sourceLineNo">943</span>      BlockCache cache = cacheConf.getBlockCache();<a name="line.943"></a>
-<span class="sourceLineNo">944</span>      // insert data. 2 Rows are added<a name="line.944"></a>
-<span class="sourceLineNo">945</span>      insertData(table);<a name="line.945"></a>
-<span class="sourceLineNo">946</span>      // flush the data<a name="line.946"></a>
-<span class="sourceLineNo">947</span>      System.out.println("Flushing cache");<a name="line.947"></a>
-<span class="sourceLineNo">948</span>      // Should create one Hfile with 2 blocks<a name="line.948"></a>
-<span class="sourceLineNo">949</span>      region.flush(true);<a name="line.949"></a>
-<span class="sourceLineNo">950</span>      // CustomInnerRegionObserver.sleepTime.set(5000);<a name="line.950"></a>
-<span class="sourceLineNo">951</span>      CustomInnerRegionObserver.throwException.set(true);<a name="line.951"></a>
-<span class="sourceLineNo">952</span>      ScanThread[] scanThreads = initiateScan(table, false);<a name="line.952"></a>
-<span class="sourceLineNo">953</span>      // The block would have been decremented for the scan case as it was<a name="line.953"></a>
-<span class="sourceLineNo">954</span>      // wrapped<a name="line.954"></a>
-<span class="sourceLineNo">955</span>      // before even the postNext hook gets executed.<a name="line.955"></a>
-<span class="sourceLineNo">956</span>      // giving some time for the block to be decremented<a name="line.956"></a>
-<span class="sourceLineNo">957</span>      Thread.sleep(100);<a name="line.957"></a>
-<span class="sourceLineNo">958</span>      Iterator&lt;CachedBlock&gt; iterator = cache.iterator();<a name="line.958"></a>
-<span class="sourceLineNo">959</span>      boolean usedBlocksFound = false;<a name="line.959"></a>
-<span class="sourceLineNo">960</span>      int refCount = 0;<a name="line.960"></a>
-<span class="sourceLineNo">961</span>      while (iterator.hasNext()) {<a name="line.961"></a>
-<span class="sourceLineNo">962</span>        CachedBlock next = iterator.next();<a name="line.962"></a>
-<span class="sourceLineNo">963</span>        BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.963"></a>
-<span class="sourceLineNo">964</span>        if (cache instanceof BucketCache) {<a name="line.964"></a>
-<span class="sourceLineNo">965</span>          refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.965"></a>
-<span class="sourceLineNo">966</span>        } else if (cache instanceof CombinedBlockCache) {<a name="line.966"></a>
-<span class="sourceLineNo">967</span>          refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.967"></a>
-<span class="sourceLineNo">968</span>        } else {<a name="line.968"></a>
-<span class="sourceLineNo">969</span>          continue;<a name="line.969"></a>
-<span class="sourceLineNo">970</span>        }<a name="line.970"></a>
-<span class="sourceLineNo">971</span>        if (refCount != 0) {<a name="line.971"></a>
-<span class="sourceLineNo">972</span>          // Blocks will be with count 3<a name="line.972"></a>
-<span class="sourceLineNo">973</span>          assertEquals(NO_OF_THREADS, refCount);<a name="line.973"></a>
-<span class="sourceLineNo">974</span>          usedBlocksFound = true;<a name="line.974"></a>
-<span class="sourceLineNo">975</span>        }<a name="line.975"></a>
-<span class="sourceLineNo">976</span>      }<a name="line.976"></a>
-<span class="sourceLineNo">977</span>      assertTrue(usedBlocksFound);<a name="line.977"></a>
-<span class="sourceLineNo">978</span>      exceptionLatch.countDown();<a name="line.978"></a>
-<span class="sourceLineNo">979</span>      // countdown the latch<a name="line.979"></a>
-<span class="sourceLineNo">980</span>      CustomInnerRegionObserver.getCdl().get().countDown();<a name="line.980"></a>
-<span class="sourceLineNo">981</span>      for (ScanThread thread : scanThreads) {<a name="line.981"></a>
-<span class="sourceLineNo">982</span>        thread.join();<a name="line.982"></a>
-<span class="sourceLineNo">983</span>      }<a name="line.983"></a>
-<span class="sourceLineNo">984</span>      iterator = cache.iterator();<a name="line.984"></a>
-<span class="sourceLineNo">985</span>      usedBlocksFound = false;<a name="line.985"></a>
-<span class="sourceLineNo">986</span>      refCount = 0;<a name="line.986"></a>
-<span class="sourceLineNo">987</span>      while (iterator.hasNext()) {<a name="line.987"></a>
-<span class="sourceLineNo">988</span>        CachedBlock next = iterator.next();<a name="line.988"></a>
-<span class="sourceLineNo">989</span>        BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.989"></a>
-<span class="sourceLineNo">990</span>        if (cache instanceof BucketCache) {<a name="line.990"></a>
-<span class="sourceLineNo">991</span>          refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.991"></a>
-<span class="sourceLineNo">992</span>        } else if (cache instanceof CombinedBlockCache) {<a name="line.992"></a>
-<span class="sourceLineNo">993</span>          refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.993"></a>
-<span class="sourceLineNo">994</span>        } else {<a name="line.994"></a>
-<span class="sourceLineNo">995</span>          continue;<a name="line.995"></a>
-<span class="sourceLineNo">996</span>        }<a name="line.996"></a>
-<span class="sourceLineNo">997</span>        if (refCount != 0) {<a name="line.997"></a>
-<span class="sourceLineNo">998</span>          // Blocks will be with count 3<a name="line.998"></a>
-<span class="sourceLineNo">999</span>          assertEquals(NO_OF_THREADS, refCount);<a name="line.999"></a>
-<span class="sourceLineNo">1000</span>          usedBlocksFound = true;<a name="line.1000"></a>
-<span class="sourceLineNo">1001</span>        }<a name="line.1001"></a>
-<span class="sourceLineNo">1002</span>      }<a name="line.1002"></a>
-<span class="sourceLineNo">1003</span>      assertTrue(usedBlocksFound);<a name="line.1003"></a>
-<span class="sourceLineNo">1004</span>      // Sleep till the scan lease would expire? Can we reduce this value?<a name="line.1004"></a>
-<span class="sourceLineNo">1005</span>      Thread.sleep(5100);<a name="line.1005"></a>
-<span class="sourceLineNo">1006</span>      iterator = cache.iterator();<a name="line.1006"></a>
-<span class="sourceLineNo">1007</span>      refCount = 0;<a name="line.1007"></a>
-<span class="sourceLineNo">1008</span>      while (iterator.hasNext()) {<a name="line.1008"></a>
-<span class="sourceLineNo">1009</span>        CachedBlock next = iterator.next();<a name="line.1009"></a>
-<span class="sourceLineNo">1010</span>        BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.1010"></a>
-<span class="sourceLineNo">1011</span>        if (cache instanceof BucketCache) {<a name="line.1011"></a>
-<span class="sourceLineNo">1012</span>          refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.1012"></a>
-<span class="sourceLineNo">1013</span>        } else if (cache instanceof CombinedBlockCache) {<a name="line.1013"></a>
-<span class="sourceLineNo">1014</span>          refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.1014"></a>
-<span class="sourceLineNo">1015</span>        } else {<a name="line.1015"></a>
-<span class="sourceLineNo">1016</span>          continue;<a name="line.1016"></a>
-<span class="sourceLineNo">1017</span>        }<a name="line.1017"></a>
-<span class="sourceLineNo">1018</span>        assertEquals(0, refCount);<a name="line.1018"></a>
-<span class="sourceLineNo">1019</span>      }<a name="line.1019"></a>
-<span class="sourceLineNo">1020</span>    } finally {<a name="line.1020"></a>
-<span class="sourceLineNo">1021</span>      if (table != null) {<a name="line.1021"></a>
-<span class="sourceLineNo">1022</span>        table.close();<a name="line.1022"></a>
-<span class="sourceLineNo">1023</span>      }<a name="line.1023"></a>
-<span class="sourceLineNo">1024</span>    }<a name="line.1024"></a>
-<span class="sourceLineNo">1025</span>  }<a name="line.1025"></a>
-<span class="sourceLineNo">1026</span><a name="line.1026"></a>
-<span class="sourceLineNo">1027</span>  private void iterateBlockCache(BlockCache cache, Iterator&lt;CachedBlock&gt; iterator) {<a name="line.1027"></a>
-<span class="sourceLineNo">1028</span>    int refCount;<a name="line.1028"></a>
-<span class="sourceLineNo">1029</span>    while (iterator.hasNext()) {<a name="line.1029"></a>
-<span class="sourceLineNo">1030</span>      CachedBlock next = iterator.next();<a name="line.1030"></a>
-<span class="sourceLineNo">1031</span>      BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.1031"></a>
-<span class="sourceLineNo">1032</span>      if (cache instanceof BucketCache) {<a name="line.1032"></a>
-<span class="sourceLineNo">1033</span>        refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.1033"></a>
-<span class="sourceLineNo">1034</span>      } else if (cache instanceof CombinedBlockCache) {<a name="line.1034"></a>
-<span class="sourceLineNo">1035</span>        refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.1035"></a>
-<span class="sourceLineNo">1036</span>      } else {<a name="line.1036"></a>
-<span class="sourceLineNo">1037</span>        continue;<a name="line.1037"></a>
-<span class="sourceLineNo">1038</span>      }<a name="line.1038"></a>
-<span class="sourceLineNo">1039</span>      assertEquals(0, refCount);<a name="line.1039"></a>
-<span class="sourceLineNo">1040</span>    }<a name="line.1040"></a>
-<span class="sourceLineNo">1041</span>  }<a name="line.1041"></a>
-<span class="sourceLineNo">1042</span><a name="line.1042"></a>
-<span class="sourceLineNo">1043</span>  private void insertData(HTable table) throws IOException {<a name="line.1043"></a>
-<span class="sourceLineNo">1044</span>    Put put = new Put(ROW);<a name="line.1044"></a>
-<span class="sourceLineNo">1045</span>    put.addColumn(FAMILY, QUALIFIER, data);<a name="line.1045"></a>
-<span class="sourceLineNo">1046</span>    table.put(put);<a name="line.1046"></a>
-<span class="sourceLineNo">1047</span>    put = new Put(ROW1);<a name="line.1047"></a>
-<span class="sourceLineNo">1048</span>    put.addColumn(FAMILY, QUALIFIER, data);<a name="line.1048"></a>
-<span class="sourceLineNo">1049</span>    table.put(put);<a name="line.1049"></a>
-<span class="sourceLineNo">1050</span>    byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);<a name="line.1050"></a>
-<span class="sourceLineNo">1051</span>    put = new Put(ROW);<a name="line.1051"></a>
-<span class="sourceLineNo">1052</span>    put.addColumn(FAMILY, QUALIFIER2, data2);<a name="line.1052"></a>
-<span class="sourceLineNo">1053</span>    table.put(put);<a name="line.1053"></a>
-<span class="sourceLineNo">1054</span>  }<a name="line.1054"></a>
-<span class="sourceLineNo">1055</span><a name="line.1055"></a>
-<span class="sourceLineNo">1056</span>  private ScanThread[] initiateScan(HTable table, boolean reverse) throws IOException,<a name="line.1056"></a>
-<span class="sourceLineNo">1057</span>      InterruptedException {<a name="line.1057"></a>
-<span class="sourceLineNo">1058</span>    ScanThread[] scanThreads = new ScanThread[NO_OF_THREADS];<a name="line.1058"></a>
-<span class="sourceLineNo">1059</span>    for (int i = 0; i &lt; NO_OF_THREADS; i++) {<a name="line.1059"></a>
-<span class="sourceLineNo">1060</span>      scanThreads[i] = new ScanThread(table, reverse);<a name="line.1060"></a>
-<span class="sourceLineNo">1061</span>    }<a name="line.1061"></a>
-<span class="sourceLineNo">1062</span>    for (ScanThread thread : scanThreads) {<a name="line.1062"></a>
-<span class="sourceLineNo">1063</span>      thread.start();<a name="line.1063"></a>
-<span class="sourceLineNo">1064</span>    }<a name="line.1064"></a>
-<span class="sourceLineNo">1065</span>    return scanThreads;<a name="line.1065"></a>
-<span class="sourceLineNo">1066</span>  }<a name="line.1066"></a>
-<span class="sourceLineNo">1067</span><a name="line.1067"></a>
-<span class="sourceLineNo">1068</span>  private GetThread[] initiateGet(HTable table, boolean tracker, boolean multipleCFs)<a name="line.1068"></a>
-<span class="sourceLineNo">1069</span>      throws IOException, InterruptedException {<a name="line.1069"></a>
-<span class="sourceLineNo">1070</span>    GetThread[] getThreads = new GetThread[NO_OF_THREADS];<a name="line.1070"></a>
-<span class="sourceLineNo">1071</span>    for (int i = 0; i &lt; NO_OF_THREADS; i++) {<a name="line.1071"></a>
-<span class="sourceLineNo">1072</span>      getThreads[i] = new GetThread(table, tracker, multipleCFs);<a name="line.1072"></a>
-<span class="sourceLineNo">1073</span>    }<a name="line.1073"></a>
-<span class="sourceLineNo">1074</span>    for (GetThread thread : getThreads) {<a name="line.1074"></a>
-<span class="sourceLineNo">1075</span>      thread.start();<a name="line.1075"></a>
-<span class="sourceLineNo">1076</span>    }<a name="line.1076"></a>
-<span class="sourceLineNo">1077</span>    return getThreads;<a name="line.1077"></a>
-<span class="sourceLineNo">1078</span>  }<a name="line.1078"></a>
-<span class="sourceLineNo">1079</span><a name="line.1079"></a>
-<span class="sourceLineNo">1080</span>  private MultiGetThread[] initiateMultiGet(HTable table)<a name="line.1080"></a>
-<span class="sourceLineNo">1081</span>      throws IOException, InterruptedException {<a name="line.1081"></a>
-<span class="sourceLineNo">1082</span>    MultiGetThread[] multiGetThreads = new MultiGetThread[NO_OF_THREADS];<a name="line.1082"></a>
-<span class="sourceLineNo">1083</span>    for (int i = 0; i &lt; NO_OF_THREADS; i++) {<a name="line.1083"></a>
-<span class="sourceLineNo">1084</span>      multiGetThreads[i] = new MultiGetThread(table);<a name="line.1084"></a>
-<span class="sourceLineNo">1085</span>    }<a name="line.1085"></a>
-<span class="sourceLineNo">1086</span>    for (MultiGetThread thread : multiGetThreads) {<a name="line.1086"></a>
-<span class="sourceLineNo">1087</span>      thread.start();<a name="line.1087"></a>
-<span class="sourceLineNo">1088</span>    }<a name="line.1088"></a>
-<span class="sourceLineNo">1089</span>    return multiGetThreads;<a name="line.1089"></a>
-<span class="sourceLineNo">1090</span>  }<a name="line.1090"></a>
-<span class="sourceLineNo">1091</span><a name="line.1091"></a>
-<span class="sourceLineNo">1092</span>  private void checkForBlockEviction(BlockCache cache, boolean getClosed, boolean expectOnlyZero,<a name="line.1092"></a>
-<span class="sourceLineNo">1093</span>      boolean wrappedCp) throws InterruptedException {<a name="line.1093"></a>
-<span class="sourceLineNo">1094</span>    int counter = NO_OF_THREADS;<a name="line.1094"></a>
-<span class="sourceLineNo">1095</span>    if (CustomInnerRegionObserver.waitForGets.get()) {<a name="line.1095"></a>
-<span class="sourceLineNo">1096</span>      // Because only one row is selected, it has only 2 blocks<a name="line.1096"></a>
-<span class="sourceLineNo">1097</span>      counter = counter - 1;<a name="line.1097"></a>
-<span class="sourceLineNo">1098</span>      while (CustomInnerRegionObserver.countOfGets.get() &lt; NO_OF_THREADS) {<a name="line.1098"></a>
-<span class="sourceLineNo">1099</span>        Thread.sleep(100);<a name="line.1099"></a>
-<span class="sourceLineNo">1100</span>      }<a name="line.1100"></a>
-<span class="sourceLineNo">1101</span>    } else {<a name="line.1101"></a>
-<span class="sourceLineNo">1102</span>      while (CustomInnerRegionObserver.countOfNext.get() &lt; NO_OF_THREADS) {<a name="line.1102"></a>
-<span class="sourceLineNo">1103</span>        Thread.sleep(100);<a name="line.1103"></a>
-<span class="sourceLineNo">1104</span>      }<a name="line.1104"></a>
-<span class="sourceLineNo">1105</span>    }<a name="line.1105"></a>
-<span class="sourceLineNo">1106</span>    Iterator&lt;CachedBlock&gt; iterator = cache.iterator();<a name="line.1106"></a>
-<span class="sourceLineNo">1107</span>    int refCount = 0;<a name="line.1107"></a>
-<span class="sourceLineNo">1108</span>    while (iterator.hasNext()) {<a name="line.1108"></a>
-<span class="sourceLineNo">1109</span>      CachedBlock next = iterator.next();<a name="line.1109"></a>
-<span class="sourceLineNo">1110</span>      BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.1110"></a>
-<span class="sourceLineNo">1111</span>      if (cache instanceof BucketCache) {<a name="line.1111"></a>
-<span class="sourceLineNo">1112</span>        refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.1112"></a>
-<span class="sourceLineNo">1113</span>      } else if (cache instanceof CombinedBlockCache) {<a name="line.1113"></a>
-<span class="sourceLineNo">1114</span>        refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.1114"></a>
-<span class="sourceLineNo">1115</span>      } else {<a name="line.1115"></a>
-<span class="sourceLineNo">1116</span>        continue;<a name="line.1116"></a>
-<span class="sourceLineNo">1117</span>      }<a name="line.1117"></a>
-<span class="sourceLineNo">1118</span>      System.out.println(" the refcount is " + refCount + " block is " + cacheKey);<a name="line.1118"></a>
-<span class="sourceLineNo">1119</span>      if (CustomInnerRegionObserver.waitForGets.get()) {<a name="line.1119"></a>
-<span class="sourceLineNo">1120</span>        if (expectOnlyZero) {<a name="line.1120"></a>
-<span class="sourceLineNo">1121</span>          assertTrue(refCount == 0);<a name="line.1121"></a>
-<span class="sourceLineNo">1122</span>        }<a name="line.1122"></a>
-<span class="sourceLineNo">1123</span>        if (refCount != 0) {<a name="line.1123"></a>
-<span class="sourceLineNo">1124</span>          // Because the scan would have also touched up on these blocks but<a name="line.1124"></a>
-<span class="sourceLineNo">1125</span>          // it<a name="line.1125"></a>
-<span class="sourceLineNo">1126</span>          // would have touched<a name="line.1126"></a>
-<span class="sourceLineNo">1127</span>          // all 3<a name="line.1127"></a>
-<span class="sourceLineNo">1128</span>          if (getClosed) {<a name="line.1128"></a>
-<span class="sourceLineNo">1129</span>            // If get has closed only the scan's blocks would be available<a name="line.1129"></a>
-<span class="sourceLineNo">1130</span>            assertEquals(refCount, CustomInnerRegionObserver.countOfGets.get());<a name="line.1130"></a>
-<span class="sourceLineNo">1131</span>          } else {<a name="line.1131"></a>
-<span class="sourceLineNo">1132</span>              assertEquals(refCount, CustomInnerRegionObserver.countOfGets.get() + (NO_OF_THREADS));<a name="line.1132"></a>
-<span class="sourceLineNo">1133</span>          }<a name="line.1133"></a>
-<span class="sourceLineNo">1134</span>        }<a name="line.1134"></a>
-<span class="sourceLineNo">1135</span>      } else {<a name="line.1135"></a>
-<span class="sourceLineNo">1136</span>        // Because the get would have also touched up on these blocks but it<a name="line.1136"></a>
-<span class="sourceLineNo">1137</span>        // would have touched<a name="line.1137"></a>
-<span class="sourceLineNo">1138</span>        // upon only 2 additionally<a name="line.1138"></a>
-<span class="sourceLineNo">1139</span>        if (expectOnlyZero) {<a name="line.1139"></a>
-<span class="sourceLineNo">1140</span>          assertTrue(refCount == 0);<a name="line.1140"></a>
-<span class="sourceLineNo">1141</span>        }<a name="line.1141"></a>
-<span class="sourceLineNo">1142</span>        if (refCount != 0) {<a name="line.1142"></a>
-<span class="sourceLineNo">1143</span>          if (getLatch == null || wrappedCp) {<a name="line.1143"></a>
-<span class="sourceLineNo">1144</span>            assertEquals(refCount, CustomInnerRegionObserver.countOfNext.get());<a name="line.1144"></a>
-<span class="sourceLineNo">1145</span>          } else {<a name="line.1145"></a>
-<span class="sourceLineNo">1146</span>            assertEquals(refCount, CustomInnerRegionObserver.countOfNext.get() + (NO_OF_THREADS));<a name="line.1146"></a>
-<span class="sourceLineNo">1147</span>          }<a name="line.1147"></a>
-<span class="sourceLineNo">1148</span>        }<a name="line.1148"></a>
-<span class="sourceLineNo">1149</span>      }<a name="line.1149"></a>
-<span class="sourceLineNo">1150</span>    }<a name="line.1150"></a>
-<span class="sourceLineNo">1151</span>    CustomInnerRegionObserver.getCdl().get().countDown();<a name="line.1151"></a>
-<span class="sourceLineNo">1152</span>  }<a name="line.1152"></a>
-<span class="sourceLineNo">1153</span><a name="line.1153"></a>
-<span class="sourceLineNo">1154</span>  private static class MultiGetThread extends Thread {<a name="line.1154"></a>
-<span class="sourceLineNo">1155</span>    private final HTable table;<a name="line.1155"></a>
-<span class="sourceLineNo">1156</span>    private final List&lt;Get&gt; gets = new ArrayList&lt;Get&gt;();<a name="line.1156"></a>
-<span class="sourceLineNo">1157</span>    public MultiGetThread(HTable table) {<a name="line.1157"></a>
-<span class="sourceLineNo">1158</span>      this.table = table;<a name="line.1158"></a>
-<span class="sourceLineNo">1159</span>    }<a name="line.1159"></a>
-<span class="sourceLineNo">1160</span>    @Override<a name="line.1160"></a>
-<span class="sourceLineNo">1161</span>    public void run() {<a name="line.1161"></a>
-<span class="sourceLineNo">1162</span>      gets.add(new Get(ROW));<a name="line.1162"></a>
-<span class="sourceLineNo">1163</span>      gets.add(new Get(ROW1));<a name="line.1163"></a>
-<span class="sourceLineNo">1164</span>      try {<a name="line.1164"></a>
-<span class="sourceLineNo">1165</span>        CustomInnerRegionObserver.getCdl().set(latch);<a name="line.1165"></a>
-<span class="sourceLineNo">1166</span>        Result[] r = table.get(gets);<a name="line.1166"></a>
-<span class="sourceLineNo">1167</span>        assertTrue(Bytes.equals(r[0].getRow(), ROW));<a name="line.1167"></a>
-<span class="sourceLineNo">1168</span>        assertTrue(Bytes.equals(r[1].getRow(), ROW1));<a name="line.1168"></a>
-<span class="sourceLineNo">1169</span>      } catch (IOException e) {<a name="line.1169"></a>
+<span class="sourceLineNo">924</span>  public void testBlockEvictionAfterHBASE13082WithCompactionAndFlush()<a name="line.924"></a>
+<span class="sourceLineNo">925</span>      throws IOException, InterruptedException {<a name="line.925"></a>
+<span class="sourceLineNo">926</span>    // do flush and scan in parallel<a name="line.926"></a>
+<span class="sourceLineNo">927</span>    HTable table = null;<a name="line.927"></a>
+<span class="sourceLineNo">928</span>    try {<a name="line.928"></a>
+<span class="sourceLineNo">929</span>      latch = new CountDownLatch(1);<a name="line.929"></a>
+<span class="sourceLineNo">930</span>      compactionLatch = new CountDownLatch(1);<a name="line.930"></a>
+<span class="sourceLineNo">931</span>      TableName tableName =<a name="line.931"></a>
+<span class="sourceLineNo">932</span>          TableName.valueOf("testBlockEvictionAfterHBASE13082WithCompactionAndFlush");<a name="line.932"></a>
+<span class="sourceLineNo">933</span>      // Create a table with block size as 1024<a name="line.933"></a>
+<span class="sourceLineNo">934</span>      table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,<a name="line.934"></a>
+<span class="sourceLineNo">935</span>          CustomInnerRegionObserverWrapper.class.getName());<a name="line.935"></a>
+<span class="sourceLineNo">936</span>      // get the block cache and region<a name="line.936"></a>
+<span class="sourceLineNo">937</span>      RegionLocator locator = table.getRegionLocator();<a name="line.937"></a>
+<span class="sourceLineNo">938</span>      String regionName = locator.getAllRegionLocations().get(0).getRegionInfo().getEncodedName();<a name="line.938"></a>
+<span class="sourceLineNo">939</span>      Region region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getFromOnlineRegions(<a name="line.939"></a>
+<span class="sourceLineNo">940</span>          regionName);<a name="line.940"></a>
+<span class="sourceLineNo">941</span>      Store store = region.getStores().iterator().next();<a name="line.941"></a>
+<span class="sourceLineNo">942</span>      CacheConfig cacheConf = store.getCacheConfig();<a name="line.942"></a>
+<span class="sourceLineNo">943</span>      cacheConf.setCacheDataOnWrite(true);<a name="line.943"></a>
+<span class="sourceLineNo">944</span>      cacheConf.setEvictOnClose(true);<a name="line.944"></a>
+<span class="sourceLineNo">945</span>      BlockCache cache = cacheConf.getBlockCache();<a name="line.945"></a>
+<span class="sourceLineNo">946</span><a name="line.946"></a>
+<span class="sourceLineNo">947</span>      // insert data. 2 Rows are added<a name="line.947"></a>
+<span class="sourceLineNo">948</span>      Put put = new Put(ROW);<a name="line.948"></a>
+<span class="sourceLineNo">949</span>      put.addColumn(FAMILY, QUALIFIER, data);<a name="line.949"></a>
+<span class="sourceLineNo">950</span>      table.put(put);<a name="line.950"></a>
+<span class="sourceLineNo">951</span>      put = new Put(ROW1);<a name="line.951"></a>
+<span class="sourceLineNo">952</span>      put.addColumn(FAMILY, QUALIFIER, data);<a name="line.952"></a>
+<span class="sourceLineNo">953</span>      table.put(put);<a name="line.953"></a>
+<span class="sourceLineNo">954</span>      assertTrue(Bytes.equals(table.get(new Get(ROW)).value(), data));<a name="line.954"></a>
+<span class="sourceLineNo">955</span>      // Should create one Hfile with 2 blocks<a name="line.955"></a>
+<span class="sourceLineNo">956</span>      region.flush(true);<a name="line.956"></a>
+<span class="sourceLineNo">957</span>      // read the data and expect same blocks, one new hit, no misses<a name="line.957"></a>
+<span class="sourceLineNo">958</span>      int refCount = 0;<a name="line.958"></a>
+<span class="sourceLineNo">959</span>      // Check how this miss is happening<a name="line.959"></a>
+<span class="sourceLineNo">960</span>      // insert a second column, read the row, no new blocks, 3 new hits<a name="line.960"></a>
+<span class="sourceLineNo">961</span>      byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);<a name="line.961"></a>
+<span class="sourceLineNo">962</span>      byte[] data2 = Bytes.add(data, data);<a name="line.962"></a>
+<span class="sourceLineNo">963</span>      put = new Put(ROW);<a name="line.963"></a>
+<span class="sourceLineNo">964</span>      put.addColumn(FAMILY, QUALIFIER2, data2);<a name="line.964"></a>
+<span class="sourceLineNo">965</span>      table.put(put);<a name="line.965"></a>
+<span class="sourceLineNo">966</span>      // flush, one new block<a name="line.966"></a>
+<span class="sourceLineNo">967</span>      System.out.println("Flushing cache");<a name="line.967"></a>
+<span class="sourceLineNo">968</span>      region.flush(true);<a name="line.968"></a>
+<span class="sourceLineNo">969</span>      Iterator&lt;CachedBlock&gt; iterator = cache.iterator();<a name="line.969"></a>
+<span class="sourceLineNo">970</span>      iterateBlockCache(cache, iterator);<a name="line.970"></a>
+<span class="sourceLineNo">971</span>      // Create three sets of scan<a name="line.971"></a>
+<span class="sourceLineNo">972</span>      ScanThread[] scanThreads = initiateScan(table, false);<a name="line.972"></a>
+<span class="sourceLineNo">973</span>      Thread.sleep(100);<a name="line.973"></a>
+<span class="sourceLineNo">974</span>      iterator = cache.iterator();<a name="line.974"></a>
+<span class="sourceLineNo">975</span>      boolean usedBlocksFound = false;<a name="line.975"></a>
+<span class="sourceLineNo">976</span>      while (iterator.hasNext()) {<a name="line.976"></a>
+<span class="sourceLineNo">977</span>        CachedBlock next = iterator.next();<a name="line.977"></a>
+<span class="sourceLineNo">978</span>        BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.978"></a>
+<span class="sourceLineNo">979</span>        if (cache instanceof BucketCache) {<a name="line.979"></a>
+<span class="sourceLineNo">980</span>          refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.980"></a>
+<span class="sourceLineNo">981</span>        } else if (cache instanceof CombinedBlockCache) {<a name="line.981"></a>
+<span class="sourceLineNo">982</span>          refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.982"></a>
+<span class="sourceLineNo">983</span>        } else {<a name="line.983"></a>
+<span class="sourceLineNo">984</span>          continue;<a name="line.984"></a>
+<span class="sourceLineNo">985</span>        }<a name="line.985"></a>
+<span class="sourceLineNo">986</span>        if (refCount != 0) {<a name="line.986"></a>
+<span class="sourceLineNo">987</span>          // Blocks will be with count 3<a name="line.987"></a>
+<span class="sourceLineNo">988</span>          assertEquals(NO_OF_THREADS, refCount);<a name="line.988"></a>
+<span class="sourceLineNo">989</span>          usedBlocksFound = true;<a name="line.989"></a>
+<span class="sourceLineNo">990</span>        }<a name="line.990"></a>
+<span class="sourceLineNo">991</span>      }<a name="line.991"></a>
+<span class="sourceLineNo">992</span>      // Make a put and do a flush<a name="line.992"></a>
+<span class="sourceLineNo">993</span>      QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);<a name="line.993"></a>
+<span class="sourceLineNo">994</span>      data2 = Bytes.add(data, data);<a name="line.994"></a>
+<span class="sourceLineNo">995</span>      put = new Put(ROW1);<a name="line.995"></a>
+<span class="sourceLineNo">996</span>      put.addColumn(FAMILY, QUALIFIER2, data2);<a name="line.996"></a>
+<span class="sourceLineNo">997</span>      table.put(put);<a name="line.997"></a>
+<span class="sourceLineNo">998</span>      // flush, one new block<a name="line.998"></a>
+<span class="sourceLineNo">999</span>      System.out.println("Flushing cache");<a name="line.999"></a>
+<span class="sourceLineNo">1000</span>      region.flush(true);<a name="line.1000"></a>
+<span class="sourceLineNo">1001</span>      assertTrue("Blocks with non zero ref count should be found ", usedBlocksFound);<a name="line.1001"></a>
+<span class="sourceLineNo">1002</span>      usedBlocksFound = false;<a name="line.1002"></a>
+<span class="sourceLineNo">1003</span>      System.out.println("Compacting");<a name="line.1003"></a>
+<span class="sourceLineNo">1004</span>      assertEquals(3, store.getStorefilesCount());<a name="line.1004"></a>
+<span class="sourceLineNo">1005</span>      store.triggerMajorCompaction();<a name="line.1005"></a>
+<span class="sourceLineNo">1006</span>      region.compact(true);<a name="line.1006"></a>
+<span class="sourceLineNo">1007</span>      waitForStoreFileCount(store, 1, 10000); // wait 10 seconds max<a name="line.1007"></a>
+<span class="sourceLineNo">1008</span>      assertEquals(1, store.getStorefilesCount());<a name="line.1008"></a>
+<span class="sourceLineNo">1009</span>      // Even after compaction is done we will have some blocks that cannot<a name="line.1009"></a>
+<span class="sourceLineNo">1010</span>      // be evicted this is because the scan is still referencing them<a name="line.1010"></a>
+<span class="sourceLineNo">1011</span>      iterator = cache.iterator();<a name="line.1011"></a>
+<span class="sourceLineNo">1012</span>      while (iterator.hasNext()) {<a name="line.1012"></a>
+<span class="sourceLineNo">1013</span>        CachedBlock next = iterator.next();<a name="line.1013"></a>
+<span class="sourceLineNo">1014</span>        BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.1014"></a>
+<span class="sourceLineNo">1015</span>        if (cache instanceof BucketCache) {<a name="line.1015"></a>
+<span class="sourceLineNo">1016</span>          refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.1016"></a>
+<span class="sourceLineNo">1017</span>        } else if (cache instanceof CombinedBlockCache) {<a name="line.1017"></a>
+<span class="sourceLineNo">1018</span>          refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.1018"></a>
+<span class="sourceLineNo">1019</span>        } else {<a name="line.1019"></a>
+<span class="sourceLineNo">1020</span>          continue;<a name="line.1020"></a>
+<span class="sourceLineNo">1021</span>        }<a name="line.1021"></a>
+<span class="sourceLineNo">1022</span>        if (refCount != 0) {<a name="line.1022"></a>
+<span class="sourceLineNo">1023</span>          // Blocks will be with count 3 as they are not yet cleared<a name="line.1023"></a>
+<span class="sourceLineNo">1024</span>          assertEquals(NO_OF_THREADS, refCount);<a name="line.1024"></a>
+<span class="sourceLineNo">1025</span>          usedBlocksFound = true;<a name="line.1025"></a>
+<span class="sourceLineNo">1026</span>        }<a name="line.1026"></a>
+<span class="sourceLineNo">1027</span>      }<a name="line.1027"></a>
+<span class="sourceLineNo">1028</span>      assertTrue("Blocks with non zero ref count should be found ", usedBlocksFound);<a name="line.1028"></a>
+<span class="sourceLineNo">1029</span>      // Should not throw exception<a name="line.1029"></a>
+<span class="sourceLineNo">1030</span>      compactionLatch.countDown();<a name="line.1030"></a>
+<span class="sourceLineNo">1031</span>      latch.countDown();<a name="line.1031"></a>
+<span class="sourceLineNo">1032</span>      for (ScanThread thread : scanThreads) {<a name="line.1032"></a>
+<span class="sourceLineNo">1033</span>        thread.join();<a name="line.1033"></a>
+<span class="sourceLineNo">1034</span>      }<a name="line.1034"></a>
+<span class="sourceLineNo">1035</span>      // by this time all blocks should have been evicted<a name="line.1035"></a>
+<span class="sourceLineNo">1036</span>      iterator = cache.iterator();<a name="line.1036"></a>
+<span class="sourceLineNo">1037</span>      // Since a flush and compaction happened after a scan started<a name="line.1037"></a>
+<span class="sourceLineNo">1038</span>      // we need to ensure that all the original blocks of the compacted file<a name="line.1038"></a>
+<span class="sourceLineNo">1039</span>      // is also removed.<a name="line.1039"></a>
+<span class="sourceLineNo">1040</span>      iterateBlockCache(cache, iterator);<a name="line.1040"></a>
+<span class="sourceLineNo">1041</span>      Result r = table.get(new Get(ROW));<a name="line.1041"></a>
+<span class="sourceLineNo">1042</span>      assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER), data));<a name="line.1042"></a>
+<span class="sourceLineNo">1043</span>      assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER2), data2));<a name="line.1043"></a>
+<span class="sourceLineNo">1044</span>      // The gets would be working on new blocks<a name="line.1044"></a>
+<span class="sourceLineNo">1045</span>      iterator = cache.iterator();<a name="line.1045"></a>
+<span class="sourceLineNo">1046</span>      iterateBlockCache(cache, iterator);<a name="line.1046"></a>
+<span class="sourceLineNo">1047</span>    } finally {<a name="line.1047"></a>
+<span class="sourceLineNo">1048</span>      if (table != null) {<a name="line.1048"></a>
+<span class="sourceLineNo">1049</span>        table.close();<a name="line.1049"></a>
+<span class="sourceLineNo">1050</span>      }<a name="line.1050"></a>
+<span class="sourceLineNo">1051</span>    }<a name="line.1051"></a>
+<span class="sourceLineNo">1052</span>  }<a name="line.1052"></a>
+<span class="sourceLineNo">1053</span><a name="line.1053"></a>
+<span class="sourceLineNo">1054</span><a name="line.1054"></a>
+<span class="sourceLineNo">1055</span>  @Test<a name="line.1055"></a>
+<span class="sourceLineNo">1056</span>  public void testScanWithException() throws IOException, InterruptedException {<a name="line.1056"></a>
+<span class="sourceLineNo">1057</span>    HTable table = null;<a name="line.1057"></a>
+<span class="sourceLineNo">1058</span>    try {<a name="line.1058"></a>
+<span class="sourceLineNo">1059</span>      latch = new CountDownLatch(1);<a name="line.1059"></a>
+<span class="sourceLineNo">1060</span>      exceptionLatch = new CountDownLatch(1);<a name="line.1060"></a>
+<span class="sourceLineNo">1061</span>      TableName tableName = TableName.valueOf("testScanWithException");<a name="line.1061"></a>
+<span class="sourceLineNo">1062</span>      // Create KV that will give you two blocks<a name="line.1062"></a>
+<span class="sourceLineNo">1063</span>      // Create a table with block size as 1024<a name="line.1063"></a>
+<span class="sourceLineNo">1064</span>      table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,<a name="line.1064"></a>
+<span class="sourceLineNo">1065</span>          CustomInnerRegionObserverWrapper.class.getName());<a name="line.1065"></a>
+<span class="sourceLineNo">1066</span>      // get the block cache and region<a name="line.1066"></a>
+<span class="sourceLineNo">1067</span>      RegionLocator locator = table.getRegionLocator();<a name="line.1067"></a>
+<span class="sourceLineNo">1068</span>      String regionName = locator.getAllRegionLocations().get(0).getRegionInfo().getEncodedName();<a name="line.1068"></a>
+<span class="sourceLineNo">1069</span>      Region region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getFromOnlineRegions(<a name="line.1069"></a>
+<span class="sourceLineNo">1070</span>          regionName);<a name="line.1070"></a>
+<span class="sourceLineNo">1071</span>      Store store = region.getStores().iterator().next();<a name="line.1071"></a>
+<span class="sourceLineNo">1072</span>      CacheConfig cacheConf = store.getCacheConfig();<a name="line.1072"></a>
+<span class="sourceLineNo">1073</span>      cacheConf.setCacheDataOnWrite(true);<a name="line.1073"></a>
+<span class="sourceLineNo">1074</span>      cacheConf.setEvictOnClose(true);<a name="line.1074"></a>
+<span class="sourceLineNo">1075</span>      BlockCache cache = cacheConf.getBlockCache();<a name="line.1075"></a>
+<span class="sourceLineNo">1076</span>      // insert data. 2 Rows are added<a name="line.1076"></a>
+<span class="sourceLineNo">1077</span>      insertData(table);<a name="line.1077"></a>
+<span class="sourceLineNo">1078</span>      // flush the data<a name="line.1078"></a>
+<span class="sourceLineNo">1079</span>      System.out.println("Flushing cache");<a name="line.1079"></a>
+<span class="sourceLineNo">1080</span>      // Should create one Hfile with 2 blocks<a name="line.1080"></a>
+<span class="sourceLineNo">1081</span>      region.flush(true);<a name="line.1081"></a>
+<span class="sourceLineNo">1082</span>      // CustomInnerRegionObserver.sleepTime.set(5000);<a name="line.1082"></a>
+<span class="sourceLineNo">1083</span>      CustomInnerRegionObserver.throwException.set(true);<a name="line.1083"></a>
+<span class="sourceLineNo">1084</span>      ScanThread[] scanThreads = initiateScan(table, false);<a name="line.1084"></a>
+<span class="sourceLineNo">1085</span>      // The block would have been decremented for the scan case as it was<a name="line.1085"></a>
+<span class="sourceLineNo">1086</span>      // wrapped<a name="line.1086"></a>
+<span class="sourceLineNo">1087</span>      // before even the postNext hook gets executed.<a name="line.1087"></a>
+<span class="sourceLineNo">1088</span>      // giving some time for the block to be decremented<a name="line.1088"></a>
+<span class="sourceLineNo">1089</span>      Thread.sleep(100);<a name="line.1089"></a>
+<span class="sourceLineNo">1090</span>      Iterator&lt;CachedBlock&gt; iterator = cache.iterator();<a name="line.1090"></a>
+<span class="sourceLineNo">1091</span>      boolean usedBlocksFound = false;<a name="line.1091"></a>
+<span class="sourceLineNo">1092</span>      int refCount = 0;<a name="line.1092"></a>
+<span class="sourceLineNo">1093</span>      while (iterator.hasNext()) {<a name="line.1093"></a>
+<span class="sourceLineNo">1094</span>        CachedBlock next = iterator.next();<a name="line.1094"></a>
+<span class="sourceLineNo">1095</span>        BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.1095"></a>
+<span class="sourceLineNo">1096</span>        if (cache instanceof BucketCache) {<a name="line.1096"></a>
+<span class="sourceLineNo">1097</span>          refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.1097"></a>
+<span class="sourceLineNo">1098</span>        } else if (cache instanceof CombinedBlockCache) {<a name="line.1098"></a>
+<span class="sourceLineNo">1099</span>          refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.1099"></a>
+<span class="sourceLineNo">1100</span>        } else {<a name="line.1100"></a>
+<span class="sourceLineNo">1101</span>          continue;<a name="line.1101"></a>
+<span class="sourceLineNo">1102</span>        }<a name="line.1102"></a>
+<span class="sourceLineNo">1103</span>        if (refCount != 0) {<a name="line.1103"></a>
+<span class="sourceLineNo">1104</span>          // Blocks will be with count 3<a name="line.1104"></a>
+<span class="sourceLineNo">1105</span>          assertEquals(NO_OF_THREADS, refCount);<a name="line.1105"></a>
+<span class="sourceLineNo">1106</span>          usedBlocksFound = true;<a name="line.1106"></a>
+<span class="sourceLineNo">1107</span>        }<a name="line.1107"></a>
+<span class="sourceLineNo">1108</span>      }<a name="line.1108"></a>
+<span class="sourceLineNo">1109</span>      assertTrue(usedBlocksFound);<a name="line.1109"></a>
+<span class="sourceLineNo">1110</span>      exceptionLatch.countDown();<a name="line.1110"></a>
+<span class="sourceLineNo">1111</span>      // countdown the latch<a name="line.1111"></a>
+<span class="sourceLineNo">1112</span>      CustomInnerRegionObserver.getCdl().get().countDown();<a name="line.1112"></a>
+<span class="sourceLineNo">1113</span>      for (ScanThread thread : scanThreads) {<a name="line.1113"></a>
+<span class="sourceLineNo">1114</span>        thread.join();<a name="line.1114"></a>
+<span class="sourceLineNo">1115</span>      }<a name="line.1115"></a>
+<span class="sourceLineNo">1116</span>      iterator = cache.iterator();<a name="line.1116"></a>
+<span class="sourceLineNo">1117</span>      usedBlocksFound = false;<a name="line.1117"></a>
+<span class="sourceLineNo">1118</span>      refCount = 0;<a name="line.1118"></a>
+<span class="sourceLineNo">1119</span>      while (iterator.hasNext()) {<a name="line.1119"></a>
+<span class="sourceLineNo">1120</span>        CachedBlock next = iterator.next();<a name="line.1120"></a>
+<span class="sourceLineNo">1121</span>        BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.1121"></a>
+<span class="sourceLineNo">1122</span>        if (cache instanceof BucketCache) {<a name="line.1122"></a>
+<span class="sourceLineNo">1123</span>          refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.1123"></a>
+<span class="sourceLineNo">1124</span>        } else if (cache instanceof CombinedBlockCache) {<a name="line.1124"></a>
+<span class="sourceLineNo">1125</span>          refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.1125"></a>
+<span class="sourceLineNo">1126</span>        } else {<a name="line.1126"></a>
+<span class="sourceLineNo">1127</span>          continue;<a name="line.1127"></a>
+<span class="sourceLineNo">1128</span>        }<a name="line.1128"></a>
+<span class="sourceLineNo">1129</span>        if (refCount != 0) {<a name="line.1129"></a>
+<span class="sourceLineNo">1130</span>          // Blocks will be with count 3<a name="line.1130"></a>
+<span class="sourceLineNo">1131</span>          assertEquals(NO_OF_THREADS, refCount);<a name="line.1131"></a>
+<span class="sourceLineNo">1132</span>          usedBlocksFound = true;<a name="line.1132"></a>
+<span class="sourceLineNo">1133</span>        }<a name="line.1133"></a>
+<span class="sourceLineNo">1134</span>      }<a name="line.1134"></a>
+<span class="sourceLineNo">1135</span>      assertTrue(usedBlocksFound);<a name="line.1135"></a>
+<span class="sourceLineNo">1136</span>      // Sleep till the scan lease would expire? Can we reduce this value?<a name="line.1136"></a>
+<span class="sourceLineNo">1137</span>      Thread.sleep(5100);<a name="line.1137"></a>
+<span class="sourceLineNo">1138</span>      iterator = cache.iterator();<a name="line.1138"></a>
+<span class="sourceLineNo">1139</span>      refCount = 0;<a name="line.1139"></a>
+<span class="sourceLineNo">1140</span>      while (iterator.hasNext()) {<a name="line.1140"></a>
+<span class="sourceLineNo">1141</span>        CachedBlock next = iterator.next();<a name="line.1141"></a>
+<span class="sourceLineNo">1142</span>        BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.1142"></a>
+<span class="sourceLineNo">1143</span>        if (cache instanceof BucketCache) {<a name="line.1143"></a>
+<span class="sourceLineNo">1144</span>          refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.1144"></a>
+<span class="sourceLineNo">1145</span>        } else if (cache instanceof CombinedBlockCache) {<a name="line.1145"></a>
+<span class="sourceLineNo">1146</span>          refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.1146"></a>
+<span class="sourceLineNo">1147</span>        } else {<a name="line.1147"></a>
+<span class="sourceLineNo">1148</span>          continue;<a name="line.1148"></a>
+<span class="sourceLineNo">1149</span>        }<a name="line.1149"></a>
+<span class="sourceLineNo">1150</span>        assertEquals(0, refCount);<a name="line.1150"></a>
+<span class="sourceLineNo">1151</span>      }<a name="line.1151"></a>
+<span class="sourceLineNo">1152</span>    } finally {<a name="line.1152"></a>
+<span class="sourceLineNo">1153</span>      if (table != null) {<a name="line.1153"></a>
+<span class="sourceLineNo">1154</span>        table.close();<a name="line.1154"></a>
+<span class="sourceLineNo">1155</span>      }<a name="line.1155"></a>
+<span class="sourceLineNo">1156</span>    }<a name="line.1156"></a>
+<span class="sourceLineNo">1157</span>  }<a name="line.1157"></a>
+<span class="sourceLineNo">1158</span><a name="line.1158"></a>
+<span class="sourceLineNo">1159</span>  private void iterateBlockCache(BlockCache cache, Iterator&lt;CachedBlock&gt; iterator) {<a name="line.1159"></a>
+<span class="sourceLineNo">1160</span>    int refCount;<a name="line.1160"></a>
+<span class="sourceLineNo">1161</span>    while (iterator.hasNext()) {<a name="line.1161"></a>
+<span class="sourceLineNo">1162</span>      CachedBlock next = iterator.next();<a name="line.1162"></a>
+<span class="sourceLineNo">1163</span>      BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.1163"></a>
+<span class="sourceLineNo">1164</span>      if (cache instanceof BucketCache) {<a name="line.1164"></a>
+<span class="sourceLineNo">1165</span>        refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.1165"></a>
+<span class="sourceLineNo">1166</span>      } else if (cache instanceof CombinedBlockCache) {<a name="line.1166"></a>
+<span class="sourceLineNo">1167</span>        refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.1167"></a>
+<span class="sourceLineNo">1168</span>      } else {<a name="line.1168"></a>
+<span class="sourceLineNo">1169</span>        continue;<a name="line.1169"></a>
 <span class="sourceLineNo">1170</span>      }<a name="line.1170"></a>
-<span class="sourceLineNo">1171</span>    }<a name="line.1171"></a>
-<span class="sourceLineNo">1172</span>  }<a name="line.1172"></a>
-<span class="sourceLineNo">1173</span><a name="line.1173"></a>
-<span class="sourceLineNo">1174</span>  private static class GetThread extends Thread {<a name="line.1174"></a>
-<span class="sourceLineNo">1175</span>    private final HTable table;<a name="line.1175"></a>
-<span class="sourceLineNo">1176</span>    private final boolean tracker;<a name="line.1176"></a>
-<span class="sourceLineNo">1177</span>    private final boolean multipleCFs;<a name="line.1177"></a>
-<span class="sourceLineNo">1178</span><a name="line.1178"></a>
-<span class="sourceLineNo">1179</span>    public GetThread(HTable table, boolean tracker, boolean multipleCFs) {<a name="line.1179"></a>
-<span class="sourceLineNo">1180</span>      this.table = table;<a name="line.1180"></a>
-<span class="sourceLineNo">1181</span>      this.tracker = tracker;<a name="line.1181"></a>
-<span class="sourceLineNo">1182</span>      this.multipleCFs = multipleCFs;<a name="line.1182"></a>
-<span class="sourceLineNo">1183</span>    }<a name="line.1183"></a>
-<span class="sourceLineNo">1184</span><a name="line.1184"></a>
-<span class="sourceLineNo">1185</span>    @Override<a name="line.1185"></a>
-<span class="sourceLineNo">1186</span>    public void run() {<a name="line.1186"></a>
-<span class="sourceLineNo">1187</span>      try {<a name="line.1187"></a>
-<span class="sourceLineNo">1188</span>        initiateGet(table);<a name="line.1188"></a>
-<span class="sourceLineNo">1189</span>      } catch (IOException e) {<a name="line.1189"></a>
-<span class="sourceLineNo">1190</span>        // do nothing<a name="line.1190"></a>
-<span class="sourceLineNo">1191</span>      }<a name="line.1191"></a>
-<span class="sourceLineNo">1192</span>    }<a name="line.1192"></a>
-<span class="sourceLineNo">1193</span><a name="line.1193"></a>
-<span class="sourceLineNo">1194</span>    private void initiateGet(HTable table) throws IOException {<a name="line.1194"></a>
-<span class="sourceLineNo">1195</span>      Get get = new Get(ROW);<a name="line.1195"></a>
-<span class="sourceLineNo">1196</span>      if (tracker) {<a name="line.1196"></a>
-<span class="sourceLineNo">1197</span>        // Change this<a name="line.1197"></a>
-<span class="sourceLineNo">1198</span>        if (!multipleCFs) {<a name="line.1198"></a>
-<span class="sourceLineNo">1199</span>          get.addColumn(FAMILY, Bytes.toBytes("testQualifier" + 3));<a name="line.1199"></a>
-<span class="sourceLineNo">1200</span>          get.addColumn(FAMILY, Bytes.toBytes("testQualifier" + 8));<a name="line.1200"></a>
-<span class="sourceLineNo">1201</span>          get.addColumn(FAMILY, Bytes.toBytes("testQualifier" + 9));<a name="line.1201"></a>
-<span class="sourceLineNo">1202</span>          // Unknown key<a name="line.1202"></a>
-<span class="sourceLineNo">1203</span>          get.addColumn(FAMILY, Bytes.toBytes("testQualifier" + 900));<a name="line.1203"></a>
-<span class="sourceLineNo">1204</span>        } else {<a name="line.1204"></a>
-<span class="sourceLineNo">1205</span>          get.addColumn(Bytes.toBytes("testFamily" + 3), Bytes.toBytes("testQualifier" + 3));<a name="line.1205"></a>
-<span class="sourceLineNo">1206</span>          get.addColumn(Bytes.toBytes("testFamily" + 8), Bytes.toBytes("testQualifier" + 8));<a name="line.1206"></a>
-<span class="sourceLineNo">1207</span>          get.addColumn(Bytes.toBytes("testFamily" + 9), Bytes.toBytes("testQualifier" + 9));<a name="line.1207"></a>
-<span class="sourceLineNo">1208</span>          // Unknown key<a name="line.1208"></a>
-<span class="sourceLineNo">1209</span>          get.addColumn(Bytes.toBytes("testFamily" + 9), Bytes.toBytes("testQualifier" + 900));<a name="line.1209"></a>
-<span class="sourceLineNo">1210</span>        }<a name="line.1210"></a>
-<span class="sourceLineNo">1211</span>      }<a name="line.1211"></a>
-<span class="sourceLineNo">1212</span>      CustomInnerRegionObserver.getCdl().set(latch);<a name="line.1212"></a>
-<span class="sourceLineNo">1213</span>      Result r = table.get(get);<a name="line.1213"></a>
-<span class="sourceLineNo">1214</span>      System.out.println(r);<a name="line.1214"></a>
-<span class="sourceLineNo">1215</span>      if (!tracker) {<a name="line.1215"></a>
-<span class="sourceLineNo">1216</span>        assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER), data));<a name="line.1216"></a>
-<span class="sourceLineNo">1217</span>        assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER2), data2));<a name="line.1217"></a>
-<span class="sourceLineNo">1218</span>      } else {<a name="line.1218"></a>
-<span class="sourceLineNo">1219</span>        if (!multipleCFs) {<a name="line.1219"></a>
-<span class="sourceLineNo">1220</span>          assertTrue(Bytes.equals(r.getValue(FAMILY, Bytes.toBytes("testQualifier" + 3)), data2));<a name="line.1220"></a>
-<span class="sourceLineNo">1221</span>          assertTrue(Bytes.equals(r.getValue(FAMILY, Bytes.toBytes("testQualifier" + 8)), data2));<a name="line.1221"></a>
-<span class="sourceLineNo">1222</span>          assertTrue(Bytes.equals(r.getValue(FAMILY, Bytes.toBytes("testQualifier" + 9)), data2));<a name="line.1222"></a>
-<span class="sourceLineNo">1223</span>        } else {<a name="line.1223"></a>
-<span class="sourceLineNo">1224</span>          assertTrue(Bytes.equals(<a name="line.1224"></a>
-<span class="sourceLineNo">1225</span>              r.getValue(Bytes.toBytes("testFamily" + 3), Bytes.toBytes("testQualifier" + 3)),<a name="line.1225"></a>
-<span class="sourceLineNo">1226</span>              data2));<a name="line.1226"></a>
-<span class="sourceLineNo">1227</span>          assertTrue(Bytes.equals(<a name="line.1227"></a>
-<span class="sourceLineNo">1228</span>              r.getValue(Bytes.toBytes("testFamily" + 8), Bytes.toBytes("testQualifier" + 8)),<a name="line.1228"></a>
-<span class="sourceLineNo">1229</span>              data2));<a name="line.1229"></a>
-<span class="sourceLineNo">1230</span>          assertTrue(Bytes.equals(<a name="line.1230"></a>
-<span class="sourceLineNo">1231</span>              r.getValue(Bytes.toBytes("testFamily" + 9), Bytes.toBytes("testQualifier" + 9)),<a name="line.1231"></a>
-<span class="sourceLineNo">1232</span>              data2));<a name="line.1232"></a>
-<span class="sourceLineNo">1233</span>        }<a name="line.1233"></a>
-<span class="sourceLineNo">1234</span>      }<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><a name="line.1237"></a>
-<span class="sourceLineNo">1238</span>  private static class ScanThread extends Thread {<a name="line.1238"></a>
-<span class="sourceLineNo">1239</span>    private final HTable table;<a name="line.1239"></a>
-<span class="sourceLineNo">1240</span>    private final boolean reverse;<a name="line.1240"></a>
-<span class="sourceLineNo">1241</span><a name="line.1241"></a>
-<span class="sourceLineNo">1242</span>    public ScanThread(HTable table, boolean reverse) {<a name="line.1242"></a>
-<span class="sourceLineNo">1243</span>      this.table = table;<a name="line.1243"></a>
-<span class="sourceLineNo">1244</span>      this.reverse = reverse;<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 void run() {<a name="line.1248"></a>
-<span class="sourceLineNo">1249</span>      try {<a name="line.1249"></a>
-<span class="sourceLineNo">1250</span>        initiateScan(table);<a name="line.1250"></a>
-<span class="sourceLineNo">1251</span>      } catch (IOException e) {<a name="line.1251"></a>
-<span class="sourceLineNo">1252</span>        // do nothing<a name="line.1252"></a>
-<span class="sourceLineNo">1253</span>      }<a name="line.1253"></a>
-<span class="sourceLineNo">1254</span>    }<a name="line.1254"></a>
-<span class="sourceLineNo">1255</span><a name="line.1255"></a>
-<span class="sourceLineNo">1256</span>    private void initiateScan(HTable table) throws IOException {<a name="line.1256"></a>
-<span class="sourceLineNo">1257</span>      Scan scan = new Scan();<a name="line.1257"></a>
-<span class="sourceLineNo">1258</span>      if (reverse) {<a name="line.1258"></a>
-<span class="sourceLineNo">1259</span>        scan.setReversed(true);<a name="line.1259"></a>
-<span class="sourceLineNo">1260</span>      }<a name="line.1260"></a>
-<span class="sourceLineNo">1261</span>      CustomInnerRegionObserver.getCdl().set(latch);<a name="line.1261"></a>
-<span class="sourceLineNo">1262</span>      ResultScanner resScanner = table.getScanner(scan);<a name="line.1262"></a>
-<span class="sourceLineNo">1263</span>      int i = (reverse ? ROWS.length - 1 : 0);<a name="line.1263"></a>
-<span class="sourceLineNo">1264</span>      boolean resultFound = false;<a name="line.1264"></a>
-<span class="sourceLineNo">1265</span>      for (Result result : resScanner) {<a name="line.1265"></a>
-<span class="sourceLineNo">1266</span>        resultFound = true;<a name="line.1266"></a>
-<span class="sourceLineNo">1267</span>        System.out.println(result);<a name="line.1267"></a>
-<span class="sourceLineNo">1268</span>        if (!reverse) {<a name="line.1268"></a>
-<span class="sourceLineNo">1269</span>          assertTrue(Bytes.equals(result.getRow(), ROWS[i]));<a name="line.1269"></a>
-<span class="sourceLineNo">1270</span>          i++;<a name="line.1270"></a>
-<span class="sourceLineNo">1271</span>        } else {<a name="line.1271"></a>
-<span class="sourceLineNo">1272</span>          assertTrue(Bytes.equals(result.getRow(), ROWS[i]));<a name="line.1272"></a>
-<span class="sourceLineNo">1273</span>          i--;<a name="line.1273"></a>
-<span class="sourceLineNo">1274</span>        }<a name="line.1274"></a>
-<span class="sourceLineNo">1275</span>      }<a name="line.1275"></a>
-<span class="sourceLineNo">1276</span>      assertTrue(resultFound);<a name="line.1276"></a>
-<span class="sourceLineNo">1277</span>    }<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>  private void waitForStoreFileCount(Store store, int count, int timeout)<a name="line.1280"></a>
-<span class="sourceLineNo">1281</span>      throws InterruptedException {<a name="line.1281"></a>
-<span class="sourceLineNo">1282</span>    long start = System.currentTimeMillis();<a name="line.1282"></a>
-<span class="sourceLineNo">1283</span>    while (start + timeout &gt; System.currentTimeMillis() &amp;&amp; store.getStorefilesCount() != count) {<a name="line.1283"></a>
-<span class="sourceLineNo">1284</span>      Thread.sleep(100);<a name="line.1284"></a>
-<span class="sourceLineNo">1285</span>    }<a name="line.1285"></a>
-<span class="sourceLineNo">1286</span>    System.out.println("start=" + start + ", now=" + System.currentTimeMillis() + ", cur="<a name="line.1286"></a>
-<span class="sourceLineNo">1287</span>        + store.getStorefilesCount());<a name="line.1287"></a>
-<span class="sourceLineNo">1288</span>    assertEquals(count, store.getStorefilesCount());<a name="line.1288"></a>
-<span class="sourceLineNo">1289</span>  }<a name="line.1289"></a>
-<span class="sourceLineNo">1290</span><a name="line.1290"></a>
-<span class="sourceLineNo">1291</span>  private static class CustomScanner implements RegionScanner {<a name="line.1291"></a>
-<span class="sourceLineNo">1292</span><a name="line.1292"></a>
-<span class="sourceLineNo">1293</span>    private RegionScanner delegate;<a name="line.1293"></a>
-<span class="sourceLineNo">1294</span><a name="line.1294"></a>
-<span class="sourceLineNo">1295</span>    public CustomScanner(RegionScanner delegate) {<a name="line.1295"></a>
-<span class="sourceLineNo">1296</span>      this.delegate = delegate;<a name="line.1296"></a>
-<span class="sourceLineNo">1297</span>    }<a name="line.1297"></a>
-<span class="sourceLineNo">1298</span><a name="line.1298"></a>
-<span class="sourceLineNo">1299</span>    @Override<a name="line.1299"></a>
-<span class="sourceLineNo">1300</span>    public boolean next(List&lt;Cell&gt; results) throws IOException {<a name="line.1300"></a>
-<span class="sourceLineNo">1301</span>      return delegate.next(results);<a name="line.1301"></a>
-<span class="sourceLineNo">1302</span>    }<a name="line.1302"></a>
-<span class="sourceLineNo">1303</span><a name="line.1303"></a>
-<span class="sourceLineNo">1304</span>    @Override<a name="line.1304"></a>
-<span class="sourceLineNo">1305</span>    public boolean next(List&lt;Cell&gt; result, ScannerContext scannerContext) throws IOException {<a name="line.1305"></a>
-<span class="sourceLineNo">1306</span>      return delegate.next(result, scannerContext);<a name="line.1306"></a>
-<span class="sourceLineNo">1307</span>    }<a name="line.1307"></a>
-<span class="sourceLineNo">1308</span><a name="line.1308"></a>
-<span class="sourceLineNo">1309</span>    @Override<a name="line.1309"></a>
-<span class="sourceLineNo">1310</span>    public boolean nextRaw(List&lt;Cell&gt; result) throws IOException {<a name="line.1310"></a>
-<span class="sourceLineNo">1311</span>      return delegate.nextRaw(result);<a name="line.1311"></a>
-<span class="sourceLineNo">1312</span>    }<a name="line.1312"></a>
-<span class="sourceLineNo">1313</span><a name="line.1313"></a>
-<span class="sourceLineNo">1314</span>    @Override<a name="line.1314"></a>
-<span class="sourceLineNo">1315</span>    public boolean nextRaw(List&lt;Cell&gt; result, ScannerContext context) throws IOException {<a name="line.1315"></a>
-<span class="sourceLineNo">1316</span>      boolean nextRaw = delegate.nextRaw(result, context);<a name="line.1316"></a>
-<span class="sourceLineNo">1317</span>      if (compactionLatch != null &amp;&amp; compactionLatch.getCount() &gt; 0) {<a name="line.1317"></a>
-<span class="sourceLineNo">1318</span>        try {<a name="line.1318"></a>
-<span class="sourceLineNo">1319</span>          compactionLatch.await();<a name="line.1319"></a>
-<span class="sourceLineNo">1320</span>        } catch (InterruptedException ie) {<a name="line.1320"></a>
-<span class="sourceLineNo">1321</span>        }<a name="line.1321"></a>
-<span class="sourceLineNo">1322</span>      }<a name="line.1322"></a>
-<span class="sourceLineNo">1323</span><a name="line.1323"></a>
-<span class="sourceLineNo">1324</span>      if (CustomInnerRegionObserver.throwException.get()) {<a name="line.1324"></a>
-<span class="sourceLineNo">1325</span>        if (exceptionLatch.getCount() &gt; 0) {<a name="line.1325"></a>
-<span class="sourceLineNo">1326</span>          try {<a name="line.1326"></a>
-<span class="sourceLineNo">1327</span>            exceptionLatch.await();<a name="line.1327"></a>
-<span class="sourceLineNo">1328</span>          } catch (InterruptedException e) {<a name="line.1328"></a>
-<span class="sourceLineNo">1329</span>          }<a name="line.1329"></a>
-<span class="sourceLineNo">1330</span>          throw new IOException("throw exception");<a name="line.1330"></a>
-<span class="sourceLineNo">1331</span>        }<a name="line.1331"></a>
-<span class="sourceLineNo">1332</span>      }<a name="line.1332"></a>
-<span class="sourceLineNo">1333</span>      return nextRaw;<a name="line.1333"></a>
-<span class="sourceLineNo">1334</span>    }<a name="line.1334"></a>
-<span class="sourceLineNo">1335</span><a name="line.1335"></a>
-<span class="sourceLineNo">1336</span>    @Override<a name="line.1336"></a>
-<span class="sourceLineNo">1337</span>    public void close() throws IOException {<a name="line.1337"></a>
-<span class="sourceLineNo">1338</span>      delegate.close();<a name="line.1338"></a>
-<span class="sourceLineNo">1339</span>    }<a name="line.1339"></a>
-<span class="sourceLineNo">1340</span><a name="line.1340"></a>
-<span class="sourceLineNo">1341</span>    @Override<a name="line.1341"></a>
-<span class="sourceLineNo">1342</span>    public HRegionInfo getRegionInfo() {<a name="line.1342"></a>
-<span class="sourceLineNo">1343</span>      return delegate.getRegionInfo();<a name="line.1343"></a>
-<span class="sourceLineNo">1344</span>    }<a name="line.1344"></a>
-<span class="sourceLineNo">1345</span><a name="line.1345"></a>
-<span class="sourceLineNo">1346</span>    @Override<a name="line.1346"></a>
-<span class="sourceLineNo">1347</span>    public boolean isFilterDone() throws IOException {<a name="line.1347"></a>
-<span class="sourceLineNo">1348</span>      return delegate.isFilterDone();<a name="line.1348"></a>
-<span class="sourceLineNo">1349</span>    }<a name="line.1349"></a>
-<span class="sourceLineNo">1350</span><a name="line.1350"></a>
-<span class="sourceLineNo">1351</span>    @Override<a name="line.1351"></a>
-<span class="sourceLineNo">1352</span>    public boolean reseek(byte[] row) throws IOException {<a name="line.1352"></a>
-<span class="sourceLineNo">1353</span>      return false;<a name="line.1353"></a>
-<span class="sourceLineNo">1354</span>    }<a name="line.1354"></a>
-<span class="sourceLineNo">1355</span><a name="line.1355"></a>
-<span class="sourceLineNo">1356</span>    @Override<a name="line.1356"></a>
-<span class="sourceLineNo">1357</span>    public long getMaxResultSize() {<a name="line.1357"></a>
-<span class="sourceLineNo">1358</span>      return delegate.getMaxResultSize();<a name="line.1358"></a>
-<span class="sourceLineNo">1359</span>    }<a name="line.1359"></a>
-<span class="sourceLineNo">1360</span><a name="line.1360"></a>
-<span class="sourceLineNo">1361</span>    @Override<a name="line.1361"></a>
-<span class="sourceLineNo">1362</span>    public long getMvccReadPoint() {<a name="line.1362"></a>
-<span class="sourceLineNo">1363</span>      return delegate.getMvccReadPoint();<a name="line.1363"></a>
-<span class="sourceLineNo">1364</span>    }<a name="line.1364"></a>
-<span class="sourceLineNo">1365</span><a name="line.1365"></a>
-<span class="sourceLineNo">1366</span>    @Override<a name="line.1366"></a>
-<span class="sourceLineNo">1367</span>    public int getBatch() {<a name="line.1367"></a>
-<span class="sourceLineNo">1368</span>      return delegate.getBatch();<a name="line.1368"></a>
-<span class="sourceLineNo">1369</span>    }<a name="line.1369"></a>
-<span class="sourceLineNo">1370</span><a name="line.1370"></a>
-<span class="sourceLineNo">1371</span>    @Override<a name="line.1371"></a>
-<span class="sourceLineNo">1372</span>    public void shipped() throws IOException {<a name="line.1372"></a>
-<span class="sourceLineNo">1373</span>      this.delegate.shipped();<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><a name="line.1376"></a>
-<span class="sourceLineNo">1377</span>  public static class CustomInnerRegionObserverWrapper extends CustomInnerRegionObserver {<a name="line.1377"></a>
-<span class="sourceLineNo">1378</span>    @Override<a name="line.1378"></a>
-<span class="sourceLineNo">1379</span>    public RegionScanner postScannerOpen(ObserverContext&lt;RegionCoprocessorEnvironment&gt; e,<a name="line.1379"></a>
-<span class="sourceLineNo">1380</span>        Scan scan, RegionScanner s) throws IOException {<a name="line.1380"></a>
-<span class="sourceLineNo">1381</span>      return new CustomScanner(s);<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>  public static class CustomInnerRegionObserver extends BaseRegionObserver {<a name="line.1385"></a>
-<span class="sourceLineNo">1386</span>    static final AtomicLong sleepTime = new AtomicLong(0);<a name="line.1386"></a>
-<span class="sourceLineNo">1387</span>    static final AtomicBoolean slowDownNext = new AtomicBoolean(false);<a name="line.1387"></a>
-<span class="sourceLineNo">1388</span>    static final AtomicInteger countOfNext = new AtomicInteger(0);<a name="line.1388"></a>
-<span class="sourceLineNo">1389</span>    static final AtomicInteger countOfGets = new AtomicInteger(0);<a name="line.1389"></a>
-<span class="sourceLineNo">1390</span>    static final AtomicBoolean waitForGets = new AtomicBoolean(false);<a name="line.1390"></a>
-<span class="sourceLineNo">1391</span>    static final AtomicBoolean throwException = new AtomicBoolean(false);<a name="line.1391"></a>
-<span class="sourceLineNo">1392</span>    private static final AtomicReference&lt;CountDownLatch&gt; cdl = new AtomicReference&lt;CountDownLatch&gt;(<a name="line.1392"></a>
-<span class="sourceLineNo">1393</span>        new CountDownLatch(0));<a name="line.1393"></a>
-<span class="sourceLineNo">1394</span><a name="line.1394"></a>
-<span class="sourceLineNo">1395</span>    @Override<a name="line.1395"></a>
-<span class="sourceLineNo">1396</span>    public boolean postScannerNext(ObserverContext&lt;RegionCoprocessorEnvironment&gt; e,<a name="line.1396"></a>
-<span class="sourceLineNo">1397</span>        InternalScanner s, List&lt;Result&gt; results, int limit, boolean hasMore) throws IOException {<a name="line.1397"></a>
-<span class="sourceLineNo">1398</span>      slowdownCode(e, false);<a name="line.1398"></a>
-<span class="sourceLineNo">1399</span>      if (getLatch != null &amp;&amp; getLatch.getCount() &gt; 0) {<a name="line.1399"></a>
-<span class="sourceLineNo">1400</span>        try {<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>          getLatch.await();<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span>        } catch (InterruptedException e1) {<a name="line.1402"></a>
-<span class="sourceLineNo">1403</span>        }<a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>      }<a name="line.1404"></a>
-<span class="sourceLineNo">1405</span>      return super.postScannerNext(e, s, results, limit, hasMore);<a name="line.1405"></a>
-<span class="sourceLineNo">1406</span>    }<a name="line.1406"></a>
-<span class="sourceLineNo">1407</span><a name="line.1407"></a>
-<span class="sourceLineNo">1408</span>    @Override<a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>    public void postGetOp(ObserverContext&lt;RegionCoprocessorEnvironment&gt; e, Get get,<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span>        List&lt;Cell&gt; results) throws IOException {<a name="line.1410"></a>
-<span class="sourceLineNo">1411</span>      slowdownCode(e, true);<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span>      super.postGetOp(e, get, results);<a name="line.1412"></a>
-<span class="sourceLineNo">1413</span>    }<a name="line.1413"></a>
-<span class="sourceLineNo">1414</span><a name="line.1414"></a>
-<span class="sourceLineNo">1415</span>    public static AtomicReference&lt;CountDownLatch&gt; getCdl() {<a name="line.1415"></a>
-<span class="sourceLineNo">1416</span>      return cdl;<a name="line.1416"></a>
+<span class="sourceLineNo">1171</span>      assertEquals(0, refCount);<a name="line.1171"></a>
+<span class="sourceLineNo">1172</span>    }<a name="line.1172"></a>
+<span class="sourceLineNo">1173</span>  }<a name="line.1173"></a>
+<span class="sourceLineNo">1174</span><a name="line.1174"></a>
+<span class="sourceLineNo">1175</span>  private void insertData(HTable table) throws IOException {<a name="line.1175"></a>
+<span class="sourceLineNo">1176</span>    Put put = new Put(ROW);<a name="line.1176"></a>
+<span class="sourceLineNo">1177</span>    put.addColumn(FAMILY, QUALIFIER, data);<a name="line.1177"></a>
+<span class="sourceLineNo">1178</span>    table.put(put);<a name="line.1178"></a>
+<span class="sourceLineNo">1179</span>    put = new Put(ROW1);<a name="line.1179"></a>
+<span class="sourceLineNo">1180</span>    put.addColumn(FAMILY, QUALIFIER, data);<a name="line.1180"></a>
+<span class="sourceLineNo">1181</span>    table.put(put);<a name="line.1181"></a>
+<span class="sourceLineNo">1182</span>    byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);<a name="line.1182"></a>
+<span class="sourceLineNo">1183</span>    put = new Put(ROW);<a name="line.1183"></a>
+<span class="sourceLineNo">1184</span>    put.addColumn(FAMILY, QUALIFIER2, data2);<a name="line.1184"></a>
+<span class="sourceLineNo">1185</span>    table.put(put);<a name="line.1185"></a>
+<span class="sourceLineNo">1186</span>  }<a name="line.1186"></a>
+<span class="sourceLineNo">1187</span><a name="line.1187"></a>
+<span class="sourceLineNo">1188</span>  private ScanThread[] initiateScan(HTable table, boolean reverse) throws IOException,<a name="line.1188"></a>
+<span class="sourceLineNo">1189</span>      InterruptedException {<a name="line.1189"></a>
+<span class="sourceLineNo">1190</span>    ScanThread[] scanThreads = new ScanThread[NO_OF_THREADS];<a name="line.1190"></a>
+<span class="sourceLineNo">1191</span>    for (int i = 0; i &lt; NO_OF_THREADS; i++) {<a name="line.1191"></a>
+<span class="sourceLineNo">1192</span>      scanThreads[i] = new ScanThread(table, reverse);<a name="line.1192"></a>
+<span class="sourceLineNo">1193</span>    }<a name="line.1193"></a>
+<span class="sourceLineNo">1194</span>    for (ScanThread thread : scanThreads) {<a name="line.1194"></a>
+<span class="sourceLineNo">1195</span>      thread.start();<a name="line.1195"></a>
+<span class="sourceLineNo">1196</span>    }<a name="line.1196"></a>
+<span class="sourceLineNo">1197</span>    return scanThreads;<a name="line.1197"></a>
+<span class="sourceLineNo">1198</span>  }<a name="line.1198"></a>
+<span class="sourceLineNo">1199</span><a name="line.1199"></a>
+<span class="sourceLineNo">1200</span>  private GetThread[] initiateGet(HTable table, boolean tracker, boolean multipleCFs)<a name="line.1200"></a>
+<span class="sourceLineNo">1201</span>      throws IOException, InterruptedException {<a name="line.1201"></a>
+<span class="sourceLineNo">1202</span>    GetThread[] getThreads = new GetThread[NO_OF_THREADS];<a name="line.1202"></a>
+<span class="sourceLineNo">1203</span>    for (int i = 0; i &lt; NO_OF_THREADS; i++) {<a name="line.1203"></a>
+<span class="sourceLineNo">1204</span>      getThreads[i] = new GetThread(table, tracker, multipleCFs);<a name="line.1204"></a>
+<span class="sourceLineNo">1205</span>    }<a name="line.1205"></a>
+<span class="sourceLineNo">1206</span>    for (GetThread thread : getThreads) {<a name="line.1206"></a>
+<span class="sourceLineNo">1207</span>      thread.start();<a name="line.1207"></a>
+<span class="sourceLineNo">1208</span>    }<a name="line.1208"></a>
+<span class="sourceLineNo">1209</span>    return getThreads;<a name="line.1209"></a>
+<span class="sourceLineNo">1210</span>  }<a name="line.1210"></a>
+<span class="sourceLineNo">1211</span><a name="line.1211"></a>
+<span class="sourceLineNo">1212</span>  private MultiGetThread[] initiateMultiGet(HTable table)<a name="line.1212"></a>
+<span class="sourceLineNo">1213</span>      throws IOException, InterruptedException {<a name="line.1213"></a>
+<span class="sourceLineNo">1214</span>    MultiGetThread[] multiGetThreads = new MultiGetThread[NO_OF_THREADS];<a name="line.1214"></a>
+<span class="sourceLineNo">1215</span>    for (int i = 0; i &lt; NO_OF_THREADS; i++) {<a name="line.1215"></a>
+<span class="sourceLineNo">1216</span>      multiGetThreads[i] = new MultiGetThread(table);<a name="line.1216"></a>
+<span class="sourceLineNo">1217</span>    }<a name="line.1217"></a>
+<span class="sourceLineNo">1218</span>    for (MultiGetThread thread : multiGetThreads) {<a name="line.1218"></a>
+<span class="sourceLineNo">1219</span>      thread.start();<a name="line.1219"></a>
+<span class="sourceLineNo">1220</span>    }<a name="line.1220"></a>
+<span class="sourceLineNo">1221</span>    return multiGetThreads;<a name="line.1221"></a>
+<span class="sourceLineNo">1222</span>  }<a name="line.1222"></a>
+<span class="sourceLineNo">1223</span><a name="line.1223"></a>
+<span class="sourceLineNo">1224</span>  private void checkForBlockEviction(BlockCache cache, boolean getClosed, boolean expectOnlyZero,<a name="line.1224"></a>
+<span class="sourceLineNo">1225</span>      boolean wrappedCp) throws InterruptedException {<a name="line.1225"></a>
+<span class="sourceLineNo">1226</span>    int counter = NO_OF_THREADS;<a name="line.1226"></a>
+<span class="sourceLineNo">1227</span>    if (CustomInnerRegionObserver.waitForGets.get()) {<a name="line.1227"></a>
+<span class="sourceLineNo">1228</span>      // Because only one row is selected, it has only 2 blocks<a name="line.1228"></a>
+<span class="sourceLineNo">1229</span>      counter = counter - 1;<a name="line.1229"></a>
+<span class="sourceLineNo">1230</span>      while (CustomInnerRegionObserver.countOfGets.get() &lt; NO_OF_THREADS) {<a name="line.1230"></a>
+<span class="sourceLineNo">1231</span>        Thread.sleep(100);<a name="line.1231"></a>
+<span class="sourceLineNo">1232</span>      }<a name="line.1232"></a>
+<span class="sourceLineNo">1233</span>    } else {<a name="line.1233"></a>
+<span class="sourceLineNo">1234</span>      while (CustomInnerRegionObserver.countOfNext.get() &lt; NO_OF_THREADS) {<a name="line.1234"></a>
+<span class="sourceLineNo">1235</span>        Thread.sleep(100);<a name="line.1235"></a>
+<span class="sourceLineNo">1236</span>      }<a name="line.1236"></a>
+<span class="sourceLineNo">1237</span>    }<a name="line.1237"></a>
+<span class="sourceLineNo">1238</span>    Iterator&lt;CachedBlock&gt; iterator = cache.iterator();<a name="line.1238"></a>
+<span class="sourceLineNo">1239</span>    int refCount = 0;<a name="line.1239"></a>
+<span class="sourceLineNo">1240</span>    while (iterator.hasNext()) {<a name="line.1240"></a>
+<span class="sourceLineNo">1241</span>      CachedBlock next = iterator.next();<a name="line.1241"></a>
+<span class="sourceLineNo">1242</span>      BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());<a name="line.1242"></a>
+<span class="sourceLineNo">1243</span>      if (cache instanceof BucketCache) {<a name="line.1243"></a>
+<span class="sourceLineNo">1244</span>        refCount = ((BucketCache) cache).getRefCount(cacheKey);<a name="line.1244"></a>
+<span class="sourceLineNo">1245</span>      } else if (cache instanceof CombinedBlockCache) {<a name="line.1245"></a>
+<span class="sourceLineNo">1246</span>        refCount = ((CombinedBlockCache) cache).getRefCount(cacheKey);<a name="line.1246"></a>
+<span class="sourceLineNo">1247</span>      } else {<a name="line.1247"></a>
+<span class="sourceLineNo">1248</span>        continue;<a name="line.1248"></a>
+<span class="sourceLineNo">1249</span>      }<a name="line.1249"></a>
+<span class="sourceLineNo">1250</span>      System.out.println(" the refcount is " + refCount + " block is " + cacheKey);<a name="line.1250"></a>
+<span class="sourceLineNo">1251</span>      if (CustomInnerRegionObserver.waitForGets.get()) {<a name="line.1251"></a>
+<span class="sourceLineNo">1252</span>        if (expectOnlyZero) {<a name="line.1252"></a>
+<span class="sourceLineNo">1253</span>          assertTrue(refCount == 0);<a name="line.1253"></a>
+<span class="sourceLineNo">1254</span>        }<a name="line.1254"></a>
+<span class="sourceLineNo">1255</span>        if (refCount != 0) {<a name="line.1255"></a>
+<span class="sourceLineNo">1256</span>          // Because the scan would have also touched up on these blocks but<a name="line.1256"></a>
+<span class="sourceLineNo">1257</span>          // it<a name="line.1257"></a>
+<span class="sourceLineNo">1258</span>          // would have touched<a name="line.1258"></a>
+<span class="sourceLineNo">1259</span>          // all 3<a name="line.1259"></a>
+<span class="sourceLineNo">1260</span>          if (getClosed) {<a name="line.1260"></a>
+<span class="sourceLineNo">1261</span>            // If get has closed only the scan's blocks would be available<a name="line.1261"></a>
+<span class="sourceLineNo">1262</span>            assertEquals(refCount, CustomInnerRegionObserver.countOfGets.get());<a name="line.1262"></a>
+<span class="sourceLineNo">1263</span>          } else {<a name="line.1263"></a>
+<span class="sourceLineNo">1264</span>              assertEquals(refCount, CustomInnerRegionObserver.countOfGets.get() + (NO_OF_THREADS));<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>      } else {<a name="line.1267"></a>
+<span class="sourceLineNo">1268</span>        // Because the get would have also touched up on these blocks but it<a name="line.1268"></a>
+<span class="sourceLineNo">1269</span>        // would have touched<a name="line.1269"></a>
+<span class="sourceLineNo">1270</span>        // upon only 2 additionally<a name="line.1270"></a>
+<span class="sourceLineNo">1271</span>        if (expectOnlyZero) {<a name="line.1271"></a>
+<span class="sourceLineNo">1272</span>          assertTrue(refCount == 0);<a name="line.1272"></a>
+<span class="sourceLineNo">1273</span>        }<a name="line.1273"></a>
+<span class="sourceLineNo">1274</span>        if (refCount != 0) {<a name="line.1274"></a>
+<span class="sourceLineNo">1275</span>          if (getLatch == null || wrappedCp) {<a name="line.1275"></a>
+<span class="sourceLineNo">1276</span>            assertEquals(refCount, CustomInnerRegionObserver.countOfNext.get());<a name="line.1276"></a>
+<span class="sourceLineNo">1277</span>          } else {<a name="line.1277"></a>
+<span class="sourceLineNo">1278</span>            assertEquals(refCount, CustomInnerRegionObserver.countOfNext.get() + (NO_OF_THREADS));<a name="line.1278"></a>
+<span class="sourceLineNo">1279</span>          }<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>    }<a name="line.1282"></a>
+<span class="sourceLineNo">1283</span>    CustomInnerRegionObserver.getCdl().get().countDown();<a name="line.1283"></a>
+<span class="sourceLineNo">1284</span>  }<a name="line.1284"></a>
+<span class="sourceLineNo">1285</span><a name="line.1285"></a>
+<span class="sourceLineNo">1286</span>  private static class MultiGetThread extends Thread {<a name="line.1286"></a>
+<span class="sourceLineNo">1287</span>    private final HTable table;<a name="line.1287"></a>
+<span class="sourceLineNo">1288</span>    private final List&lt;Get&gt; gets = new ArrayList&lt;Get&gt;();<a name="line.1288"></a>
+<span class="sourceLineNo">1289</span>    public MultiGetThread(HTable table) {<a name="line.1289"></a>
+<span class="sourceLineNo">1290</span>      this.table = table;<a name="line.1290"></a>
+<span class="sourceLineNo">1291</span>    }<a name="line.1291"></a>
+<span class="sourceLineNo">1292</span>    @Override<a name="line.1292"></a>
+<span class="sourceLineNo">1293</span>    public void run() {<a name="line.1293"></a>
+<span class="sourceLineNo">1294</span>      gets.add(new Get(ROW));<a name="line.1294"></a>
+<span class="sourceLineNo">1295</span>      gets.add(new Get(ROW1));<a name="line.1295"></a>
+<span class="sourceLineNo">1296</span>      try {<a name="line.1296"></a>
+<span class="sourceLineNo">1297</span>        CustomInnerRegionObserver.getCdl().set(latch);<a name="line.1297"></a>
+<span class="sourceLineNo">1298</span>        Result[] r = table.get(gets);<a name="line.1298"></a>
+<span class="sourceLineNo">1299</span>        assertTrue(Bytes.equals(r[0].getRow(), ROW));<a name="line.1299"></a>
+<span class="sourceLineNo">1300</span>        assertTrue(Bytes.equals(r[1].getRow(), ROW1));<a name="line.1300"></a>
+<span class="sourceLineNo">1301</span>      } catch (IOException e) {<a name="line.1301"></a>
+<span class="sourceLineNo">1302</span>      }<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><a name="line.1305"></a>
+<span class="sourceLineNo">1306</span>  private static class GetThread extends Thread {<a name="line.1306"></a>
+<span class="sourceLineNo">1307</span>    private final HTable table;<a name="line.1307"></a>
+<span class="sourceLineNo">1308</span>    private final boolean tracker;<a name="line.1308"></a>
+<span class="sourceLineNo">1309</span>    private final boolean multipleCFs;<a name="line.1309"></a>
+<span class="sourceLineNo">1310</span><a name="line.1310"></a>
+<span class="sourceLineNo">1311</span>    public GetThread(HTable table, boolean tracker, boolean multipleCFs) {<a name="line.1311"></a>
+<span class="sourceLineNo">1312</span>      this.table = table;<a name="line.1312"></a>
+<span class="sourceLineNo">1313</span>      this.tracker = tracker;<a name="line.1313"></a>
+<span class="sourceLineNo">1314</span>      this.multipleCFs = multipleCFs;<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 void run() {<a name="line.1318"></a>
+<span class="sourceLineNo">1319</span>      try {<a name="line.1319"></a>
+<span class="sourceLineNo">1320</span>        initiateGet(table);<a name="line.1320"></a>
+<span class="sourceLineNo">1321</span>      } catch (IOException e) {<a name="line.1321"></a>
+<span class="sourceLineNo">1322</span>        // do nothing<a name="line.1322"></a>
+<span class="sourceLineNo">1323</span>      }<a name="line.1323"></a>
+<span class="sourceLineNo">1324</span>    }<a name="line.1324"

<TRUNCATED>

Mime
View raw message