HBASE-10487 Avoid allocating new KeyValue and according bytes-copying for appended kvs which don't have existing values (Honghua)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1566981 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
89f1d1a051
commit
ed423e2deb
|
@ -5010,30 +5010,22 @@ public class HRegion implements HeapSize { // , Writable{
|
||||||
newKV.getTagsOffset(), oldKv.getTagsLength());
|
newKV.getTagsOffset(), oldKv.getTagsLength());
|
||||||
System.arraycopy(kv.getTagsArray(), kv.getTagsOffset(), newKV.getTagsArray(),
|
System.arraycopy(kv.getTagsArray(), kv.getTagsOffset(), newKV.getTagsArray(),
|
||||||
newKV.getTagsOffset() + oldKv.getTagsLength(), kv.getTagsLength());
|
newKV.getTagsOffset() + oldKv.getTagsLength(), kv.getTagsLength());
|
||||||
|
// copy in row, family, and qualifier
|
||||||
|
System.arraycopy(kv.getRowArray(), kv.getRowOffset(),
|
||||||
|
newKV.getRowArray(), newKV.getRowOffset(), kv.getRowLength());
|
||||||
|
System.arraycopy(kv.getFamilyArray(), kv.getFamilyOffset(),
|
||||||
|
newKV.getFamilyArray(), newKV.getFamilyOffset(),
|
||||||
|
kv.getFamilyLength());
|
||||||
|
System.arraycopy(kv.getQualifierArray(), kv.getQualifierOffset(),
|
||||||
|
newKV.getQualifierArray(), newKV.getQualifierOffset(),
|
||||||
|
kv.getQualifierLength());
|
||||||
idx++;
|
idx++;
|
||||||
} else {
|
} else {
|
||||||
// allocate an empty kv once
|
newKV = kv;
|
||||||
newKV = new KeyValue(row.length, kv.getFamilyLength(),
|
// Append's KeyValue.Type==Put and ts==HConstants.LATEST_TIMESTAMP,
|
||||||
kv.getQualifierLength(), now, KeyValue.Type.Put,
|
// so only need to update the timestamp to 'now'
|
||||||
kv.getValueLength(), kv.getTagsLength());
|
newKV.updateLatestStamp(Bytes.toBytes(now));
|
||||||
// copy in the value
|
}
|
||||||
System.arraycopy(kv.getValueArray(), kv.getValueOffset(),
|
|
||||||
newKV.getValueArray(), newKV.getValueOffset(),
|
|
||||||
kv.getValueLength());
|
|
||||||
// copy in tags
|
|
||||||
System.arraycopy(kv.getTagsArray(), kv.getTagsOffset(), newKV.getTagsArray(),
|
|
||||||
newKV.getTagsOffset(), kv.getTagsLength());
|
|
||||||
}
|
|
||||||
// copy in row, family, and qualifier
|
|
||||||
System.arraycopy(kv.getRowArray(), kv.getRowOffset(),
|
|
||||||
newKV.getRowArray(), newKV.getRowOffset(), kv.getRowLength());
|
|
||||||
System.arraycopy(kv.getFamilyArray(), kv.getFamilyOffset(),
|
|
||||||
newKV.getFamilyArray(), newKV.getFamilyOffset(),
|
|
||||||
kv.getFamilyLength());
|
|
||||||
System.arraycopy(kv.getQualifierArray(), kv.getQualifierOffset(),
|
|
||||||
newKV.getQualifierArray(), newKV.getQualifierOffset(),
|
|
||||||
kv.getQualifierLength());
|
|
||||||
|
|
||||||
newKV.setMvccVersion(w.getWriteNumber());
|
newKV.setMvccVersion(w.getWriteNumber());
|
||||||
// Give coprocessors a chance to update the new cell
|
// Give coprocessors a chance to update the new cell
|
||||||
if (coprocessorHost != null) {
|
if (coprocessorHost != null) {
|
||||||
|
|
|
@ -4422,7 +4422,7 @@ public class TestFromClientSide {
|
||||||
byte[] v1 = Bytes.toBytes("42");
|
byte[] v1 = Bytes.toBytes("42");
|
||||||
byte[] v2 = Bytes.toBytes("23");
|
byte[] v2 = Bytes.toBytes("23");
|
||||||
byte [][] QUALIFIERS = new byte [][] {
|
byte [][] QUALIFIERS = new byte [][] {
|
||||||
Bytes.toBytes("b"), Bytes.toBytes("a")
|
Bytes.toBytes("b"), Bytes.toBytes("a"), Bytes.toBytes("c")
|
||||||
};
|
};
|
||||||
Append a = new Append(ROW);
|
Append a = new Append(ROW);
|
||||||
a.add(FAMILY, QUALIFIERS[0], v1);
|
a.add(FAMILY, QUALIFIERS[0], v1);
|
||||||
|
@ -4433,9 +4433,14 @@ public class TestFromClientSide {
|
||||||
a = new Append(ROW);
|
a = new Append(ROW);
|
||||||
a.add(FAMILY, QUALIFIERS[0], v2);
|
a.add(FAMILY, QUALIFIERS[0], v2);
|
||||||
a.add(FAMILY, QUALIFIERS[1], v1);
|
a.add(FAMILY, QUALIFIERS[1], v1);
|
||||||
|
a.add(FAMILY, QUALIFIERS[2], v2);
|
||||||
Result r = t.append(a);
|
Result r = t.append(a);
|
||||||
assertEquals(0, Bytes.compareTo(Bytes.add(v1,v2), r.getValue(FAMILY, QUALIFIERS[0])));
|
assertEquals(0, Bytes.compareTo(Bytes.add(v1,v2), r.getValue(FAMILY, QUALIFIERS[0])));
|
||||||
assertEquals(0, Bytes.compareTo(Bytes.add(v2,v1), r.getValue(FAMILY, QUALIFIERS[1])));
|
assertEquals(0, Bytes.compareTo(Bytes.add(v2,v1), r.getValue(FAMILY, QUALIFIERS[1])));
|
||||||
|
// QUALIFIERS[2] previously not exist, verify both value and timestamp are correct
|
||||||
|
assertEquals(0, Bytes.compareTo(v2, r.getValue(FAMILY, QUALIFIERS[2])));
|
||||||
|
assertEquals(r.getColumnLatest(FAMILY, QUALIFIERS[0]).getTimestamp(),
|
||||||
|
r.getColumnLatest(FAMILY, QUALIFIERS[2]).getTimestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue