diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java index 8132365625c..b3f7fa6b995 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java @@ -132,12 +132,22 @@ public class StoreFileScanner implements KeyValueScanner { List scanners = new ArrayList(files.size()); List sorted_files = new ArrayList<>(files); Collections.sort(sorted_files, StoreFile.Comparators.SEQ_ID); - for (int i = 0; i < sorted_files.size(); i++) { - StoreFile.Reader r = sorted_files.get(i).createReader(canUseDrop); - r.setReplicaStoreFile(isPrimaryReplica); - StoreFileScanner scanner = r.getStoreFileScanner(cacheBlocks, usePread, isCompaction, readPt, - i, matcher != null ? !matcher.hasNullColumnInQuery() : false); - scanners.add(scanner); + boolean succ = false; + try { + for (int i = 0; i < sorted_files.size(); i++) { + StoreFile.Reader r = sorted_files.get(i).createReader(canUseDrop); + r.setReplicaStoreFile(isPrimaryReplica); + 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; }