mirror of
https://github.com/minio/minio
synced 2024-09-06 00:37:25 +00:00
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:
parent
1647fc7edc
commit
37aa5934a1
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue