resolve some issues with out of order remove from plist

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@915281 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2010-02-23 11:07:53 +00:00
parent fed39c3619
commit f24edca190
3 changed files with 46 additions and 11 deletions

View File

@ -325,6 +325,10 @@ public class PList {
result = doRemove(tx, entry);
break;
}
nextId = entry.getNext();
} else {
// not found
break;
}
}
return result;
@ -341,6 +345,10 @@ public class PList {
result = doRemove(tx, entry);
break;
}
nextId = entry.getNext();
} else {
// not found
break;
}
count++;
}
@ -437,7 +445,9 @@ public class PList {
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 {

View File

@ -308,17 +308,18 @@ public class PListStore extends ServiceSupport {
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 {

View File

@ -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 @@ public class PListTest {
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 {