HBASE-25507 Leak of ESTABLISHED sockets when compaction encountered "java.io.IOException: Invalid HFile block magic" (#2882)

Signed-off-by: Ramkrishna <ramkrishna@apache.org>
Signed-off-by: stack <stack@apache.org>
This commit is contained in:
haxl 2021-02-09 14:14:00 +08:00 committed by stack
parent de9bbd6968
commit 6849279023
1 changed files with 14 additions and 3 deletions

View File

@ -321,10 +321,10 @@ public abstract class Compactor<T extends CellSink> {
dropCache = this.dropCacheMinor; dropCache = this.dropCacheMinor;
} }
List<StoreFileScanner> scanners =
createFileScanners(request.getFiles(), smallestReadPoint, dropCache);
InternalScanner scanner = null; InternalScanner scanner = null;
boolean finished = false; boolean finished = false;
List<StoreFileScanner> scanners =
createFileScanners(request.getFiles(), smallestReadPoint, dropCache);
try { try {
/* Include deletes, unless we are doing a major compaction */ /* Include deletes, unless we are doing a major compaction */
ScanType scanType = scannerFactory.getScanType(request); ScanType scanType = scannerFactory.getScanType(request);
@ -345,7 +345,18 @@ public abstract class Compactor<T extends CellSink> {
+ store.getRegionInfo().getRegionNameAsString() + " because it was interrupted."); + store.getRegionInfo().getRegionNameAsString() + " because it was interrupted.");
} }
} finally { } finally {
// createScanner may fail when seeking hfiles encounter Exception, e.g. even only one hfile
// reader encounters java.io.IOException: Invalid HFile block magic:
// \x00\x00\x00\x00\x00\x00\x00\x00
// and then scanner will be null, but scanners for all the hfiles should be closed,
// or else we will find leak of ESTABLISHED sockets.
if (scanner == null) {
for (StoreFileScanner sfs : scanners) {
sfs.close();
}
} else {
Closeables.close(scanner, true); Closeables.close(scanner, true);
}
if (!finished && writer != null) { if (!finished && writer != null) {
abortWriter(writer); abortWriter(writer);
} }