From 4b49b3f3713001c94e5efeca017d8a9f3db499f3 Mon Sep 17 00:00:00 2001 From: Benjamin Graf Date: Mon, 23 Mar 2020 13:10:12 +0100 Subject: [PATCH] ARTEMIS-975: Add transactional records to deletedRecords to check for committed transactions that also hold references to --- .../artemis/jdbc/store/journal/JDBCJournalImpl.java | 1 + .../jdbc/store/journal/JDBCJournalTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/journal/JDBCJournalImpl.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/journal/JDBCJournalImpl.java index cde361e126..181a61c419 100644 --- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/journal/JDBCJournalImpl.java +++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/journal/JDBCJournalImpl.java @@ -232,6 +232,7 @@ public class JDBCJournalImpl extends AbstractJDBCDriver implements Journal { holder = transactions.get(record.getTxId()); for (RecordInfo info : holder.recordsToDelete) { deletedRecords.add(record.getId()); + deletedRecords.add(info.id); deleteJournalRecords.setLong(1, info.id); deleteJournalRecords.addBatch(); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jdbc/store/journal/JDBCJournalTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jdbc/store/journal/JDBCJournalTest.java index 0b832a8507..46a102752b 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jdbc/store/journal/JDBCJournalTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jdbc/store/journal/JDBCJournalTest.java @@ -178,6 +178,19 @@ public class JDBCJournalTest extends ActiveMQTestBase { assertEquals(0, journal.getNumberOfRecords()); } + @Test + public void testCleanupTxRecords4TransactionalRecords() throws Exception { + // add committed transactional record e.g. paging + journal.appendAddRecordTransactional(152, 154, (byte) 13, new byte[0]); + journal.appendCommitRecord(152, true); + assertEquals(2, journal.getNumberOfRecords()); + + // delete transactional record in new transaction e.g. depaging + journal.appendDeleteRecordTransactional(236, 154); + journal.appendCommitRecord(236, true); + assertEquals(0, journal.getNumberOfRecords()); + } + @Test public void testCallbacks() throws Exception { final int noRecords = 10;