activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r560352 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/kaha/impl/KahaStore.java main/java/org/apache/activemq/kaha/impl/index/IndexManager.java test/java/org/apache/activemq/kaha/StoreTest.java
Date Fri, 27 Jul 2007 18:49:49 GMT
Author: chirino
Date: Fri Jul 27 11:49:47 2007
New Revision: 560352

URL: http://svn.apache.org/viewvc?view=rev&rev=560352
Log:
Fix for http://issues.apache.org/activemq/browse/AMQ-1348

Better file locking on windows.  We now use a seperate lock file to signifiy the lock on the
kaha db.


Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/StoreTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java?view=diff&rev=560352&r1=560351&r2=560352
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
Fri Jul 27 11:49:47 2007
@@ -20,6 +20,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.RandomAccessFile;
 import java.nio.channels.FileLock;
 import java.util.Date;
 import java.util.HashSet;
@@ -27,6 +28,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+
 import org.apache.activemq.kaha.ContainerId;
 import org.apache.activemq.kaha.ListContainer;
 import org.apache.activemq.kaha.MapContainer;
@@ -34,6 +36,7 @@
 import org.apache.activemq.kaha.Store;
 import org.apache.activemq.kaha.StoreLocation;
 import org.apache.activemq.kaha.impl.async.AsyncDataManager;
+import org.apache.activemq.kaha.impl.async.ControlFile;
 import org.apache.activemq.kaha.impl.async.DataManagerFacade;
 import org.apache.activemq.kaha.impl.container.ListContainerImpl;
 import org.apache.activemq.kaha.impl.container.MapContainerImpl;
@@ -54,12 +57,13 @@
 public class KahaStore implements Store{
 
     private final static String PROPERTY_PREFIX="org.apache.activemq.kaha.Store";
-    private final static boolean brokenFileLock="true".equals(System.getProperty(PROPERTY_PREFIX+".broken","false"));
-    private final static boolean disableLocking="true".equals(System.getProperty(PROPERTY_PREFIX+"DisableLocking",
+    private final static boolean brokenFileLock="true".equals(System.getProperty(PROPERTY_PREFIX+".FileLockBroken","false"));
+    private final static boolean disableLocking="true".equals(System.getProperty(PROPERTY_PREFIX+".DisableLocking",
             "false"));
    
     private static final Log log=LogFactory.getLog(KahaStore.class);
-    private File directory;
+    private final File directory;
+    private final String mode;
     private IndexRootContainer mapsContainer;
     private IndexRootContainer listsContainer;
     private Map<ContainerId, ListContainerImpl> lists=new ConcurrentHashMap<ContainerId,
ListContainerImpl>();
@@ -68,13 +72,13 @@
     private Map<String, IndexManager> indexManagers=new ConcurrentHashMap<String,
IndexManager>();
     private IndexManager rootIndexManager; // contains all the root indexes
     private boolean closed=false;
-    private String mode;
     private boolean initialized;
     private boolean logIndexChanges=false;
     private boolean useAsyncDataManager=false;
     private long maxDataFileLength=1024*1024*32;
     private FileLock lock;
     private boolean persistentIndex=true;
+	private RandomAccessFile lockFile;
 
     public KahaStore(String name,String mode) throws IOException{
         this.mode=mode;
@@ -107,6 +111,8 @@
                     iter.remove();
                 }
             }
+            if( lockFile!=null )
+            	lockFile.close();            
         }
     }
 
@@ -423,6 +429,9 @@
         if(!initialized){
            
             log.info("Kaha Store using data directory "+directory);
+            lockFile = new RandomAccessFile(new File(directory, "lock"), "rw"); 
+            lock();
+
             DataManager defaultDM=getDataManager(DEFAULT_CONTAINER_NAME);
             rootIndexManager=getIndexManager(defaultDM,DEFAULT_CONTAINER_NAME);
             IndexItem mapRoot=new IndexItem();
@@ -437,7 +446,6 @@
                 mapRoot=rootIndexManager.getIndex(0);
                 listRoot=rootIndexManager.getIndex(IndexItem.INDEX_SIZE);
             }
-            lock();
             initialized=true;
             mapsContainer=new IndexRootContainer(mapRoot,rootIndexManager,defaultDM);
             listsContainer=new IndexRootContainer(listRoot,rootIndexManager,defaultDM);
@@ -459,7 +467,7 @@
             String property = System.getProperty(key);
             if (null == property) {
                 if (!brokenFileLock) {
-                    lock = rootIndexManager.getLock();
+                	lock = lockFile.getChannel().tryLock();
                     if (lock == null) {
     throw new StoreLockedExcpetion("Kaha Store " + directory.getName() + "  is already opened
by another application");
                     } else

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java?view=diff&rev=560352&r1=560351&r2=560352
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
Fri Jul 27 11:49:47 2007
@@ -159,10 +159,6 @@
         this.length=value;
     }
 
-    public synchronized FileLock getLock() throws IOException{
-        return indexFile.getChannel().tryLock();
-    }
-
     public String toString(){
         return "IndexManager:("+NAME_PREFIX+name+")";
     }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/StoreTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/StoreTest.java?view=diff&rev=560352&r1=560351&r2=560352
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/StoreTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/StoreTest.java Fri
Jul 27 11:49:47 2007
@@ -186,12 +186,14 @@
     }
     
     public void testLock() throws Exception{
-        try {
         store.doesListContainerExist("fred");
         Store s = getStore();
-        s.doesListContainerExist("fred");
+        try {
+        	s.doesListContainerExist("fred");
         }catch(StoreLockedExcpetion e) {
             return;
+        } finally {
+        	s.close();
         }
         fail("Expected to catch an exception");
     }



Mime
View raw message