hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From la...@apache.org
Subject svn commit: r1325453 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/regionserver/HRegion.java test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
Date Thu, 12 Apr 2012 19:18:17 GMT
Author: larsh
Date: Thu Apr 12 19:18:16 2012
New Revision: 1325453

URL: http://svn.apache.org/viewvc?rev=1325453&view=rev
Log:
HBASE-3443 ICV optimization to look in memstore first and then store files (HBASE-3082) does
not work when deletes are in the mix

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=1325453&r1=1325452&r2=1325453&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java Thu
Apr 12 19:18:16 2012
@@ -94,7 +94,6 @@ import org.apache.hadoop.hbase.client.co
 import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
 import org.apache.hadoop.hbase.filter.Filter;
 import org.apache.hadoop.hbase.filter.IncompatibleFilterException;
-import org.apache.hadoop.hbase.filter.NullComparator;
 import org.apache.hadoop.hbase.filter.WritableByteArrayComparable;
 import org.apache.hadoop.hbase.io.HeapSize;
 import org.apache.hadoop.hbase.io.TimeRange;
@@ -4063,89 +4062,6 @@ public class HRegion implements HeapSize
     return new Result(results);
   }
 
-  /**
-   * An optimized version of {@link #get(Get)} that checks MemStore first for
-   * the specified query.
-   * <p>
-   * This is intended for use by increment operations where we have the
-   * guarantee that versions are never inserted out-of-order so if a value
-   * exists in MemStore it is the latest value.
-   * <p>
-   * It only makes sense to use this method without a TimeRange and maxVersions
-   * equal to 1.
-   * @param get
-   * @return result
-   * @throws IOException
-   */
-  private List<KeyValue> getLastIncrement(final Get get) throws IOException {
-    InternalScan iscan = new InternalScan(get);
-
-    List<KeyValue> results = new ArrayList<KeyValue>();
-
-    // memstore scan
-    iscan.checkOnlyMemStore();
-    RegionScanner scanner = null;
-    try {
-      scanner = getScanner(iscan);
-      scanner.next(results);
-    } finally {
-      if (scanner != null)
-        scanner.close();
-    }
-
-    // count how many columns we're looking for
-    int expected = 0;
-    Map<byte[], NavigableSet<byte[]>> familyMap = get.getFamilyMap();
-    for (NavigableSet<byte[]> qfs : familyMap.values()) {
-      expected += qfs.size();
-    }
-
-    // found everything we were looking for, done
-    if (results.size() == expected) {
-      return results;
-    }
-
-    // still have more columns to find
-    if (results != null && !results.isEmpty()) {
-      // subtract what was found in memstore
-      for (KeyValue kv : results) {
-        byte [] family = kv.getFamily();
-        NavigableSet<byte[]> qfs = familyMap.get(family);
-        qfs.remove(kv.getQualifier());
-        if (qfs.isEmpty()) familyMap.remove(family);
-        expected--;
-      }
-      // make a new get for just what is left
-      Get newGet = new Get(get.getRow());
-      for (Map.Entry<byte[], NavigableSet<byte[]>> f : familyMap.entrySet())
{
-        byte [] family = f.getKey();
-        for (byte [] qualifier : f.getValue()) {
-          newGet.addColumn(family, qualifier);
-        }
-      }
-      newGet.setTimeRange(get.getTimeRange().getMin(),
-          get.getTimeRange().getMax());
-      iscan = new InternalScan(newGet);
-    }
-
-    // check store files for what is left
-    List<KeyValue> fileResults = new ArrayList<KeyValue>();
-    iscan.checkOnlyStoreFiles();
-    scanner = null;
-    try {
-      scanner = getScanner(iscan);
-      scanner.next(fileResults);
-    } finally {
-      if (scanner != null)
-        scanner.close();
-    }
-
-    // combine and return
-    results.addAll(fileResults);
-    Collections.sort(results, KeyValue.COMPARATOR);
-    return results;
-  }
-
   /*
    * Do a get based on the get parameter.
    * @param withCoprocessor invoke coprocessor or not. We don't want to
@@ -4562,7 +4478,7 @@ public class HRegion implements HeapSize
             get.addColumn(family.getKey(), column.getKey());
           }
           get.setTimeRange(tr.getMin(), tr.getMax());
-          List<KeyValue> results = getLastIncrement(get);
+          List<KeyValue> results = get(get, false);
 
           // Iterate the input columns and update existing values if they were
           // found, otherwise add new column initialized to the increment amount
@@ -4662,7 +4578,7 @@ public class HRegion implements HeapSize
 
         // we don't want to invoke coprocessor in this case; ICV is wrapped
         // in HRegionServer, so we leave getLastIncrement alone
-        List<KeyValue> results = getLastIncrement(get);
+        List<KeyValue> results = get(get, false);
 
         if (!results.isEmpty()) {
           KeyValue kv = results.get(0);

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=1325453&r1=1325452&r2=1325453&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
(original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
Thu Apr 12 19:18:16 2012
@@ -4116,6 +4116,27 @@ public class TestFromClientSide {
   }
  
   @Test
+  public void testIncrementWithDeletes() throws Exception {
+    LOG.info("Starting testIncrement");
+    final byte [] TABLENAME = Bytes.toBytes("testIncrementWithDeletes");
+    HTable ht = TEST_UTIL.createTable(TABLENAME, FAMILY);
+    final byte[] COLUMN = Bytes.toBytes("column");
+
+    ht.incrementColumnValue(ROW, FAMILY, COLUMN, 5);
+    TEST_UTIL.flush(TABLENAME);
+
+    Delete del = new Delete(ROW);
+    ht.delete(del);
+
+    ht.incrementColumnValue(ROW, FAMILY, COLUMN, 5);
+
+    Get get = new Get(ROW);
+    Result r = ht.get(get);
+    assertEquals(1, r.size());
+    assertEquals(5, Bytes.toLong(r.getValue(FAMILY, COLUMN)));
+  }
+
+  @Test
   public void testIncrement() throws Exception {
     LOG.info("Starting testIncrement");
     final byte [] TABLENAME = Bytes.toBytes("testIncrement");



Mime
View raw message