activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r499797 - /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
Date Thu, 25 Jan 2007 13:58:03 GMT
Author: rajdavies
Date: Thu Jan 25 05:58:02 2007
New Revision: 499797

URL: http://svn.apache.org/viewvc?view=rev&rev=499797
Log:
fix for http://issues.apache.org/activemq/browse/AMQ-1082

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

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java?view=diff&rev=499797&r1=499796&r2=499797
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
Thu Jan 25 05:58:02 2007
@@ -43,10 +43,12 @@
     private RandomAccessFile indexFile;
     private StoreIndexReader reader;
     private StoreIndexWriter writer;
-    private LinkedList freeList=new LinkedList();
+ 
     private DataManager redoLog;
     private String mode;
     private long length=0;
+    private IndexItem firstFree;
+    private IndexItem lastFree;
 
     public IndexManager(File directory,String name,String mode,DataManager redoLog) throws
IOException{
         this.directory = directory;
@@ -57,7 +59,7 @@
     }
 
     public synchronized boolean isEmpty(){
-        return freeList.isEmpty()&&length==0;
+        return lastFree == null &&length==0;
     }
 
     public synchronized IndexItem getIndex(long offset) throws IOException{
@@ -70,10 +72,16 @@
     }
 
     public synchronized void freeIndex(IndexItem item) throws IOException{
-        //item.reset();
+        item.reset();
         item.setActive(false);
+        if (lastFree == null) {
+            firstFree=lastFree=item;
+        }
+        else {
+            lastFree.setNextItem(item.getOffset());
+        }
         writer.updateIndexes(item);
-        freeList.add(item);
+        
     }
 
     public synchronized void storeIndex(IndexItem index) throws IOException{
@@ -84,7 +92,7 @@
         try {
         writer.updateIndexes(index);
         }catch(Throwable e) {
-            log.error(name + " GORT ERROR! ",e);
+            log.error(name + " error updating indexes ",e);
         }
     }
 
@@ -92,7 +100,7 @@
         writer.redoStoreItem(redo);
     }
 
-    public synchronized IndexItem createNewIndex(){
+    public synchronized IndexItem createNewIndex() throws IOException{
         IndexItem result=getNextFreeIndex();
         if(result==null){
             // allocate one
@@ -118,7 +126,7 @@
 
         
     public synchronized boolean delete() throws IOException{
-        freeList.clear();
+        firstFree = lastFree = null;
         if(indexFile!=null){
             indexFile.close();
             indexFile=null;
@@ -126,12 +134,23 @@
         return file.delete();
     }
 
-    private synchronized IndexItem getNextFreeIndex(){
+    private synchronized IndexItem getNextFreeIndex() throws IOException{
         IndexItem result=null;
-        if(!freeList.isEmpty()){
-            result=(IndexItem) freeList.removeLast();
+        if (firstFree != null) {
+            if (firstFree.equals(lastFree)) {
+                result = firstFree;
+                firstFree=lastFree=null;
+                
+            }else {
+                result = firstFree;
+                firstFree = getIndex(firstFree.getNextItem());
+                if (firstFree==null) {
+                    lastFree=null;
+                }
+            }
             result.reset();
         }
+       
         return result;
     }
 
@@ -158,11 +177,19 @@
         reader=new StoreIndexReader(indexFile);
         writer=new StoreIndexWriter(indexFile,name,redoLog);
         long offset=0;
+        
         while((offset+IndexItem.INDEX_SIZE)<=indexFile.length()){
             IndexItem index=reader.readItem(offset);
             if(!index.isActive()){
                 index.reset();
-                freeList.add(index);
+                if (lastFree != null) {
+                    lastFree.setNextItem(index.getOffset());
+                    updateIndexes(lastFree);
+                    lastFree=index;
+                }else {
+                    lastFree=firstFree=index;
+                }
+                
             }
             offset+=IndexItem.INDEX_SIZE;
         }



Mime
View raw message