From cae253d1367c4d3423670af9c769f7885579b631 Mon Sep 17 00:00:00 2001 From: Francesco Nigro Date: Wed, 17 Oct 2018 15:10:04 +0200 Subject: [PATCH] ARTEMIS-2131 Error compacting journal Compaction cannot free a sliced view of a ByteBuffer on Java >=9: the fix is using the original ByteBuffer instead of the slice to perform a file write and allow it to be correctly released by the Cleaner. --- .../core/journal/impl/AbstractJournalUpdateTask.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractJournalUpdateTask.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractJournalUpdateTask.java index 7740beff48..10f5008f60 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractJournalUpdateTask.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractJournalUpdateTask.java @@ -56,6 +56,8 @@ public abstract class AbstractJournalUpdateTask implements JournalReaderCallback private ActiveMQBuffer writingChannel; + private ByteBuffer bufferWrite; + private final ConcurrentLongHashSet recordsSnapshot; protected final List newDataFiles = new ArrayList<>(); @@ -214,11 +216,17 @@ public abstract class AbstractJournalUpdateTask implements JournalReaderCallback // To Fix the size of the file writingChannel.writerIndex(writingChannel.capacity()); - sequentialFile.writeDirect(writingChannel.toByteBuffer(), true); + bufferWrite.clear() + .position(writingChannel.readerIndex()) + .limit(writingChannel.readableBytes()); + + sequentialFile.writeDirect(bufferWrite, true); sequentialFile.close(); newDataFiles.add(currentFile); } + bufferWrite = null; + writingChannel = null; } @@ -237,7 +245,7 @@ public abstract class AbstractJournalUpdateTask implements JournalReaderCallback protected void openFile() throws Exception { flush(); - ByteBuffer bufferWrite = fileFactory.newBuffer(journal.getFileSize()); + bufferWrite = fileFactory.newBuffer(journal.getFileSize()); writingChannel = ActiveMQBuffers.wrappedBuffer(bufferWrite);