Fixing the order of locks acquired in the KahaDB journal to prevent a
deadlock during file rotation
This commit is contained in:
Christopher L. Shannon (cshannon) 2016-12-16 12:27:34 -05:00
parent d76cabe344
commit 5fd63a0e4e
1 changed files with 14 additions and 3 deletions

View File

@ -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();
}
}