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

Method Run

cmd/tempo-cli/cmd-migrate-tenant.go:21–79  ·  view source on GitHub ↗
(opts *globalOptions)

Source from the content-addressed store, hash-verified

19}
20
21func (cmd *migrateTenantCmd) Run(opts *globalOptions) error {
22 ctx := context.Background()
23
24 readerSource, readerDest, writerDest, err := cmd.setupBackends(opts)
25 if err != nil {
26 return fmt.Errorf("setting up backends: %w", err)
27 }
28 defer func() {
29 readerSource.Shutdown()
30 readerDest.Shutdown()
31 }()
32
33 sourceTenantIndex, err := readerSource.TenantIndex(ctx, cmd.SourceTenantID)
34 if err != nil {
35 return fmt.Errorf("reading source tenant index: %w", err)
36 }
37 fmt.Printf("Blocks in source: %d, compacted: %d\n", len(sourceTenantIndex.Meta), len(sourceTenantIndex.CompactedMeta))
38
39 // TODO create dest directory if it doesn't exist yet?
40
41 blocksDest, _, err := readerDest.Blocks(ctx, cmd.DestTenantID)
42 if err != nil {
43 return err
44 }
45 fmt.Printf("Blocks in destination: %d\n", len(blocksDest))
46
47 var copiedBlocks, copiedSize uint64
48
49blocks:
50 for _, sourceBlockMeta := range sourceTenantIndex.Meta {
51 // check for collisions
52 for _, uuidDest := range blocksDest {
53 if (uuid.UUID)(sourceBlockMeta.BlockID) == uuidDest {
54 fmt.Printf("UUID %s exists in source and destination, skipping block\n", sourceBlockMeta.BlockID)
55 continue blocks
56 }
57 }
58
59 // create a copy with destination tenant ID
60 destBlockMeta := *sourceBlockMeta
61 destBlockMeta.TenantID = cmd.DestTenantID
62
63 encoder, err := encoding.FromVersion(sourceBlockMeta.Version)
64 if err != nil {
65 return fmt.Errorf("creating encoder from version: %w", err)
66 }
67
68 err = encoder.MigrateBlock(ctx, sourceBlockMeta, &destBlockMeta, readerSource, writerDest)
69 if err != nil {
70 return fmt.Errorf("copying block: %w", err)
71 }
72
73 copiedBlocks++
74 copiedSize += sourceBlockMeta.Size_
75 }
76
77 fmt.Printf("Finished migrating data. Copied %d blocks, %s\n", copiedBlocks, humanize.Bytes(copiedSize))
78 return nil

Callers

nothing calls this directly

Calls 7

setupBackendsMethod · 0.95
FromVersionFunction · 0.92
BytesMethod · 0.80
ShutdownMethod · 0.65
TenantIndexMethod · 0.65
BlocksMethod · 0.65
MigrateBlockMethod · 0.65

Tested by

no test coverage detected