activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r915281 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/store/kahadb/plist/PList.java main/java/org/apache/activemq/store/kahadb/plist/PListStore.java test/java/org/apache/activemq/store/kahadb/plist/PListTest.java
Date Tue, 23 Feb 2010 11:07:54 GMT
Author: gtully
Date: Tue Feb 23 11:07:53 2010
New Revision: 915281

URL: http://svn.apache.org/viewvc?rev=915281&view=rev
Log:
resolve some issues with out of order remove from plist

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PList.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PListStore.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/plist/PListTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PList.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PList.java?rev=915281&r1=915280&r2=915281&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PList.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PList.java
Tue Feb 23 11:07:53 2010
@@ -325,6 +325,10 @@
                     result = doRemove(tx, entry);
                     break;
                 }
+                nextId = entry.getNext();
+            } else {
+                // not found
+                break;
             }
         }
         return result;
@@ -341,6 +345,10 @@
                     result = doRemove(tx, entry);
                     break;
                 }
+                nextId = entry.getNext();
+            } else {
+                // not found
+                break;
             }
             count++;
         }
@@ -437,7 +445,9 @@
     EntryLocation loadEntry(Transaction tx, long pageId) throws IOException {
         Page<EntryLocation> page = tx.load(pageId, EntryLocationMarshaller.INSTANCE);
         EntryLocation entry = page.get();
-        entry.setPage(page);
+        if (entry != null) {
+            entry.setPage(page);
+        }
         return entry;
     }
     private void storeEntry(Transaction tx, EntryLocation entry) throws IOException {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PListStore.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PListStore.java?rev=915281&r1=915280&r2=915281&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PListStore.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PListStore.java
Tue Feb 23 11:07:53 2010
@@ -308,17 +308,18 @@
 
     synchronized void decrementJournalCount(Transaction tx, Location location) throws IOException
{
         int logId = location.getDataFileId();
-        int refCount = this.metaData.journalRC.get(tx, logId);
-        refCount--;
-        if (refCount <= 0) {
-            this.metaData.journalRC.remove(tx, logId);
-            Set<Integer> set = new HashSet<Integer>();
-            set.add(logId);
-            this.journal.removeDataFiles(set);
-        } else {
-            this.metaData.journalRC.put(tx, logId, refCount);
+        if (logId != Location.NOT_SET) {
+            int refCount = this.metaData.journalRC.get(tx, logId);
+            refCount--;
+            if (refCount <= 0) {
+                this.metaData.journalRC.remove(tx, logId);
+                Set<Integer> set = new HashSet<Integer>();
+                set.add(logId);
+                this.journal.removeDataFiles(set);
+            } else {
+                this.metaData.journalRC.put(tx, logId, refCount);
+            }
         }
-
     }
 
     synchronized ByteSequence getPayload(Location location) throws IllegalStateException,
IOException {

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/plist/PListTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/plist/PListTest.java?rev=915281&r1=915280&r2=915281&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/plist/PListTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/plist/PListTest.java
Tue Feb 23 11:07:53 2010
@@ -17,7 +17,9 @@
 package org.apache.activemq.store.kahadb.plist;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
@@ -124,6 +126,28 @@
         assertEquals(0,plist.size());
         assertNull("no first entry", plist.getFirst());
     }
+    
+    @Test
+    public void testRemoveSecond() throws Exception {
+        plist.addLast("First", new ByteSequence("A".getBytes()));
+        plist.addLast("Second", new ByteSequence("B".getBytes()));
+        
+        assertTrue(plist.remove("Second"));
+        assertTrue(plist.remove("First"));
+        assertFalse(plist.remove("doesNotExist"));
+    }
+    
+    
+    @Test
+    public void testRemoveSecondPosition() throws Exception {
+        plist.addLast("First", new ByteSequence("A".getBytes()));
+        plist.addLast("Second", new ByteSequence("B".getBytes()));
+        
+        assertTrue(plist.remove(1));
+        assertTrue(plist.remove(0));
+        assertFalse(plist.remove(3));
+    }
+    
 
     @Before
     public void setUp() throws Exception {



Mime
View raw message