mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
fix: log once updating dataUsageCache versions (#11190)
also reduce usage of *bytes.Buffer for reading `usage-cache.bin`
This commit is contained in:
parent
c1f6ca6697
commit
3e1221a01c
@ -17,11 +17,11 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -458,7 +458,7 @@ func (d *dataUsageCache) merge(other dataUsageCache) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type objectIO interface {
|
type objectIO interface {
|
||||||
GetObject(ctx context.Context, bucket, object string, startOffset int64, length int64, writer io.Writer, etag string, opts ObjectOptions) (err error)
|
GetObjectNInfo(ctx context.Context, bucket, object string, rs *HTTPRangeSpec, h http.Header, lockType LockType, opts ObjectOptions) (reader *GetObjectReader, err error)
|
||||||
PutObject(ctx context.Context, bucket, object string, data *PutObjReader, opts ObjectOptions) (objInfo ObjectInfo, err error)
|
PutObject(ctx context.Context, bucket, object string, data *PutObjReader, opts ObjectOptions) (objInfo ObjectInfo, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,8 +466,7 @@ type objectIO interface {
|
|||||||
// Only backend errors are returned as errors.
|
// Only backend errors are returned as errors.
|
||||||
// If the object is not found or unable to deserialize d is cleared and nil error is returned.
|
// If the object is not found or unable to deserialize d is cleared and nil error is returned.
|
||||||
func (d *dataUsageCache) load(ctx context.Context, store objectIO, name string) error {
|
func (d *dataUsageCache) load(ctx context.Context, store objectIO, name string) error {
|
||||||
var buf bytes.Buffer
|
r, err := store.GetObjectNInfo(ctx, dataUsageBucket, name, nil, http.Header{}, readLock, ObjectOptions{})
|
||||||
err := store.GetObject(ctx, dataUsageBucket, name, 0, -1, &buf, "", ObjectOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case ObjectNotFound:
|
case ObjectNotFound:
|
||||||
@ -479,10 +478,9 @@ func (d *dataUsageCache) load(ctx context.Context, store objectIO, name string)
|
|||||||
*d = dataUsageCache{}
|
*d = dataUsageCache{}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
err = d.deserialize(&buf)
|
if err := d.deserialize(r); err != nil {
|
||||||
if err != nil {
|
|
||||||
*d = dataUsageCache{}
|
*d = dataUsageCache{}
|
||||||
logger.LogIf(ctx, err)
|
logger.LogOnceIf(ctx, err, err.Error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -494,6 +492,7 @@ func (d *dataUsageCache) save(ctx context.Context, store objectIO, name string)
|
|||||||
pw.CloseWithError(d.serializeTo(pw))
|
pw.CloseWithError(d.serializeTo(pw))
|
||||||
}()
|
}()
|
||||||
defer pr.Close()
|
defer pr.Close()
|
||||||
|
|
||||||
r, err := hash.NewReader(pr, -1, "", "", -1, false)
|
r, err := hash.NewReader(pr, -1, "", "", -1, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user