scanner: Fix loading data usage cache structure (#18037)

Return an empty data usage cache structure when the data usage cache
file does not exist, otherwise, the scanner won't work.
This commit is contained in:
Anis Eleuch 2023-09-15 13:11:08 -07:00 committed by GitHub
parent 1647fc7edc
commit 37aa5934a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -928,6 +928,9 @@ type objectIO interface {
// The loader is optimistic and has no locking, but tries 5 times before giving up.
// If the object is not found or unable to deserialize d is cleared and nil error is returned.
func (d *dataUsageCache) load(ctx context.Context, store objectIO, name string) error {
// By defaut, empty data usage cache
*d = dataUsageCache{}
load := func(name string, timeout time.Duration) (bool, error) {
// Abandon if more than time.Minute, so we don't hold up scanner.
// drive timeout by default is 2 minutes, we do not need to wait longer.
@ -938,10 +941,11 @@ func (d *dataUsageCache) load(ctx context.Context, store objectIO, name string)
if err != nil {
switch err.(type) {
case ObjectNotFound, BucketNotFound:
return false, nil
case InsufficientReadQuorum, StorageErr:
return true, nil
}
return false, toObjectErr(err, dataUsageBucket, name)
return false, err
}
err = d.deserialize(r)
r.Close()
@ -953,20 +957,18 @@ func (d *dataUsageCache) load(ctx context.Context, store objectIO, name string)
for retries < 5 {
retry, err := load(name, time.Minute)
if err != nil {
return err
return toObjectErr(err, dataUsageBucket, name)
}
if retry {
retry, _ = load(name+".bkp", 30*time.Second)
if !retry {
break
}
retries++
time.Sleep(time.Duration(rand.Int63n(int64(time.Second))))
continue
if !retry {
break
}
return nil
retry, _ = load(name+".bkp", 30*time.Second)
if !retry {
break
}
retries++
time.Sleep(time.Duration(rand.Int63n(int64(time.Second))))
}
*d = dataUsageCache{}
return nil
}