From 44afe8cfde427b30231ca2c0a1f307a3562b9d18 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Mon, 14 Oct 2019 18:09:57 +0800 Subject: [PATCH] HBASE-23163 Refactor HStore.getStorefilesSize related methods (#719) Signed-off-by: Lijin Bin --- .../hadoop/hbase/regionserver/HStore.java | 53 ++++++++----------- 1 file changed, 23 insertions(+), 30 deletions(-) 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 1d018917d29..345821aacb3 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 @@ -306,7 +306,7 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat // update the storeSize in the completeCompaction(..) finally (just like compaction) , so // no need calculate the storeSize twice. this.storeSize.addAndGet(getStorefilesSize(hStoreFiles, sf -> true)); - this.totalUncompressedBytes.addAndGet(getTotalUmcompressedBytes(hStoreFiles)); + this.totalUncompressedBytes.addAndGet(getTotalUncompressedBytes(hStoreFiles)); this.storeEngine.getStoreFileManager().loadFiles(hStoreFiles); // Initialize checksum type from name. The names are CRC32, CRC32C, etc. @@ -2134,53 +2134,46 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat HStoreFile::isHFile); } - private long getTotalUmcompressedBytes(List files) { - return files.stream().filter(f -> f != null).mapToLong(f -> { - StoreFileReader reader = f.getReader(); - if (reader == null) { - return 0; - } else { - return reader.getTotalUncompressedBytes(); - } - }).sum(); + private long getTotalUncompressedBytes(List files) { + return files.stream() + .mapToLong(file -> getStorefileFieldSize(file, StoreFileReader::getTotalUncompressedBytes)) + .sum(); } private long getStorefilesSize(Collection files, Predicate predicate) { - return files.stream().filter(f -> f != null && f.getReader() != null).filter(predicate) - .mapToLong(f -> { - StoreFileReader reader = f.getReader(); - if (reader == null) { - return 0; - } else { - return reader.length(); - } - }).sum(); + return files.stream().filter(predicate) + .mapToLong(file -> getStorefileFieldSize(file, StoreFileReader::length)).sum(); } - private long getStoreFileFieldSize(ToLongFunction f) { + private long getStorefileFieldSize(HStoreFile file, ToLongFunction f) { + if (file == null) { + return 0L; + } + StoreFileReader reader = file.getReader(); + if (reader == null) { + return 0L; + } + return f.applyAsLong(reader); + } + + private long getStorefilesFieldSize(ToLongFunction f) { return this.storeEngine.getStoreFileManager().getStorefiles().stream() - .map(HStoreFile::getReader).filter(reader -> { - if (reader == null) { - return false; - } else { - return true; - } - }).mapToLong(f).sum(); + .mapToLong(file -> getStorefileFieldSize(file, f)).sum(); } @Override public long getStorefilesRootLevelIndexSize() { - return getStoreFileFieldSize(StoreFileReader::indexSize); + return getStorefilesFieldSize(StoreFileReader::indexSize); } @Override public long getTotalStaticIndexSize() { - return getStoreFileFieldSize(StoreFileReader::getUncompressedDataIndexSize); + return getStorefilesFieldSize(StoreFileReader::getUncompressedDataIndexSize); } @Override public long getTotalStaticBloomSize() { - return getStoreFileFieldSize(StoreFileReader::getTotalBloomSize); + return getStorefilesFieldSize(StoreFileReader::getTotalBloomSize); } @Override