You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@artemis.apache.org by cl...@apache.org on 2026/09/22 02:44:05 UTC
(artemis) branch main updated: ARTEMIS-6268 page writes can prematurely satisfy delayed commit completions
This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/artemis.git
The following commit(s) were added to refs/heads/main by this push:
new 644921d73b ARTEMIS-6268 page writes can prematurely satisfy delayed commit completions
644921d73b is described below
commit 644921d73b5c48817473998be69b5334cb9dfcd3
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Mon Sep 21 18:50:47 2026 -0500
ARTEMIS-6268 page writes can prematurely satisfy delayed commit completions
Co-Authored-By: Claude <no...@anthropic.com>
---
.../artemis/core/paging/impl/PageTimedWriter.java | 4 +-
.../core/paging/impl/PageTimedWriterUnitTest.java | 126 +++++++++++++++++++++
2 files changed, 128 insertions(+), 2 deletions(-)
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PageTimedWriter.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PageTimedWriter.java
index 91b53e812f..65de252b8f 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PageTimedWriter.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PageTimedWriter.java
@@ -144,7 +144,7 @@ public class PageTimedWriter extends ActiveMQScheduledComponent {
final boolean replicated = storageManager.isReplicated();
PageEvent event = new PageEvent(context, message, tx, listCtx, credits, replicated, useFlowControl);
- context.storeLineUp();
+ context.pageSyncLineUp();
if (replicated) {
context.replicationLineUp();
}
@@ -230,7 +230,7 @@ public class PageTimedWriter extends ActiveMQScheduledComponent {
}
logger.trace("Completing events");
for (PageEvent event : pendingEvents) {
- event.context.done();
+ event.context.pageSyncDone();
}
}
} catch (Throwable e) {
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTimedWriterUnitTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTimedWriterUnitTest.java
index cc8e11d66d..b184743d99 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTimedWriterUnitTest.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTimedWriterUnitTest.java
@@ -19,6 +19,8 @@ package org.apache.activemq.artemis.tests.unit.core.paging.impl;
import javax.transaction.xa.Xid;
import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@@ -41,6 +43,7 @@ import org.apache.activemq.artemis.core.io.IOCallback;
import org.apache.activemq.artemis.core.io.OperationConsistencyLevel;
import org.apache.activemq.artemis.core.io.SequentialFileFactory;
import org.apache.activemq.artemis.core.journal.EncodingSupport;
+import org.apache.activemq.artemis.core.journal.IOCompletion;
import org.apache.activemq.artemis.core.journal.Journal;
import org.apache.activemq.artemis.core.message.impl.CoreMessage;
import org.apache.activemq.artemis.core.paging.PagedMessage;
@@ -1024,4 +1027,127 @@ public class PageTimedWriterUnitTest extends ArtemisTestCase {
assertEquals(interceptorOriginalSize, sentOriginalSize);
assertEquals(sentNumber.get(), interceptorOriginalSize);
}
+
+ /**
+ * When two transactions share an {@link OperationContext}, a callback registered via
+ * {@code afterCompleteOperations} for the first transaction must not run until that transaction's own delayed
+ * commit (parked via {@link Transaction#delay()}) has completed - regardless of any page writes the second
+ * transaction lines up on the same context in the meantime.
+ */
+ @Test
+ public void testDelayedCommitCompletionNotSatisfiedByUnrelatedPageWrites() throws Exception {
+ OperationContextImpl.clearContext();
+
+ // a single context shared by both transactions
+ OperationContext sessionContext = OperationContextImpl.getContext(executorFactory);
+ OperationContextImpl.setContext(sessionContext);
+
+ /*
+ * Hold the commit records rather than completing them inline so the test decides when the IO finishes.
+ * JournalImpl::appendCommitRecord lines the context up when lineUpContext is set, so do the same here.
+ */
+ List<IOCompletion> pendingCommits = Collections.synchronizedList(new ArrayList<>());
+ Mockito.doAnswer(a -> {
+ IOCompletion completion = a.getArgument(2);
+ if (completion != null && (Boolean) a.getArgument(3)) {
+ completion.storeLineUp();
+ pendingCommits.add(completion);
+ }
+ return commitCall();
+ }).when(mockMessageJournal).appendCommitRecord(Mockito.anyLong(), Mockito.anyBoolean(), Mockito.any(), Mockito.anyBoolean());
+
+ AtomicBoolean firstCompleted = new AtomicBoolean(false);
+ AtomicBoolean secondCompleted = new AtomicBoolean(false);
+
+ TransactionImpl firstTx = new TransactionImpl(realJournalStorageManager, Integer.MAX_VALUE);
+ firstTx.setContainsPersistent();
+ assertTrue(realJournalStorageManager.addToPage(pageStore, createMessage(), firstTx, Mockito.mock(RouteContextList.class)));
+ firstTx.commit();
+ realJournalStorageManager.afterCompleteOperations(completionFlag(firstCompleted));
+
+ TransactionImpl secondTx = new TransactionImpl(realJournalStorageManager, Integer.MAX_VALUE);
+ secondTx.setContainsPersistent();
+ assertTrue(realJournalStorageManager.addToPage(pageStore, createMessage(), secondTx, Mockito.mock(RouteContextList.class)));
+ secondTx.commit();
+ realJournalStorageManager.afterCompleteOperations(completionFlag(secondCompleted));
+
+ assertFalse(firstCompleted.get());
+ assertFalse(secondCompleted.get());
+
+ allowRunning.countDown();
+
+ // both delayed commits have reached the journal, neither has completed its IO
+ Wait.assertTrue(() -> pendingCommits.size() == 2, 5000, 10);
+
+ assertFalse(Wait.waitFor(firstCompleted::get, 2000, 10),
+ "the completion for the first transaction ran while its commit record was still outstanding: the " +
+ "two page writes' done() calls satisfied the counter its delayed commit had lined up on");
+ assertFalse(secondCompleted.get());
+
+ // completing the commit IO is what should release the callbacks, so the assertion above is not vacuous
+ final List<IOCompletion> toComplete;
+ synchronized (pendingCommits) {
+ toComplete = new ArrayList<>(pendingCommits);
+ }
+ toComplete.forEach(IOCompletion::done);
+
+ Wait.assertTrue(firstCompleted::get, 5000, 10);
+ Wait.assertTrue(secondCompleted::get, 5000, 10);
+ }
+
+ /**
+ * Control for {@link #testDelayedCommitCompletionNotSatisfiedByUnrelatedPageWrites()}: with only one transaction
+ * on the context, a callback registered via {@code afterCompleteOperations} must wait for that transaction's
+ * delayed commit to complete before running. This confirms the timeout used to detect a premature completion in
+ * the sibling test reflects real blocking on the mocked journal, not an artifact of the test setup.
+ */
+ @Test
+ public void testDelayedCommitCompletionWaitsForCommitRecord() throws Exception {
+ OperationContextImpl.clearContext();
+
+ OperationContext sessionContext = OperationContextImpl.getContext(executorFactory);
+ OperationContextImpl.setContext(sessionContext);
+
+ List<IOCompletion> pendingCommits = Collections.synchronizedList(new ArrayList<>());
+ Mockito.doAnswer(a -> {
+ IOCompletion completion = a.getArgument(2);
+ if (completion != null && (Boolean) a.getArgument(3)) {
+ completion.storeLineUp();
+ pendingCommits.add(completion);
+ }
+ return commitCall();
+ }).when(mockMessageJournal).appendCommitRecord(Mockito.anyLong(), Mockito.anyBoolean(), Mockito.any(), Mockito.anyBoolean());
+
+ AtomicBoolean completed = new AtomicBoolean(false);
+
+ TransactionImpl tx = new TransactionImpl(realJournalStorageManager, Integer.MAX_VALUE);
+ tx.setContainsPersistent();
+ assertTrue(realJournalStorageManager.addToPage(pageStore, createMessage(), tx, Mockito.mock(RouteContextList.class)));
+ tx.commit();
+ realJournalStorageManager.afterCompleteOperations(completionFlag(completed));
+
+ allowRunning.countDown();
+
+ Wait.assertTrue(() -> pendingCommits.size() == 1, 5000, 10);
+
+ assertFalse(Wait.waitFor(completed::get, 2000, 10),
+ "the completion ran before the commit record completed");
+
+ pendingCommits.get(0).done();
+
+ Wait.assertTrue(completed::get, 5000, 10);
+ }
+
+ private IOCallback completionFlag(AtomicBoolean flag) {
+ return new IOCallback() {
+ @Override
+ public void done() {
+ flag.set(true);
+ }
+
+ @Override
+ public void onError(int errorCode, String errorMessage) {
+ }
+ };
+ }
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@artemis.apache.org
For additional commands, e-mail: commits-help@artemis.apache.org