belliottsmith commented on code in PR #3431:
URL: https://github.com/apache/cassandra/pull/3431#discussion_r1686582824


##########
src/java/org/apache/cassandra/journal/Journal.java:
##########
@@ -112,31 +116,92 @@ public class Journal<K, V> implements Shutdownable
     private final WaitQueue segmentPrepared = newWaitQueue();
     private final WaitQueue allocatorThreadWaitQueue = newWaitQueue();
     private final BooleanSupplier allocatorThreadWaitCondition = () -> 
(availableSegment == null);
+    private final FlusherCallbacks flusherCallbacks;
 
     SequentialExecutorPlus closer;
     //private final Set<Descriptor> invalidations = 
Collections.newSetFromMap(new ConcurrentHashMap<>());
 
+    private class FlusherCallbacks implements Flusher.Callbacks
+    {
+        private final Queue<WaitingFor> waitingFor = new 
ConcurrentLinkedQueue<>();
+
+        @Override
+        public void onFlush(long segment, int position)
+        {
+            Iterator<WaitingFor> iter = waitingFor.iterator();
+            while (iter.hasNext())
+            {
+                WaitingFor wait = iter.next();
+                if (wait.segment == segment && wait.position <= position)
+                {
+                    wait.run();
+                    iter.remove();
+                }
+            }
+        }
+
+        @Override
+        public void onFlushFailed(Throwable cause)
+        {
+            // TODO: panic
+        }
+
+        public void submit(RecordPointer pointer, Runnable runnable)
+        {
+            WaitingFor wait = new WaitingFor(pointer.segment, 
pointer.position, runnable);
+            waitingFor.add(wait);
+            if (isFlushed(pointer))
+                wait.run();
+        }
+    }
+
+    private static class WaitingFor extends RecordPointer implements Runnable
+    {
+        private final AtomicReference<Runnable> onFlushed;

Review Comment:
   It would be nice not to rely on additional atomics here. Is there any reason 
the journal thread won't promptly catch up any that could have run immediately?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to