Repository: activemq-artemis Updated Branches: refs/heads/2.6.x af98efd58 -> e358fbde6
ARTEMIS-2090 JDBC Journal is not deleting TX records JDBCJournalImpl::cleanupTxRecords is not committing the deleteJournalTxRecords statement leaving the TX records into the journal (cherry picked from commit cfa3290209ae6eddc88808e8c0c391e3d4f54be8) Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/e358fbde Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/e358fbde Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/e358fbde Branch: refs/heads/2.6.x Commit: e358fbde6610c6a7fbfa69650741cab0a5be3d46 Parents: af98efd Author: Francesco Nigro <[email protected]> Authored: Fri Sep 14 17:22:53 2018 +0200 Committer: Clebert Suconic <[email protected]> Committed: Wed Sep 19 15:32:24 2018 -0400 ---------------------------------------------------------------------- .../artemis/jdbc/store/journal/JDBCJournalImpl.java | 12 +++++++++--- .../integration/jdbc/store/journal/JDBCJournalTest.java | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/e358fbde/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/journal/JDBCJournalImpl.java ---------------------------------------------------------------------- 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 e450620..aa9ee8d 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 @@ -252,7 +252,11 @@ public class JDBCJournalImpl extends AbstractJDBCDriver implements Journal { logger.trace("JDBC commit worked"); } - cleanupTxRecords(deletedRecords, committedTransactions); + if (cleanupTxRecords(deletedRecords, committedTransactions)) { + deleteJournalTxRecords.executeBatch(); + connection.commit(); + logger.trace("JDBC commit worked on cleanupTxRecords"); + } executeCallbacks(recordRef, true); return recordRef.size(); @@ -292,7 +296,7 @@ public class JDBCJournalImpl extends AbstractJDBCDriver implements Journal { /* We store Transaction reference in memory (once all records associated with a Tranascation are Deleted, we remove the Tx Records (i.e. PREPARE, COMMIT). */ - private synchronized void cleanupTxRecords(List<Long> deletedRecords, List<Long> committedTx) throws SQLException { + private synchronized boolean cleanupTxRecords(List<Long> deletedRecords, List<Long> committedTx) throws SQLException { List<RecordInfo> iterableCopy; List<TransactionHolder> iterableCopyTx = new ArrayList<>(); iterableCopyTx.addAll(transactions.values()); @@ -300,7 +304,7 @@ public class JDBCJournalImpl extends AbstractJDBCDriver implements Journal { for (Long txId : committedTx) { transactions.get(txId).committed = true; } - + boolean hasDeletedJournalTxRecords = false; // TODO (mtaylor) perhaps we could store a reverse mapping of IDs to prevent this O(n) loop for (TransactionHolder h : iterableCopyTx) { @@ -316,9 +320,11 @@ public class JDBCJournalImpl extends AbstractJDBCDriver implements Journal { if (h.recordInfos.isEmpty() && h.committed) { deleteJournalTxRecords.setLong(1, h.transactionID); deleteJournalTxRecords.addBatch(); + hasDeletedJournalTxRecords = true; transactions.remove(h.transactionID); } } + return hasDeletedJournalTxRecords; } private void executeCallbacks(final List<JDBCJournalRecord> records, final boolean success) { http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/e358fbde/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jdbc/store/journal/JDBCJournalTest.java ---------------------------------------------------------------------- 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 1661df9..018a3de 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 @@ -130,6 +130,13 @@ public class JDBCJournalTest extends ActiveMQTestBase { } @Test + public void testCleanupTxRecords() throws Exception { + journal.appendDeleteRecordTransactional(1, 1); + journal.appendCommitRecord(1, true); + assertEquals(0, journal.getNumberOfRecords()); + } + + @Test public void testCallbacks() throws Exception { final int noRecords = 10; final CountDownLatch done = new CountDownLatch(noRecords);
