MCPcopy Create free account
hub / github.com/AbelChe/evil_minio / save

Method save

cmd/data-usage-cache.go:924–966  ·  view source on GitHub ↗

save the content of the cache to minioMetaBackgroundOpsBucket with the provided name. Note that no locking is done when saving.

(ctx context.Context, store objectIO, name string)

Source from the content-addressed store, hash-verified

922// save the content of the cache to minioMetaBackgroundOpsBucket with the provided name.
923// Note that no locking is done when saving.
924func (d *dataUsageCache) save(ctx context.Context, store objectIO, name string) error {
925 var r io.Reader
926 maxConcurrentScannerSaves <- struct{}{}
927 defer func() {
928 <-maxConcurrentScannerSaves
929 }()
930 // If big, do streaming...
931 size := int64(-1)
932 if len(d.Cache) > 10000 {
933 pr, pw := io.Pipe()
934 go func() {
935 pw.CloseWithError(d.serializeTo(pw))
936 }()
937 defer pr.Close()
938 r = pr
939 } else {
940 var buf bytes.Buffer
941 err := d.serializeTo(&buf)
942 if err != nil {
943 return err
944 }
945 r = &buf
946 size = int64(buf.Len())
947 }
948
949 hr, err := hash.NewReader(r, size, "", "", size)
950 if err != nil {
951 return err
952 }
953
954 // Abandon if more than 5 minutes, so we don't hold up scanner.
955 ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
956 defer cancel()
957 _, err = store.PutObject(ctx,
958 dataUsageBucket,
959 name,
960 NewPutObjReader(hr),
961 ObjectOptions{NoLock: true})
962 if isErrBucketNotFound(err) {
963 return nil
964 }
965 return err
966}
967
968// dataUsageCacheVer indicates the cache version.
969// Bumping the cache version will drop data from previous versions

Callers 1

nsScannerMethod · 0.95

Calls 8

serializeToMethod · 0.95
NewReaderFunction · 0.92
NewPutObjReaderFunction · 0.85
isErrBucketNotFoundFunction · 0.85
CloseMethod · 0.65
LenMethod · 0.65
PutObjectMethod · 0.65
CloseWithErrorMethod · 0.45

Tested by

no test coverage detected