belliottsmith commented on code in PR #226:
URL: https://github.com/apache/cassandra-accord/pull/226#discussion_r2222739821


##########
accord-core/src/main/java/accord/impl/progresslog/DefaultProgressLog.java:
##########
@@ -466,40 +484,67 @@ public void invalidIfUncommitted(TxnId txnId)
     @Override
     public void accept(@Nullable SafeCommandStore safeStore)
     {
+        if (stopped || processing)
+            return;
+
         long nowMicros = node.elapsed(TimeUnit.MICROSECONDS);
+        processing = true;
         try
         {
-            if (DefaultProgressLogs.pauseForTest(this))
+            processAwaitingEpoch();
+            try (BufferList<TxnState> preRunBuffer = new BufferList<>())
             {
-                logger.info("Skipping progress log because it is paused for 
test");
-                return;
-            }
-
-            try (BufferList<RunInvoker> readyToRun = safeStore == null ? null 
: new BufferList<>())
-            {
-                processAwaitingEpoch(safeStore, readyToRun);
                 // drain to a buffer to avoid reentrancy in timers
-                runBuffer = EMPTY_RUN_BUFFER;
-                runBufferCount = 0;
-                timers.advance(nowMicros, this, 
DefaultProgressLog::addToRunBuffer);
-                processRunBuffer(safeStore, nowMicros, readyToRun);
-                cachedAny().forceDiscard(runBuffer, runBufferCount);
-                processReadyToRun(safeStore, readyToRun);
+                timers.advance(nowMicros, preRunBuffer, BufferList::add);
+                updateRunBuffer(nowMicros, preRunBuffer);
             }
+            processRunBuffer(safeStore);
+
             if (awaitingEpochBufferCount > 0)
                 rerunWithPendingEpoch();
         }
         catch (Throwable t)
         {
             node.agent().onUncaughtException(t);
         }
+        finally
+        {
+            processing = false;
+        }
     }
 
-    private void addToRunBuffer(TxnState add)
+    private void addToRunBuffer(RunInvoker readyToRun)
     {
         if (runBufferCount == runBuffer.length)
-            runBuffer = cachedAny().resize(runBuffer, runBufferCount, 
Math.max(8, runBuffer.length * 2));
-        runBuffer[runBufferCount++] = add;
+        {
+            int newCount = runBufferCount - runBufferIndex;
+            Object[] newBuffer = cachedAny().get(Math.max(8, newCount * 2));
+            replaceRunBuffer(newBuffer);
+        }
+        runBuffer[runBufferCount++] = readyToRun;
+    }
+
+    private void replaceRunBuffer(Object[] newBuffer)
+    {
+        Object[] prevBuffer = runBuffer;
+        int prevCount = runBufferCount;
+        int newCount = prevCount - runBufferIndex;
+        System.arraycopy(prevBuffer, runBufferIndex, newBuffer, 0, newCount);
+        runBuffer = newBuffer;
+        runBufferIndex = 0;
+        runBufferCount = newCount;
+        if (prevBuffer.length >= ArrayBuffers.MIN_BUFFER_SIZE)
+            cachedAny().forceDiscard(prevBuffer, prevCount);
+    }
+
+    private void maybeShrinkRunBuffer()
+    {
+        if (runBuffer.length >= (runBufferCount - runBufferIndex)/2)

Review Comment:
   Oh, whoops. Good catch.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to