diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java index 903b2f3305d..8303121cc36 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java @@ -84,8 +84,7 @@ public class Result implements CellScannable, CellScanner { // Ditto for familyMap. It can be composed on fly from passed in kvs. private transient NavigableMap>> familyMap = null; - // never use directly - private static byte [] buffer = null; + private static ThreadLocal localBuffer = new ThreadLocal(); private static final int PAD_WIDTH = 128; public static final Result EMPTY_RESULT = new Result(); @@ -275,9 +274,11 @@ public class Result implements CellScannable, CellScanner { double keyValueSize = (double) KeyValue.getKeyValueDataStructureSize(kvs[0].getRowLength(), flength, qlength, 0); + byte[] buffer = localBuffer.get(); if (buffer == null || keyValueSize > buffer.length) { // pad to the smallest multiple of the pad width buffer = new byte[(int) Math.ceil(keyValueSize / PAD_WIDTH) * PAD_WIDTH]; + localBuffer.set(buffer); } Cell searchTerm = KeyValueUtil.createFirstOnRow(buffer, 0,