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();
}
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();
}
}
Aggregations