Repository: hbase Updated Branches: refs/heads/branch-2.0 f4f5765c8 -> 872dcd236
HBASE-21355 (addendum) replace the expensive reload storefiles with reading the merge result of compacted storefiles and current storefiles Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/872dcd23 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/872dcd23 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/872dcd23 Branch: refs/heads/branch-2.0 Commit: 872dcd23634fb1d46f2b2de80949007fb8bb17b2 Parents: f4f5765 Author: huzheng <open...@gmail.com> Authored: Mon Oct 22 15:17:32 2018 +0800 Committer: huzheng <open...@gmail.com> Committed: Mon Oct 22 19:32:40 2018 +0800 ---------------------------------------------------------------------- .../hadoop/hbase/regionserver/HStore.java | 30 ++++++++------------ 1 file changed, 12 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/872dcd23/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java ---------------------------------------------------------------------- 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 78228b6..35270e8 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 @@ -290,6 +290,10 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat this.storeEngine = createStoreEngine(this, this.conf, this.comparator); List<HStoreFile> hStoreFiles = loadStoreFiles(); + // Move the storeSize calculation out of loadStoreFiles() method, because the secondary read + // replica's refreshStoreFiles() will also use loadStoreFiles() to refresh its store files and + // 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.storeEngine.getStoreFileManager().loadFiles(hStoreFiles); @@ -1635,26 +1639,16 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat @Override public boolean hasReferences() { List<HStoreFile> reloadedStoreFiles = null; + // Grab the read lock here, because we need to ensure that: only when the atomic + // replaceStoreFiles(..) finished, we can get all the complete store file list. + this.lock.readLock().lock(); try { - // Reloading the store files from file system due to HBASE-20940. As split can happen with an - // region which has references - reloadedStoreFiles = loadStoreFiles(); - return StoreUtils.hasReferences(reloadedStoreFiles); - } catch (IOException ioe) { - LOG.error("Error trying to determine if store has references, assuming references exists", - ioe); - return true; + // Merge the current store files with compacted files here due to HBASE-20940. + Collection<HStoreFile> allStoreFiles = new ArrayList<>(getStorefiles()); + allStoreFiles.addAll(getCompactedFiles()); + return StoreUtils.hasReferences(allStoreFiles); } finally { - if (reloadedStoreFiles != null) { - for (HStoreFile storeFile : reloadedStoreFiles) { - try { - storeFile.closeStoreFile(false); - } catch (IOException ioe) { - LOG.warn("Encountered exception closing " + storeFile + ": " + ioe.getMessage()); - // continue with closing the remaining store files - } - } - } + this.lock.readLock().unlock(); } }