hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1377366 - in /hbase/trunk/hbase-server/src: main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java main/java/org/apache/hadoop/hbase/regionserver/HStore.java test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java
Date Sun, 26 Aug 2012 00:29:33 GMT
Author: stack
Date: Sun Aug 26 00:29:33 2012
New Revision: 1377366

URL: http://svn.apache.org/viewvc?rev=1377366&view=rev
Log:
HBASE-5997 Fix concerns raised in HBASE-5922 related to HalfStoreFileReader

Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java?rev=1377366&r1=1377365&r2=1377366&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java
Sun Aug 26 00:29:33 2012
@@ -54,6 +54,10 @@ public class HalfStoreFileReader extends
   // This is the key we split around.  Its the first possible entry on a row:
   // i.e. empty column and a timestamp of LATEST_TIMESTAMP.
   protected final byte [] splitkey;
+  
+  private byte[] firstKey = null;
+  
+  private boolean firstKeySeeked = false;
 
   /**
    * @param fs
@@ -143,8 +147,11 @@ public class HalfStoreFileReader extends
       public boolean seekBefore(byte [] key, int offset, int length)
       throws IOException {
         if (top) {
-          if (getComparator().compare(key, offset, length, splitkey, 0,
-              splitkey.length) < 0) {
+          byte[] fk = getFirstKey();
+          // This will be null when the file is empty in which we can not seekBefore to any
key
+          if (fk == null) return false;
+          if (getComparator().compare(key, offset, length, fk, 0,
+              fk.length) <= 0) {
             return false;
           }
         } else {
@@ -273,4 +280,20 @@ public class HalfStoreFileReader extends
     // Returns null to indicate file is not splitable.
     return null;
   }
+  
+  @Override
+  public byte[] getFirstKey() {
+    if (!firstKeySeeked) {
+      HFileScanner scanner = getScanner(true, true, false);
+      try {
+        if (scanner.seekTo()) {
+          this.firstKey = Bytes.toBytes(scanner.getKey());
+        }
+        firstKeySeeked = true;
+      } catch (IOException e) {
+        LOG.warn("Failed seekTo first KV in the file", e);
+      }
+    }
+    return this.firstKey;
+  }
 }

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java?rev=1377366&r1=1377365&r2=1377366&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java
Sun Aug 26 00:29:33 2012
@@ -1698,6 +1698,7 @@ public class HStore extends SchemaConfig
     }
     // TODO: Cache these keys rather than make each time?
     byte [] fk = r.getFirstKey();
+    if (fk == null) return;
     KeyValue firstKV = KeyValue.createKeyValueFromKey(fk, 0, fk.length);
     byte [] lk = r.getLastKey();
     KeyValue lastKV = KeyValue.createKeyValueFromKey(lk, 0, lk.length);
@@ -1711,7 +1712,7 @@ public class HStore extends SchemaConfig
       firstOnRow = new KeyValue(lastKV.getRow(), HConstants.LATEST_TIMESTAMP);
     }
     // Get a scanner that caches blocks and that uses pread.
-    HFileScanner scanner = r.getHFileReader().getScanner(true, true, false);
+    HFileScanner scanner = r.getScanner(true, true, false);
     // Seek scanner.  If can't seek it, return.
     if (!seekToScanner(scanner, firstOnRow, firstKV)) return;
     // If we found candidate on firstOnRow, just return. THIS WILL NEVER HAPPEN!

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java?rev=1377366&r1=1377365&r2=1377366&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java
Sun Aug 26 00:29:33 2012
@@ -195,6 +195,9 @@ public class TestHalfStoreFileReader {
       foundKeyValue = doTestOfSeekBefore(p, fs, bottom, items.get(1), cacheConf);
       assertEquals(items.get(0), foundKeyValue);
 
+      // Try to seek before the splitKey in the top file
+      foundKeyValue = doTestOfSeekBefore(p, fs, top, midKV, cacheConf);
+      assertNull(foundKeyValue);
     }
 
   private KeyValue doTestOfSeekBefore(Path p, FileSystem fs, Reference bottom, KeyValue seekBefore,



Mime
View raw message