fix: [OCISDEV-855] bound CAS-conflict resync retry by wall-clock time instead of attempt count
This commit is contained in:
1 file changed
+32
-19
Generated
Vendored
+32
-19
@@ -35,6 +35,7 @@ import (
|
||||
"github.com/owncloud/reva/v2/pkg/errtypes"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/mtimesyncedcache"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/utils/metadata"
|
||||
"github.com/rs/zerolog"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
)
|
||||
@@ -269,26 +270,10 @@ func (c *Cache) retryPersist(ctx context.Context, userID, spaceID string, persis
|
||||
log.Error().Int("attempt", attempt).Err(err).Msg("persisting received share failed, giving up")
|
||||
return err
|
||||
}
|
||||
timer := time.NewTimer(expBackoff(attempt))
|
||||
select {
|
||||
case <-timer.C:
|
||||
case <-ctx.Done():
|
||||
timer.Stop()
|
||||
return ctx.Err()
|
||||
}
|
||||
// The CAS winner already committed, so the first resync needs no delay.
|
||||
serr := c.resyncAfterConflict(ctx, userID)
|
||||
// Retrying persistFunc now would just repeat the same conflict against stale
|
||||
// state -- keep retrying the resync itself until it refreshes that state.
|
||||
for resyncAttempt := 0; serr != nil && isSyncTransient(serr) && resyncAttempt < 20; resyncAttempt++ {
|
||||
log.Warn().Int("attempt", attempt).Int("resyncAttempt", resyncAttempt).Err(serr).Msg("lost update: re-read before retry")
|
||||
timer := time.NewTimer(expBackoff(resyncAttempt))
|
||||
select {
|
||||
case <-timer.C:
|
||||
case <-ctx.Done():
|
||||
timer.Stop()
|
||||
return ctx.Err()
|
||||
}
|
||||
serr = c.resyncAfterConflict(ctx, userID)
|
||||
if serr != nil && isSyncTransient(serr) {
|
||||
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")
|
||||
@@ -298,6 +283,34 @@ func (c *Cache) retryPersist(ctx context.Context, userID, spaceID string, persis
|
||||
return err
|
||||
}
|
||||
|
||||
// resyncRetryBudget caps retry time instead of attempt count, so a stuck
|
||||
// resync fails fast instead of accumulating seconds of backoff.
|
||||
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.
|
||||
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
|
||||
for resyncAttempt := 0; serr != nil && isSyncTransient(serr); resyncAttempt++ {
|
||||
log.Warn().Int("attempt", attempt).Int("resyncAttempt", resyncAttempt).Err(serr).Msg("lost update: re-read before retry")
|
||||
timer := time.NewTimer(expBackoff(resyncAttempt))
|
||||
select {
|
||||
case <-timer.C:
|
||||
case <-resyncCtx.Done():
|
||||
timer.Stop()
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
}
|
||||
return serr
|
||||
}
|
||||
serr = c.resyncAfterConflict(ctx, userID)
|
||||
}
|
||||
return serr
|
||||
}
|
||||
|
||||
// syncIfStale pulls the authoritative state from storage when the local replica is stale; caller must hold the user lock.
|
||||
func (c *Cache) syncIfStale(ctx context.Context, userID string) error {
|
||||
return c.doSync(ctx, userID, true)
|
||||
|
||||
Reference in new issue
Block a user