Skip to content

Commit 04635f4

Browse files
HBASE-26467 Fix bug for MemStoreLABImpl.forceCopyOfBigCellInto(Cell) (#3858)
Signed-off-by: Duo Zhang <zhangduo@apache.org> Reviewed-by: chenglei <chenglei@apache.org>
1 parent 7a80b3a commit 04635f4

3 files changed

Lines changed: 60 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ public Cell copyCellInto(Cell cell) {
124124
@Override
125125
public Cell forceCopyOfBigCellInto(Cell cell) {
126126
int size = Segment.getCellLength(cell);
127-
size += ChunkCreator.SIZEOF_CHUNK_HEADER;
128127
Preconditions.checkArgument(size >= 0, "negative size");
129-
if (size <= dataChunkSize) {
128+
if (size + ChunkCreator.SIZEOF_CHUNK_HEADER <= dataChunkSize) {
130129
// Using copyCellInto for cells which are bigger than the original maxAlloc
131130
return copyCellInto(cell, dataChunkSize);
132131
} else {

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingToCellFlatMapMemStore.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.ArrayList;
2525
import java.util.List;
2626
import org.apache.hadoop.conf.Configuration;
27+
import org.apache.hadoop.hbase.Cell;
2728
import org.apache.hadoop.hbase.CellComparatorImpl;
2829
import org.apache.hadoop.hbase.HBaseClassTestRule;
2930
import org.apache.hadoop.hbase.HBaseConfiguration;
@@ -797,7 +798,7 @@ public void testFlatteningToJumboCellChunkMap() throws IOException {
797798
totalHeapSize = MutableSegment.DEEP_OVERHEAD + CellChunkImmutableSegment.DEEP_OVERHEAD_CCM
798799
+ numOfCells * oneCellOnCCMHeapSize;
799800

800-
assertEquals(totalCellsLen+ChunkCreator.SIZEOF_CHUNK_HEADER, regionServicesForStores
801+
assertEquals(totalCellsLen, regionServicesForStores
801802
.getMemStoreSize());
802803

803804
assertEquals(totalHeapSize, ((CompactingMemStore) memstore).heapSize());
@@ -903,6 +904,31 @@ public void testForceCopyOfBigCellIntoImmutableSegment() throws IOException {
903904
}
904905
}
905906

907+
/**
908+
* Test big cell size after in memory compaction. (HBASE-26467)
909+
*/
910+
@Test
911+
public void testBigCellSizeAfterInMemoryCompaction() throws IOException {
912+
MemoryCompactionPolicy compactionType = MemoryCompactionPolicy.BASIC;
913+
memstore.getConfiguration().setInt(MemStoreCompactionStrategy
914+
.COMPACTING_MEMSTORE_THRESHOLD_KEY, 1);
915+
memstore.getConfiguration().set(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY,
916+
String.valueOf(compactionType));
917+
((MyCompactingMemStore) memstore).initiateType(compactionType, memstore.getConfiguration());
918+
919+
byte[] val = new byte[MemStoreLAB.CHUNK_SIZE_DEFAULT];
920+
921+
long size = addRowsByKeys(memstore, new String[]{"A"}, val);
922+
((MyCompactingMemStore) memstore).flushInMemory();
923+
924+
for(KeyValueScanner scanner : memstore.getScanners(Long.MAX_VALUE)) {
925+
Cell cell;
926+
while ((cell = scanner.next()) != null) {
927+
assertEquals(size, cell.getSerializedSize());
928+
}
929+
}
930+
}
931+
906932

907933
private long addRowsByKeysDataSize(final AbstractMemStore hmc, String[] keys) {
908934
byte[] fam = Bytes.toBytes("testfamily");

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStoreLAB.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* limitations under the License.
1717
*/
1818
package org.apache.hadoop.hbase.regionserver;
19+
import static org.apache.hadoop.hbase.regionserver.MemStoreLAB.CHUNK_SIZE_KEY;
20+
import static org.apache.hadoop.hbase.regionserver.MemStoreLAB.MAX_ALLOC_KEY;
1921
import static org.junit.Assert.assertEquals;
2022
import static org.junit.Assert.assertNull;
2123
import static org.junit.Assert.assertTrue;
@@ -38,6 +40,7 @@
3840
import org.apache.hadoop.hbase.testclassification.MediumTests;
3941
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
4042
import org.apache.hadoop.hbase.util.Bytes;
43+
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
4144
import org.junit.AfterClass;
4245
import org.junit.BeforeClass;
4346
import org.junit.ClassRule;
@@ -212,7 +215,7 @@ public void testLABChunkQueue() throws Exception {
212215
Configuration conf = HBaseConfiguration.create();
213216
conf.setDouble(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, 0.1);
214217
// set chunk size to default max alloc size, so we could easily trigger chunk retirement
215-
conf.setLong(MemStoreLABImpl.CHUNK_SIZE_KEY, MemStoreLABImpl.MAX_ALLOC_DEFAULT);
218+
conf.setLong(CHUNK_SIZE_KEY, MemStoreLABImpl.MAX_ALLOC_DEFAULT);
216219
// reconstruct mslab
217220
long globalMemStoreLimit = (long) (ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()
218221
.getMax() * MemorySizeUtil.getGlobalMemStoreHeapPercent(conf, false));
@@ -266,6 +269,34 @@ public void testLABChunkQueue() throws Exception {
266269
}
267270
}
268271

272+
/**
273+
* Test cell with right length, which constructed by testForceCopyOfBigCellInto. (HBASE-26467)
274+
*/
275+
@Test
276+
public void testForceCopyOfBigCellInto() {
277+
Configuration conf = HBaseConfiguration.create();
278+
int chunkSize = ChunkCreator.getInstance().getChunkSize();
279+
conf.setInt(CHUNK_SIZE_KEY, chunkSize);
280+
conf.setInt(MAX_ALLOC_KEY, chunkSize / 2);
281+
282+
MemStoreLABImpl mslab = new MemStoreLABImpl(conf);
283+
byte[] row = Bytes.toBytes("row");
284+
byte[] columnFamily = Bytes.toBytes("columnFamily");
285+
byte[] qualify = Bytes.toBytes("qualify");
286+
byte[] smallValue = new byte[chunkSize / 2];
287+
byte[] bigValue = new byte[chunkSize];
288+
KeyValue smallKV = new KeyValue(row, columnFamily, qualify, EnvironmentEdgeManager
289+
.currentTime(), smallValue);
290+
291+
assertEquals(smallKV.getSerializedSize(),
292+
mslab.forceCopyOfBigCellInto(smallKV).getSerializedSize());
293+
294+
KeyValue bigKV = new KeyValue(row, columnFamily, qualify, EnvironmentEdgeManager
295+
.currentTime(), bigValue);
296+
assertEquals(bigKV.getSerializedSize(),
297+
mslab.forceCopyOfBigCellInto(bigKV).getSerializedSize());
298+
}
299+
269300
private Thread getChunkQueueTestThread(final MemStoreLABImpl mslab, String threadName,
270301
Cell cellToCopyInto) {
271302
Thread thread = new Thread() {

0 commit comments

Comments
 (0)