Merge lp:~pbeaman/akiban-persistit/fix-JournalManagerTest into lp:akiban-persistit

Proposed by Peter Beaman
Status: Merged
Approved by: Nathan Williams
Approved revision: 345
Merged at revision: 344
Proposed branch: lp:~pbeaman/akiban-persistit/fix-JournalManagerTest
Merge into: lp:akiban-persistit
Diff against target: 50 lines (+20/-20)
1 file modified
src/test/java/com/persistit/JournalManagerTest.java (+20/-20)
To merge this branch: bzr merge lp:~pbeaman/akiban-persistit/fix-JournalManagerTest
Reviewer Review Type Date Requested Status
Nathan Williams Approve
Review via email: mp+117816@code.launchpad.net

Description of the change

Fixes a subtle timing-related failure in JournalManagerTest#testJournalRecords. At one point this test needs to clear the handle for a Tree instance; it does so too early in the code, however, since there is a later call to Persistit#getExchange that can repopulate the handle. If the later call does reinstantiate the tree handle, then subsequent operations fail and an assertion fires to fail the test.

Apparently this problem has been present but undetected for many months.

The problem is timing-related because the getExchange method attempts to look up a cached copy of the Tree from a WeakHashMap. If that lookup is successful then the test succeeds; if it fails then a new Tree object with a freshly instantiated tree handle is created. It appears that GC is more aggressive on the Mac version of the JDK which is where we started to see the failures. This interaction is created by the very special internal twiddling done by this test and is not a general problem.

The modified version of the test passes on Mac and Cent OS.

Since this is a bug in a test, we have no unit test; the fact that the original test passes is confirmation of the fix.

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

Makes sense.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/test/java/com/persistit/JournalManagerTest.java'
2--- src/test/java/com/persistit/JournalManagerTest.java 2012-07-25 19:32:11 +0000
3+++ src/test/java/com/persistit/JournalManagerTest.java 2012-08-01 23:18:19 +0000
4@@ -72,27 +72,27 @@
5
6 final Volume volume = _persistit.getVolume(_volumeName);
7 volume.resetHandle();
8+
9+ final JournalManager jman = new JournalManager(_persistit);
10+ final String path = UnitTestProperties.DATA_PATH + "/JournalManagerTest_journal_";
11+ jman.init(null, path, 100 * 1000 * 1000);
12+ final BufferPool pool = _persistit.getBufferPool(16384);
13+ final long pages = Math.min(1000, volume.getStorage().getNextAvailablePage() - 1);
14+ for (int i = 0; i < 1000; i++) {
15+ final Buffer buffer = pool.get(volume, i % pages, true, true);
16+ if ((i % 400) == 0) {
17+ jman.rollover();
18+ }
19+ buffer.setDirtyAtTimestamp(_persistit.getTimestampAllocator().updateTimestamp());
20+ jman.writePageToJournal(buffer);
21+ buffer.clearDirty();
22+ buffer.releaseTouched();
23+ }
24+
25+ final Checkpoint checkpoint1 = _persistit.getCheckpointManager().createCheckpoint();
26+ jman.writeCheckpointToJournal(checkpoint1);
27+ final Exchange exchange = _persistit.getExchange(_volumeName, "JournalManagerTest1", false);
28 volume.getTree("JournalManagerTest1", false).resetHandle();
29-
30- final JournalManager jman = new JournalManager(_persistit);
31- final String path = UnitTestProperties.DATA_PATH + "/JournalManagerTest_journal_";
32- jman.init(null, path, 100 * 1000 * 1000);
33- final BufferPool pool = _persistit.getBufferPool(16384);
34- final long pages = Math.min(1000, volume.getStorage().getNextAvailablePage() - 1);
35- for (int i = 0; i < 1000; i++) {
36- final Buffer buffer = pool.get(volume, i % pages, true, true);
37- if ((i % 400) == 0) {
38- jman.rollover();
39- }
40- buffer.setDirtyAtTimestamp(_persistit.getTimestampAllocator().updateTimestamp());
41- jman.writePageToJournal(buffer);
42- buffer.clearDirty();
43- buffer.releaseTouched();
44- }
45-
46- final Checkpoint checkpoint1 = _persistit.getCheckpointManager().createCheckpoint();
47- jman.writeCheckpointToJournal(checkpoint1);
48- final Exchange exchange = _persistit.getExchange(_volumeName, "JournalManagerTest1", false);
49 assertTrue(exchange.next(true));
50 final long[] timestamps = new long[100];
51

Subscribers

People subscribed via source and target branches