From 63e0c0d310850fb59f800d2cc5cf9c5cfc0060ec Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Fri, 9 Feb 2018 11:59:45 -0500 Subject: [PATCH] ARTEMIS-1650 Fixing Testsuite on PageReference Transactions may initialize a PagedReference without a valid message yet during load of prepared transactions. Caching has to be lazy on this case and it should load on demand. --- .../paging/cursor/PagedReferenceImpl.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/PagedReferenceImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/PagedReferenceImpl.java index f5d49cf35a..23f01f9577 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/PagedReferenceImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/PagedReferenceImpl.java @@ -53,11 +53,11 @@ public class PagedReferenceImpl extends LinkedListImpl.Node private Object protocolData; - private final boolean largeMessage; + private Boolean largeMessage; - private final long transactionID; + private long transactionID = -1; - private final long messageID; + private long messageID = -1; private long messageSize = -1; @@ -103,12 +103,19 @@ public class PagedReferenceImpl extends LinkedListImpl.Node this.position = position; this.message = new WeakReference<>(message); this.subscription = subscription; - this.largeMessage = message.getMessage().isLargeMessage(); - this.transactionID = message.getTransactionID(); - this.messageID = message.getMessage().getMessageID(); + if (message != null) { + this.largeMessage = message.getMessage().isLargeMessage(); + this.transactionID = message.getTransactionID(); + this.messageID = message.getMessage().getMessageID(); - //pre-cache the message size so we don't have to reload the message later if it is GC'd - getPersistentSize(); + //pre-cache the message size so we don't have to reload the message later if it is GC'd + getPersistentSize(); + } else { + this.largeMessage = null; + this.transactionID = -1; + this.messageID = -1; + this.messageSize = -1; + } } @Override @@ -272,16 +279,25 @@ public class PagedReferenceImpl extends LinkedListImpl.Node @Override public boolean isLargeMessage() { + if (largeMessage == null && message != null) { + largeMessage = getMessage().isLargeMessage(); + } return largeMessage; } @Override public long getTransactionID() { + if (transactionID < 0) { + transactionID = getPagedMessage().getTransactionID(); + } return transactionID; } @Override public long getMessageID() { + if (messageID < 0) { + messageID = getPagedMessage().getMessage().getMessageID(); + } return messageID; }