hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeffr...@apache.org
Subject svn commit: r1559551 - in /hbase/branches/0.96/hbase-server/src: main/java/org/apache/hadoop/hbase/regionserver/HRegion.java test/java/org/apache/hadoop/hbase/filter/TestFilter.java
Date Sun, 19 Jan 2014 18:55:20 GMT
Author: jeffreyz
Date: Sun Jan 19 18:55:20 2014
New Revision: 1559551

URL: http://svn.apache.org/r1559551
Log:
HBASE-10366: 0.94 filterRow() may be skipped in 0.96(or onwards) code

Modified:
    hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
    hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java

Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=1559551&r1=1559550&r2=1559551&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
(original)
+++ hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
Sun Jan 19 18:55:20 2014
@@ -3696,10 +3696,12 @@ public class HRegion implements HeapSize
           if (filter != null && filter.hasFilterRow()) {
             filter.filterRowCells(results);
           }
-          if (isEmptyRow) {
+          
+          if (isEmptyRow || filterRow()) {
+            results.clear();
             boolean moreRows = nextRow(currentRow, offset, length);
             if (!moreRows) return false;
-            results.clear();
+
             // This row was totally filtered out, if this is NOT the last row,
             // we should continue on. Otherwise, nothing else to do.
             if (!stopRow) continue;
@@ -3749,6 +3751,20 @@ public class HRegion implements HeapSize
       }
     }
 
+    /**
+     * This function is to maintain backward compatibility for 0.94 filters. HBASE-6429 combines
+     * both filterRow & filterRow(List<KeyValue> kvs) functions. While 0.94 code
or older, it may
+     * not implement hasFilterRow as HBase-6429 expects because 0.94 hasFilterRow() only
returns
+     * true when filterRow(List<KeyValue> kvs) is overridden not the filterRow(). Therefore,
the
+     * filterRow() will be skipped.
+     */
+    private boolean filterRow() throws IOException {
+      // when hasFilterRow returns true, filter.filterRow() will be called automatically
inside
+      // filterRowCells(List<Cell> kvs) so we skip that scenario here.
+      return filter != null && (!filter.hasFilterRow())
+          && filter.filterRow();
+    }
+    
     private boolean filterRowKey(byte[] row, int offset, short length) throws IOException
{
       return filter != null
           && filter.filterRowKey(row, offset, length);

Modified: hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java?rev=1559551&r1=1559550&r2=1559551&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java
(original)
+++ hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java
Sun Jan 19 18:55:20 2014
@@ -434,6 +434,47 @@ public class TestFilter {
     assertEquals("The page filter returned more rows than expected", pageSize, scannerCounter);
   }
 
+
+  /**
+   * The following filter simulates a pre-0.96 filter where filterRow() is defined while

+   * hasFilterRow() returns false
+   */
+  static class OldTestFilter extends FilterBase {
+    @Override
+    public byte [] toByteArray() {return null;}
+
+    @Override
+    public boolean hasFilterRow() {
+      return false;
+    }
+    
+    @Override
+    public boolean filterRow() {
+      // always filter out rows
+      return true;
+    }
+  }
+  
+  /**
+   * The following test is to ensure old(such as hbase0.94) filterRow() can be correctly
fired in 
+   * 0.96+ code base.  
+   * 
+   * See HBASE-10366
+   * 
+   * @throws Exception
+   */
+  @Test
+  public void tes94FilterRowCompatibility() throws Exception {
+    Scan s = new Scan();
+    OldTestFilter filter = new OldTestFilter();
+    s.setFilter(filter);
+
+    InternalScanner scanner = this.region.getScanner(s);
+    ArrayList<Cell> values = new ArrayList<Cell>();
+    scanner.next(values);
+    assertTrue("All rows should be filtered out", values.isEmpty());
+  }
+
   /**
    * Tests the the {@link WhileMatchFilter} works in combination with a
    * {@link Filter} that uses the



Mime
View raw message