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 {
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 {
return nil, err
}
@ -887,26 +887,22 @@ func listDeletedBuckets(ctx context.Context, storageDisks []StorageAPI, delBucke
}
volsInfo, err := storageDisks[index].ListDir(ctx, minioMetaBucket, pathJoin(bucketMetaPrefix, deletedBucketsPrefix), -1)
if err != nil {
if err == errFileNotFound {
if errors.Is(err, errFileNotFound) {
return nil
}
return err
}
for _, volName := range volsInfo {
vi, err := storageDisks[index].StatVol(ctx, pathJoin(minioMetaBucket, bucketMetaPrefix, deletedBucketsPrefix, volName))
if err == nil {
vi.Name = strings.TrimSuffix(volName, SlashSeparator)
mu.Lock()
if _, ok := delBuckets[volName]; !ok {
vi, err := storageDisks[index].StatVol(ctx, pathJoin(minioMetaBucket, bucketMetaPrefix, deletedBucketsPrefix, volName))
if err != nil {
return err
}
bkt := strings.TrimPrefix(vi.Name, pathJoin(minioMetaBucket, bucketMetaPrefix, deletedBucketsPrefix))
bkt = strings.TrimPrefix(bkt, slashSeparator)
bkt = strings.TrimSuffix(bkt, slashSeparator)
vi.Name = bkt
delBuckets[bkt] = vi
delBuckets[volName] = vi
}
mu.Unlock()
}
}
return nil
}, index)
}