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:47:27 +08:00
parent a1ec048d2d
commit 54ca1db6bd
1 changed files with 16 additions and 6 deletions

View File

@ -132,12 +132,22 @@ public class StoreFileScanner implements KeyValueScanner {
List<StoreFileScanner> scanners = new ArrayList<StoreFileScanner>(files.size()); List<StoreFileScanner> scanners = new ArrayList<StoreFileScanner>(files.size());
List<StoreFile> sorted_files = new ArrayList<>(files); List<StoreFile> sorted_files = new ArrayList<>(files);
Collections.sort(sorted_files, StoreFile.Comparators.SEQ_ID); Collections.sort(sorted_files, StoreFile.Comparators.SEQ_ID);
for (int i = 0; i < sorted_files.size(); i++) { boolean succ = false;
StoreFile.Reader r = sorted_files.get(i).createReader(canUseDrop); try {
r.setReplicaStoreFile(isPrimaryReplica); for (int i = 0; i < sorted_files.size(); i++) {
StoreFileScanner scanner = r.getStoreFileScanner(cacheBlocks, usePread, isCompaction, readPt, StoreFile.Reader r = sorted_files.get(i).createReader(canUseDrop);
i, matcher != null ? !matcher.hasNullColumnInQuery() : false); r.setReplicaStoreFile(isPrimaryReplica);
scanners.add(scanner); StoreFileScanner scanner = r.getStoreFileScanner(cacheBlocks, usePread, isCompaction, readPt,
i, matcher != null ? !matcher.hasNullColumnInQuery() : false);
scanners.add(scanner);
}
succ = true;
} finally {
if (!succ) {
for (StoreFileScanner scanner : scanners) {
scanner.close();
}
}
} }
return scanners; return scanners;
} }