mirror of
https://github.com/minio/minio.git
synced 2025-02-02 17:35:58 -05:00
opt: Only stream big data usage caches (#16168)
This commit is contained in:
parent
a713aee3d5
commit
3fd9059b4e
@ -18,6 +18,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -879,13 +880,28 @@ func (d *dataUsageCache) load(ctx context.Context, store objectIO, name string)
|
|||||||
|
|
||||||
// save the content of the cache to minioMetaBackgroundOpsBucket with the provided name.
|
// save the content of the cache to minioMetaBackgroundOpsBucket with the provided name.
|
||||||
func (d *dataUsageCache) save(ctx context.Context, store objectIO, name string) error {
|
func (d *dataUsageCache) save(ctx context.Context, store objectIO, name string) error {
|
||||||
pr, pw := io.Pipe()
|
var r io.Reader
|
||||||
go func() {
|
|
||||||
pw.CloseWithError(d.serializeTo(pw))
|
|
||||||
}()
|
|
||||||
defer pr.Close()
|
|
||||||
|
|
||||||
r, err := hash.NewReader(pr, -1, "", "", -1)
|
// If big, do streaming...
|
||||||
|
size := int64(-1)
|
||||||
|
if len(d.Cache) > 10000 {
|
||||||
|
pr, pw := io.Pipe()
|
||||||
|
go func() {
|
||||||
|
pw.CloseWithError(d.serializeTo(pw))
|
||||||
|
}()
|
||||||
|
defer pr.Close()
|
||||||
|
r = pr
|
||||||
|
} else {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
err := d.serializeTo(&buf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r = &buf
|
||||||
|
size = int64(buf.Len())
|
||||||
|
}
|
||||||
|
|
||||||
|
hr, err := hash.NewReader(r, size, "", "", size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -896,7 +912,7 @@ func (d *dataUsageCache) save(ctx context.Context, store objectIO, name string)
|
|||||||
_, err = store.PutObject(ctx,
|
_, err = store.PutObject(ctx,
|
||||||
dataUsageBucket,
|
dataUsageBucket,
|
||||||
name,
|
name,
|
||||||
NewPutObjReader(r),
|
NewPutObjReader(hr),
|
||||||
ObjectOptions{})
|
ObjectOptions{})
|
||||||
if isErrBucketNotFound(err) {
|
if isErrBucketNotFound(err) {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user