hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1462275 - in /hbase/trunk/hbase-server/src: main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java
Date Thu, 28 Mar 2013 19:50:19 GMT
Author: tedyu
Date: Thu Mar 28 19:50:19 2013
New Revision: 1462275

URL: http://svn.apache.org/r1462275
Log:
HBASE-8152 Avoid creating empty reference file when splitkey is outside the key range of a
store file (clockfly)


Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java?rev=1462275&r1=1462274&r2=1462275&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
Thu Mar 28 19:50:19 2013
@@ -43,6 +43,7 @@ import org.apache.hadoop.hbase.HColumnDe
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.backup.HFileArchiver;
 import org.apache.hadoop.hbase.fs.HFileSystem;
 import org.apache.hadoop.hbase.io.Reference;
@@ -519,6 +520,27 @@ public class HRegionFileSystem {
    */
   Path splitStoreFile(final HRegionInfo hri, final String familyName,
       final StoreFile f, final byte[] splitRow, final boolean top) throws IOException {
+    
+    // Check whether the split row lies in the range of the store file
+    // If it is outside the range, return directly.
+    if (top) {
+      //check if larger than last key.
+      KeyValue splitKey = KeyValue.createFirstOnRow(splitRow);
+      byte[] lastKey = f.createReader().getLastKey();      
+      if (f.getReader().getComparator().compare(splitKey.getBuffer(), 
+          splitKey.getKeyOffset(), splitKey.getKeyLength(), lastKey, 0, lastKey.length) >
0) {
+        return null;
+      }
+    } else {
+      //check if smaller than first key
+      KeyValue splitKey = KeyValue.createLastOnRow(splitRow);
+      byte[] firstKey = f.createReader().getFirstKey();
+      if (f.getReader().getComparator().compare(splitKey.getBuffer(), 
+          splitKey.getKeyOffset(), splitKey.getKeyLength(), firstKey, 0, firstKey.length)
< 0) {
+        return null;
+      }      
+    }
+    
     Path splitDir = new Path(getSplitsDir(hri), familyName);
     // A reference to the bottom half of the hsf store file.
     Reference r =

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java?rev=1462275&r1=1462274&r2=1462275&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java
Thu Mar 28 19:50:19 2013
@@ -109,7 +109,7 @@ public class TestStoreFile extends HBase
   }
 
   // pick an split point (roughly halfway)
-  byte[] SPLITKEY = new byte[] { (LAST_CHAR-FIRST_CHAR)/2, FIRST_CHAR};
+  byte[] SPLITKEY = new byte[] { (LAST_CHAR + FIRST_CHAR)/2, FIRST_CHAR};
 
   /*
    * Writes HStoreKey and ImmutableBytes data to passed writer and
@@ -280,6 +280,9 @@ public class TestStoreFile extends HBase
     // Now confirm that I can read from the ref to link
     HFileScanner sB = hsfB.createReader().getScanner(false, false);
     sB.seekTo();
+    
+    //count++ as seekTo() will advance the scanner
+    count++;
     while (sB.next()) {
       count++;
     }
@@ -358,18 +361,11 @@ public class TestStoreFile extends HBase
       assertTrue(fs.exists(f.getPath()));
       topPath = splitStoreFile(regionFs, topHri, TEST_FAMILY, f, badmidkey, true);
       bottomPath = splitStoreFile(regionFs, bottomHri, TEST_FAMILY, f, badmidkey, false);
+      
+      assertNull(bottomPath);
+      
       top = new StoreFile(this.fs, topPath, conf, cacheConf, BloomType.NONE,
           NoOpDataBlockEncoder.INSTANCE).createReader();
-      bottom = new StoreFile(this.fs, bottomPath, conf, cacheConf, BloomType.NONE,
-          NoOpDataBlockEncoder.INSTANCE).createReader();
-      bottomScanner = bottom.getScanner(false, false);
-      int count = 0;
-      while ((!bottomScanner.isSeeked() && bottomScanner.seekTo()) ||
-          bottomScanner.next()) {
-        count++;
-      }
-      // When badkey is < than the bottom, should return no values.
-      assertTrue(count == 0);
       // Now read from the top.
       first = true;
       topScanner = top.getScanner(false, false);
@@ -402,8 +398,7 @@ public class TestStoreFile extends HBase
       badmidkey = Bytes.toBytes("|||");
       topPath = splitStoreFile(regionFs,topHri, TEST_FAMILY, f, badmidkey, true);
       bottomPath = splitStoreFile(regionFs, bottomHri, TEST_FAMILY, f, badmidkey, false);
-      top = new StoreFile(this.fs, topPath, conf, cacheConf, BloomType.NONE,
-          NoOpDataBlockEncoder.INSTANCE).createReader();
+      assertNull(topPath);
       bottom = new StoreFile(this.fs, bottomPath, conf, cacheConf, BloomType.NONE,
           NoOpDataBlockEncoder.INSTANCE).createReader();
       first = true;
@@ -426,14 +421,6 @@ public class TestStoreFile extends HBase
       for (int i = 0; i < tmp.length(); i++) {
         assertTrue(Bytes.toString(keyKV.getRow()).charAt(i) == 'z');
       }
-      count = 0;
-      topScanner = top.getScanner(false, false);
-      while ((!topScanner.isSeeked() && topScanner.seekTo()) ||
-          (topScanner.isSeeked() && topScanner.next())) {
-        count++;
-      }
-      // When badkey is < than the bottom, should return no values.
-      assertTrue(count == 0);
     } finally {
       if (top != null) {
         top.close(true); // evict since we are about to delete the file
@@ -929,6 +916,9 @@ public class TestStoreFile extends HBase
       throws IOException {
     FileSystem fs = regionFs.getFileSystem();
     Path path = regionFs.splitStoreFile(hri, family, sf, splitKey, isTopRef);
+    if (null == path) {
+      return null;
+    }
     Path regionDir = regionFs.commitDaughterRegion(hri);
     return new Path(new Path(regionDir, family), path.getName());
   }



Mime
View raw message