Skip to content

Commit 8fbc9a2

Browse files
committed
HBASE-26674 Should modify filesCompacting under storeWriteLock (#4040)
Signed-off-by: Josh Elser <[email protected]>
1 parent d4f2b66 commit 8fbc9a2

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,13 +1229,14 @@ private void writeCompactionWalRecord(Collection<HStoreFile> filesCompacted,
12291229
allowedOnPath = ".*/(HStore|TestHStore).java")
12301230
void replaceStoreFiles(Collection<HStoreFile> compactedFiles, Collection<HStoreFile> result,
12311231
boolean writeCompactionMarker) throws IOException {
1232-
storeEngine.replaceStoreFiles(compactedFiles, result);
1232+
storeEngine.replaceStoreFiles(compactedFiles, result, () -> {
1233+
synchronized(filesCompacting) {
1234+
filesCompacting.removeAll(compactedFiles);
1235+
}
1236+
});
12331237
if (writeCompactionMarker) {
12341238
writeCompactionWalRecord(compactedFiles, result);
12351239
}
1236-
synchronized (filesCompacting) {
1237-
filesCompacting.removeAll(compactedFiles);
1238-
}
12391240
// These may be null when the RS is shutting down. The space quota Chores will fix the Region
12401241
// sizes later so it's not super-critical if we miss these.
12411242
RegionServerServices rsServices = region.getRegionServerServices();

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreEngine.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ private void refreshStoreFilesInternal(Collection<StoreFileInfo> newFiles) throw
410410
List<HStoreFile> openedFiles = openStoreFiles(toBeAddedFiles, false);
411411

412412
// propogate the file changes to the underlying store file manager
413-
replaceStoreFiles(toBeRemovedStoreFiles, openedFiles); // won't throw an exception
413+
replaceStoreFiles(toBeRemovedStoreFiles, openedFiles, () -> {
414+
}); // won't throw an exception
414415
}
415416

416417
/**
@@ -493,12 +494,13 @@ public void addStoreFiles(Collection<HStoreFile> storeFiles,
493494
}
494495

495496
public void replaceStoreFiles(Collection<HStoreFile> compactedFiles,
496-
Collection<HStoreFile> newFiles) throws IOException {
497+
Collection<HStoreFile> newFiles, Runnable actionUnderLock) throws IOException {
497498
storeFileTracker.replace(StoreUtils.toStoreFileInfo(compactedFiles),
498499
StoreUtils.toStoreFileInfo(newFiles));
499500
writeLock();
500501
try {
501502
storeFileManager.addCompactionResults(compactedFiles, newFiles);
503+
actionUnderLock.run();
502504
} finally {
503505
writeUnlock();
504506
}

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,14 +1034,14 @@ public void testRefreshStoreFilesNotChanged() throws IOException {
10341034
// call first time after files changed
10351035
spiedStoreEngine.refreshStoreFiles();
10361036
assertEquals(2, this.store.getStorefilesCount());
1037-
verify(spiedStoreEngine, times(1)).replaceStoreFiles(any(), any());
1037+
verify(spiedStoreEngine, times(1)).replaceStoreFiles(any(), any(), any());
10381038

10391039
// call second time
10401040
spiedStoreEngine.refreshStoreFiles();
10411041

10421042
// ensure that replaceStoreFiles is not called, i.e, the times does not change, if files are not
10431043
// refreshed,
1044-
verify(spiedStoreEngine, times(1)).replaceStoreFiles(any(), any());
1044+
verify(spiedStoreEngine, times(1)).replaceStoreFiles(any(), any(), any());
10451045
}
10461046

10471047
private long countMemStoreScanner(StoreScanner scanner) {

0 commit comments

Comments
 (0)