activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cshan...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-6545
Date Fri, 16 Dec 2016 18:48:46 GMT
Repository: activemq
Updated Branches:
  refs/heads/activemq-5.14.x 1c625e116 -> fc3897af6


https://issues.apache.org/jira/browse/AMQ-6545

Fixing the order of locks acquired in the KahaDB journal to prevent a
deadlock during file rotation

(cherry picked from commit 5fd63a0e4ee71bb93843ab6bfbba6f93b023a3c3)


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

Branch: refs/heads/activemq-5.14.x
Commit: fc3897af67dc7d17255869d13aecba352f366b2f
Parents: 1c625e1
Author: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Authored: Fri Dec 16 12:27:34 2016 -0500
Committer: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Committed: Fri Dec 16 13:48:28 2016 -0500

----------------------------------------------------------------------
 .../store/kahadb/disk/journal/Journal.java         | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/fc3897af/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java
b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java
index 5db5df7..a68b460 100644
--- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java
+++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java
@@ -977,11 +977,22 @@ public class Journal {
     }
 
     public DataFile getCurrentDataFile(int capacity) throws IOException {
+        //First just acquire the currentDataFile lock and return if no rotation needed
         synchronized (currentDataFile) {
-            if (currentDataFile.get().getLength() + capacity >= maxFileLength) {
-                rotateWriteFile();
+            if (currentDataFile.get().getLength() + capacity < maxFileLength) {
+                return currentDataFile.get();
+            }
+        }
+
+        //AMQ-6545 - if rotation needed, acquire dataFileIdLock first to prevent deadlocks
+        //then re-check if rotation is needed
+        synchronized (dataFileIdLock) {
+            synchronized (currentDataFile) {
+                if (currentDataFile.get().getLength() + capacity >= maxFileLength) {
+                    rotateWriteFile();
+                }
+                return currentDataFile.get();
             }
-            return currentDataFile.get();
         }
     }
 


Mime
View raw message