lianetm commented on code in PR #23008:
URL: https://github.com/apache/kafka/pull/23008#discussion_r3777217482
##########
clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java:
##########
@@ -382,6 +401,70 @@ protected RecordAppendResult
updatePartitionInfoOnAppend(RecordAppendResult appe
return appendResult;
}
+ /**
+ * Adds {@code maxTimeToBlock} to {@code nowMs}, capped at {@link
Long#MAX_VALUE} so that a large
+ * {@code max.block.ms} cannot overflow into a deadline in the past.
+ */
+ protected static long appendDeadlineMs(long nowMs, long maxTimeToBlock) {
+ return maxTimeToBlock > Long.MAX_VALUE - nowMs ? Long.MAX_VALUE :
nowMs + maxTimeToBlock;
+ }
+
+ /**
+ * What is left of {@code deadlineMs} to wait for memory. An acquire given
this rather than the raw
+ * {@code max.block.ms} has the time already spent retrying counted
against its wait. Reads the clock, not a
+ * cached {@code nowMs}, which retries that acquired nothing never refresh.
+ * <p>
+ * Only {@link ChunkedRecordAccumulator#append} uses it so far; {@link
#append} still passes the raw value.
+ */
+ protected long remainingTimeToBlockMs(long deadlineMs) {
+ return Math.max(0L, deadlineMs - time.milliseconds());
+ }
+
+ /**
+ * Decide whether an append pass may run, and throw if it may not because
no time is left.
+ * <ul>
+ * <li>the first pass is always allowed — the deadline is not even read,
so an append that completes in one
+ * pass never depends on the clock;</li>
+ * <li>retries are allowed while there is time left before {@code
deadlineMs};</li>
+ * <li>after the deadline, one more retry is allowed, since it may need no
memory at all and
Review Comment:
> If max.block.ms=0, does one more retry guarantee success when the blocking
part is never hit?
no, it doesn;t (this extra allowed was mainly thinking of the case where it
could guarantee success. But agree that it's weird, changed it to the simper
approach : first pass always allowed. Following passes (retries) allowed while
there is time.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]