From 90ca87c5e16df9812a65db37d05306f444dd7fb1 Mon Sep 17 00:00:00 2001 From: Howard Gao Date: Fri, 14 Sep 2018 10:52:02 +0800 Subject: [PATCH] ARTEMIS-2088 - Page.write() should throw exception if file is closed In Page.write(final PagedMessage message) if the page file is closed it returns silently. The caller has no way to know that if the message is paged to file or not. It should throw an exception so that the caller can handle it correctly. This causes random failure PagingTest#testExpireLargeMessageOnPaging(). The test shows that when the server stops it closes the page file. In the mean time a message is expired to the expiry queue and if the expiry queue is in paging mode, it goes to Page.write() and returns without any error. The result is that the message is removed from the original queue and not added to the expiry queue. If we throw exception here it makes the expiration failed, the message will not be removed from the orginal queue. Next time broker is started, the message will be reloaded and expired again. no message lost. --- .../org/apache/activemq/artemis/core/paging/impl/Page.java | 2 +- .../activemq/artemis/core/server/ActiveMQMessageBundle.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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 dfe73873ad..c8fbb3d944 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 @@ -223,7 +223,7 @@ public final class Page implements Comparable { public synchronized void write(final PagedMessage message) throws Exception { if (!file.isOpen()) { - return; + throw ActiveMQMessageBundle.BUNDLE.cannotWriteToClosedFile(file); } final int messageEncodedSize = message.getEncodeSize(); final int bufferSize = messageEncodedSize + Page.SIZE_RECORD; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java index 5d94da79c4..d649d8da02 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java @@ -44,6 +44,7 @@ import org.apache.activemq.artemis.api.core.ActiveMQUnexpectedRoutingTypeForAddr import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.core.io.SequentialFile; import org.apache.activemq.artemis.core.postoffice.Binding; import org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationSyncFileMessage; import org.apache.activemq.artemis.core.security.CheckType; @@ -444,4 +445,8 @@ public interface ActiveMQMessageBundle { @Message(id = 229216, value = "Invalid queue name: {0}", format = Message.Format.MESSAGE_FORMAT) ActiveMQIllegalStateException invalidQueueName(SimpleString queueName); + + @Message(id = 119217, value = "Can't write to closed file: {0}", format = Message.Format.MESSAGE_FORMAT) + ActiveMQIOErrorException cannotWriteToClosedFile(SequentialFile file); + }