MCPcopy Index your code
hub / github.com/cortexproject/cortex / WriteUserIndex

Function WriteUserIndex

pkg/util/users/index.go:42–67  ·  view source on GitHub ↗

WriteUserIndex uploads the provided index to the storage.

(ctx context.Context, bkt objstore.Bucket, idx *UserIndex)

Source from the content-addressed store, hash-verified

40
41// WriteUserIndex uploads the provided index to the storage.
42func WriteUserIndex(ctx context.Context, bkt objstore.Bucket, idx *UserIndex) error {
43 // Marshal the index.
44 content, err := json.Marshal(idx)
45 if err != nil {
46 return errors.Wrap(err, "marshal user index")
47 }
48
49 // Compress it.
50 var gzipContent bytes.Buffer
51 gzip := gzip.NewWriter(&gzipContent)
52 gzip.Name = UserIndexFilename
53
54 if _, err := gzip.Write(content); err != nil {
55 return errors.Wrap(err, "gzip user index")
56 }
57 if err := gzip.Close(); err != nil {
58 return errors.Wrap(err, "close gzip user index")
59 }
60
61 // Upload the index to the storage.
62 if err := bkt.Upload(ctx, UserIndexCompressedFilename, bytes.NewReader(gzipContent.Bytes())); err != nil {
63 return errors.Wrap(err, "upload user index")
64 }
65
66 return nil
67}
68
69func ReadUserIndex(ctx context.Context, bkt objstore.InstrumentedBucket, logger log.Logger) (*UserIndex, error) {
70 // Get the user index.

Callers 3

UpdateUserIndexMethod · 0.85
TestWriteUserIndex_ErrorFunction · 0.85

Calls 6

BytesMethod · 0.95
WrapMethod · 0.65
CloseMethod · 0.65
MarshalMethod · 0.45
WriteMethod · 0.45
UploadMethod · 0.45

Tested by 2

TestWriteUserIndex_ErrorFunction · 0.68