MCPcopy
hub / github.com/prometheus/prometheus / OpenBlock

Function OpenBlock

tsdb/block.go:339–390  ·  view source on GitHub ↗

OpenBlock opens the block in the directory. It can be passed a chunk pool, which is used to instantiate chunk structs.

(logger *slog.Logger, dir string, pool chunkenc.Pool, postingsDecoderFactory PostingsDecoderFactory)

Source from the content-addressed store, hash-verified

337// OpenBlock opens the block in the directory. It can be passed a chunk pool, which is used
338// to instantiate chunk structs.
339func OpenBlock(logger *slog.Logger, dir string, pool chunkenc.Pool, postingsDecoderFactory PostingsDecoderFactory) (pb *Block, err error) {
340 if logger == nil {
341 logger = promslog.NewNopLogger()
342 }
343 var closers []io.Closer
344 defer func() {
345 if err != nil {
346 err = errors.Join(err, closeAll(closers))
347 }
348 }()
349 meta, sizeMeta, err := readMetaFile(dir)
350 if err != nil {
351 return nil, err
352 }
353
354 cr, err := chunks.NewDirReader(chunkDir(dir), pool)
355 if err != nil {
356 return nil, err
357 }
358 closers = append(closers, cr)
359
360 decoder := index.DecodePostingsRaw
361 if postingsDecoderFactory != nil {
362 decoder = postingsDecoderFactory(meta)
363 }
364 ir, err := index.NewFileReader(filepath.Join(dir, indexFilename), decoder)
365 if err != nil {
366 return nil, err
367 }
368 closers = append(closers, ir)
369
370 tr, sizeTomb, err := tombstones.ReadTombstones(dir)
371 if err != nil {
372 return nil, err
373 }
374 closers = append(closers, tr)
375
376 pb = &Block{
377 dir: dir,
378 meta: *meta,
379 chunkr: cr,
380 indexr: ir,
381 tombstones: tr,
382 symbolTableSize: ir.SymbolTableSize(),
383 logger: logger,
384 numBytesChunks: cr.Size(),
385 numBytesIndex: ir.Size(),
386 numBytesTombstone: sizeTomb,
387 numBytesMeta: sizeMeta,
388 }
389 return pb, nil
390}
391
392// Close closes the on-disk block. It blocks as long as there are readers reading from the block.
393func (pb *Block) Close() error {

Callers 15

TestBlockWriterFunction · 0.85
BenchmarkQueryIteratorFunction · 0.85
BenchmarkQuerySeekFunction · 0.85
BenchmarkSetMatcherFunction · 0.85
BenchmarkQueriesFunction · 0.85
BenchmarkCompactionFunction · 0.85
BlockMethod · 0.85
openBlocksFunction · 0.85

Calls 8

NewDirReaderFunction · 0.92
NewFileReaderFunction · 0.92
ReadTombstonesFunction · 0.92
readMetaFileFunction · 0.85
chunkDirFunction · 0.85
SymbolTableSizeMethod · 0.80
closeAllFunction · 0.70
SizeMethod · 0.65

Tested by 15

TestBlockWriterFunction · 0.68
BenchmarkQueryIteratorFunction · 0.68
BenchmarkQuerySeekFunction · 0.68
BenchmarkSetMatcherFunction · 0.68
BenchmarkQueriesFunction · 0.68
BenchmarkCompactionFunction · 0.68
TestTombstoneCleanFailFunction · 0.68
WriteMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…