Search in sources :

Example 1 with TransactionOperationAbstract

use of org.apache.activemq.artemis.core.transaction.TransactionOperationAbstract in project activemq-artemis by apache.

the class PageSubscriptionImpl method cleanupEntries.

/**
 * It will cleanup all the records for completed pages
 */
@Override
public void cleanupEntries(final boolean completeDelete) throws Exception {
    if (completeDelete) {
        counter.delete();
    }
    if (logger.isTraceEnabled()) {
        logger.trace("cleanupEntries", new Exception("trace"));
    }
    Transaction tx = new TransactionImpl(store);
    boolean persist = false;
    final ArrayList<PageCursorInfo> completedPages = new ArrayList<>();
    // First get the completed pages using a lock
    synchronized (consumedPages) {
        // lastAckedPosition = null means no acks were done yet, so we are not ready to cleanup
        if (lastAckedPosition == null) {
            return;
        }
        for (Entry<Long, PageCursorInfo> entry : consumedPages.entrySet()) {
            PageCursorInfo info = entry.getValue();
            if (info.isDone() && !info.isPendingDelete()) {
                Page currentPage = pageStore.getCurrentPage();
                if (currentPage != null && entry.getKey() == pageStore.getCurrentPage().getPageId() && currentPage.isLive()) {
                    logger.trace("We can't clear page " + entry.getKey() + " now since it's the current page");
                } else {
                    info.setPendingDelete();
                    completedPages.add(entry.getValue());
                }
            }
        }
    }
    for (PageCursorInfo infoPG : completedPages) {
        // first will mark the page as complete
        if (isPersistent()) {
            PagePosition completePage = new PagePositionImpl(infoPG.getPageId(), infoPG.getNumberOfMessages());
            infoPG.setCompleteInfo(completePage);
            store.storePageCompleteTransactional(tx.getID(), this.getId(), completePage);
            if (!persist) {
                persist = true;
                tx.setContainsPersistent();
            }
        }
        // it will delete the page ack records
        for (PagePosition pos : infoPG.acks) {
            if (pos.getRecordID() >= 0) {
                store.deleteCursorAcknowledgeTransactional(tx.getID(), pos.getRecordID());
                if (!persist) {
                    // only need to set it once
                    tx.setContainsPersistent();
                    persist = true;
                }
            }
        }
        infoPG.acks.clear();
        infoPG.acks = Collections.synchronizedSet(new LinkedHashSet<PagePosition>());
        infoPG.removedReferences.clear();
        infoPG.removedReferences = new ConcurrentHashSet<>();
    }
    tx.addOperation(new TransactionOperationAbstract() {

        @Override
        public void afterCommit(final Transaction tx1) {
            executor.execute(new Runnable() {

                @Override
                public void run() {
                    if (!completeDelete) {
                        cursorProvider.scheduleCleanup();
                    }
                }
            });
        }
    });
    tx.commit();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Page(org.apache.activemq.artemis.core.paging.impl.Page) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) TransactionOperationAbstract(org.apache.activemq.artemis.core.transaction.TransactionOperationAbstract) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) AtomicLong(java.util.concurrent.atomic.AtomicLong) PagePosition(org.apache.activemq.artemis.core.paging.cursor.PagePosition)

Example 2 with TransactionOperationAbstract

use of org.apache.activemq.artemis.core.transaction.TransactionOperationAbstract in project activemq-artemis by apache.

the class PageSubscriptionCounterImpl method cleanupNonTXCounters.

/**
 * Cleanup temporary page counters on non transactional paged messages
 *
 * @param pageID
 */
@Override
public void cleanupNonTXCounters(final long pageID) throws Exception {
    PendingCounter pendingInfo;
    synchronized (this) {
        pendingInfo = pendingCounters.remove(pageID);
    }
    if (pendingInfo != null) {
        final int valueCleaned = pendingInfo.getCount();
        final long valueSizeCleaned = pendingInfo.getPersistentSize();
        Transaction tx = new TransactionImpl(storage);
        storage.deletePendingPageCounter(tx.getID(), pendingInfo.getId());
        // To apply the increment of the value just being cleaned
        increment(tx, valueCleaned, valueSizeCleaned);
        tx.addOperation(new TransactionOperationAbstract() {

            @Override
            public void afterCommit(Transaction tx) {
                pendingValue.addAndGet(-valueCleaned);
                pendingPersistentSize.updateAndGet(val -> val >= valueSizeCleaned ? val - valueSizeCleaned : 0);
            }
        });
        tx.commit();
    }
}
Also used : AtomicIntegerFieldUpdater(java.util.concurrent.atomic.AtomicIntegerFieldUpdater) PageSubscriptionCounter(org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter) Executor(java.util.concurrent.Executor) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) Logger(org.jboss.logging.Logger) HashMap(java.util.HashMap) AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater) ArrayList(java.util.ArrayList) Page(org.apache.activemq.artemis.core.paging.impl.Page) AtomicLong(java.util.concurrent.atomic.AtomicLong) TransactionOperationAbstract(org.apache.activemq.artemis.core.transaction.TransactionOperationAbstract) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) TransactionOperation(org.apache.activemq.artemis.core.transaction.TransactionOperation) Map(java.util.Map) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) ActiveMQServerLogger(org.apache.activemq.artemis.core.server.ActiveMQServerLogger) LinkedList(java.util.LinkedList) TransactionPropertyIndexes(org.apache.activemq.artemis.core.transaction.TransactionPropertyIndexes) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) TransactionOperationAbstract(org.apache.activemq.artemis.core.transaction.TransactionOperationAbstract)

Aggregations

ArrayList (java.util.ArrayList)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Page (org.apache.activemq.artemis.core.paging.impl.Page)2 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)2 TransactionOperationAbstract (org.apache.activemq.artemis.core.transaction.TransactionOperationAbstract)2 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)2 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Executor (java.util.concurrent.Executor)1 AtomicIntegerFieldUpdater (java.util.concurrent.atomic.AtomicIntegerFieldUpdater)1 AtomicLongFieldUpdater (java.util.concurrent.atomic.AtomicLongFieldUpdater)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 PagePosition (org.apache.activemq.artemis.core.paging.cursor.PagePosition)1 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)1 PageSubscriptionCounter (org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter)1 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)1 ActiveMQServerLogger (org.apache.activemq.artemis.core.server.ActiveMQServerLogger)1 TransactionOperation (org.apache.activemq.artemis.core.transaction.TransactionOperation)1