MCPcopy
hub / github.com/prometheus/prometheus / writeMetaFile

Function writeMetaFile

tsdb/block.go:275–310  ·  view source on GitHub ↗
(logger *slog.Logger, dir string, meta *BlockMeta)

Source from the content-addressed store, hash-verified

273}
274
275func writeMetaFile(logger *slog.Logger, dir string, meta *BlockMeta) (int64, error) {
276 meta.Version = metaVersion1
277
278 // Make any changes to the file appear atomic.
279 path := filepath.Join(dir, metaFilename)
280 tmp := path + ".tmp"
281 defer func() {
282 if err := os.RemoveAll(tmp); err != nil {
283 logger.Error("remove tmp file", "err", err.Error())
284 }
285 }()
286
287 f, err := os.Create(tmp)
288 if err != nil {
289 return 0, err
290 }
291
292 jsonMeta, err := json.MarshalIndent(meta, "", "\t")
293 if err != nil {
294 return 0, errors.Join(err, f.Close())
295 }
296
297 n, err := f.Write(jsonMeta)
298 if err != nil {
299 return 0, errors.Join(err, f.Close())
300 }
301
302 // Force the kernel to persist the file on disk to avoid data loss if the host crashes.
303 if err := f.Sync(); err != nil {
304 return 0, errors.Join(err, f.Close())
305 }
306 if err := f.Close(); err != nil {
307 return 0, err
308 }
309 return int64(n), fileutil.Replace(tmp, path)
310}
311
312// Block represents a directory of time series data covering a continuous time range.
313type Block struct {

Callers 9

TestLeveledCompactorFunction · 0.85
repairBadIndexVersionFunction · 0.85
setCompactionFailedMethod · 0.85
DeleteMethod · 0.85
writeMethod · 0.85

Calls 5

ReplaceFunction · 0.92
ErrorMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.65
SyncMethod · 0.65

Used in the wild real call sites across dependent graphs

searching dependent graphs…