yifan-c commented on code in PR #192:
URL: https://github.com/apache/cassandra-sidecar/pull/192#discussion_r1955326939


##########
server/src/main/java/org/apache/cassandra/sidecar/tasks/PeriodicTaskExecutor.java:
##########
@@ -130,22 +147,33 @@ private void schedule(PeriodicTaskKey key, long 
priorExecDurationMillis, long de
      */
     private void executeAndScheduleNext(PeriodicTaskKey key, long execCount)
     {
+        Promise<Void> runPromise = Promise.promise();
+        if (activeRuns.computeIfAbsent(key, k -> runPromise.future()) != 
runPromise)
+        {
+            LOGGER.debug("already active. task='{}' execCount={}", key, 
execCount);
+            return;
+        }
         long startTime = System.nanoTime();
-        internalPool.<Void>executeBlocking(promise -> executeInternal(promise, 
key, execCount), false)
-                    .onComplete(ignored -> {
-                        LOGGER.debug("Task run finishes. task='{}' 
execCount={}", key, execCount);
-                        // schedule the next run iff the task is not killed
-                        if (poisonPilledTasks.remove(key))
+        internalPool.<Result>executeBlocking(promise -> 
executeInternal(promise, key, execCount), false)
+                    .onComplete(outcome -> {
+                        LOGGER.debug("Task run finishes. task='{}' outcome={} 
execCount={}", key, outcome, execCount);
+                        runPromise.complete(); // mark the completion, 
regardless of the result from last run
+                        activeRuns.remove(key);
+
+                        DurationSpec delay;
+                        long priorExecutionDurationMillis;
+                        if (outcome.result() == Result.RESCHEDULED)
+                        {
+                            priorExecutionDurationMillis = 0;
+                            delay = key.task.initialDelay();

Review Comment:
   Yes. It is to implement the semantics of "reschedule". When it is 
rescheduled, the first run the rescheduled task take the `initialDelay`. It is 
consistent with the prior `reschedule` method. 



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