|
|
@ -30,6 +30,7 @@ import ( |
|
|
|
"github.com/minio/minio/pkg/bucket/policy" |
|
|
|
"github.com/minio/minio/pkg/bucket/policy" |
|
|
|
"github.com/minio/minio/pkg/event" |
|
|
|
"github.com/minio/minio/pkg/event" |
|
|
|
"github.com/minio/minio/pkg/madmin" |
|
|
|
"github.com/minio/minio/pkg/madmin" |
|
|
|
|
|
|
|
"github.com/minio/minio/pkg/sync/errgroup" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// BucketMetadataSys captures all bucket metadata for a given cluster.
|
|
|
|
// BucketMetadataSys captures all bucket metadata for a given cluster.
|
|
|
@ -291,21 +292,44 @@ func (sys *BucketMetadataSys) Init(ctx context.Context, buckets []BucketInfo, ob |
|
|
|
return sys.load(ctx, buckets, objAPI) |
|
|
|
return sys.load(ctx, buckets, objAPI) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Loads bucket metadata for all buckets into BucketMetadataSys.
|
|
|
|
// concurrently load bucket metadata to speed up loading bucket metadata.
|
|
|
|
func (sys *BucketMetadataSys) load(ctx context.Context, buckets []BucketInfo, objAPI ObjectLayer) error { |
|
|
|
func (sys *BucketMetadataSys) concurrentLoad(ctx context.Context, buckets []BucketInfo, objAPI ObjectLayer) error { |
|
|
|
sys.Lock() |
|
|
|
g := errgroup.WithNErrs(len(buckets)) |
|
|
|
defer sys.Unlock() |
|
|
|
for index := range buckets { |
|
|
|
|
|
|
|
index := index |
|
|
|
for _, bucket := range buckets { |
|
|
|
g.Go(func() error { |
|
|
|
meta, err := loadBucketMetadata(ctx, objAPI, bucket.Name) |
|
|
|
meta, err := loadBucketMetadata(ctx, objAPI, buckets[index].Name) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sys.Lock() |
|
|
|
|
|
|
|
sys.metadataMap[buckets[index].Name] = meta |
|
|
|
|
|
|
|
sys.Unlock() |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
}, index) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _, err := range g.Wait() { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
sys.metadataMap[bucket.Name] = meta |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Loads bucket metadata for all buckets into BucketMetadataSys.
|
|
|
|
|
|
|
|
func (sys *BucketMetadataSys) load(ctx context.Context, buckets []BucketInfo, objAPI ObjectLayer) error { |
|
|
|
|
|
|
|
count := 100 // load 100 bucket metadata at a time.
|
|
|
|
|
|
|
|
for { |
|
|
|
|
|
|
|
if len(buckets) < count { |
|
|
|
|
|
|
|
return sys.concurrentLoad(ctx, buckets, objAPI) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := sys.concurrentLoad(ctx, buckets[:count], objAPI); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
buckets = buckets[count:] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// NewBucketMetadataSys - creates new policy system.
|
|
|
|
// NewBucketMetadataSys - creates new policy system.
|
|
|
|
func NewBucketMetadataSys() *BucketMetadataSys { |
|
|
|
func NewBucketMetadataSys() *BucketMetadataSys { |
|
|
|
return &BucketMetadataSys{ |
|
|
|
return &BucketMetadataSys{ |
|
|
|