HBASE-19502 Make sure we have closed all StoreFileScanner if we fail to open any StoreFileScanners

This commit is contained in:
Chia-Ping Tsai 2017-12-13 21:30:08 +08:00
parent 536187446d
commit 7f586995a8
1 changed files with 19 additions and 9 deletions

View File

@ -137,16 +137,26 @@ public class StoreFileScanner implements KeyValueScanner {
file.initReader();
sortedFiles.add(file);
}
for (int i = 0, n = files.size(); i < n; i++) {
HStoreFile sf = sortedFiles.remove();
StoreFileScanner scanner;
if (usePread) {
scanner = sf.getPreadScanner(cacheBlocks, readPt, i, canOptimizeForNonNullColumn);
} else {
scanner = sf.getStreamScanner(canUseDrop, cacheBlocks, isCompaction, readPt, i,
canOptimizeForNonNullColumn);
boolean succ = false;
try {
for (int i = 0, n = files.size(); i < n; i++) {
HStoreFile sf = sortedFiles.remove();
StoreFileScanner scanner;
if (usePread) {
scanner = sf.getPreadScanner(cacheBlocks, readPt, i, canOptimizeForNonNullColumn);
} else {
scanner = sf.getStreamScanner(canUseDrop, cacheBlocks, isCompaction, readPt, i,
canOptimizeForNonNullColumn);
}
scanners.add(scanner);
}
succ = true;
} finally {
if (!succ) {
for (StoreFileScanner scanner : scanners) {
scanner.close();
}
}
scanners.add(scanner);
}
return scanners;
}