diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java index 61474b7e357..042209c076a 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java @@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory; @InterfaceAudience.Public public class Append extends Mutation { private static final Logger LOG = LoggerFactory.getLogger(Append.class); - private static final long HEAP_OVERHEAD = ClassSize.REFERENCE + ClassSize.TIMERANGE; + private static final long HEAP_OVERHEAD = (long)ClassSize.REFERENCE + ClassSize.TIMERANGE; private TimeRange tr = new TimeRange(); /** diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java index 1569d261668..4398fd6816f 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java @@ -66,7 +66,7 @@ public abstract class Mutation extends OperationWithAttributes implements Row, C HeapSize { public static final long MUTATION_OVERHEAD = ClassSize.align( // This - ClassSize.OBJECT + + (long)ClassSize.OBJECT + // row + OperationWithAttributes.attributes 2 * ClassSize.REFERENCE + // Timestamp @@ -791,10 +791,10 @@ public abstract class Mutation extends OperationWithAttributes implements Row, C private static final class CellWrapper implements ExtendedCell { private static final long FIXED_OVERHEAD = ClassSize.align( - ClassSize.OBJECT // object header + (long)ClassSize.OBJECT // object header + KeyValue.TIMESTAMP_SIZE // timestamp + Bytes.SIZEOF_LONG // sequence id - + 1 * ClassSize.REFERENCE); // references to cell + + 1L * ClassSize.REFERENCE); // references to cell private final Cell cell; private long sequenceId; private long timestamp; diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCell.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCell.java index 7093b4b2dcf..6a95a7c67e5 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCell.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCell.java @@ -27,7 +27,7 @@ import org.apache.yetus.audience.InterfaceAudience; public class IndividualBytesFieldCell implements ExtendedCell { private static final long FIXED_OVERHEAD = ClassSize.align( // do alignment(padding gap) - ClassSize.OBJECT // object header + (long)ClassSize.OBJECT // object header + KeyValue.TIMESTAMP_TYPE_SIZE // timestamp and type + Bytes.SIZEOF_LONG // sequence id + 5 * ClassSize.REFERENCE); // references to all byte arrays: row, family, qualifier, value, tags diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/PrivateCellUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/PrivateCellUtil.java index 87501836072..f2e749ef899 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/PrivateCellUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/PrivateCellUtil.java @@ -1783,7 +1783,7 @@ public final class PrivateCellUtil { FirstOnRowCell.FIXED_HEAPSIZE + Bytes.SIZEOF_BYTE // flength + Bytes.SIZEOF_INT * 3 // foffset, qoffset, qlength - + ClassSize.REFERENCE * 2; // fArray, qArray + + (long)ClassSize.REFERENCE * 2; // fArray, qArray private final byte[] fArray; private final int foffset; private final byte flength; @@ -1944,7 +1944,7 @@ public final class PrivateCellUtil { } private static class LastOnRowColCell extends LastOnRowCell { - private static final long FIXED_OVERHEAD = LastOnRowCell.FIXED_OVERHEAD + private static final long FIXED_OVERHEAD = (long)LastOnRowCell.FIXED_OVERHEAD + ClassSize.REFERENCE * 2 // fArray and qArray + Bytes.SIZEOF_INT * 3 // foffset, qoffset, qlength + Bytes.SIZEOF_BYTE; // flength diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactionPipeline.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactionPipeline.java index bc43c9891ce..6cd5e31ceca 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactionPipeline.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactionPipeline.java @@ -57,7 +57,7 @@ public class CompactionPipeline { private static final Logger LOG = LoggerFactory.getLogger(CompactionPipeline.class); public final static long FIXED_OVERHEAD = ClassSize - .align(ClassSize.OBJECT + (3 * ClassSize.REFERENCE) + Bytes.SIZEOF_LONG); + .align((long)ClassSize.OBJECT + (3 * ClassSize.REFERENCE) + Bytes.SIZEOF_LONG); public final static long DEEP_OVERHEAD = FIXED_OVERHEAD + (2 * ClassSize.LINKEDLIST); private final RegionServicesForStores region; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 7a6af75c4da..0fffe88e820 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -447,7 +447,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } static final long HEAP_SIZE = ClassSize.align( - ClassSize.OBJECT + 5 * Bytes.SIZEOF_BOOLEAN); + (long)ClassSize.OBJECT + 5 * Bytes.SIZEOF_BOOLEAN); } /** @@ -7877,7 +7877,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } public static final long FIXED_OVERHEAD = ClassSize.align( - ClassSize.OBJECT + + (long)ClassSize.OBJECT + ClassSize.ARRAY + 50 * ClassSize.REFERENCE + 3 * Bytes.SIZEOF_INT + (14 * Bytes.SIZEOF_LONG) + diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java index b00758f14e2..f283a655329 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java @@ -42,7 +42,6 @@ import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.Future; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.function.Predicate; @@ -150,8 +149,8 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat volatile boolean forceMajor = false; /* how many bytes to write between status checks */ static int closeCheckInterval = 0; - private AtomicLong storeSize = new AtomicLong(); - private AtomicLong totalUncompressedBytes = new AtomicLong(); + private volatile long storeSize = 0L; + private volatile long totalUncompressedBytes = 0L; /** * RWLock for store operations. @@ -210,13 +209,13 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat private int compactionCheckMultiplier; protected Encryption.Context cryptoContext = Encryption.Context.NONE; - private AtomicLong flushedCellsCount = new AtomicLong(); - private AtomicLong compactedCellsCount = new AtomicLong(); - private AtomicLong majorCompactedCellsCount = new AtomicLong(); - private AtomicLong flushedCellsSize = new AtomicLong(); - private AtomicLong flushedOutputFileSize = new AtomicLong(); - private AtomicLong compactedCellsSize = new AtomicLong(); - private AtomicLong majorCompactedCellsSize = new AtomicLong(); + private volatile long flushedCellsCount = 0; + private volatile long compactedCellsCount = 0; + private volatile long majorCompactedCellsCount = 0; + private volatile long flushedCellsSize = 0; + private volatile long flushedOutputFileSize = 0; + private volatile long compactedCellsSize = 0; + private volatile long majorCompactedCellsSize = 0; /** * Constructor @@ -545,9 +544,8 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat HStoreFile storeFile = completionService.take().get(); if (storeFile != null) { long length = storeFile.getReader().length(); - this.storeSize.addAndGet(length); - this.totalUncompressedBytes - .addAndGet(storeFile.getReader().getTotalUncompressedBytes()); + this.storeSize += length; + this.totalUncompressedBytes += storeFile.getReader().getTotalUncompressedBytes(); LOG.debug("loaded {}", storeFile); results.add(storeFile); } @@ -846,8 +844,8 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat private void bulkLoadHFile(HStoreFile sf) throws IOException { StoreFileReader r = sf.getReader(); - this.storeSize.addAndGet(r.length()); - this.totalUncompressedBytes.addAndGet(r.getTotalUncompressedBytes()); + this.storeSize += r.length(); + this.totalUncompressedBytes += r.getTotalUncompressedBytes(); // Append the new storefile into the list this.lock.writeLock().lock(); @@ -1023,8 +1021,8 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat HStoreFile sf = createStoreFileAndReader(dstPath); StoreFileReader r = sf.getReader(); - this.storeSize.addAndGet(r.length()); - this.totalUncompressedBytes.addAndGet(r.getTotalUncompressedBytes()); + this.storeSize += r.length(); + this.totalUncompressedBytes += r.getTotalUncompressedBytes(); if (LOG.isInfoEnabled()) { LOG.info("Added " + sf + ", entries=" + r.getEntries() + @@ -1375,11 +1373,11 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat writeCompactionWalRecord(filesToCompact, sfs); replaceStoreFiles(filesToCompact, sfs); if (cr.isMajor()) { - majorCompactedCellsCount.addAndGet(getCompactionProgress().totalCompactingKVs); - majorCompactedCellsSize.addAndGet(getCompactionProgress().totalCompactedSize); + majorCompactedCellsCount += getCompactionProgress().totalCompactingKVs; + majorCompactedCellsSize += getCompactionProgress().totalCompactedSize; } else { - compactedCellsCount.addAndGet(getCompactionProgress().totalCompactingKVs); - compactedCellsSize.addAndGet(getCompactionProgress().totalCompactedSize); + compactedCellsCount += getCompactionProgress().totalCompactingKVs; + compactedCellsSize += getCompactionProgress().totalCompactedSize; } long outputBytes = getTotalSize(sfs); @@ -1451,9 +1449,7 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat this.lock.writeLock().lock(); try { this.storeEngine.getStoreFileManager().addCompactionResults(compactedFiles, result); - synchronized (filesCompacting) { - filesCompacting.removeAll(compactedFiles); - } + filesCompacting.removeAll(compactedFiles); // safe bc: lock.writeLock(); } finally { this.lock.writeLock().unlock(); } @@ -1482,7 +1478,7 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat } } message.append("total size for store is ") - .append(StringUtils.TraditionalBinaryPrefix.long2String(storeSize.get(), "", 1)) + .append(StringUtils.TraditionalBinaryPrefix.long2String(storeSize, "", 1)) .append(". This selection was in queue for ") .append(StringUtils.formatTimeDiff(compactionStartTime, cr.getSelectionTime())) .append(", and took ").append(StringUtils.formatTimeDiff(now, compactionStartTime)) @@ -1776,8 +1772,7 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat completeCompaction(delSfs); LOG.info("Completed removal of " + delSfs.size() + " unnecessary (expired) file(s) in " + this + " of " + this.getRegionInfo().getRegionNameAsString() - + "; total size for store is " - + TraditionalBinaryPrefix.long2String(storeSize.get(), "", 1)); + + "; total size for store is " + TraditionalBinaryPrefix.long2String(storeSize, "", 1)); } public void cancelRequestedCompaction(CompactionContext compaction) { @@ -1831,16 +1826,16 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat @VisibleForTesting protected void completeCompaction(Collection compactedFiles) throws IOException { - this.storeSize.set(0L); - this.totalUncompressedBytes.set(0L); + this.storeSize = 0L; + this.totalUncompressedBytes = 0L; for (HStoreFile hsf : this.storeEngine.getStoreFileManager().getStorefiles()) { StoreFileReader r = hsf.getReader(); if (r == null) { LOG.warn("StoreFile {} has a null Reader", hsf); continue; } - this.storeSize.addAndGet(r.length()); - this.totalUncompressedBytes.addAndGet(r.getTotalUncompressedBytes()); + this.storeSize += r.length(); + this.totalUncompressedBytes += r.getTotalUncompressedBytes(); } } @@ -1901,7 +1896,7 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat @Override public long getSize() { - return storeSize.get(); + return storeSize; } public void triggerMajorCompaction() { @@ -2048,7 +2043,7 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat @Override public long getStoreSizeUncompressed() { - return this.totalUncompressedBytes.get(); + return this.totalUncompressedBytes; } @Override @@ -2240,9 +2235,9 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat committedFiles.add(sf.getPath()); } - HStore.this.flushedCellsCount.addAndGet(cacheFlushCount); - HStore.this.flushedCellsSize.addAndGet(cacheFlushSize); - HStore.this.flushedOutputFileSize.addAndGet(outputFileSize); + HStore.this.flushedCellsCount += cacheFlushCount; + HStore.this.flushedCellsSize += cacheFlushSize; + HStore.this.flushedOutputFileSize += outputFileSize; // Add new file to store files. Clear snapshot too while we have the Store write lock. return HStore.this.updateStorefiles(storeFiles, snapshot.getId()); @@ -2275,9 +2270,8 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat StoreFileInfo storeFileInfo = fs.getStoreFileInfo(getColumnFamilyName(), file); HStoreFile storeFile = createStoreFileAndReader(storeFileInfo); storeFiles.add(storeFile); - HStore.this.storeSize.addAndGet(storeFile.getReader().length()); - HStore.this.totalUncompressedBytes - .addAndGet(storeFile.getReader().getTotalUncompressedBytes()); + HStore.this.storeSize += storeFile.getReader().length(); + HStore.this.totalUncompressedBytes += storeFile.getReader().getTotalUncompressedBytes(); if (LOG.isInfoEnabled()) { LOG.info("Region: " + HStore.this.getRegionInfo().getEncodedName() + " added " + storeFile + ", entries=" + storeFile.getReader().getEntries() + @@ -2308,11 +2302,7 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat @Override public boolean needsCompaction() { - List filesCompactingClone = null; - synchronized (filesCompacting) { - filesCompactingClone = Lists.newArrayList(filesCompacting); - } - return this.storeEngine.needsCompaction(filesCompactingClone); + return this.storeEngine.needsCompaction(this.filesCompacting); } /** @@ -2325,7 +2315,7 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat } public static final long FIXED_OVERHEAD = - ClassSize.align(ClassSize.OBJECT + (26 * ClassSize.REFERENCE) + (2 * Bytes.SIZEOF_LONG) + ClassSize.align((long)ClassSize.OBJECT + (17 * ClassSize.REFERENCE) + (11 * Bytes.SIZEOF_LONG) + (5 * Bytes.SIZEOF_INT) + (2 * Bytes.SIZEOF_BOOLEAN)); public static final long DEEP_OVERHEAD = ClassSize.align(FIXED_OVERHEAD @@ -2364,37 +2354,37 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat @Override public long getFlushedCellsCount() { - return flushedCellsCount.get(); + return flushedCellsCount; } @Override public long getFlushedCellsSize() { - return flushedCellsSize.get(); + return flushedCellsSize; } @Override public long getFlushedOutputFileSize() { - return flushedOutputFileSize.get(); + return flushedOutputFileSize; } @Override public long getCompactedCellsCount() { - return compactedCellsCount.get(); + return compactedCellsCount; } @Override public long getCompactedCellsSize() { - return compactedCellsSize.get(); + return compactedCellsSize; } @Override public long getMajorCompactedCellsCount() { - return majorCompactedCellsCount.get(); + return majorCompactedCellsCount; } @Override public long getMajorCompactedCellsSize() { - return majorCompactedCellsSize.get(); + return majorCompactedCellsSize; } /** diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreCompactor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreCompactor.java index a8c3362db23..b85df996152 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreCompactor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MemStoreCompactor.java @@ -48,7 +48,7 @@ import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesti public class MemStoreCompactor { public static final long DEEP_OVERHEAD = ClassSize - .align(ClassSize.OBJECT + 4 * ClassSize.REFERENCE + .align((long)ClassSize.OBJECT + 4 * ClassSize.REFERENCE // compactingMemStore, versionedList, isInterrupted, strategy (the reference) // "action" is an enum and thus it is a class with static final constants, // so counting only the size of the reference to it and not the size of the internals diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MultiVersionConcurrencyControl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MultiVersionConcurrencyControl.java index 0c3551b5479..9e54ad74b81 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MultiVersionConcurrencyControl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MultiVersionConcurrencyControl.java @@ -291,7 +291,7 @@ public class MultiVersionConcurrencyControl { } public static final long FIXED_SIZE = ClassSize.align( - ClassSize.OBJECT + + (long)ClassSize.OBJECT + 2 * Bytes.SIZEOF_LONG + 2 * ClassSize.REFERENCE); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfo.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfo.java index 2fde311ccfe..6fae04f4a04 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfo.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfo.java @@ -51,7 +51,7 @@ public class ScanInfo { private final long preadMaxBytes; private final boolean newVersionBehavior; - public static final long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT + public static final long FIXED_OVERHEAD = ClassSize.align((long)ClassSize.OBJECT + (2 * ClassSize.REFERENCE) + (2 * Bytes.SIZEOF_INT) + (4 * Bytes.SIZEOF_LONG) + (4 * Bytes.SIZEOF_BOOLEAN)); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Segment.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Segment.java index 781efcc9024..5bfab522613 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Segment.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Segment.java @@ -48,7 +48,7 @@ import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesti @InterfaceAudience.Private public abstract class Segment { - public final static long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT + public final static long FIXED_OVERHEAD = ClassSize.align((long)ClassSize.OBJECT + 6 * ClassSize.REFERENCE // cellSet, comparator, memStoreLAB, dataSize, // heapSize, and timeRangeTracker + Bytes.SIZEOF_LONG // minSequenceId diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java index 101e64b1db2..a9a3835772a 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java @@ -751,7 +751,7 @@ public class FSHLog extends AbstractFSWAL { } public static final long FIXED_OVERHEAD = ClassSize - .align(ClassSize.OBJECT + (5 * ClassSize.REFERENCE) + ClassSize.ATOMIC_INTEGER + .align((long)ClassSize.OBJECT + (5 * ClassSize.REFERENCE) + ClassSize.ATOMIC_INTEGER + Bytes.SIZEOF_INT + (3 * Bytes.SIZEOF_LONG)); /** diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALSplitter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALSplitter.java index e442fd81f55..46f38e1004f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALSplitter.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALSplitter.java @@ -979,7 +979,7 @@ public class WALSplitter { internify(entry); entryBuffer.add(entry); long incrHeap = entry.getEdit().heapSize() + - ClassSize.align(2 * ClassSize.REFERENCE) + // WALKey pointers + ClassSize.align(2L * ClassSize.REFERENCE) + // WALKey pointers 0; // TODO linkedlist entry heapInBuffer += incrHeap; return incrHeap;