diff --git a/kahadb/src/main/java/org/apache/kahadb/index/ListNode.java b/kahadb/src/main/java/org/apache/kahadb/index/ListNode.java index 4bd4501dbe..bd993ce8ff 100644 --- a/kahadb/src/main/java/org/apache/kahadb/index/ListNode.java +++ b/kahadb/src/main/java/org/apache/kahadb/index/ListNode.java @@ -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 { } 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 { ListNode 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); } diff --git a/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java b/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java index b58df01b8f..b51ab6a088 100644 --- a/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java +++ b/kahadb/src/test/java/org/apache/kahadb/index/ListIndexTest.java @@ -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()); }