This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 9e0c754ae56 [fix](bdb) reset interrupted flag before calling bdbje 
(#47874)
9e0c754ae56 is described below

commit 9e0c754ae56bbfecde24a7014a3f7ca179a72ea2
Author: Mingyu Chen (Rayner) <morning...@163.com>
AuthorDate: Fri Feb 14 23:06:26 2025 +0800

    [fix](bdb) reset interrupted flag before calling bdbje (#47874)
    
    ### What problem does this PR solve?
    
    This pull request includes changes to ensure that the interrupted flag
    of the current thread is reset before performing certain operations to
    prevent failures in acquiring locks. The changes primarily affect the
    `BDBEnvironment` and `BDBJEJournal` classes.
    
    ```
    Caused by: java.lang.InterruptedException
            at 
java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1326)
 ~[?:1.8.0_352-352]
            at 
java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.tryLock(ReentrantReadWriteLock.java:871)
 ~[?:1.8.0_352-352]
            at 
com.sleepycat.je.latch.SharedLatchImpl.acquireShared(SharedLatchImpl.java:103) 
~[je-18.3.14-doris-SNAPSHOT.jar:18.3.14-doris-SNAPSHOT]
            at com.sleepycat.je.tree.Tree.getRootINInternal(Tree.java:447) 
~[je-18.3.14-doris-SNAPSHOT.jar:18.3.14-doris-SNAPSHOT]
            at com.sleepycat.je.tree.Tree.getRootIN(Tree.java:431) 
~[je-18.3.14-doris-SNAPSHOT.jar:18.3.14-doris-SNAPSHOT]
            at com.sleepycat.je.tree.Tree.search(Tree.java:2185) 
~[je-18.3.14-doris-SNAPSHOT.jar:18.3.14-doris-SNAPSHOT]
            at com.sleepycat.je.tree.Tree.getFirstNode(Tree.java:812) 
~[je-18.3.14-doris-SNAPSHOT.jar:18.3.14-doris-SNAPSHOT]
            at 
com.sleepycat.je.dbi.CursorImpl.positionFirstOrLast(CursorImpl.java:1776) 
~[je-18.3.14-doris-SNAPSHOT.jar:18.3.14-doris-SNAPSHOT]
            at 
com.sleepycat.je.dbi.CursorImpl.traverseDbWithCursor(CursorImpl.java:3953) 
~[je-18.3.14-doris-SNAPSHOT.jar:18.3.14-doris-SNAPSHOT]
            at com.sleepycat.je.dbi.DbTree.getDbNames(DbTree.java:1808) 
~[je-18.3.14-doris-SNAPSHOT.jar:18.3.14-doris-SNAPSHOT]
            at 
com.sleepycat.je.Environment.getDatabaseNames(Environment.java:2458) 
~[je-18.3.14-doris-SNAPSHOT.jar:18.3.14-doris-SNAPSHOT]
            ... 21 more
    ```
    
    This a self-defend logic. Because we found that some times other logic
    may set the thread as interrupted and
    does not handle it.
---
 .../src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java | 5 +++++
 .../src/main/java/org/apache/doris/journal/bdbje/BDBJEJournal.java   | 5 +++++
 2 files changed, 10 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java 
b/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java
index ff162b0c9fa..14105232e0f 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java
@@ -336,6 +336,11 @@ public class BDBEnvironment {
 
     // get journal db names and sort the names
     public List<Long> getDatabaseNames() {
+        // The operation before may set the current thread as interrupted.
+        // MUST reset the interrupted flag of current thread to false,
+        // otherwise replicatedEnvironment.getDatabaseNames() will fail 
because it will call lock.tryLock(),
+        // which will check the interrupted flag.
+        Thread.interrupted();
         List<Long> ret = new ArrayList<Long>();
         List<String> names = null;
         int tried = 0;
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBJEJournal.java 
b/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBJEJournal.java
index 1c1bcf6354c..2a6a5b201e0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBJEJournal.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBJEJournal.java
@@ -225,6 +225,11 @@ public class BDBJEJournal implements Journal { // 
CHECKSTYLE IGNORE THIS LINE: B
 
     @Override
     public synchronized long write(short op, Writable writable) throws 
IOException {
+        // The operation before may set the current thread as interrupted.
+        // MUST reset the interrupted flag of current thread to false,
+        // otherwise edit log writing may fail because it will call 
lock.tryLock(),
+        // which will check the interrupted flag.
+        Thread.interrupted();
         JournalEntity entity = new JournalEntity();
         entity.setOpCode(op);
         entity.setData(writable);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to