core/expiration: Add backoff jitter to the expiration retries (#10937)
This commit is contained in:
parent
4a96126d5a
commit
0ad63e5a20
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -218,8 +219,7 @@ func (r *revocationJob) OnFailure(err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO vault 1.8 we added an exponential backoff library, check to see if it would be useful here
|
pending.timer.Reset(revokeExponentialBackoff(pending.revokesAttempted))
|
||||||
pending.timer.Reset((1 << pending.revokesAttempted) * revokeRetryBase)
|
|
||||||
r.m.pending.Store(r.leaseID, pending)
|
r.m.pending.Store(r.leaseID, pending)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,6 +248,15 @@ func expireLeaseStrategyFairsharing(ctx context.Context, m *ExpirationManager, l
|
||||||
m.jobManager.AddJob(job, mountAccessor)
|
m.jobManager.AddJob(job, mountAccessor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func revokeExponentialBackoff(attempt uint8) time.Duration {
|
||||||
|
exp := (1 << attempt) * revokeRetryBase
|
||||||
|
randomDelta := 0.5 * float64(exp)
|
||||||
|
|
||||||
|
// Allow backoff time to be a random value between exp +/- (0.5*exp)
|
||||||
|
backoffTime := (float64(exp) - randomDelta) + (rand.Float64() * (2 * randomDelta))
|
||||||
|
return time.Duration(backoffTime)
|
||||||
|
}
|
||||||
|
|
||||||
// revokeIDFunc is invoked when a given ID is expired
|
// revokeIDFunc is invoked when a given ID is expired
|
||||||
func expireLeaseStrategyRevoke(ctx context.Context, m *ExpirationManager, leaseID string, ns *namespace.Namespace) {
|
func expireLeaseStrategyRevoke(ctx context.Context, m *ExpirationManager, leaseID string, ns *namespace.Namespace) {
|
||||||
for attempt := uint(0); attempt < maxRevokeAttempts; attempt++ {
|
for attempt := uint(0); attempt < maxRevokeAttempts; attempt++ {
|
||||||
|
|
Loading…
Reference in New Issue