From 6ff32a1a890f26e42a3c9e75193bae4b3c8c2c4d Mon Sep 17 00:00:00 2001 From: larsh Date: Fri, 6 Jul 2012 18:22:00 +0000 Subject: [PATCH] Data error after majorCompaction caused by keeping MVCC for opened scanners (chunhui shen) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1358331 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/regionserver/ScanQueryMatcher.java | 7 ++- .../hbase/regionserver/TestHRegion.java | 50 +++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanQueryMatcher.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanQueryMatcher.java index 7e8c2b6a441..20e29786485 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanQueryMatcher.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanQueryMatcher.java @@ -293,10 +293,9 @@ public class ScanQueryMatcher { } // Can't early out now, because DelFam come before any other keys } - if (retainDeletesInOutput || - (!isUserScan && - (EnvironmentEdgeManager.currentTimeMillis() - timestamp) <= - timeToPurgeDeletes)) { + if (retainDeletesInOutput + || (!isUserScan && (EnvironmentEdgeManager.currentTimeMillis() - timestamp) <= timeToPurgeDeletes) + || kv.getMemstoreTS() > maxReadPointToTrackVersions) { // always include or it is not time yet to check whether it is OK // to purge deltes or not return MatchCode.INCLUDE; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java index 19f535af864..a4b7a8e4e21 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java @@ -151,6 +151,56 @@ public class TestHRegion extends HBaseTestCase { // /tmp/testtable ////////////////////////////////////////////////////////////////////////////// + public void testCompactionAffectedByScanners() throws Exception { + String method = "testCompactionAffectedByScanners"; + byte[] tableName = Bytes.toBytes(method); + byte[] family = Bytes.toBytes("family"); + Configuration conf = HBaseConfiguration.create(); + this.region = initHRegion(tableName, method, conf, family); + + Put put = new Put(Bytes.toBytes("r1")); + put.add(family, Bytes.toBytes("q1"), Bytes.toBytes("v1")); + region.put(put); + region.flushcache(); + + + Scan scan = new Scan(); + scan.setMaxVersions(3); + // open the first scanner + RegionScanner scanner1 = region.getScanner(scan); + + Delete delete = new Delete(Bytes.toBytes("r1")); + region.delete(delete, null, false); + region.flushcache(); + + // open the second scanner + RegionScanner scanner2 = region.getScanner(scan); + + List results = new ArrayList(); + + System.out.println("Smallest read point:" + region.getSmallestReadPoint()); + + // make a major compaction + region.compactStores(true); + + // open the third scanner + RegionScanner scanner3 = region.getScanner(scan); + + // get data from scanner 1, 2, 3 after major compaction + scanner1.next(results); + System.out.println(results); + assertEquals(1, results.size()); + + results.clear(); + scanner2.next(results); + System.out.println(results); + assertEquals(0, results.size()); + + results.clear(); + scanner3.next(results); + System.out.println(results); + assertEquals(0, results.size()); + } public void testSkipRecoveredEditsReplay() throws Exception { String method = "testSkipRecoveredEditsReplay";