From a88a513e3c91d65a311614ca84c9d2725d694bbe Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Wed, 10 Jun 2009 14:06:59 +0000 Subject: [PATCH] fix file lock usage in kahadb store, so shared file system master slave can work git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@783364 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/activemq/store/kahadb/MessageDatabase.java | 2 +- kahadb/src/main/java/org/apache/kahadb/util/LockFile.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java index db4c838656..95b3f5e33a 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java @@ -229,7 +229,7 @@ public class MessageDatabase { lockFile.lock(); break; } catch (IOException e) { - LOG.info("Database "+lockFileName+" is locked... waiting " + (DATABASE_LOCKED_WAIT_DELAY / 1000) + " seconds for the database to be unlocked."); + LOG.info("Database "+lockFileName+" is locked... waiting " + (DATABASE_LOCKED_WAIT_DELAY / 1000) + " seconds for the database to be unlocked. Reason: " + e); try { Thread.sleep(DATABASE_LOCKED_WAIT_DELAY); } catch (InterruptedException e1) { diff --git a/kahadb/src/main/java/org/apache/kahadb/util/LockFile.java b/kahadb/src/main/java/org/apache/kahadb/util/LockFile.java index c7338565ea..1d7b5b6ba3 100644 --- a/kahadb/src/main/java/org/apache/kahadb/util/LockFile.java +++ b/kahadb/src/main/java/org/apache/kahadb/util/LockFile.java @@ -50,8 +50,7 @@ public class LockFile { return; } - lockCounter++; - if( lockCounter!=1 ) { + if( lockCounter>0 ) { return; } @@ -63,9 +62,12 @@ public class LockFile { } catch (OverlappingFileLockException e) { throw IOExceptionSupport.create("File '" + file + "' could not be locked.",e); } - if (lock == null) { + if (lock != null) { + lockCounter++; + } else { throw new IOException("File '" + file + "' could not be locked."); } + } }