From bb07de19606cce699e539d49af3ba1c5a12b75fe Mon Sep 17 00:00:00 2001 From: stack Date: Wed, 3 Dec 2014 22:34:27 -0800 Subject: [PATCH] HBASE-12431 Use of getColumnLatestCell(byte[], int, int, byte[], int, int) is Not Thread Safe (Jingcheng Du) (cherry picked from commit c45772e76a581838ea89ff303d0ff67ceaa82845) --- .../src/main/java/org/apache/hadoop/hbase/client/Result.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 86070de2786..401710e9190 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(); @@ -334,9 +333,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,