The ListIndex was not properly configured after a split occurred during put operations, the
page Ids weren't set correctly on split and the tail page Id was never set. 

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1306780 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2012-03-29 10:33:11 +00:00
parent 6d58dbef32
commit d2610faff4
2 changed files with 14 additions and 15 deletions

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import org.apache.kahadb.page.Page;
import org.apache.kahadb.page.Transaction;
import org.apache.kahadb.util.LinkedNode;
@ -325,6 +326,11 @@ public final class ListNode<Key,Value> {
} else {
getContainingList().storeNode(tx, this, false);
}
if (this.next == -1) {
getContainingList().setTailPageId(getPageId());
}
} catch ( Transaction.PageOverflowIOException e ) {
// If we get an overflow
split(tx, addFirst);
@ -343,15 +349,16 @@ public final class ListNode<Key,Value> {
ListNode<Key, Value> extension = getContainingList().createNode(tx);
if (isAddFirst) {
// head keeps the first entry, insert extension with the rest
extension.setNext(this.getNext());
this.setNext(extension.getPageId());
extension.setEntries(entries.getHead().splitAfter());
} else {
extension.setNext(this.getNext());
extension.store(tx, isAddFirst);
this.setNext(extension.getPageId());
} else {
extension.setEntries(entries.getTail().getPrevious().splitAfter());
extension.store(tx, isAddFirst);
getContainingList().setTailPageId(extension.getPageId());
this.setNext(extension.getPageId());
}
extension.store(tx, isAddFirst);
store(tx, true);
}

View File

@ -452,11 +452,8 @@ public class ListIndexTest extends IndexTestSupport {
LOG.info("Loading up the ListIndex with "+NUM_ITERATIONS+" entires and sparsely populating the sequences.");
for (int i = 0; i < NUM_ITERATIONS; ++i) {
tx = pf.tx();
test.add(tx, String.valueOf(expectedListEntries++), new SequenceSet());
tx.commit();
tx = pf.tx();
for (int j = 0; j < expectedListEntries; j++) {
SequenceSet sequenceSet = test.get(tx, String.valueOf(j));
@ -474,16 +471,13 @@ public class ListIndexTest extends IndexTestSupport {
test.put(tx, String.valueOf(j), sequenceSet);
}
}
tx.commit();
}
LOG.info("Checking if Index has the expected number of entries.");
for (int i = 0; i < NUM_ITERATIONS; ++i) {
tx = pf.tx();
assertTrue("List should contain Key["+i+"]",test.containsKey(tx, String.valueOf(i)));
assertNotNull("List contents of Key["+i+"] should not be null", test.get(tx, String.valueOf(i)));
tx.commit();
}
LOG.info("Index has the expected number of entries.");
@ -491,13 +485,11 @@ public class ListIndexTest extends IndexTestSupport {
assertEquals(expectedListEntries, test.size());
for (int i = 0; i < NUM_ITERATIONS; ++i) {
LOG.info("Size of ListIndex before removal of entry ["+i+"] is: " + test.size());
tx = pf.tx();
LOG.debug("Size of ListIndex before removal of entry ["+i+"] is: " + test.size());
// assertTrue("List should contain Key["+i+"]",test.containsKey(tx, String.valueOf(i)));
assertTrue("List should contain Key["+i+"]",test.containsKey(tx, String.valueOf(i)));
assertNotNull("List contents of Key["+i+"] should not be null", test.remove(tx, String.valueOf(i)));
tx.commit();
LOG.info("Size of ListIndex after removal of entry ["+i+"] is: " + test.size());
LOG.debug("Size of ListIndex after removal of entry ["+i+"] is: " + test.size());
assertEquals(expectedListEntries - (i + 1), test.size());
}