MCPcopy
hub / github.com/grafana/tempo / completeBlock

Method completeBlock

modules/livestore/instance.go:589–693  ·  view source on GitHub ↗
(ctx context.Context, id uuid.UUID)

Source from the content-addressed store, hash-verified

587}
588
589func (i *instance) completeBlock(ctx context.Context, id uuid.UUID) (*LocalBlock, error) {
590 ctx, span := tracer.Start(ctx, "instance.completeBlock",
591 oteltrace.WithAttributes(
592 attribute.String("tenant", i.tenantID),
593 attribute.String("blockID", id.String()),
594 ))
595 defer span.End()
596
597 walBlock := i.blocks.Load().walBlocks[id]
598
599 if walBlock == nil {
600 level.Warn(i.logger).Log("msg", "WAL block disappeared before being completed", "id", id)
601 span.AddEvent("WAL block not found")
602 return nil, nil
603 }
604
605 blockSize := walBlock.DataLength()
606
607 level.Info(i.logger).Log("msg", "completing WAL block", "blockSize", blockSize, "blockId", id.String())
608 metricCompletionSize.Observe(float64(blockSize))
609 span.SetAttributes(attribute.Int64("wal_block_size", int64(blockSize)))
610
611 // Create completed block
612 reader := backend.NewReader(i.wal.LocalBackend())
613 writer := backend.NewWriter(i.wal.LocalBackend())
614
615 iter, err := walBlock.Iterator(ctx)
616 if err != nil {
617 level.Error(i.logger).Log("msg", "failed to get WAL block iterator", "id", id, "err", err)
618 span.SetStatus(codes.Error, err.Error())
619 span.RecordError(err)
620 return nil, err
621 }
622 defer iter.Close()
623
624 span.AddEvent("creating block")
625 newMeta, err := i.completeBlockEncoding.CreateBlock(ctx, &i.Cfg.BlockConfig, walBlock.BlockMeta(), iter, reader, writer)
626 if err != nil {
627 level.Error(i.logger).Log("msg", "failed to create complete block", "id", id, "err", err)
628 span.RecordError(err)
629 span.SetStatus(codes.Error, err.Error())
630 return nil, err
631 }
632 span.AddEvent("created block")
633 span.SetAttributes(
634 attribute.Int64("block_size", int64(newMeta.Size_)),
635 attribute.Int64("total_objects", newMeta.TotalObjects),
636 )
637
638 level.Info(i.logger).Log("msg", "opening newly completed block", "blockId", newMeta.BlockID.String())
639 span.AddEvent("opening block")
640 newBlock, err := i.completeBlockEncoding.OpenBlock(newMeta, reader)
641 if err != nil {
642 level.Error(i.logger).Log("msg", "failed to open complete block", "id", id, "err", err)
643 span.RecordError(err)
644 span.SetStatus(codes.Error, err.Error())
645 return nil, err
646 }

Callers 15

TestInstanceLimitsFunction · 0.80
TestInstanceSearchFunction · 0.80
TestInstanceSearchTagsFunction · 0.80
TestSearchTagsV2LimitsFunction · 0.80

Calls 15

NewReaderFunction · 0.92
NewWriterFunction · 0.92
NewLocalBlockFunction · 0.85
LocalBackendMethod · 0.80
withWALBlockRemovedMethod · 0.80
StartMethod · 0.65
LogMethod · 0.65
DataLengthMethod · 0.65
ObserveMethod · 0.65
IteratorMethod · 0.65
ErrorMethod · 0.65

Tested by 15

TestInstanceLimitsFunction · 0.64
TestInstanceSearchFunction · 0.64
TestInstanceSearchTagsFunction · 0.64
TestSearchTagsV2LimitsFunction · 0.64