HBASE-3433 : KeyValue API to explicitly distinguish between deep & shallow copies

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1061648 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nicolas Spiegelberg 2011-01-21 06:24:36 +00:00
parent 2267af90c9
commit 2514a87ad6
3 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -566,6 +566,26 @@ public class KeyValue implements Writable, HeapSize {
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

View File

@ -253,7 +253,7 @@ class StoreScanner implements KeyValueScanner, InternalScanner, ChangedReadersOb
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) {