@@ -171,9 +171,16 @@ public DriverContext driverContext() {
171171    SubscribableListener <Void > run (TimeValue  maxTime , int  maxIterations , LongSupplier  nowSupplier ) {
172172        updateStatus (0 , 0 , DriverStatus .Status .RUNNING , "driver running" );
173173        long  maxTimeNanos  = maxTime .nanos ();
174+         // Start time, used to stop the calculations after maxTime has passed. 
174175        long  startTime  = nowSupplier .getAsLong ();
176+         // The time of the next forced status update. 
175177        long  nextStatus  = startTime  + statusNanos ;
176-         int  iter  = 0 ;
178+         // Total executed iterations this run, used to stop the calculations after maxIterations have passed. 
179+         int  totalIterationsThisRun  = 0 ;
180+         // The iterations to be reported on the next status update. 
181+         int  iterationsSinceLastStatusUpdate  = 0 ;
182+         // The time passed since the last status update. 
183+         long  lastStatusUpdateTime  = startTime ;
177184        while  (true ) {
178185            IsBlockedResult  isBlocked  = Operator .NOT_BLOCKED ;
179186            try  {
@@ -182,29 +189,33 @@ SubscribableListener<Void> run(TimeValue maxTime, int maxIterations, LongSupplie
182189                closeEarlyFinishedOperators ();
183190                assert  isFinished () : "not finished after early termination" ;
184191            }
185-             iter ++;
192+             totalIterationsThisRun ++;
193+             iterationsSinceLastStatusUpdate ++;
194+ 
195+             long  now  = nowSupplier .getAsLong ();
186196            if  (isBlocked .listener ().isDone () == false ) {
187-                 updateStatus (nowSupplier . getAsLong ()  - startTime ,  iter , DriverStatus .Status .ASYNC , isBlocked .reason ());
197+                 updateStatus (now  - lastStatusUpdateTime ,  iterationsSinceLastStatusUpdate , DriverStatus .Status .ASYNC , isBlocked .reason ());
188198                return  isBlocked .listener ();
189199            }
190200            if  (isFinished ()) {
191-                 finishNanos  = nowSupplier . getAsLong () ;
192-                 updateStatus (finishNanos  - startTime ,  iter , DriverStatus .Status .DONE , "driver done" );
201+                 finishNanos  = now ;
202+                 updateStatus (finishNanos  - lastStatusUpdateTime ,  iterationsSinceLastStatusUpdate , DriverStatus .Status .DONE , "driver done" );
193203                driverContext .finish ();
194204                Releasables .close (releasable , driverContext .getSnapshot ());
195205                return  Operator .NOT_BLOCKED .listener ();
196206            }
197-             long  now  = nowSupplier .getAsLong ();
198-             if  (iter  >= maxIterations ) {
199-                 updateStatus (now  - startTime , iter , DriverStatus .Status .WAITING , "driver iterations" );
207+             if  (totalIterationsThisRun  >= maxIterations ) {
208+                 updateStatus (now  - lastStatusUpdateTime , iterationsSinceLastStatusUpdate , DriverStatus .Status .WAITING , "driver iterations" );
200209                return  Operator .NOT_BLOCKED .listener ();
201210            }
202211            if  (now  - startTime  >= maxTimeNanos ) {
203-                 updateStatus (now  - startTime ,  iter , DriverStatus .Status .WAITING , "driver time" );
212+                 updateStatus (now  - lastStatusUpdateTime ,  iterationsSinceLastStatusUpdate , DriverStatus .Status .WAITING , "driver time" );
204213                return  Operator .NOT_BLOCKED .listener ();
205214            }
206215            if  (now  > nextStatus ) {
207-                 updateStatus (now  - startTime , iter , DriverStatus .Status .RUNNING , "driver running" );
216+                 updateStatus (now  - lastStatusUpdateTime , iterationsSinceLastStatusUpdate , DriverStatus .Status .RUNNING , "driver running" );
217+                 iterationsSinceLastStatusUpdate  = 0 ;
218+                 lastStatusUpdateTime  = now ;
208219                nextStatus  = now  + statusNanos ;
209220            }
210221        }
0 commit comments