/
compactor.go
58 lines (45 loc) · 1.39 KB
/
compactor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package local
import (
"encoding/json"
"fmt"
"os"
"path"
"github.com/google/uuid"
"github.com/grafana/tempo/tempodb/backend"
)
func (rw *Backend) MarkBlockCompacted(blockID uuid.UUID, tenantID string) error {
// move meta file to a new location
metaFilename := rw.metaFileName(blockID, tenantID)
compactedMetaFilename := rw.compactedMetaFileName(blockID, tenantID)
return os.Rename(metaFilename, compactedMetaFilename)
}
func (rw *Backend) ClearBlock(blockID uuid.UUID, tenantID string) error {
if len(tenantID) == 0 {
return fmt.Errorf("empty tenant id")
}
if blockID == uuid.Nil {
return fmt.Errorf("empty block id")
}
return os.RemoveAll(rw.rootPath(backend.KeyPathForBlock(blockID, tenantID)))
}
func (rw *Backend) CompactedBlockMeta(blockID uuid.UUID, tenantID string) (*backend.CompactedBlockMeta, error) {
filename := rw.compactedMetaFileName(blockID, tenantID)
fi, err := os.Stat(filename)
if err != nil {
return nil, readError(err)
}
bytes, err := os.ReadFile(filename)
if err != nil {
return nil, readError(err)
}
out := &backend.CompactedBlockMeta{}
err = json.Unmarshal(bytes, out)
if err != nil {
return nil, err
}
out.CompactedTime = fi.ModTime()
return out, nil
}
func (rw *Backend) compactedMetaFileName(blockID uuid.UUID, tenantID string) string {
return path.Join(rw.rootPath(backend.KeyPathForBlock(blockID, tenantID)), backend.CompactedMetaName)
}