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

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

                Author: ASF GitHub Bot
            Created on: 12/Dec/22 18:01
            Start Date: 12/Dec/22 18:01
    Worklog Time Spent: 10m 
      Work Description: clebertsuconic commented on code in PR #4265:
URL: https://github.com/apache/activemq-artemis/pull/4265#discussion_r1046194019


##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageCounterRebuildManager.java:
##########
@@ -0,0 +1,334 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.core.paging.cursor.impl;
+
+import io.netty.util.collection.IntObjectHashMap;
+import io.netty.util.collection.LongObjectHashMap;
+import org.apache.activemq.artemis.core.paging.PagedMessage;
+import org.apache.activemq.artemis.core.paging.PagingStore;
+import org.apache.activemq.artemis.core.paging.cursor.ConsumedPage;
+import org.apache.activemq.artemis.core.paging.cursor.PagePosition;
+import org.apache.activemq.artemis.core.paging.cursor.PageSubscription;
+import org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter;
+import org.apache.activemq.artemis.core.paging.impl.Page;
+import org.apache.activemq.artemis.core.persistence.StorageManager;
+import org.apache.activemq.artemis.utils.collections.LinkedList;
+import org.apache.activemq.artemis.utils.collections.LinkedListIterator;
+import org.apache.activemq.artemis.utils.collections.LongHashSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.invoke.MethodHandles;
+import java.util.function.BiConsumer;
+
+/** this class will copy current data from the Subscriptions, count messages 
while the server is already active
+ * performing other activity */
+public class PageCounterRebuildManager implements Runnable {
+
+   private static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+   private final PagingStore pgStore;
+   private final StorageManager sm;
+   private final LongHashSet transactions;
+
+   public PageCounterRebuildManager(PagingStore store, LongHashSet 
transactions) {
+      // we make a copy of the data because we are allowing data to influx. We 
will consolidate the values at the end
+      initialize(store);
+      this.pgStore = store;
+      this.sm = store.getStorageManager();
+      this.transactions = transactions;
+   }
+
+   boolean paging;
+   long limitPageId;
+   int limitMessageNr;
+
+   LongObjectHashMap<CopiedSubscription> copiedSubscriptionMap = new 
LongObjectHashMap<>();
+
+   private static class CopiedSubscription {
+      CopiedSubscription(PageSubscription subscription) {
+         CopiedSubscription.this.subscriptionCounter = 
subscription.getCounter();
+         CopiedSubscription.this.subscription = subscription;
+      }
+
+      private boolean empty = true;
+
+      LongObjectHashMap<LocalCopiedConsumedPage> consumedPageMap = new 
LongObjectHashMap<>();
+
+      // this is not a copy! This will be the actual object listed in the 
PageSubscription
+      // any changes to this object will reflect in the system and management;
+      PageSubscriptionCounter subscriptionCounter;
+
+      PageSubscription subscription;
+
+      LocalCopiedConsumedPage getPage(long pageNr) {
+         return consumedPageMap.get(pageNr);
+      }
+
+      int addUp;
+      long sizeUp;
+
+   }
+
+   private static class LocalCopiedConsumedPage implements ConsumedPage {
+      boolean done;
+      IntObjectHashMap<Boolean> acks;
+
+      @Override
+      public long getPageId() {
+         // i'm using an assertion instead of always throwing it just because 
it wouldn't be a big deal to call this method
+         // since this is an internal clss;
+         // however I would like to catch it during dev
+         assert false : "Not Implemented";
+         return 0;

Review Comment:
   I wanted to play safe and not throw the error in a production server. I'm 
just changing it to throw RuntimeException now.





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

    Worklog Id:     (was: 832838)
    Time Spent: 1.5h  (was: 1h 20m)

> Option to use non persistent counters in paging. Rebuild them upon start if 
> persistence is disabled on them
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: ARTEMIS-4065
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-4065
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>            Reporter: Clebert Suconic
>            Priority: Major
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> Instead of storing records on journal for counting how many records there are 
> in paging, the system should instead just swipe the paging system in parallel 
> with processing data.
> The changes I'm making will take a snapshot of the current records of paging, 
> and then it will read all the pages to rebuild the counters.
> On tests I am making from a real data server, a system that had a lot of 
> pages (700) needed less than 1 minute to rebuild the counters, and the 
> messages were available to be delivered while the swipe was being done.



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

Reply via email to