[ 
https://issues.apache.org/jira/browse/ARTEMIS-4505?focusedWorklogId=890800&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-890800
 ]

ASF GitHub Bot logged work on ARTEMIS-4505:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 15/Nov/23 21:28
            Start Date: 15/Nov/23 21:28
    Worklog Time Spent: 10m 
      Work Description: tabish121 commented on code in PR #4677:
URL: https://github.com/apache/activemq-artemis/pull/4677#discussion_r1394823587


##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingManagerImpl.java:
##########
@@ -583,22 +591,65 @@ public void forEachTransaction(BiConsumer<Long, 
PageTransactionInfo> transaction
    public Future<Object> rebuildCounters(Set<Long> storedLargeMessages) {
       Map<Long, PageTransactionInfo> transactionsSet = new LongObjectHashMap();
       // making a copy
-      transactions.forEach(transactionsSet::put);
+      transactions.forEach((a, b) -> {
+         transactionsSet.put(a, b);
+         b.setOrphaned(true);
+      });
+      AtomicLong minLargeMessageID = new AtomicLong(Long.MAX_VALUE);
+
+      // make a copy of the stores
+      Map<SimpleString, PagingStore> currentStoreMap = new HashMap<>();
+      stores.forEach(currentStoreMap::put);
 
       if (logger.isDebugEnabled()) {
          logger.debug("Page Transactions during rebuildCounters:");
          transactionsSet.forEach((a, b) -> logger.debug("{} = {}", a, b));
       }
 
-      stores.forEach((address, pgStore) -> {
-         PageCounterRebuildManager rebuildManager = new 
PageCounterRebuildManager(this, pgStore, transactionsSet, storedLargeMessages);
+      currentStoreMap.forEach((address, pgStore) -> {
+         PageCounterRebuildManager rebuildManager = new 
PageCounterRebuildManager(this, pgStore, transactionsSet, storedLargeMessages, 
minLargeMessageID);
          logger.debug("Setting destination {} to rebuild counters", address);
          managerExecutor.execute(rebuildManager);
       });
 
+      managerExecutor.execute(() -> cleanupPageTransactions(transactionsSet, 
currentStoreMap));
+
       FutureTask<Object> task = new FutureTask<>(() -> null);
       managerExecutor.execute(task);
 
       return task;
    }
+
+   private void cleanupPageTransactions(Map<Long, PageTransactionInfo> 
transactionSet, Map<SimpleString, PagingStore> currentStoreMap) {
+      if (server == null) {
+         logger.warn("Server attribute was not set, cannot proceed with page 
transaction cleanup");
+      }
+      AtomicBoolean proceed = new AtomicBoolean(true);
+      currentStoreMap.forEach((a, b) -> {
+         if (!b.getCursorProvider().isRebuildDone()) {
+            logger.warn("cannot proceed on cleaning up page transactions as 
page cursor for {} is not done rebuilding it", b.getAddress());
+            proceed.set(false);
+         }
+      });
+
+      if (!proceed.get()) {

Review Comment:
   Might be worth a comment explaining the thinking as I stared at it for 
awhile trying to figure out where it was being restarted etc. 





Issue Time Tracking
-------------------

    Worklog Id:     (was: 890800)
    Time Spent: 50m  (was: 40m)

> Cleanup page transactions in case paged files were removed
> ----------------------------------------------------------
>
>                 Key: ARTEMIS-4505
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-4505
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>    Affects Versions: 2.31.2
>            Reporter: Clebert Suconic
>            Assignee: Clebert Suconic
>            Priority: Major
>             Fix For: 2.32.0
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Say you removed page files. Their page transactions will now leak forever in 
> the journal.
> I'm adding a check at startup time to clear them up.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to