Merge lp:~pbeaman/akiban-persistit/fix_912514_again into lp:akiban-persistit

Proposed by Peter Beaman
Status: Merged
Approved by: Nathan Williams
Approved revision: 309
Merged at revision: 309
Proposed branch: lp:~pbeaman/akiban-persistit/fix_912514_again
Merge into: lp:akiban-persistit
Diff against target: 111 lines (+47/-2)
4 files modified
src/main/java/com/persistit/Exchange.java (+2/-2)
src/main/java/com/persistit/Persistit.java (+1/-0)
src/test/java/com/persistit/ConfigurationTest.java (+8/-0)
src/test/java/com/persistit/unit/ExchangeTest.java (+36/-0)
To merge this branch: bzr merge lp:~pbeaman/akiban-persistit/fix_912514_again
Reviewer Review Type Date Requested Status
Akiban Build User Needs Fixing
Nathan Williams Approve
Review via email: mp+107879@code.launchpad.net

Description of the change

Fix two small bugs detected while running the stress tests.

(a) start-stop-plan reuses a Persistit instance; releaseAllResources() now sets the initialized flag to false so that this will work correctly.

(b) fetchAndRemove is still broken - some bits need to be masked in two conditionals that test whether the from and to key of a remove operation are adjacent.

This branch fixes both bugs and adds trivial unit tests.

(Note - this is the second merge proposal for this branch. We pulled the first one because of uncertainty over some other changes.)

To post a comment you must log in.
Revision history for this message
Nathan Williams (nwilliams) wrote :

Looks good.

review: Approve
Revision history for this message
Akiban Build User (build-akiban) wrote :

There was one failure during build/test:

* unknown exception (check log)

review: Needs Fixing
Revision history for this message
Nathan Williams (nwilliams) wrote :

Unrelated LBJ timeout waiting for dumbo.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/main/java/com/persistit/Exchange.java'
2--- src/main/java/com/persistit/Exchange.java 2012-05-25 18:50:59 +0000
3+++ src/main/java/com/persistit/Exchange.java 2012-05-29 21:03:19 +0000
4@@ -3559,13 +3559,13 @@
5
6 private void removeFetchFirst(Buffer buffer1, int foundAt1, Buffer buffer2, int foundAt2) throws PersistitException {
7 if (buffer1 == buffer2) {
8- if (buffer1.nextKeyBlock(foundAt1) == foundAt2) {
9+ if (buffer1.nextKeyBlock(foundAt1) == (foundAt2 & P_MASK)) {
10 buffer1.fetch(foundAt1 | EXACT_MASK, _spareValue);
11 }
12 } else {
13 if (buffer1.getRightSibling() == buffer2.getPageAddress() && buffer1.nextKeyBlock(foundAt1) == -1) {
14 foundAt1 = buffer2.toKeyBlock(0);
15- if (buffer2.nextKeyBlock(foundAt1) == foundAt2) {
16+ if (buffer2.nextKeyBlock(foundAt1) == (foundAt2 & P_MASK)) {
17 buffer2.fetch(foundAt1 | EXACT_MASK, _spareValue);
18 }
19 }
20
21=== modified file 'src/main/java/com/persistit/Persistit.java'
22--- src/main/java/com/persistit/Persistit.java 2012-05-25 18:50:59 +0000
23+++ src/main/java/com/persistit/Persistit.java 2012-05-29 21:03:19 +0000
24@@ -1794,6 +1794,7 @@
25 _intArrayThreadLocal.set(null);
26 _keyThreadLocal.set(null);
27 _valueThreadLocal.set(null);
28+ _initialized.set(false);
29 }
30
31 /**
32
33=== modified file 'src/test/java/com/persistit/ConfigurationTest.java'
34--- src/test/java/com/persistit/ConfigurationTest.java 2012-05-25 18:50:59 +0000
35+++ src/test/java/com/persistit/ConfigurationTest.java 2012-05-29 21:03:19 +0000
36@@ -222,6 +222,14 @@
37 assertTrue("Should contain expected text 'hwdemo'", configuration.getJournalPath().contains("hwdemo"));
38 }
39
40+ @Test
41+ public void canReinitialize() throws Exception {
42+ _persistit.close();
43+ assertTrue("Should have closed all volumes", _persistit.getVolumes().isEmpty());
44+ _persistit.initialize(_persistit.getConfiguration());
45+ assertTrue("Should have reopened volumes", !_persistit.getVolumes().isEmpty());
46+ }
47+
48 private Configuration testLoadPropertiesBufferSpecificationsHelper(final Properties properties) throws Exception {
49 Configuration configuration = new Configuration();
50 configuration.merge(properties);
51
52=== modified file 'src/test/java/com/persistit/unit/ExchangeTest.java'
53--- src/test/java/com/persistit/unit/ExchangeTest.java 2012-05-25 18:50:59 +0000
54+++ src/test/java/com/persistit/unit/ExchangeTest.java 2012-05-29 21:03:19 +0000
55@@ -21,6 +21,7 @@
56 package com.persistit.unit;
57
58 import static org.junit.Assert.assertEquals;
59+import static org.junit.Assert.assertTrue;
60 import static org.junit.Assert.fail;
61
62 import java.util.Random;
63@@ -30,6 +31,7 @@
64 import com.persistit.Exchange;
65 import com.persistit.Key;
66 import com.persistit.KeyFilter;
67+import com.persistit.Transaction;
68 import com.persistit.Volume;
69 import com.persistit.exception.ConversionException;
70 import com.persistit.exception.PersistitException;
71@@ -281,6 +283,40 @@
72 assertEquals(1, ex.getValue().getInt());
73 }
74
75+ @Test
76+ public void testRemoveAndFetch() throws Exception {
77+ testRemoveAndFetch(false);
78+ testRemoveAndFetch(true);
79+ }
80+
81+ private void testRemoveAndFetch(boolean inTransaction) throws Exception {
82+ Exchange ex = _persistit.getExchange("persistit", "gogo", true);
83+ Transaction txn = ex.getTransaction();
84+ ex.getValue().put(RED_FOX);
85+ for (int i = 1; i < 10000; i++) {
86+ if (inTransaction) {
87+ txn.begin();
88+ }
89+ ex.to(i).store();
90+ if (inTransaction) {
91+ txn.commit();
92+ txn.end();
93+ }
94+ }
95+ for (int i = 1; i < 10000; i++) {
96+ if (inTransaction) {
97+ txn.begin();
98+ }
99+ ex.getValue().clear();
100+ ex.to(i).fetchAndRemove();
101+ assertTrue("A value was fetched", ex.getValue().isDefined());
102+ if (inTransaction) {
103+ txn.commit();
104+ txn.end();
105+ }
106+ }
107+ }
108+
109 /*
110 * This function is "borrowed" from the YCSB benchmark framework developed
111 * by Yahoo Research.

Subscribers

People subscribed via source and target branches