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/activemq-artemis.git
commit 22540cc3ab5802e1b3019f55791a20e5adca8983 Author: Clebert Suconic <[email protected]> AuthorDate: Mon May 13 11:57:30 2024 -0400 ARTEMIS-4773 Performance improvement on page.sync the sync should be called outside of the lock. if the file was already closed it should then just be ignored as the data was locked anyway. --- .../apache/activemq/artemis/core/paging/impl/Page.java | 16 ++++++++++++++++ .../artemis/core/paging/impl/PagingStoreImpl.java | 10 ++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java index 8e919fb670..b2c01852a8 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java @@ -16,7 +16,9 @@ */ package org.apache.activemq.artemis.core.paging.impl; +import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; @@ -196,6 +198,20 @@ public final class Page { file.sync(); } + public void trySync() throws IOException { + try { + if (file.isOpen()) { + file.sync(); + } + } catch (IOException e) { + if (e instanceof ClosedChannelException) { + logger.debug("file.sync on file {} thrown a ClosedChannelException that will just be ignored", file.getFileName()); + } else { + throw e; + } + } + } + public boolean isOpen() { return file != null && file.isOpen(); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java index 3b60ef2f06..63baad12c4 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java @@ -515,16 +515,18 @@ public class PagingStoreImpl implements PagingStore { @Override public void ioSync() throws Exception { if (!fileFactory.supportsIndividualContext()) { + Page page; lock.readLock().lock(); try { - final Page page = currentPage; - if (page != null) { - page.sync(); - } + page = currentPage; } finally { lock.readLock().unlock(); } + + if (page != null) { + page.trySync(); + } } }
