fix: a deadlock by refactoring listBuckets() under site replication (#16323)

This commit is contained in:
Harshavardhana 2022-12-29 00:08:31 -08:00 committed by GitHub
parent 2937711390
commit f93183f66e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -842,7 +842,7 @@ func (s *erasureSets) ListBuckets(ctx context.Context, opts BucketOptions) (buck
if opts.Deleted { if opts.Deleted {
for _, set := range s.sets { for _, set := range s.sets {
// lists all unique buckets across drives. // lists all deleted buckets across drives.
if err := listDeletedBuckets(ctx, set.getDisks(), deletedBuckets, s.defaultParityCount); err != nil { if err := listDeletedBuckets(ctx, set.getDisks(), deletedBuckets, s.defaultParityCount); err != nil {
return nil, err return nil, err
} }
@ -887,25 +887,21 @@ func listDeletedBuckets(ctx context.Context, storageDisks []StorageAPI, delBucke
} }
volsInfo, err := storageDisks[index].ListDir(ctx, minioMetaBucket, pathJoin(bucketMetaPrefix, deletedBucketsPrefix), -1) volsInfo, err := storageDisks[index].ListDir(ctx, minioMetaBucket, pathJoin(bucketMetaPrefix, deletedBucketsPrefix), -1)
if err != nil { if err != nil {
if err == errFileNotFound { if errors.Is(err, errFileNotFound) {
return nil return nil
} }
return err return err
} }
for _, volName := range volsInfo { for _, volName := range volsInfo {
mu.Lock() vi, err := storageDisks[index].StatVol(ctx, pathJoin(minioMetaBucket, bucketMetaPrefix, deletedBucketsPrefix, volName))
if _, ok := delBuckets[volName]; !ok { if err == nil {
vi, err := storageDisks[index].StatVol(ctx, pathJoin(minioMetaBucket, bucketMetaPrefix, deletedBucketsPrefix, volName)) vi.Name = strings.TrimSuffix(volName, SlashSeparator)
if err != nil { mu.Lock()
return err if _, ok := delBuckets[volName]; !ok {
delBuckets[volName] = vi
} }
bkt := strings.TrimPrefix(vi.Name, pathJoin(minioMetaBucket, bucketMetaPrefix, deletedBucketsPrefix)) mu.Unlock()
bkt = strings.TrimPrefix(bkt, slashSeparator)
bkt = strings.TrimSuffix(bkt, slashSeparator)
vi.Name = bkt
delBuckets[bkt] = vi
} }
mu.Unlock()
} }
return nil return nil
}, index) }, index)