From 8197c181aaf397515127e56d9ff40ce8f153f701 Mon Sep 17 00:00:00 2001 From: Valera V Harseko Date: Sun, 12 Jul 2026 09:56:37 +0300 Subject: [PATCH] persistit: stabilize flaky MVCCPruneTest.testPruneAlternatingAbortedAndCommittedVersions (#272) The store-time prune in Exchange consults the ActiveTransactionCache: a stale cache conservatively keeps the previous committed version while a fresh one removes it. The test hardcoded the stale-cache outcome (2 versions removed), which only holds while the whole store loop fits between two ticks of the 10 ms TXN_UPDATE poll task. Under CI load a recompute lands mid-loop, an extra version is pruned and the assertion fails with "stored versions expected:<4> but was:<3>". Settle the active transaction cache explicitly before every store so pruning always sees fresh commit status, and update the expected count to the deterministic fully-pruned outcome (4 versions removed, 2 surviving). Fixes #272. --- .../src/test/java/com/persistit/MVCCPruneTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/persistit/core/src/test/java/com/persistit/MVCCPruneTest.java b/persistit/core/src/test/java/com/persistit/MVCCPruneTest.java index dd86a2096..9eb2de7bb 100644 --- a/persistit/core/src/test/java/com/persistit/MVCCPruneTest.java +++ b/persistit/core/src/test/java/com/persistit/MVCCPruneTest.java @@ -12,6 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * Portions Copyrighted 2026 3A Systems, LLC */ package com.persistit; @@ -253,6 +254,15 @@ public void testPruneAlternatingAbortedAndCommittedVersions() throws PersistitEx storePrimordial(ex1, KEY, VALUE); for (int i = 0; i < VERSIONS.length; ++i) { + /* + * The prune that runs inside each store consults the active + * transaction cache: a stale cache conservatively keeps the + * previous committed version, a fresh one removes it. Settle the + * cache before every store so the surviving version count does + * not depend on whether the background TXN_UPDATE timer fired + * mid-loop (issue #272). + */ + _persistit.getTransactionIndex().updateActiveTransactionCache(); trx1.begin(); try { store(ex1, KEY, VALUE + VERSIONS[i] + i); @@ -265,7 +275,7 @@ public void testPruneAlternatingAbortedAndCommittedVersions() throws PersistitEx trx1.end(); } } - final int VERSIONS_NOW_REMOVED_BY_PRUNING_BEFORE_STORE = 2; + final int VERSIONS_NOW_REMOVED_BY_PRUNING_BEFORE_STORE = 4; assertEquals("stored versions", VERSIONS.length + 1 - VERSIONS_NOW_REMOVED_BY_PRUNING_BEFORE_STORE, storedVersionCount(ex2, KEY));