tanmayrauth commented on code in PR #1640:
URL: https://github.com/apache/iceberg-go/pull/1640#discussion_r3717179624


##########
catalog/hive/lock.go:
##########
@@ -160,6 +165,60 @@ func calculateBackoff(attempt int, minWait, maxWait 
time.Duration) time.Duration
        return minWait << attempt
 }
 
+// applyJitter spreads a backoff interval by adding a random amount on top of 
it,
+// bounded so the result never exceeds maxWait.
+//
+// calculateBackoff is a pure function of the attempt number and the configured
+// bounds, so every client waiting on the same table lock computes an identical
+// sequence of delays. Contention is the precondition for entering the retry 
loop
+// at all, which means those clients are waiting simultaneously by 
construction:
+// they re-check the lock in lockstep, and each round of CheckLock calls 
arrives
+// at the metastore as a burst. Spreading the wait decorrelates them.
+//
+// The jitter is added rather than subtracted so that the result is never 
shorter
+// than the interval calculateBackoff produced. That keeps the guarantee 
implied
+// by the lock-check-min-wait-time property: a caller who configures a minimum
+// wait never polls sooner than it.
+//
+// Once the backoff saturates at maxWait there is no headroom left to add into.
+// calculateBackoff reaches that point deliberately, so leaving it unjittered
+// would put contending clients back in lockstep for every retry after the
+// sequence tops out. The wait is therefore spread downwards instead, floored 
at

Review Comment:
   Small doc nit: this says the downward spread is "floored at minWait", but 
the code at line 211 floors at max(d/2, minWait) — so the real floor is d/2, 
and minWait only takes over when it's larger than half the interval. Worth  
rewording to "floored at half the interval, or at minWait when minWait exceeds 
half" so a future reader doesn't assume the at-cap wait can fall all the way to 
minWait when it can't.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to