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

Proposed by Peter Beaman
Status: Merged
Merged at revision: 314
Proposed branch: lp:~pbeaman/akiban-persistit/fix_1006576_long_record_pruning
Merge into: lp:akiban-persistit
Diff against target: 118 lines (+42/-10)
3 files modified
src/main/java/com/persistit/Buffer.java (+1/-0)
src/main/java/com/persistit/Value.java (+20/-10)
src/test/java/com/persistit/MVCCPruneBufferTest.java (+21/-0)
To merge this branch: bzr merge lp:~pbeaman/akiban-persistit/fix_1006576_long_record_pruning
Reviewer Review Type Date Requested Status
Akiban Build User Needs Fixing
Nathan Williams Needs Information
Review via email: mp+108091@code.launchpad.net

Description of the change

Fix a critical bug that was added with lp:~pbeaman/akiban-persistit/fix_945244_incomplete_pruning.

New code added with that branch failed to restore a Value to normal, non-long-record-mode after using it. When that value is used again, it is in an incorrect state.

This branch fixes the specific problem and adds a test to cover it.

Longer term the handling of "long record mode" in the Value object is murky at best and will be cleaned up when we refactor the Exchange class.

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

Ack, nasty one.

I think this is right. I said that last time, but I've believed it both times!

About the test:
Do we want the pollInterval to be -1 instead of MAX? If correct as-is, feel free to Approve.

review: Needs Information
Revision history for this message
Peter Beaman (pbeaman) wrote :

Yes, -1 is correct. Confusion was caused by my earlier mistake when I set some of these to MAX. I'll press the big-A button.

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

There were 2 failures during build/test:

* job server-mt failed at build number 1747: http://172.16.20.104:8080/job/server-mt/1747/

* view must-pass failed: server-mt is red

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

All the way through and then network hiccup on server-mt.

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/Buffer.java'
2--- src/main/java/com/persistit/Buffer.java 2012-05-25 18:50:59 +0000
3+++ src/main/java/com/persistit/Buffer.java 2012-05-31 02:25:21 +0000
4@@ -3729,6 +3729,7 @@
5 // Rewrite the tail block header
6 putInt(tail, encodeTailBlock(newTailSize, klength));
7 valueByte = newSize > 0 ? _bytes[offset] & 0xFF : -1;
8+ value.changeLongRecordMode(false);
9 }
10 }
11 boolean prunedAntiValue = pruneAntiValue(valueByte, p, tree);
12
13=== modified file 'src/main/java/com/persistit/Value.java'
14--- src/main/java/com/persistit/Value.java 2012-05-25 18:50:59 +0000
15+++ src/main/java/com/persistit/Value.java 2012-05-31 02:25:21 +0000
16@@ -683,9 +683,12 @@
17 * The <code>Value</code> to which state should be copied.
18 */
19 public void copyTo(Value target) {
20- if (target == this)
21+ if (target == this) {
22 return;
23- target.changeLongRecordMode(isLongRecordMode());
24+ }
25+ Debug.$assert0.t(!isLongRecordMode());
26+ Debug.$assert0.t(!target.isLongRecordMode());
27+
28 target.ensureFit(_size);
29 System.arraycopy(_bytes, 0, target._bytes, 0, _size);
30 target._size = _size;
31@@ -775,12 +778,14 @@
32 * larger array.
33 */
34 public boolean ensureFit(int length) {
35+
36 if (length > 0 && length * SIZE_GROWTH_DENOMINATOR < _size) {
37 length = _size / SIZE_GROWTH_DENOMINATOR;
38 }
39 final int newSize = _size + length;
40- if (newSize <= _bytes.length)
41+ if (newSize <= _bytes.length) {
42 return false;
43+ }
44 int newArraySize = ((newSize + SIZE_GRANULARITY - 1) / SIZE_GRANULARITY) * SIZE_GRANULARITY;
45 if (newArraySize > _maximumSize)
46 newArraySize = _maximumSize;
47@@ -4064,6 +4069,7 @@
48
49 void changeLongRecordMode(boolean mode) {
50 if (mode != _longMode) {
51+
52 if (_longBytes == null || _longBytes.length < Buffer.LONGREC_SIZE) {
53 _longBytes = new byte[Buffer.LONGREC_SIZE];
54 _longSize = Buffer.LONGREC_SIZE;
55@@ -4080,11 +4086,15 @@
56 _longSize = tempSize;
57 _longMode = mode;
58
59- if (mode) {
60- Debug.$assert1.t(_bytes.length == Buffer.LONGREC_SIZE);
61- } else {
62- Debug.$assert1.t(_longBytes.length == Buffer.LONGREC_SIZE);
63- }
64+ assertLongRecordModeIsCorrect();
65+ }
66+ }
67+
68+ private void assertLongRecordModeIsCorrect() {
69+ if (_longMode) {
70+ Debug.$assert1.t(_bytes.length == Buffer.LONGREC_SIZE);
71+ } else {
72+ Debug.$assert1.t(_longBytes == null || _longBytes.length == Buffer.LONGREC_SIZE);
73 }
74 }
75
76@@ -5071,8 +5081,8 @@
77 }
78
79 /**
80- * Construct a list of <code>Version</code> objects, each denoting one of the
81- * multi-value versions currently held in this Value object.
82+ * Construct a list of <code>Version</code> objects, each denoting one of
83+ * the multi-value versions currently held in this Value object.
84 *
85 * @return the list of <code>Version<code>s
86 * @throws PersistitException
87
88=== modified file 'src/test/java/com/persistit/MVCCPruneBufferTest.java'
89--- src/test/java/com/persistit/MVCCPruneBufferTest.java 2012-05-25 18:50:59 +0000
90+++ src/test/java/com/persistit/MVCCPruneBufferTest.java 2012-05-31 02:25:21 +0000
91@@ -183,6 +183,27 @@
92 ex1.prune();
93 assertTrue("Should no longer be an MVV", !ex1.isValueLongMVV());
94 }
95+
96+ @Test
97+ public void induceBug1006576() throws Exception {
98+ _persistit.getCleanupManager().setPollInterval(Long.MAX_VALUE);
99+ trx1.begin();
100+ storeLongMVV(ex1, "x");
101+ storeLongMVV(ex1, "y");
102+ trx1.commit();
103+ trx1.end();
104+ _persistit.getTransactionIndex().cleanup();
105+ ex1.prune();
106+ assertTrue("Should no longer be an MVV", !ex1.isValueLongMVV());
107+
108+ trx1.begin();
109+ storeLongMVV(ex1, "x");
110+ trx1.commit();
111+ trx1.end();
112+ _persistit.getTransactionIndex().cleanup();
113+ ex1.prune();
114+ assertTrue("Should no longer be an MVV", !ex1.isValueLongMVV());
115+ }
116
117 @Test
118 public void testComplexPruning() throws Exception {

Subscribers

People subscribed via source and target branches