mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* Remove tenant when last block is removed from local backend Signed-off-by: Joe Elliott <[email protected]> * test err Signed-off-by: Joe Elliott <[email protected]> * better check for local blocks Signed-off-by: Joe Elliott <[email protected]> * changelog Signed-off-by: Joe Elliott <[email protected]> * remove tenant cleanup on clearblock Signed-off-by: Joe Elliott <[email protected]> * cleanup local backend on shutdown Signed-off-by: Joe Elliott <[email protected]> * more tests Signed-off-by: Joe Elliott <[email protected]> * i hate linting so much Signed-off-by: Joe Elliott <[email protected]> Signed-off-by: Joe Elliott <[email protected]>
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package local
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"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 errors.New("empty tenant id")
|
|
}
|
|
|
|
if blockID == uuid.Nil {
|
|
return errors.New("empty block id")
|
|
}
|
|
|
|
path := rw.rootPath(backend.KeyPathForBlock(blockID, tenantID))
|
|
err := os.RemoveAll(path)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to remove keypath for block %s: %w", path, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
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)
|
|
}
|