revert: [OCISDEV-855] drop persist-retry wall-clock budget, it cancels sibling cache writes via errgroup

This commit is contained in:
Michal Klos committed 2026-10-20 09:21:52 +02:00
1 parent 59514d9332
commit 2b19ad150c
1 file changed
+7 -25
@@ -232,31 +232,17 @@ func isSyncTransient(err error) bool {
return isTooEarly || isUnavailable
}
// persistRetryBudget bounds the whole CAS-conflict retry/resync dance by
// wall-clock time, so repeated per-attempt backoffs can't accumulate into a
// large tail for one request even though each attempt is individually capped.
const persistRetryBudget = 300 * time.Millisecond
func (c *Cache) retryPersist(ctx context.Context, userID, spaceID string, persistFunc func() error) error {
log := appctx.GetLogger(ctx).With().
Str("hostname", os.Getenv("HOSTNAME")).
Str("userID", userID).
Str("spaceID", spaceID).Logger()
persistCtx, cancel := context.WithTimeout(ctx, persistRetryBudget)
defer cancel()
var err error
for attempt := 0; attempt < 20; attempt++ {
select {
case <-persistCtx.Done():
if ctx.Err() != nil {
return ctx.Err()
}
if err != nil {
return err
}
return persistCtx.Err()
case <-ctx.Done():
return ctx.Err()
default:
}
err = persistFunc()
@@ -293,17 +279,14 @@ func (c *Cache) retryPersist(ctx context.Context, userID, spaceID string, persis
timer := time.NewTimer(expBackoff(attempt))
select {
case <-timer.C:
case <-persistCtx.Done():
case <-ctx.Done():
timer.Stop()
if ctx.Err() != nil {
return ctx.Err()
}
return err
return ctx.Err()
}
}
serr := c.resyncAfterConflict(ctx, userID)
if serr != nil && isSyncTransient(serr) {
serr = c.retryTransientResync(ctx, persistCtx, userID, attempt, serr, log)
serr = c.retryTransientResync(ctx, userID, attempt, serr, log)
}
if serr != nil {
log.Error().Int("attempt", attempt).Err(serr).Msg("lost update: re-read failed, aborting")
@@ -319,9 +302,8 @@ const resyncRetryBudget = 150 * time.Millisecond
// retryTransientResync re-reads state while the resync keeps failing
// transiently (lock contention or a 502/503/504), until it refreshes or the budget runs out.
// Its timeout is derived from persistCtx so it can't outlive the caller's own retry budget.
func (c *Cache) retryTransientResync(ctx, persistCtx context.Context, userID string, attempt int, lastErr error, log zerolog.Logger) error {
resyncCtx, cancel := context.WithTimeout(persistCtx, resyncRetryBudget)
func (c *Cache) retryTransientResync(ctx context.Context, userID string, attempt int, lastErr error, log zerolog.Logger) error {
resyncCtx, cancel := context.WithTimeout(ctx, resyncRetryBudget)
defer cancel()
serr := lastErr