ARTEMIS-2216 Avoid unnecessary page cache queries on ack TX

PageSubscriptionImpl::ackTx is already performing a counter update
using the message persistent size: the size can be reused on
PagePosition::setPersistentSize, avoiding to query the page cache just
to compute it.
This commit is contained in:
Francesco Nigro 2019-01-06 11:48:14 +01:00 committed by Clebert Suconic
parent e541126ca6
commit 47db4714fc
1 changed files with 27 additions and 5 deletions

View File

@ -461,11 +461,22 @@ public final class PageSubscriptionImpl implements PageSubscription {
} }
private void confirmPosition(final Transaction tx, final PagePosition position, final long persistentSize) throws Exception {
// if the cursor is persistent
if (persistent) {
store.storeCursorAcknowledgeTransactional(tx.getID(), cursorId, position);
}
installTXCallback(tx, position, persistentSize);
}
@Override @Override
public void ackTx(final Transaction tx, final PagedReference reference) throws Exception { public void ackTx(final Transaction tx, final PagedReference reference) throws Exception {
confirmPosition(tx, reference.getPosition()); //pre-calculate persistentSize
final long persistentSize = getPersistentSize(reference);
counter.increment(tx, -1, -getPersistentSize(reference)); confirmPosition(tx, reference.getPosition(), persistentSize);
counter.increment(tx, -1, -persistentSize);
PageTransactionInfo txInfo = getPageTransaction(reference); PageTransactionInfo txInfo = getPageTransaction(reference);
if (txInfo != null) { if (txInfo != null) {
@ -864,11 +875,16 @@ public final class PageSubscriptionImpl implements PageSubscription {
return info; return info;
} }
private void installTXCallback(final Transaction tx, final PagePosition position) {
installTXCallback(tx, position, -1);
}
/** /**
* @param tx * @param tx
* @param position * @param position
* @param persistentSize if negative it needs to be calculated on the fly
*/ */
private void installTXCallback(final Transaction tx, final PagePosition position) { private void installTXCallback(final Transaction tx, final PagePosition position, final long persistentSize) {
if (position.getRecordID() >= 0) { if (position.getRecordID() >= 0) {
// It needs to persist, otherwise the cursor will return to the fist page position // It needs to persist, otherwise the cursor will return to the fist page position
tx.setContainsPersistent(); tx.setContainsPersistent();
@ -876,9 +892,15 @@ public final class PageSubscriptionImpl implements PageSubscription {
PageCursorInfo info = getPageInfo(position); PageCursorInfo info = getPageInfo(position);
PageCache cache = info.getCache(); PageCache cache = info.getCache();
long size = 0;
if (cache != null) { if (cache != null) {
size = getPersistentSize(cache.getMessage(position.getMessageNr())); final long size;
if (persistentSize < 0) {
//cache.getMessage is potentially expensive depending
//on the current cache size and which message is queried
size = getPersistentSize(cache.getMessage(position.getMessageNr()));
} else {
size = persistentSize;
}
position.setPersistentSize(size); position.setPersistentSize(size);
} }