HBASE-20322 CME in StoreScanner causes region server crash

Signed-off-by: Andrew Purtell <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/7e2d7edb
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/7e2d7edb
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/7e2d7edb

Branch: refs/heads/branch-1.4
Commit: 7e2d7edbcc7e01880bc6899703807472f6939106
Parents: 52ea979
Author: Thiruvel Thirumoolan <[email protected]>
Authored: Fri Mar 30 13:21:26 2018 -0700
Committer: Andrew Purtell <[email protected]>
Committed: Mon Apr 2 19:36:12 2018 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/regionserver/StoreScanner.java | 35 +++++++++++++++-----
 1 file changed, 26 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/7e2d7edb/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
index bb761ba..0280906 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
@@ -462,17 +462,29 @@ public class StoreScanner extends 
NonReversedNonLazyKeyValueScanner
 
   @Override
   public void close() {
-    if (this.closing) return;
-    this.closing = true;
-    clearAndClose(scannersForDelayedClose);
-    clearAndClose(memStoreScannersAfterFlush);
-    // clear them at any case. In case scanner.next() was never called
-    // and there were some lease expiry we need to close all the scanners
-    // on the flushed files which are open
-    clearAndClose(flushedstoreFileScanners);
+    if (this.closing) {
+      return;
+    }
+    // Lets remove from observers as early as possible
     // Under test, we dont have a this.store
-    if (this.store != null)
+    if (this.store != null) {
       this.store.deleteChangedReaderObserver(this);
+    }
+    // There is a race condition between close() and updateReaders(), during 
region flush. So,
+    // even though its just close, we will still acquire the flush lock, as a
+    // ConcurrentModificationException will abort the regionserver.
+    flushLock.lock();
+    try {
+      this.closing = true;
+      clearAndClose(scannersForDelayedClose);
+      clearAndClose(memStoreScannersAfterFlush);
+      // clear them at any case. In case scanner.next() was never called
+      // and there were some lease expiry we need to close all the scanners
+      // on the flushed files which are open
+      clearAndClose(flushedstoreFileScanners);
+    } finally {
+      flushLock.unlock();
+    }
     if (this.heap != null)
       this.heap.close();
     this.heap = null; // CLOSED!
@@ -845,6 +857,11 @@ public class StoreScanner extends 
NonReversedNonLazyKeyValueScanner
     }
     flushLock.lock();
     try {
+      if (this.closing) {
+        // Lets close scanners created by caller, since close() won't notice 
this.
+        clearAndClose(memStoreScanners);
+        return;
+      }
       flushed = true;
       final boolean isCompaction = false;
       boolean usePread = get || scanUsePread;

Reply via email to