|
|
@ -489,9 +489,12 @@ 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 { |
|
|
|
b := d.serialize() |
|
|
|
pr, pw := io.Pipe() |
|
|
|
size := int64(len(b)) |
|
|
|
go func() { |
|
|
|
r, err := hash.NewReader(bytes.NewReader(b), size, "", "", size, false) |
|
|
|
pw.CloseWithError(d.serializeTo(pw)) |
|
|
|
|
|
|
|
}() |
|
|
|
|
|
|
|
defer pr.Close() |
|
|
|
|
|
|
|
r, err := hash.NewReader(pr, -1, "", "", -1, false) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
@ -513,32 +516,33 @@ func (d *dataUsageCache) save(ctx context.Context, store objectIO, name string) |
|
|
|
const dataUsageCacheVer = 3 |
|
|
|
const dataUsageCacheVer = 3 |
|
|
|
|
|
|
|
|
|
|
|
// serialize the contents of the cache.
|
|
|
|
// serialize the contents of the cache.
|
|
|
|
func (d *dataUsageCache) serialize() []byte { |
|
|
|
func (d *dataUsageCache) serializeTo(dst io.Writer) error { |
|
|
|
// Prepend version and compress.
|
|
|
|
// Add version and compress.
|
|
|
|
dst := make([]byte, 0, d.Msgsize()+1) |
|
|
|
_, err := dst.Write([]byte{dataUsageCacheVer}) |
|
|
|
dst = append(dst, dataUsageCacheVer) |
|
|
|
if err != nil { |
|
|
|
buf := bytes.NewBuffer(dst) |
|
|
|
return err |
|
|
|
enc, err := zstd.NewWriter(buf, |
|
|
|
} |
|
|
|
|
|
|
|
enc, err := zstd.NewWriter(dst, |
|
|
|
zstd.WithEncoderLevel(zstd.SpeedFastest), |
|
|
|
zstd.WithEncoderLevel(zstd.SpeedFastest), |
|
|
|
zstd.WithWindowSize(1<<20), |
|
|
|
zstd.WithWindowSize(1<<20), |
|
|
|
zstd.WithEncoderConcurrency(2)) |
|
|
|
zstd.WithEncoderConcurrency(2)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
logger.LogIf(GlobalContext, err) |
|
|
|
return err |
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
mEnc := msgp.NewWriter(enc) |
|
|
|
mEnc := msgp.NewWriter(enc) |
|
|
|
err = d.EncodeMsg(mEnc) |
|
|
|
err = d.EncodeMsg(mEnc) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
logger.LogIf(GlobalContext, err) |
|
|
|
return err |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
err = mEnc.Flush() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
mEnc.Flush() |
|
|
|
|
|
|
|
err = enc.Close() |
|
|
|
err = enc.Close() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
logger.LogIf(GlobalContext, err) |
|
|
|
return err |
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return buf.Bytes() |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// deserialize the supplied byte slice into the cache.
|
|
|
|
// deserialize the supplied byte slice into the cache.
|
|
|
|