mirror of
https://github.com/minio/minio.git
synced 2025-05-21 09:33:50 -04: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.
|
// 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.
|
// 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 {
|
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) {
|
load := func(name string, timeout time.Duration) (bool, error) {
|
||||||
// Abandon if more than time.Minute, so we don't hold up scanner.
|
// 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.
|
// 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 {
|
if err != nil {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case ObjectNotFound, BucketNotFound:
|
case ObjectNotFound, BucketNotFound:
|
||||||
|
return false, nil
|
||||||
case InsufficientReadQuorum, StorageErr:
|
case InsufficientReadQuorum, StorageErr:
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return false, toObjectErr(err, dataUsageBucket, name)
|
return false, err
|
||||||
}
|
}
|
||||||
err = d.deserialize(r)
|
err = d.deserialize(r)
|
||||||
r.Close()
|
r.Close()
|
||||||
@ -953,20 +957,18 @@ func (d *dataUsageCache) load(ctx context.Context, store objectIO, name string)
|
|||||||
for retries < 5 {
|
for retries < 5 {
|
||||||
retry, err := load(name, time.Minute)
|
retry, err := load(name, time.Minute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return toObjectErr(err, dataUsageBucket, name)
|
||||||
}
|
}
|
||||||
if retry {
|
if !retry {
|
||||||
retry, _ = load(name+".bkp", 30*time.Second)
|
break
|
||||||
if !retry {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
retries++
|
|
||||||
time.Sleep(time.Duration(rand.Int63n(int64(time.Second))))
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user