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)
| 922 | // save the content of the cache to minioMetaBackgroundOpsBucket with the provided name. |
| 923 | // Note that no locking is done when saving. |
| 924 | func (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 |
no test coverage detected