zentol commented on a change in pull request #10551: [FLINK-13662][kinesis]
Relax timing requirements
URL: https://github.com/apache/flink/pull/10551#discussion_r360390236
##########
File path:
flink-core/src/main/java/org/apache/flink/api/common/time/Deadline.java
##########
@@ -47,6 +48,19 @@ public Duration timeLeft() {
return Duration.ofNanos(Math.subtractExact(timeNanos,
System.nanoTime()));
}
+ /**
+ * Returns the time left between the deadline and now. If no time is
left, a {@link TimeoutException} will be thrown.
+ *
+ * @throws TimeoutException if no time is left
+ */
+ public Duration timeLeftIfAny() throws TimeoutException {
+ long nanos = Math.subtractExact(timeNanos, System.nanoTime());
+ if (nanos <= 0) {
+ throw new TimeoutException();
+ }
+ return Duration.ofNanos(nanos);
Review comment:
You haven't understood the problem.
Presume that hasTimeLeft() returns true because there's still 1 nanosecond
left. Your subsequent call to timeLeft() may return a value < 0, because time
doesn't stop. This results in you passing in a negative value to sleep() calls
which is commonly rejected with things like IllegalArgumentException, when for
clarity you want to fail with a TimeoutException.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services