From 2846113b5974fe7f2305fadcdbb48cdc588c2476 Mon Sep 17 00:00:00 2001 From: tedyu Date: Wed, 22 Jun 2016 02:08:45 -0700 Subject: [PATCH] HBASE-16012 Major compaction can't work due to obsolete scanner read point in RegionServer (Guanghao Zhang) --- .../apache/hadoop/hbase/regionserver/HRegion.java | 28 +++++++++++++++++----- .../hadoop/hbase/regionserver/RSRpcServices.java | 19 +++++++++------ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index bf7f31cc84..1e007e7142 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -5656,12 +5656,8 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } } initializeKVHeap(scanners, joinedScanners, region); - } catch (IOException e) { - // close all already instantiated scanners before throwing the exception - for (KeyValueScanner scanner : instantiatedScanners) { - scanner.close(); - } - throw e; + } catch (Throwable t) { + throw handleException(instantiatedScanners, t); } } @@ -5674,6 +5670,26 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } } + private IOException handleException(List instantiatedScanners, + Throwable t) { + // remove scaner read point before throw the exception + scannerReadPoints.remove(this); + if (storeHeap != null) { + storeHeap.close(); + storeHeap = null; + if (joinedHeap != null) { + joinedHeap.close(); + joinedHeap = null; + } + } else { + // close all already instantiated scanners before throwing the exception + for (KeyValueScanner scanner : instantiatedScanners) { + scanner.close(); + } + } + return t instanceof IOException ? (IOException) t : new IOException(t); + } + @Override public long getMaxResultSize() { return maxResultSize; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java index f45fc6934c..c3626fdbba 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java @@ -378,18 +378,23 @@ public class RSRpcServices implements HBaseRPCErrorHandler, RegionScanner s = rsh.s; LOG.info("Scanner " + this.scannerName + " lease expired on region " + s.getRegionInfo().getRegionNameAsString()); + Region region = null; try { - Region region = regionServer.getRegion(s.getRegionInfo().getRegionName()); + region = regionServer.getRegion(s.getRegionInfo().getRegionName()); if (region != null && region.getCoprocessorHost() != null) { region.getCoprocessorHost().preScannerClose(s); } - s.close(); - if (region != null && region.getCoprocessorHost() != null) { - region.getCoprocessorHost().postScannerClose(s); - } } catch (IOException e) { - LOG.error("Closing scanner for " - + s.getRegionInfo().getRegionNameAsString(), e); + LOG.error("Closing scanner for " + s.getRegionInfo().getRegionNameAsString(), e); + } finally { + try { + s.close(); + if (region != null && region.getCoprocessorHost() != null) { + region.getCoprocessorHost().postScannerClose(s); + } + } catch (IOException e) { + LOG.error("Closing scanner for " + s.getRegionInfo().getRegionNameAsString(), e); + } } } else { LOG.warn("Scanner " + this.scannerName + " lease expired, but no related" + -- 2.11.4.GIT