@@ -182,9 +182,16 @@ public DriverContext driverContext() {
182182    SubscribableListener <Void > run (TimeValue  maxTime , int  maxIterations , LongSupplier  nowSupplier ) {
183183        updateStatus (0 , 0 , DriverStatus .Status .RUNNING , "driver running" );
184184        long  maxTimeNanos  = maxTime .nanos ();
185+         // Start time, used to stop the calculations after maxTime has passed. 
185186        long  startTime  = nowSupplier .getAsLong ();
187+         // The time of the next forced status update. 
186188        long  nextStatus  = startTime  + statusNanos ;
187-         int  iter  = 0 ;
189+         // Total executed iterations this run, used to stop the calculations after maxIterations have passed. 
190+         int  totalIterationsThisRun  = 0 ;
191+         // The iterations to be reported on the next status update. 
192+         int  iterationsSinceLastStatusUpdate  = 0 ;
193+         // The time passed since the last status update. 
194+         long  lastStatusUpdateTime  = startTime ;
188195        while  (true ) {
189196            IsBlockedResult  isBlocked  = Operator .NOT_BLOCKED ;
190197            try  {
@@ -193,29 +200,33 @@ SubscribableListener<Void> run(TimeValue maxTime, int maxIterations, LongSupplie
193200                closeEarlyFinishedOperators ();
194201                assert  isFinished () : "not finished after early termination" ;
195202            }
196-             iter ++;
203+             totalIterationsThisRun ++;
204+             iterationsSinceLastStatusUpdate ++;
205+ 
206+             long  now  = nowSupplier .getAsLong ();
197207            if  (isBlocked .listener ().isDone () == false ) {
198-                 updateStatus (nowSupplier . getAsLong ()  - startTime ,  iter , DriverStatus .Status .ASYNC , isBlocked .reason ());
208+                 updateStatus (now  - lastStatusUpdateTime ,  iterationsSinceLastStatusUpdate , DriverStatus .Status .ASYNC , isBlocked .reason ());
199209                return  isBlocked .listener ();
200210            }
201211            if  (isFinished ()) {
202-                 finishNanos  = nowSupplier . getAsLong () ;
203-                 updateStatus (finishNanos  - startTime ,  iter , DriverStatus .Status .DONE , "driver done" );
212+                 finishNanos  = now ;
213+                 updateStatus (finishNanos  - lastStatusUpdateTime ,  iterationsSinceLastStatusUpdate , DriverStatus .Status .DONE , "driver done" );
204214                driverContext .finish ();
205215                Releasables .close (releasable , driverContext .getSnapshot ());
206216                return  Operator .NOT_BLOCKED .listener ();
207217            }
208-             long  now  = nowSupplier .getAsLong ();
209-             if  (iter  >= maxIterations ) {
210-                 updateStatus (now  - startTime , iter , DriverStatus .Status .WAITING , "driver iterations" );
218+             if  (totalIterationsThisRun  >= maxIterations ) {
219+                 updateStatus (now  - lastStatusUpdateTime , iterationsSinceLastStatusUpdate , DriverStatus .Status .WAITING , "driver iterations" );
211220                return  Operator .NOT_BLOCKED .listener ();
212221            }
213222            if  (now  - startTime  >= maxTimeNanos ) {
214-                 updateStatus (now  - startTime ,  iter , DriverStatus .Status .WAITING , "driver time" );
223+                 updateStatus (now  - lastStatusUpdateTime ,  iterationsSinceLastStatusUpdate , DriverStatus .Status .WAITING , "driver time" );
215224                return  Operator .NOT_BLOCKED .listener ();
216225            }
217226            if  (now  > nextStatus ) {
218-                 updateStatus (now  - startTime , iter , DriverStatus .Status .RUNNING , "driver running" );
227+                 updateStatus (now  - lastStatusUpdateTime , iterationsSinceLastStatusUpdate , DriverStatus .Status .RUNNING , "driver running" );
228+                 iterationsSinceLastStatusUpdate  = 0 ;
229+                 lastStatusUpdateTime  = now ;
219230                nextStatus  = now  + statusNanos ;
220231            }
221232        }
0 commit comments