From 7883e55da2b9a9055a69e313e739a7ba8b4e263b Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 4 Jan 2023 17:53:58 +0100 Subject: [PATCH] Merge buckets list from different nodes in ListBuckets() call (#16357) --- cmd/peer-s3-client.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/peer-s3-client.go b/cmd/peer-s3-client.go index f8fc79433..62393594d 100644 --- a/cmd/peer-s3-client.go +++ b/cmd/peer-s3-client.go @@ -81,7 +81,7 @@ func NewS3PeerSys(endpoints EndpointServerPools) *S3PeerSys { } // ListBuckets lists buckets across all servers and returns a possible consistent view -func (sys *S3PeerSys) ListBuckets(ctx context.Context, opts BucketOptions) (buckets []BucketInfo, err error) { +func (sys *S3PeerSys) ListBuckets(ctx context.Context, opts BucketOptions) (result []BucketInfo, err error) { g := errgroup.WithNErrs(len(sys.peerClients)) localBuckets, err := listBucketsLocal(ctx, opts) @@ -116,13 +116,21 @@ func (sys *S3PeerSys) ListBuckets(ctx context.Context, opts BucketOptions) (buck return nil, err } + bucketsMap := make(map[string]struct{}) for idx, buckets := range nodeBuckets { - if errs[idx] == nil { - return buckets, nil + if errs[idx] != nil { + continue + } + for _, bi := range buckets { + _, ok := bucketsMap[bi.Name] + if !ok { + bucketsMap[bi.Name] = struct{}{} + result = append(result, bi) + } } } - return []BucketInfo{}, nil + return result, nil } // GetBucketInfo returns bucket stat info about bucket on disk across all peers