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

Method deleteTenant

tempodb/blocklist/poller.go:533–586  ·  view source on GitHub ↗

deleteTenant will delete all of a tenant's objects if there is not a tenant index present.

(ctx context.Context, tenantID string)

Source from the content-addressed store, hash-verified

531
532// deleteTenant will delete all of a tenant's objects if there is not a tenant index present.
533func (p *Poller) deleteTenant(ctx context.Context, tenantID string) error {
534 // If we have not enabled empty tenant deletion, do nothing.
535 if !p.cfg.EmptyTenantDeletionEnabled {
536 return nil
537 }
538
539 level.Info(p.logger).Log("msg", "deleting tenant", "tenant", tenantID)
540
541 if p.cfg.EmptyTenantDeletionAge == 0 {
542 return fmt.Errorf("empty tenant deletion age must be greater than 0")
543 }
544
545 var (
546 foundObjects []string
547 recentObjects int
548 )
549 err := p.reader.Find(ctx, backend.KeyPath{tenantID}, func(opts backend.FindMatch) {
550 level.Info(p.logger).Log("msg", "checking object for deletion", "object", opts.Key, "modified", opts.Modified)
551
552 if time.Since(opts.Modified) > p.cfg.EmptyTenantDeletionAge {
553 foundObjects = append(foundObjects, opts.Key)
554 } else {
555 recentObjects++
556 }
557 })
558 if err != nil {
559 return err
560 }
561
562 // do nothing if there are recent objects for this tenant.
563 if recentObjects > 0 {
564 return nil
565 }
566
567 // do nothing if the tenant index has appeared.
568 _, err = p.reader.TenantIndex(ctx, tenantID)
569 // If we have any error other than that which indicates that the tenant index
570 // call was made successfully, and that it does not exist, do nothing. Only
571 // proceed if we know that the index does not exist.
572 if !errors.Is(err, backend.ErrDoesNotExist) {
573 return nil
574 }
575
576 for _, object := range foundObjects {
577 dir, name := path.Split(object)
578 level.Info(p.logger).Log("msg", "deleting", "tenant", tenantID, "object", object)
579 err = p.writer.Delete(ctx, name, backend.KeyPath{dir})
580 if err != nil {
581 return err
582 }
583 }
584
585 return nil
586}
587
588type backendMetaMetrics struct {
589 blockMetaTotalObjects int

Callers 1

Calls 4

LogMethod · 0.65
FindMethod · 0.65
TenantIndexMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected