From 63577c7264799add9fcec5d10751eb0e080f1eba Mon Sep 17 00:00:00 2001 From: franz1981 Date: Tue, 27 Jul 2021 15:34:13 +0200 Subject: [PATCH] ARTEMIS-3405 Log the end of paging mode for a destination --- .../core/paging/impl/PagingStoreImpl.java | 12 +++-- .../core/server/ActiveMQServerLogger.java | 4 ++ .../core/paging/impl/PagingStoreImplTest.java | 50 +++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) 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 f7e0186fc3..bec3f54b1b 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 @@ -506,7 +506,11 @@ public class PagingStoreImpl implements PagingStore { public void stopPaging() { lock.writeLock().lock(); try { - paging = false; + final boolean isPaging = this.paging; + if (isPaging) { + paging = false; + ActiveMQServerLogger.LOGGER.pageStoreStop(storeName, sizeInBytes.get(), maxSize, pagingManager.getGlobalSize()); + } this.cursorProvider.onPageModeCleared(); } finally { lock.writeLock().unlock(); @@ -549,8 +553,8 @@ public class PagingStoreImpl implements PagingStore { return false; } } - paging = true; + ActiveMQServerLogger.LOGGER.pageStoreStart(storeName, sizeInBytes.get(), maxSize, pagingManager.getGlobalSize()); return true; } finally { @@ -762,9 +766,7 @@ public class PagingStoreImpl implements PagingStore { } else if (addressFullMessagePolicy == AddressFullMessagePolicy.PAGE) { if (size > 0) { if (maxSize != -1 && newSize > maxSize || globalFull) { - if (startPaging()) { - ActiveMQServerLogger.LOGGER.pageStoreStart(storeName, newSize, maxSize, pagingManager.getGlobalSize()); - } + startPaging(); } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java index 03add71e45..bc415edb5f 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java @@ -2146,4 +2146,8 @@ public interface ActiveMQServerLogger extends BasicLogger { @LogMessage(level = Logger.Level.INFO) @Message(id = 224107, value = "The Critical Analyzer detected slow paths on the broker. It is recommended that you enable trace logs on org.apache.activemq.artemis.utils.critical while you troubleshoot this issue. You should disable the trace logs when you have finished troubleshooting.", format = Message.Format.MESSAGE_FORMAT) void enableTraceForCriticalAnalyzer(); + + @LogMessage(level = Logger.Level.WARN) + @Message(id = 224108, value = "Stopped paging on address ''{0}''; size is currently: {1} bytes; max-size-bytes: {2}; global-size-bytes: {3}", format = Message.Format.MESSAGE_FORMAT) + void pageStoreStop(SimpleString storeName, long addressSize, long maxSize, long globalMaxSize); } diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java index 7867b7c805..7101f327f1 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java @@ -56,6 +56,7 @@ import org.apache.activemq.artemis.core.server.impl.RoutingContextImpl; import org.apache.activemq.artemis.core.settings.HierarchicalRepository; import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; +import org.apache.activemq.artemis.logs.AssertionLoggerHandler; import org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessagePersister; import org.apache.activemq.artemis.spi.core.protocol.MessagePersister; import org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory; @@ -71,6 +72,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import static org.apache.activemq.artemis.logs.AssertionLoggerHandler.findText; + public class PagingStoreImplTest extends ActiveMQTestBase { private static final Logger log = Logger.getLogger(PagingStoreImplTest.class); @@ -802,6 +805,53 @@ public class PagingStoreImplTest extends ActiveMQTestBase { storeImpl.stop(); } + @Test + public void testLogStartPaging() throws Exception { + SequentialFileFactory factory = new FakeSequentialFileFactory(); + + PagingStoreFactory storeFactory = new FakeStoreFactory(factory); + + PagingStoreImpl store = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, + createMockManager(), createStorageManagerMock(), factory, storeFactory, + PagingStoreImplTest.destinationTestName, + new AddressSettings() + .setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), + getExecutorFactory().getExecutor(), true); + + store.start(); + AssertionLoggerHandler.startCapture(); + try { + store.startPaging(); + store.stopPaging(); + Assert.assertTrue(findText("AMQ222038")); + } finally { + AssertionLoggerHandler.stopCapture(); + } + } + + @Test + public void testLogStopPaging() throws Exception { + SequentialFileFactory factory = new FakeSequentialFileFactory(); + + PagingStoreFactory storeFactory = new FakeStoreFactory(factory); + + PagingStoreImpl store = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, + createMockManager(), createStorageManagerMock(), factory, storeFactory, + PagingStoreImplTest.destinationTestName, + new AddressSettings() + .setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), + getExecutorFactory().getExecutor(), true); + store.start(); + AssertionLoggerHandler.startCapture(); + try { + store.startPaging(); + store.stopPaging(); + Assert.assertTrue(findText("AMQ224108")); + } finally { + AssertionLoggerHandler.stopCapture(); + } + } + /** * @return */