You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/01/21 07:24:37 UTC

svn commit: r1061648 - in /hbase/trunk: CHANGES.txt src/main/java/org/apache/hadoop/hbase/KeyValue.java src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java

Author: nspiegelberg
Date: Fri Jan 21 06:24:36 2011
New Revision: 1061648

URL: http://svn.apache.org/viewvc?rev=1061648&view=rev
Log:
HBASE-3433 : KeyValue API to explicitly distinguish between deep & shallow copies

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/KeyValue.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java

Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1061648&r1=1061647&r2=1061648&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Fri Jan 21 06:24:36 2011
@@ -51,6 +51,7 @@ Release 0.91.0 - Unreleased
    HBASE-3393  Update Avro gateway to use Avro 1.4.1 and the new
                server.join() method (Jeff Hammerbacher via Stack)
    HBASE-3437  Support Explict Split Points from the Shell
+   HBASE-3433  KeyValue API to explicitly distinguish between deep & shallow copies
 
 
   NEW FEATURES

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/KeyValue.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/KeyValue.java?rev=1061648&r1=1061647&r2=1061648&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/KeyValue.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/KeyValue.java Fri Jan 21 06:24:36 2011
@@ -566,6 +566,26 @@ public class KeyValue implements Writabl
     return ret;
   }
 
+  /**
+   * Creates a deep copy of this KeyValue, re-allocating the buffer.
+   * Same function as {@link #clone()}.  Added for clarity vs shallowCopy()
+   * @return Deep copy of this KeyValue
+   */
+  public KeyValue deepCopy() {
+    return clone();
+  }
+
+  /**
+   * Creates a shallow copy of this KeyValue, reusing the data byte buffer.
+   * http://en.wikipedia.org/wiki/Object_copy
+   * @return Shallow copy of this KeyValue
+   */
+  public KeyValue shallowCopy() {
+    KeyValue shallowCopy = new KeyValue(this.bytes, this.offset, this.length);
+    shallowCopy.setMemstoreTS(this.memstoreTS);
+    return shallowCopy;
+  }
+
   //---------------------------------------------------------------------------
   //
   //  String representation

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java?rev=1061648&r1=1061647&r2=1061648&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java Fri Jan 21 06:24:36 2011
@@ -253,7 +253,7 @@ class StoreScanner implements KeyValueSc
     List<KeyValue> results = new ArrayList<KeyValue>();
     LOOP: while((kv = this.heap.peek()) != null) {
       // kv is no longer immutable due to KeyOnlyFilter! use copy for safety
-      KeyValue copyKv = new KeyValue(kv.getBuffer(), kv.getOffset(), kv.getLength());
+      KeyValue copyKv = kv.shallowCopy();
       ScanQueryMatcher.MatchCode qcode = matcher.match(copyKv);
       //DebugPrint.println("SS peek kv = " + kv + " with qcode = " + qcode);
       switch(qcode) {