From d63ca4febef93e71afdf5677987342a7a9c69049 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Wed, 19 Jan 2022 13:59:35 +0800 Subject: [PATCH] HBASE-26674 Should modify filesCompacting under storeWriteLock (#4040) Signed-off-by: Josh Elser --- .../org/apache/hadoop/hbase/regionserver/HStore.java | 11 ++++++----- .../apache/hadoop/hbase/regionserver/StoreEngine.java | 6 ++++-- .../apache/hadoop/hbase/regionserver/TestHStore.java | 4 ++-- 3 files changed, 12 insertions(+), 9 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 851257de9828..730182866300 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 @@ -1230,13 +1230,14 @@ private void writeCompactionWalRecord(Collection filesCompacted, allowedOnPath = ".*/(HStore|TestHStore).java") void replaceStoreFiles(Collection compactedFiles, Collection result, boolean writeCompactionMarker) throws IOException { - storeEngine.replaceStoreFiles(compactedFiles, result); + storeEngine.replaceStoreFiles(compactedFiles, result, () -> { + synchronized(filesCompacting) { + filesCompacting.removeAll(compactedFiles); + } + }); if (writeCompactionMarker) { writeCompactionWalRecord(compactedFiles, result); } - synchronized (filesCompacting) { - filesCompacting.removeAll(compactedFiles); - } // These may be null when the RS is shutting down. The space quota Chores will fix the Region // sizes later so it's not super-critical if we miss these. RegionServerServices rsServices = region.getRegionServerServices(); @@ -1567,7 +1568,7 @@ public void cancelRequestedCompaction(CompactionContext compaction) { finishCompactionRequest(compaction.getRequest()); } - protected void finishCompactionRequest(CompactionRequestImpl cr) { + private void finishCompactionRequest(CompactionRequestImpl cr) { this.region.reportCompactionRequestEnd(cr.isMajor(), cr.getFiles().size(), cr.getSize()); if (cr.isOffPeak()) { offPeakCompactionTracker.set(false); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreEngine.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreEngine.java index ddb52d10ffd5..d85553ac8082 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreEngine.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreEngine.java @@ -410,7 +410,8 @@ private void refreshStoreFilesInternal(Collection newFiles) throw List openedFiles = openStoreFiles(toBeAddedFiles, false); // propogate the file changes to the underlying store file manager - replaceStoreFiles(toBeRemovedStoreFiles, openedFiles); // won't throw an exception + replaceStoreFiles(toBeRemovedStoreFiles, openedFiles, () -> { + }); // won't throw an exception } /** @@ -493,12 +494,13 @@ public void addStoreFiles(Collection storeFiles, } public void replaceStoreFiles(Collection compactedFiles, - Collection newFiles) throws IOException { + Collection newFiles, Runnable actionUnderLock) throws IOException { storeFileTracker.replace(StoreUtils.toStoreFileInfo(compactedFiles), StoreUtils.toStoreFileInfo(newFiles)); writeLock(); try { storeFileManager.addCompactionResults(compactedFiles, newFiles); + actionUnderLock.run(); } finally { writeUnlock(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java index f6d58aad172d..7cc81938bd3f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java @@ -1033,14 +1033,14 @@ public void testRefreshStoreFilesNotChanged() throws IOException { // call first time after files changed spiedStoreEngine.refreshStoreFiles(); assertEquals(2, this.store.getStorefilesCount()); - verify(spiedStoreEngine, times(1)).replaceStoreFiles(any(), any()); + verify(spiedStoreEngine, times(1)).replaceStoreFiles(any(), any(), any()); // call second time spiedStoreEngine.refreshStoreFiles(); // ensure that replaceStoreFiles is not called, i.e, the times does not change, if files are not // refreshed, - verify(spiedStoreEngine, times(1)).replaceStoreFiles(any(), any()); + verify(spiedStoreEngine, times(1)).replaceStoreFiles(any(), any(), any()); } private long countMemStoreScanner(StoreScanner scanner) {