HBASE-9868 Remove some array copy, especially around protobuf

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1537988 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2013-11-01 17:10:37 +00:00
parent 8fb1958b67
commit 336b5c52ef
8 changed files with 31 additions and 14 deletions

View File

@ -2736,7 +2736,7 @@ public class HConnectionManager {
* - nested exceptions * - nested exceptions
* *
* Looks for: RegionMovedException / RegionOpeningException / RegionTooBusyException * Looks for: RegionMovedException / RegionOpeningException / RegionTooBusyException
* @returns null if we didn't find the exception, the exception otherwise. * @return null if we didn't find the exception, the exception otherwise.
*/ */
public static Throwable findException(Object exception) { public static Throwable findException(Object exception) {
if (exception == null || !(exception instanceof Throwable)) { if (exception == null || !(exception instanceof Throwable)) {

View File

@ -181,7 +181,8 @@ public class Increment extends Mutation implements Comparable<Row> {
NavigableMap<byte [], Long> longs = new TreeMap<byte [], Long>(Bytes.BYTES_COMPARATOR); NavigableMap<byte [], Long> longs = new TreeMap<byte [], Long>(Bytes.BYTES_COMPARATOR);
for (Cell cell: entry.getValue()) { for (Cell cell: entry.getValue()) {
KeyValue kv = KeyValueUtil.ensureKeyValue(cell); KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
longs.put(kv.getQualifier(), Bytes.toLong(kv.getValue())); longs.put(kv.getQualifier(),
Bytes.toLong(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()));
} }
results.put(entry.getKey(), longs); results.put(entry.getKey(), longs);
} }
@ -224,7 +225,8 @@ public class Increment extends Mutation implements Comparable<Row> {
moreThanOneB = true; moreThanOneB = true;
} }
KeyValue kv = KeyValueUtil.ensureKeyValue(cell); KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
sb.append(Bytes.toStringBinary(kv.getKey()) + "+=" + Bytes.toLong(kv.getValue())); sb.append(Bytes.toStringBinary(kv.getKey()) + "+=" +
Bytes.toLong(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()));
} }
sb.append("}"); sb.append("}");
} }

View File

@ -136,7 +136,7 @@ public class Put extends Mutation implements HeapSize, Comparable<Row> {
List<Cell> list = getCellList(family); List<Cell> list = getCellList(family);
KeyValue kv = createPutKeyValue(family, qualifier, ts, value); KeyValue kv = createPutKeyValue(family, qualifier, ts, value);
list.add(kv); list.add(kv);
familyMap.put(CellUtil.cloneFamily(kv), list); familyMap.put(family, list);
return this; return this;
} }

View File

@ -47,7 +47,8 @@ public class BigDecimalColumnInterpreter extends ColumnInterpreter<BigDecimal, B
if (kv == null || CellUtil.cloneValue(kv) == null) { if (kv == null || CellUtil.cloneValue(kv) == null) {
return null; return null;
} }
return Bytes.toBigDecimal(CellUtil.cloneValue(kv)).setScale(2, RoundingMode.HALF_EVEN); return Bytes.toBigDecimal(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()).
setScale(2, RoundingMode.HALF_EVEN);
} }
@Override @Override

View File

@ -969,8 +969,10 @@ public final class ProtobufUtil {
if (values != null && values.size() > 0) { if (values != null && values.size() > 0) {
for (Cell cell: values) { for (Cell cell: values) {
KeyValue kv = KeyValueUtil.ensureKeyValue(cell); KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
valueBuilder.setQualifier(ZeroCopyLiteralByteString.wrap(kv.getQualifier())); valueBuilder.setQualifier(ZeroCopyLiteralByteString.wrap(
valueBuilder.setValue(ZeroCopyLiteralByteString.wrap(kv.getValue())); kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength()));
valueBuilder.setValue(ZeroCopyLiteralByteString.wrap(
kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()));
columnBuilder.addQualifierValue(valueBuilder.build()); columnBuilder.addQualifierValue(valueBuilder.build());
} }
} }
@ -1006,8 +1008,10 @@ public final class ProtobufUtil {
columnBuilder.clearQualifierValue(); columnBuilder.clearQualifierValue();
for (Cell cell: family.getValue()) { for (Cell cell: family.getValue()) {
KeyValue kv = KeyValueUtil.ensureKeyValue(cell); KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
valueBuilder.setQualifier(ZeroCopyLiteralByteString.wrap(kv.getQualifier())); valueBuilder.setQualifier(ZeroCopyLiteralByteString.wrap(
valueBuilder.setValue(ZeroCopyLiteralByteString.wrap(kv.getValue())); kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength()));
valueBuilder.setValue(ZeroCopyLiteralByteString.wrap(
kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()));
valueBuilder.setTimestamp(kv.getTimestamp()); valueBuilder.setTimestamp(kv.getTimestamp());
if(cell.getTagsLength() > 0) { if(cell.getTagsLength() > 0) {
valueBuilder.setTags(ByteString.copyFrom(CellUtil.getTagArray(kv))); valueBuilder.setTags(ByteString.copyFrom(CellUtil.getTagArray(kv)));

View File

@ -487,10 +487,12 @@ public final class RequestConverter {
final List<Action<R>> actions) final List<Action<R>> actions)
throws IOException { throws IOException {
RegionAction.Builder builder = getRegionActionBuilderWithRegion(regionName); RegionAction.Builder builder = getRegionActionBuilderWithRegion(regionName);
ClientProtos.Action.Builder actionBuilder = ClientProtos.Action.newBuilder();
MutationProto.Builder mutationBuilder = ClientProtos.MutationProto.newBuilder();
for (Action<R> action: actions) { for (Action<R> action: actions) {
Row row = action.getAction(); Row row = action.getAction();
ClientProtos.Action.Builder actionBuilder = actionBuilder.clear();
ClientProtos.Action.newBuilder().setIndex(action.getOriginalIndex()); actionBuilder.setIndex(action.getOriginalIndex());
if (row instanceof Get) { if (row instanceof Get) {
Get g = (Get)row; Get g = (Get)row;
builder.addAction(actionBuilder.setGet(ProtobufUtil.toGet(g))); builder.addAction(actionBuilder.setGet(ProtobufUtil.toGet(g)));
@ -535,10 +537,11 @@ public final class RequestConverter {
final List<Action<R>> actions, final List<CellScannable> cells) final List<Action<R>> actions, final List<CellScannable> cells)
throws IOException { throws IOException {
RegionAction.Builder builder = getRegionActionBuilderWithRegion(regionName); RegionAction.Builder builder = getRegionActionBuilderWithRegion(regionName);
ClientProtos.Action.Builder actionBuilder = ClientProtos.Action.newBuilder();
for (Action<R> action: actions) { for (Action<R> action: actions) {
Row row = action.getAction(); Row row = action.getAction();
ClientProtos.Action.Builder actionBuilder = actionBuilder.clear();
ClientProtos.Action.newBuilder().setIndex(action.getOriginalIndex()); actionBuilder.setIndex(action.getOriginalIndex());
if (row instanceof Get) { if (row instanceof Get) {
Get g = (Get)row; Get g = (Get)row;
builder.addAction(actionBuilder.setGet(ProtobufUtil.toGet(g))); builder.addAction(actionBuilder.setGet(ProtobufUtil.toGet(g)));

View File

@ -42,6 +42,13 @@ public final class ZeroCopyLiteralByteString extends LiteralByteString {
return new LiteralByteString(array); return new LiteralByteString(array);
} }
/**
* Wraps a subset of a byte array in a {@link ByteString} without copying it.
*/
public static ByteString wrap(final byte[] array, int offset, int length) {
return new BoundedByteString(array, offset, length);
}
// TODO: // TODO:
// ZeroCopyLiteralByteString.wrap(this.buf, 0, this.count); // ZeroCopyLiteralByteString.wrap(this.buf, 0, this.count);

View File

@ -294,7 +294,7 @@ public final class Constraints {
* <tt>true</tt> if it should be run * <tt>true</tt> if it should be run
* @param priority * @param priority
* relative to other constraints * relative to other constraints
* @returns a new configuration, storable in the {@link HTableDescriptor} * @return a new configuration, storable in the {@link HTableDescriptor}
*/ */
private static Configuration configure(Configuration conf, boolean enabled, private static Configuration configure(Configuration conf, boolean enabled,
long priority) { long priority) {