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

Function TestClearTombstonedBlocks_walSweep

tempodb/wal/wal_test.go:567–625  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

565}
566
567func TestClearTombstonedBlocks_walSweep(t *testing.T) {
568 dir := t.TempDir()
569 wal, err := New(&Config{
570 Filepath: dir,
571 IngestionSlack: 3 * time.Minute,
572 Version: encoding.DefaultEncoding().Version(),
573 })
574 require.NoError(t, err)
575
576 enc := encoding.DefaultEncoding()
577
578 // Three WAL block dirs:
579 // tombstoned: meta.deleted.json present, meta.json gone
580 // alive: meta.json present
581 // bare: directory exists but no meta files
582 mkBlock := func(id uuid.UUID) string {
583 meta := backend.NewBlockMeta("fake", id, enc.Version())
584 _, err := wal.NewBlock(meta, model.CurrentEncoding)
585 require.NoError(t, err)
586 // Find the dir on disk for this block. The wal block doesn't write
587 // meta.json until Flush(); seed one so the tombstone rename works.
588 entries, err := os.ReadDir(dir)
589 require.NoError(t, err)
590 for _, e := range entries {
591 if e.IsDir() && uuidInName(e.Name(), id) {
592 bdir := filepath.Join(dir, e.Name())
593 require.NoError(t, os.WriteFile(filepath.Join(bdir, backend.MetaName), []byte(`{}`), 0o600))
594 return bdir
595 }
596 }
597 t.Fatalf("could not find dir for block %s", id)
598 return ""
599 }
600
601 tombID := uuid.New()
602 aliveID := uuid.New()
603 tombDir := mkBlock(tombID)
604 aliveDir := mkBlock(aliveID)
605
606 bareDir := filepath.Join(dir, "bare-orphan-noop")
607 require.NoError(t, os.MkdirAll(bareDir, 0o755))
608
609 // Tombstone the first block by renaming meta.json → meta.deleted.json.
610 require.NoError(t,
611 os.Rename(filepath.Join(tombDir, backend.MetaName),
612 filepath.Join(tombDir, backend.DeletedMetaName)))
613
614 cleared, err := wal.ClearTombstonedBlocks()
615 require.NoError(t, err)
616 require.Equal(t, 1, cleared)
617
618 // tombstoned dir gone, alive intact, bare untouched.
619 _, err = os.Stat(tombDir)
620 require.True(t, os.IsNotExist(err), "tombstoned wal dir should be removed")
621 _, err = os.Stat(filepath.Join(aliveDir, backend.MetaName))
622 require.NoError(t, err, "alive wal dir's meta should be intact")
623 _, err = os.Stat(bareDir)
624 require.NoError(t, err, "bare dir without marker should be untouched")

Callers

nothing calls this directly

Calls 10

DefaultEncodingFunction · 0.92
NewBlockMetaFunction · 0.92
uuidInNameFunction · 0.85
NewBlockMethod · 0.80
NewFunction · 0.70
VersionMethod · 0.65
NameMethod · 0.65
JoinMethod · 0.65
ClearTombstonedBlocksMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected