Skip to content

Commit 9eae36c

Browse files
stotyapurtell
authored andcommitted
HBASE-26777 BufferedDataBlockEncoder$OffheapDecodedExtendedCell.deepC… (apache#4139)
Signed-off-by: Andrew Purtell <[email protected]> (cherry picked from commit 622c436) Change-Id: Ic3a4acb79a540175a42b37940ed5f5baf7a1b37c
1 parent 9d5fb49 commit 9eae36c

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public static byte[] copyToNewByteArray(final Cell cell) {
131131
//Cell#getSerializedSize returns the serialized size of the Source cell, which may
132132
//not serialize all fields. We are constructing a KeyValue backing array here,
133133
//which does include all fields, and must allocate accordingly.
134+
//TODO we could probably use Cell#getSerializedSize safely, the errors were
135+
//caused by cells corrupted by use-after-free bugs
134136
int v1Length = length(cell.getRowLength(), cell.getFamilyLength(),
135137
cell.getQualifierLength(), cell.getValueLength(), cell.getTagsLength(), true);
136138
byte[] backingBytes = new byte[v1Length];

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
import org.apache.hadoop.hbase.HConstants.OperationStatusCode;
9696
import org.apache.hadoop.hbase.HDFSBlocksDistribution;
9797
import org.apache.hadoop.hbase.KeyValue;
98+
import org.apache.hadoop.hbase.KeyValueUtil;
9899
import org.apache.hadoop.hbase.MetaCellComparator;
99100
import org.apache.hadoop.hbase.NamespaceDescriptor;
100101
import org.apache.hadoop.hbase.NotServingRegionException;
@@ -8276,7 +8277,7 @@ public List<Cell> get(Get get, boolean withCoprocessor, long nonceGroup, long no
82768277
// See more details in HBASE-26036.
82778278
for (Cell cell : tmp) {
82788279
results.add(cell instanceof ByteBufferExtendedCell ?
8279-
((ByteBufferExtendedCell) cell).deepClone(): cell);
8280+
KeyValueUtil.copyToNewKeyValue(cell) : cell);
82808281
}
82818282
}
82828283

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCheckAndMutateWithByteBuff.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.hadoop.hbase.TableName;
3232
import org.apache.hadoop.hbase.io.ByteBuffAllocator;
3333
import org.apache.hadoop.hbase.io.DeallocateRewriteByteBuffAllocator;
34+
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
3435
import org.apache.hadoop.hbase.io.hfile.BlockCacheFactory;
3536
import org.apache.hadoop.hbase.regionserver.HRegion;
3637
import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;
@@ -86,8 +87,20 @@ public static void tearDownAfterClass() throws Exception {
8687
}
8788

8889
@Test
89-
public void testCheckAndMutateWithByteBuff() throws Exception {
90-
Table testTable = createTable(TableName.valueOf(name.getMethodName()));
90+
public void testCheckAndMutateWithByteBuffNoEncode() throws Exception {
91+
testCheckAndMutateWithByteBuff(TableName.valueOf(name.getMethodName()), DataBlockEncoding.NONE);
92+
}
93+
94+
@Test
95+
public void testCheckAndMutateWithByteBuffEncode() throws Exception {
96+
// Tests for HBASE-26777.
97+
// As most HBase.getRegion() calls have been factored out from HBase, you'd need to revert
98+
// both HBASE-26777, and the HBase.get() replacements from HBASE-26036 for this test to fail
99+
testCheckAndMutateWithByteBuff(TableName.valueOf(name.getMethodName()), DataBlockEncoding.FAST_DIFF);
100+
}
101+
102+
private void testCheckAndMutateWithByteBuff(TableName tableName, DataBlockEncoding dbe) throws Exception {
103+
Table testTable = createTable(tableName, dbe);
91104
byte[] checkRow = Bytes.toBytes("checkRow");
92105
byte[] checkQualifier = Bytes.toBytes("cq");
93106
byte[] checkValue = Bytes.toBytes("checkValue");
@@ -103,10 +116,13 @@ public void testCheckAndMutateWithByteBuff() throws Exception {
103116
Bytes.toBytes("testValue"))));
104117
}
105118

106-
private Table createTable(TableName tableName)
119+
private Table createTable(TableName tableName, DataBlockEncoding dbe)
107120
throws IOException {
108121
TableDescriptor td = TableDescriptorBuilder.newBuilder(tableName)
109-
.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(CF).setBlocksize(100).build())
122+
.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(CF)
123+
.setBlocksize(100)
124+
.setDataBlockEncoding(dbe)
125+
.build())
110126
.build();
111127
return TEST_UTIL.createTable(td, null);
112128
}

0 commit comments

Comments
 (0)