mirror of https://github.com/apache/activemq.git
Fixing the order of locks acquired in the KahaDB journal to prevent a deadlock during file rotation
This commit is contained in:
parent
d76cabe344
commit
5fd63a0e4e
|
@ -994,11 +994,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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue