Skip to content

Commit 622c436

Browse files
stotyapurtell
authored andcommitted
HBASE-26777 BufferedDataBlockEncoder$OffheapDecodedExtendedCell.deepC… (#4139)
Signed-off-by: Andrew Purtell <apurtell@apache.org>
1 parent 6ec1659 commit 622c436

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

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
@@ -93,6 +93,7 @@
9393
import org.apache.hadoop.hbase.HConstants.OperationStatusCode;
9494
import org.apache.hadoop.hbase.HDFSBlocksDistribution;
9595
import org.apache.hadoop.hbase.KeyValue;
96+
import org.apache.hadoop.hbase.KeyValueUtil;
9697
import org.apache.hadoop.hbase.MetaCellComparator;
9798
import org.apache.hadoop.hbase.NamespaceDescriptor;
9899
import org.apache.hadoop.hbase.NotServingRegionException;
@@ -8282,7 +8283,7 @@ public List<Cell> get(Get get, boolean withCoprocessor, long nonceGroup, long no
82828283
// See more details in HBASE-26036.
82838284
for (Cell cell : tmp) {
82848285
results.add(cell instanceof ByteBufferExtendedCell ?
8285-
((ByteBufferExtendedCell) cell).deepClone(): cell);
8286+
KeyValueUtil.copyToNewKeyValue(cell) : cell);
82868287
}
82878288
}
82888289

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)