@@ -198,9 +198,16 @@ public DriverContext driverContext() {
198198 SubscribableListener <Void > run (TimeValue maxTime , int maxIterations , LongSupplier nowSupplier ) {
199199 updateStatus (0 , 0 , DriverStatus .Status .RUNNING , "driver running" );
200200 long maxTimeNanos = maxTime .nanos ();
201+ // Start time, used to stop the calculations after maxTime has passed.
201202 long startTime = nowSupplier .getAsLong ();
203+ // The time of the next forced status update.
202204 long nextStatus = startTime + statusNanos ;
203- int iter = 0 ;
205+ // Total executed iterations this run, used to stop the calculations after maxIterations have passed.
206+ int totalIterationsThisRun = 0 ;
207+ // The iterations to be reported on the next status update.
208+ int iterationsSinceLastStatusUpdate = 0 ;
209+ // The time passed since the last status update.
210+ long lastStatusUpdateTime = startTime ;
204211 while (true ) {
205212 IsBlockedResult isBlocked = Operator .NOT_BLOCKED ;
206213 try {
@@ -209,29 +216,33 @@ SubscribableListener<Void> run(TimeValue maxTime, int maxIterations, LongSupplie
209216 closeEarlyFinishedOperators ();
210217 assert isFinished () : "not finished after early termination" ;
211218 }
212- iter ++;
219+ totalIterationsThisRun ++;
220+ iterationsSinceLastStatusUpdate ++;
221+
222+ long now = nowSupplier .getAsLong ();
213223 if (isBlocked .listener ().isDone () == false ) {
214- updateStatus (nowSupplier . getAsLong () - startTime , iter , DriverStatus .Status .ASYNC , isBlocked .reason ());
224+ updateStatus (now - lastStatusUpdateTime , iterationsSinceLastStatusUpdate , DriverStatus .Status .ASYNC , isBlocked .reason ());
215225 return isBlocked .listener ();
216226 }
217227 if (isFinished ()) {
218- finishNanos = nowSupplier . getAsLong () ;
219- updateStatus (finishNanos - startTime , iter , DriverStatus .Status .DONE , "driver done" );
228+ finishNanos = now ;
229+ updateStatus (finishNanos - lastStatusUpdateTime , iterationsSinceLastStatusUpdate , DriverStatus .Status .DONE , "driver done" );
220230 driverContext .finish ();
221231 Releasables .close (releasable , driverContext .getSnapshot ());
222232 return Operator .NOT_BLOCKED .listener ();
223233 }
224- long now = nowSupplier .getAsLong ();
225- if (iter >= maxIterations ) {
226- updateStatus (now - startTime , iter , DriverStatus .Status .WAITING , "driver iterations" );
234+ if (totalIterationsThisRun >= maxIterations ) {
235+ updateStatus (now - lastStatusUpdateTime , iterationsSinceLastStatusUpdate , DriverStatus .Status .WAITING , "driver iterations" );
227236 return Operator .NOT_BLOCKED .listener ();
228237 }
229238 if (now - startTime >= maxTimeNanos ) {
230- updateStatus (now - startTime , iter , DriverStatus .Status .WAITING , "driver time" );
239+ updateStatus (now - lastStatusUpdateTime , iterationsSinceLastStatusUpdate , DriverStatus .Status .WAITING , "driver time" );
231240 return Operator .NOT_BLOCKED .listener ();
232241 }
233242 if (now > nextStatus ) {
234- updateStatus (now - startTime , iter , DriverStatus .Status .RUNNING , "driver running" );
243+ updateStatus (now - lastStatusUpdateTime , iterationsSinceLastStatusUpdate , DriverStatus .Status .RUNNING , "driver running" );
244+ iterationsSinceLastStatusUpdate = 0 ;
245+ lastStatusUpdateTime = now ;
235246 nextStatus = now + statusNanos ;
236247 }
237248 }
0 commit comments