Skip to content

Commit f397308

Browse files
committed
HBASE-25749 Improved logging when interrupting active RPC handlers holding the region close lock
We should add the thread to regionlockholders map to make sure we have can track the threads holding a lock even if it is not interuuptable. When calling interrupt we will not interrupt such threads but will print warn with thread name to help with debugging
1 parent 7c21e71 commit f397308

File tree

1 file changed

+15
-9
lines changed
  • hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver

1 file changed

+15
-9
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java

+15-9
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,11 @@ private Map<byte[], List<HStoreFile>> doClose(boolean abort, MonitoredTask statu
18261826
LOG.error(msg);
18271827
if (canAbort) {
18281828
// If we failed to acquire the write lock, abort the server
1829+
// print all thread stacks which are still holding locks and are the cause of RS abort
1830+
for (Map.Entry<Thread, Boolean> rslocks : regionLockHolders.entrySet()) {
1831+
LOG.warn("Thread still holding lock {} : Stack trace : {}", rslocks.getKey(),
1832+
Threads.printStackTrace(rslocks.getKey()));
1833+
}
18291834
rsServices.abort(msg, null);
18301835
}
18311836
throw new IOException(msg);
@@ -8441,9 +8446,9 @@ public void startRegionOperation(Operation op) throws IOException {
84418446
// Update regionLockHolders ONLY for any startRegionOperation call that is invoked from
84428447
// an RPC handler
84438448
Thread thisThread = Thread.currentThread();
8444-
if (isInterruptableOp) {
8445-
regionLockHolders.put(thisThread, true);
8446-
}
8449+
8450+
regionLockHolders.put(thisThread, isInterruptableOp);
8451+
84478452
if (this.closed.get()) {
84488453
lock.readLock().unlock();
84498454
throw new NotServingRegionException(getRegionInfo().getRegionNameAsString() + " is closed");
@@ -8458,11 +8463,7 @@ public void startRegionOperation(Operation op) throws IOException {
84588463
coprocessorHost.postStartRegionOperation(op);
84598464
}
84608465
} catch (Exception e) {
8461-
if (isInterruptableOp) {
8462-
// would be harmless to remove what we didn't add but we know by 'isInterruptableOp'
8463-
// if we added this thread to regionLockHolders
8464-
regionLockHolders.remove(thisThread);
8465-
}
8466+
regionLockHolders.remove(thisThread);
84668467
lock.readLock().unlock();
84678468
throw new IOException(e);
84688469
}
@@ -8702,8 +8703,13 @@ private void interruptRegionOperations() {
87028703
for (Map.Entry<Thread, Boolean> entry : regionLockHolders.entrySet()) {
87038704
// An entry in this map will have a boolean value indicating if it is currently
87048705
// eligible for interrupt; if so, we should interrupt it.
8706+
Thread key = entry.getKey();
87058707
if (entry.getValue().booleanValue()) {
8706-
entry.getKey().interrupt();
8708+
key.interrupt();
8709+
} else {
8710+
String s = Threads.printStackTrace(key);
8711+
LOG.warn("Can't interrupt thread {} : holding lock. Stack trace : {}", key, s);
8712+
87078713
}
87088714
}
87098715
}

0 commit comments

Comments
 (0)