hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-15676 FuzzyRowFilter fails and matches all the rows in the table if the mask consists of all 0s (Matt Warhaftig)
Date Thu, 28 Apr 2016 04:12:59 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.1 6b54917d5 -> 46dda26df


HBASE-15676 FuzzyRowFilter fails and matches all the rows in the table if the mask consists
of all 0s (Matt Warhaftig)


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

Branch: refs/heads/branch-1.1
Commit: 46dda26df8864cb009e2e715235368784ed0b61f
Parents: 6b54917
Author: tedyu <yuzhihong@gmail.com>
Authored: Wed Apr 27 21:12:53 2016 -0700
Committer: tedyu <yuzhihong@gmail.com>
Committed: Wed Apr 27 21:12:53 2016 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/filter/FuzzyRowFilter.java     | 16 +++++---
 .../filter/TestFuzzyRowFilterEndToEnd.java      | 43 +++++++++++++++++++-
 2 files changed, 53 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/46dda26d/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FuzzyRowFilter.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FuzzyRowFilter.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FuzzyRowFilter.java
index 50e9041..c8ddb92 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FuzzyRowFilter.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FuzzyRowFilter.java
@@ -86,7 +86,7 @@ public class FuzzyRowFilter extends FilterBase {
                 .getSecond()));
         throw new IllegalArgumentException("Fuzzy pair lengths do not match: " + readable);
       }
-      // update mask ( 0 -> -1 (0xff), 1 -> 0)
+      // update mask ( 0 -> -1 (0xff), 1 -> 2)
       p.setSecond(preprocessMask(p.getSecond()));
       preprocessSearchKey(p);
     }
@@ -102,12 +102,14 @@ public class FuzzyRowFilter extends FilterBase {
     byte[] mask = p.getSecond();
     for (int i = 0; i < mask.length; i++) {
       // set non-fixed part of a search key to 0.
-      if (mask[i] == 0) key[i] = 0;
+      if (mask[i] == 2) {
+        key[i] = 0;
+      }
     }
   }
 
   /**
-   * We need to preprocess mask array, as since we treat 0's as unfixed positions and -1
(0xff) as
+   * We need to preprocess mask array, as since we treat 2's as unfixed positions and -1
(0xff) as
    * fixed positions
    * @param mask
    * @return mask array
@@ -121,7 +123,7 @@ public class FuzzyRowFilter extends FilterBase {
       if (mask[i] == 0) {
         mask[i] = -1; // 0 -> -1
       } else if (mask[i] == 1) {
-        mask[i] = 0;// 1 -> 0
+        mask[i] = 2;// 1 -> 2
       }
     }
     return mask;
@@ -129,7 +131,7 @@ public class FuzzyRowFilter extends FilterBase {
 
   private boolean isPreprocessedMask(byte[] mask) {
     for (int i = 0; i < mask.length; i++) {
-      if (mask[i] != -1 && mask[i] != 0) {
+      if (mask[i] != -1 && mask[i] != 2) {
         return false;
       }
     }
@@ -143,6 +145,10 @@ public class FuzzyRowFilter extends FilterBase {
     for (int i = startIndex; i < size + startIndex; i++) {
       final int index = i % size;
       Pair<byte[], byte[]> fuzzyData = fuzzyKeysData.get(index);
+      // This shift is idempotent - always end up with 0 and -1 as mask values.
+      for (int j = 0; j < fuzzyData.getSecond().length; j++) {
+        fuzzyData.getSecond()[j] >>= 2;
+      }
       SatisfiesCode satisfiesCode =
           satisfies(isReversed(), c.getRowArray(), c.getRowOffset(), c.getRowLength(),
             fuzzyData.getFirst(), fuzzyData.getSecond());

http://git-wip-us.apache.org/repos/asf/hbase/blob/46dda26d/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFuzzyRowFilterEndToEnd.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFuzzyRowFilterEndToEnd.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFuzzyRowFilterEndToEnd.java
index 9179549..fa738b2 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFuzzyRowFilterEndToEnd.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFuzzyRowFilterEndToEnd.java
@@ -110,7 +110,48 @@ public class TestFuzzyRowFilterEndToEnd {
     // Nothing to do.
   }
 
-  @Test  
+  // HBASE-15676 Test that fuzzy info of all fixed bits (0s) finds matching row.
+  @Test
+  public void testAllFixedBits() throws IOException {
+    String cf = "f";
+    String cq = "q";
+    String table = "testAllFixedBits";
+
+    Table ht =
+        TEST_UTIL.createTable(TableName.valueOf(table), Bytes.toBytes(cf), Integer.MAX_VALUE);
+    // Load data
+    String[] rows = new String[] { "\\x9C\\x00\\x044\\x00\\x00\\x00\\x00",
+        "\\x9C\\x00\\x044\\x01\\x00\\x00\\x00", "\\x9C\\x00\\x044\\x00\\x01\\x00\\x00",
+        "\\x9B\\x00\\x044e\\x9B\\x02\\xBB", "\\x9C\\x00\\x044\\x00\\x00\\x01\\x00",
+        "\\x9C\\x00\\x044\\x00\\x01\\x00\\x01", "\\x9B\\x00\\x044e\\xBB\\xB2\\xBB", };
+
+    for (int i = 0; i < rows.length; i++) {
+      Put p = new Put(Bytes.toBytesBinary(rows[i]));
+      p.addColumn(cf.getBytes(), cq.getBytes(), "value".getBytes());
+      ht.put(p);
+    }
+
+    TEST_UTIL.flush();
+
+    List<Pair<byte[], byte[]>> data = new ArrayList<Pair<byte[], byte[]>>();
+    byte[] fuzzyKey = Bytes.toBytesBinary("\\x9B\\x00\\x044e");
+    byte[] mask = new byte[] { 0, 0, 0, 0, 0 };
+    data.add(new Pair<byte[], byte[]>(fuzzyKey, mask));
+    FuzzyRowFilter filter = new FuzzyRowFilter(data);
+
+    Scan scan = new Scan();
+    scan.setFilter(filter);
+
+    ResultScanner scanner = ht.getScanner(scan);
+    int total = 0;
+    while (scanner.next() != null) {
+      total++;
+    }
+    assertEquals(2, total);
+    TEST_UTIL.deleteTable(TableName.valueOf(table));
+  }
+
+  @Test
   public void testHBASE14782() throws IOException
   {
     String cf = "f";


Mime
View raw message