HBASE-17896 The FIXED_OVERHEAD of Segment is incorrect

This commit is contained in:
CHIA-PING TSAI 2017-04-11 16:31:20 +08:00 committed by Chia-Ping Tsai
parent d7ddc79198
commit 3aadc675b0
3 changed files with 20 additions and 9 deletions

View File

@ -20,6 +20,7 @@
package org.apache.hadoop.hbase.util; package org.apache.hadoop.hbase.util;
import com.google.common.annotations.VisibleForTesting;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -235,6 +236,12 @@ public class ClassSize {
} }
private static final MemoryLayout memoryLayout = getMemoryLayout(); private static final MemoryLayout memoryLayout = getMemoryLayout();
private static final boolean USE_UNSAFE_LAYOUT = (memoryLayout instanceof UnsafeLayout);
@VisibleForTesting
public static boolean useUnsafeLayout() {
return USE_UNSAFE_LAYOUT;
}
/** /**
* Method for reading the arc settings and setting overheads according * Method for reading the arc settings and setting overheads according

View File

@ -48,12 +48,13 @@ import com.google.common.annotations.VisibleForTesting;
@InterfaceAudience.Private @InterfaceAudience.Private
public abstract class Segment { public abstract class Segment {
final static long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT public final static long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT
+ 5 * ClassSize.REFERENCE // cellSet, comparator, memStoreLAB, size, timeRangeTracker + 6 * ClassSize.REFERENCE // cellSet, comparator, memStoreLAB, dataSize,
// heapSize, and timeRangeTracker
+ Bytes.SIZEOF_LONG // minSequenceId + Bytes.SIZEOF_LONG // minSequenceId
+ Bytes.SIZEOF_BOOLEAN); // tagsPresent + Bytes.SIZEOF_BOOLEAN); // tagsPresent
public final static long DEEP_OVERHEAD = FIXED_OVERHEAD + ClassSize.ATOMIC_REFERENCE public final static long DEEP_OVERHEAD = FIXED_OVERHEAD + ClassSize.ATOMIC_REFERENCE
+ ClassSize.CELL_SET + ClassSize.ATOMIC_LONG + ClassSize.TIMERANGE_TRACKER; + ClassSize.CELL_SET + 2 * ClassSize.ATOMIC_LONG + ClassSize.TIMERANGE_TRACKER;
private AtomicReference<CellSet> cellSet= new AtomicReference<>(); private AtomicReference<CellSet> cellSet= new AtomicReference<>();
private final CellComparator comparator; private final CellComparator comparator;

View File

@ -344,7 +344,7 @@ public class TestHeapSize {
cl = Segment.class; cl = Segment.class;
actual = Segment.DEEP_OVERHEAD; actual = Segment.DEEP_OVERHEAD;
expected = ClassSize.estimateBase(cl, false); expected = ClassSize.estimateBase(cl, false);
expected += ClassSize.estimateBase(AtomicLong.class, false); expected += 2 * ClassSize.estimateBase(AtomicLong.class, false);
expected += ClassSize.estimateBase(AtomicReference.class, false); expected += ClassSize.estimateBase(AtomicReference.class, false);
expected += ClassSize.estimateBase(CellSet.class, false); expected += ClassSize.estimateBase(CellSet.class, false);
expected += ClassSize.estimateBase(TimeRangeTracker.class, false); expected += ClassSize.estimateBase(TimeRangeTracker.class, false);
@ -361,7 +361,7 @@ public class TestHeapSize {
cl = MutableSegment.class; cl = MutableSegment.class;
actual = MutableSegment.DEEP_OVERHEAD; actual = MutableSegment.DEEP_OVERHEAD;
expected = ClassSize.estimateBase(cl, false); expected = ClassSize.estimateBase(cl, false);
expected += ClassSize.estimateBase(AtomicLong.class, false); expected += 2 * ClassSize.estimateBase(AtomicLong.class, false);
expected += ClassSize.estimateBase(AtomicReference.class, false); expected += ClassSize.estimateBase(AtomicReference.class, false);
expected += ClassSize.estimateBase(CellSet.class, false); expected += ClassSize.estimateBase(CellSet.class, false);
expected += ClassSize.estimateBase(TimeRangeTracker.class, false); expected += ClassSize.estimateBase(TimeRangeTracker.class, false);
@ -380,7 +380,7 @@ public class TestHeapSize {
cl = ImmutableSegment.class; cl = ImmutableSegment.class;
actual = ImmutableSegment.DEEP_OVERHEAD_CSLM; actual = ImmutableSegment.DEEP_OVERHEAD_CSLM;
expected = ClassSize.estimateBase(cl, false); expected = ClassSize.estimateBase(cl, false);
expected += ClassSize.estimateBase(AtomicLong.class, false); expected += 2 * ClassSize.estimateBase(AtomicLong.class, false);
expected += ClassSize.estimateBase(AtomicReference.class, false); expected += ClassSize.estimateBase(AtomicReference.class, false);
expected += ClassSize.estimateBase(CellSet.class, false); expected += ClassSize.estimateBase(CellSet.class, false);
expected += ClassSize.estimateBase(TimeRangeTracker.class, false); expected += ClassSize.estimateBase(TimeRangeTracker.class, false);
@ -398,7 +398,7 @@ public class TestHeapSize {
} }
actual = ImmutableSegment.DEEP_OVERHEAD_CAM; actual = ImmutableSegment.DEEP_OVERHEAD_CAM;
expected = ClassSize.estimateBase(cl, false); expected = ClassSize.estimateBase(cl, false);
expected += ClassSize.estimateBase(AtomicLong.class, false); expected += 2 * ClassSize.estimateBase(AtomicLong.class, false);
expected += ClassSize.estimateBase(AtomicReference.class, false); expected += ClassSize.estimateBase(AtomicReference.class, false);
expected += ClassSize.estimateBase(CellSet.class, false); expected += ClassSize.estimateBase(CellSet.class, false);
expected += ClassSize.estimateBase(TimeRangeTracker.class, false); expected += ClassSize.estimateBase(TimeRangeTracker.class, false);
@ -504,8 +504,11 @@ public class TestHeapSize {
} else { } else {
assertTrue(ClassSize.OBJECT == 12 || ClassSize.OBJECT == 16); // depending on CompressedOops assertTrue(ClassSize.OBJECT == 12 || ClassSize.OBJECT == 16); // depending on CompressedOops
} }
if (ClassSize.useUnsafeLayout()) {
assertEquals(ClassSize.OBJECT + 4, ClassSize.ARRAY); assertEquals(ClassSize.OBJECT + 4, ClassSize.ARRAY);
} } else {
assertEquals(ClassSize.OBJECT + 8, ClassSize.ARRAY);
}
}
} }