hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramkris...@apache.org
Subject hbase git commit: HBASE-14643 Avoid Splits from once again opening a closed reader for fetching the first and last key (Heng Chen)
Date Wed, 21 Oct 2015 08:39:37 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.0 1c53bec22 -> d1e672807


HBASE-14643 Avoid Splits from once again opening a closed reader for
fetching the first and last key (Heng Chen)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/d1e67280
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/d1e67280
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/d1e67280

Branch: refs/heads/branch-1.0
Commit: d1e67280770b3061f1bf9890e5cdb9a57a91e17b
Parents: 1c53bec
Author: ramkrishna <ramkrishna.s.vasudevan@gmail.com>
Authored: Wed Oct 21 12:57:59 2015 +0530
Committer: ramkrishna <ramkrishna.s.vasudevan@gmail.com>
Committed: Wed Oct 21 14:08:51 2015 +0530

----------------------------------------------------------------------
 .../hbase/regionserver/HRegionFileSystem.java   |  8 +++----
 .../hadoop/hbase/regionserver/StoreFile.java    | 23 ++++++++++++++++++++
 .../hbase/regionserver/TestStoreFile.java       |  6 ++++-
 3 files changed, 32 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/d1e67280/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
index a4e5d8f..d939d6b 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
@@ -581,24 +581,24 @@ public class HRegionFileSystem {
         if (top) {
           //check if larger than last key.
           KeyValue splitKey = KeyValueUtil.createFirstOnRow(splitRow);
-          byte[] lastKey = f.createReader().getLastKey();
+          byte[] lastKey = f.getLastKey();
           // If lastKey is null means storefile is empty.
           if (lastKey == null) {
             return null;
           }
-          if (f.getReader().getComparator().compareFlatKey(splitKey.getBuffer(),
+          if (f.getComparator().compareFlatKey(splitKey.getBuffer(),
             splitKey.getKeyOffset(), splitKey.getKeyLength(), lastKey, 0, lastKey.length)
> 0) {
             return null;
           }
         } else {
           //check if smaller than first key
           KeyValue splitKey = KeyValueUtil.createLastOnRow(splitRow);
-          byte[] firstKey = f.createReader().getFirstKey();
+          byte[] firstKey = f.getFirstKey();
           // If firstKey is null means storefile is empty.
           if (firstKey == null) {
             return null;
           }
-          if (f.getReader().getComparator().compareFlatKey(splitKey.getBuffer(),
+          if (f.getComparator().compareFlatKey(splitKey.getBuffer(),
             splitKey.getKeyOffset(), splitKey.getKeyLength(), firstKey, 0, firstKey.length)
< 0) {
             return null;
           }

http://git-wip-us.apache.org/repos/asf/hbase/blob/d1e67280/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java
index 1033d95..fc58236 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java
@@ -126,6 +126,25 @@ public class StoreFile {
   // Set when we obtain a Reader.
   private long maxMemstoreTS = -1;
 
+  // firstKey, lastkey and cellComparator will be set when openReader.
+  private byte[] firstKey;
+
+  private byte[] lastKey;
+
+  private KVComparator comparator;
+
+  public byte[] getFirstKey() {
+    return firstKey;
+  }
+
+  public byte[] getLastKey() {
+    return lastKey;
+  }
+
+  public KVComparator getComparator() {
+    return comparator;
+  }
+
   public long getMaxMemstoreTS() {
     return maxMemstoreTS;
   }
@@ -461,6 +480,10 @@ public class StoreFile {
           "proceeding without", e);
       this.reader.timeRangeTracker = null;
     }
+    // initialize so we can reuse them after reader closed.
+    firstKey = reader.getFirstKey();
+    lastKey = reader.getLastKey();
+    comparator = reader.getComparator();
     return this.reader;
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/d1e67280/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java
index 36a7f77..cfb2841 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java
@@ -164,10 +164,13 @@ public class TestStoreFile extends HBaseTestCase {
     // Split on a row, not in middle of row.  Midkey returned by reader
     // may be in middle of row.  Create new one with empty column and
     // timestamp.
+
     KeyValue kv = KeyValue.createKeyValueFromKey(reader.midkey());
     byte [] midRow = kv.getRow();
     kv = KeyValue.createKeyValueFromKey(reader.getLastKey());
     byte [] finalRow = kv.getRow();
+    hsf.closeReader(true);
+
     // Make a reference
     HRegionInfo splitHri = new HRegionInfo(hri.getTable(), null, midRow);
     Path refPath = splitStoreFile(regionFs, splitHri, TEST_FAMILY, hsf, midRow, true);
@@ -264,9 +267,10 @@ public class TestStoreFile extends HBaseTestCase {
     HRegionInfo splitHriA = new HRegionInfo(hri.getTable(), null, SPLITKEY);
     HRegionInfo splitHriB = new HRegionInfo(hri.getTable(), SPLITKEY, null);
     StoreFile f = new StoreFile(fs, linkFilePath, testConf, cacheConf, BloomType.NONE);
+    f.createReader();
     Path pathA = splitStoreFile(cloneRegionFs, splitHriA, TEST_FAMILY, f, SPLITKEY, true);
// top
     Path pathB = splitStoreFile(cloneRegionFs, splitHriB, TEST_FAMILY, f, SPLITKEY, false);//
bottom
-
+    f.closeReader(true);
     // OK test the thing
     FSUtils.logFileSystemState(fs, this.testDir, LOG);
 


Mime
View raw message