dcapwell commented on code in PR #101:
URL: https://github.com/apache/cassandra-accord/pull/101#discussion_r1664685496


##########
accord-core/src/main/java/accord/topology/TopologyManager.java:
##########
@@ -371,15 +391,87 @@ private int indexOf(long epoch)
         }
     }
 
+    private static class FutureEpoch
+    {
+        private volatile AsyncResult.Settable<Void> future;
+        private long deadlineMillis;
+
+        public FutureEpoch(long deadlineMillis)
+        {
+            this.future = AsyncResults.settable();
+            this.deadlineMillis = deadlineMillis;
+        }
+
+        /*
+         * Notify any listeners that are waiting for the epoch that is has 
been a long time since
+         * we started waiting for the epoch. We may still eventually get the 
epoch so also create
+         * a new future so subsequent operations may have a chance at seeing 
the epoch if it ever appears.
+         *
+         * Subsequent waiters may get a timeout notification far sooner 
(WATCHDOG_INTERVAL_MILLISS)
+         * instead of EPOCH_INITIAL_TIMEOUT_MILLIS
+         */
+        @GuardedBy("TopologyManager.this")
+        private void timeOutCurrentListeners(long newDeadline, Agent agent)
+        {
+            deadlineMillis = newDeadline;
+            AsyncResult.Settable<Void> oldFuture = future;
+            if (oldFuture.isDone())
+                return;
+            future = AsyncResults.settable();
+            future.addCallback(agent);
+            oldFuture.tryFailure(new Timeout(null, null));
+        }
+    }
+
     private final TopologySorter.Supplier sorter;
+    private final Agent agent;
     private final Id node;
+    private final Scheduler scheduler;
+    private final ToLongFunction<TimeUnit> nowTimeUnit;
     private volatile Epochs epochs;
+    private Scheduler.Scheduled topologyUpdateWatchdog;
+
+    private final LocalConfig localConfig;
 
-    public TopologyManager(TopologySorter.Supplier sorter, Id node)
+    public TopologyManager(TopologySorter.Supplier sorter, Agent agent, Id 
node, Scheduler scheduler, ToLongFunction<TimeUnit> nowTimeUnit, LocalConfig 
localConfig)
     {
         this.sorter = sorter;
+        this.agent = agent;
         this.node = node;
+        this.scheduler = scheduler;
+        this.nowTimeUnit = nowTimeUnit;
         this.epochs = Epochs.EMPTY;
+        this.localConfig = localConfig;
+    }
+
+    public void shutdown()
+    {
+        topologyUpdateWatchdog.cancel();
+    }
+
+    public void scheduleTopologyUpdateWatchdog()

Review Comment:
   thinking about this more, here is an annoying edge case
   
   ```
   awaitEpoch(1) -> timeout is 10s
   ...
   
   // 10 seconds later, but before `scheduleTopologyUpdateWatchdog` is called
   awaitEpoch(1) -> this is going to see a timeout right away rather than 10 
seconds later...
   ```
   
   since timeouts are for the start of the batch, anything that joined *after* 
will timeout much sooner than the timeout window...



-- 
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