|
@@ -171,9 +171,16 @@ public class Driver implements Releasable, Describable {
|
|
SubscribableListener<Void> run(TimeValue maxTime, int maxIterations, LongSupplier nowSupplier) {
|
|
SubscribableListener<Void> run(TimeValue maxTime, int maxIterations, LongSupplier nowSupplier) {
|
|
updateStatus(0, 0, DriverStatus.Status.RUNNING, "driver running");
|
|
updateStatus(0, 0, DriverStatus.Status.RUNNING, "driver running");
|
|
long maxTimeNanos = maxTime.nanos();
|
|
long maxTimeNanos = maxTime.nanos();
|
|
|
|
+ // Start time, used to stop the calculations after maxTime has passed.
|
|
long startTime = nowSupplier.getAsLong();
|
|
long startTime = nowSupplier.getAsLong();
|
|
|
|
+ // The time of the next forced status update.
|
|
long nextStatus = startTime + statusNanos;
|
|
long nextStatus = startTime + statusNanos;
|
|
- int iter = 0;
|
|
|
|
|
|
+ // Total executed iterations this run, used to stop the calculations after maxIterations have passed.
|
|
|
|
+ int totalIterationsThisRun = 0;
|
|
|
|
+ // The iterations to be reported on the next status update.
|
|
|
|
+ int iterationsSinceLastStatusUpdate = 0;
|
|
|
|
+ // The time passed since the last status update.
|
|
|
|
+ long lastStatusUpdateTime = startTime;
|
|
while (true) {
|
|
while (true) {
|
|
IsBlockedResult isBlocked = Operator.NOT_BLOCKED;
|
|
IsBlockedResult isBlocked = Operator.NOT_BLOCKED;
|
|
try {
|
|
try {
|
|
@@ -182,29 +189,33 @@ public class Driver implements Releasable, Describable {
|
|
closeEarlyFinishedOperators();
|
|
closeEarlyFinishedOperators();
|
|
assert isFinished() : "not finished after early termination";
|
|
assert isFinished() : "not finished after early termination";
|
|
}
|
|
}
|
|
- iter++;
|
|
|
|
|
|
+ totalIterationsThisRun++;
|
|
|
|
+ iterationsSinceLastStatusUpdate++;
|
|
|
|
+
|
|
|
|
+ long now = nowSupplier.getAsLong();
|
|
if (isBlocked.listener().isDone() == false) {
|
|
if (isBlocked.listener().isDone() == false) {
|
|
- updateStatus(nowSupplier.getAsLong() - startTime, iter, DriverStatus.Status.ASYNC, isBlocked.reason());
|
|
|
|
|
|
+ updateStatus(now - lastStatusUpdateTime, iterationsSinceLastStatusUpdate, DriverStatus.Status.ASYNC, isBlocked.reason());
|
|
return isBlocked.listener();
|
|
return isBlocked.listener();
|
|
}
|
|
}
|
|
if (isFinished()) {
|
|
if (isFinished()) {
|
|
- finishNanos = nowSupplier.getAsLong();
|
|
|
|
- updateStatus(finishNanos - startTime, iter, DriverStatus.Status.DONE, "driver done");
|
|
|
|
|
|
+ finishNanos = now;
|
|
|
|
+ updateStatus(finishNanos - lastStatusUpdateTime, iterationsSinceLastStatusUpdate, DriverStatus.Status.DONE, "driver done");
|
|
driverContext.finish();
|
|
driverContext.finish();
|
|
Releasables.close(releasable, driverContext.getSnapshot());
|
|
Releasables.close(releasable, driverContext.getSnapshot());
|
|
return Operator.NOT_BLOCKED.listener();
|
|
return Operator.NOT_BLOCKED.listener();
|
|
}
|
|
}
|
|
- long now = nowSupplier.getAsLong();
|
|
|
|
- if (iter >= maxIterations) {
|
|
|
|
- updateStatus(now - startTime, iter, DriverStatus.Status.WAITING, "driver iterations");
|
|
|
|
|
|
+ if (totalIterationsThisRun >= maxIterations) {
|
|
|
|
+ updateStatus(now - lastStatusUpdateTime, iterationsSinceLastStatusUpdate, DriverStatus.Status.WAITING, "driver iterations");
|
|
return Operator.NOT_BLOCKED.listener();
|
|
return Operator.NOT_BLOCKED.listener();
|
|
}
|
|
}
|
|
if (now - startTime >= maxTimeNanos) {
|
|
if (now - startTime >= maxTimeNanos) {
|
|
- updateStatus(now - startTime, iter, DriverStatus.Status.WAITING, "driver time");
|
|
|
|
|
|
+ updateStatus(now - lastStatusUpdateTime, iterationsSinceLastStatusUpdate, DriverStatus.Status.WAITING, "driver time");
|
|
return Operator.NOT_BLOCKED.listener();
|
|
return Operator.NOT_BLOCKED.listener();
|
|
}
|
|
}
|
|
if (now > nextStatus) {
|
|
if (now > nextStatus) {
|
|
- updateStatus(now - startTime, iter, DriverStatus.Status.RUNNING, "driver running");
|
|
|
|
|
|
+ updateStatus(now - lastStatusUpdateTime, iterationsSinceLastStatusUpdate, DriverStatus.Status.RUNNING, "driver running");
|
|
|
|
+ iterationsSinceLastStatusUpdate = 0;
|
|
|
|
+ lastStatusUpdateTime = now;
|
|
nextStatus = now + statusNanos;
|
|
nextStatus = now + statusNanos;
|
|
}
|
|
}
|
|
}
|
|
}
|