Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
delete only valid ULID dirs, some better logging.
Browse files Browse the repository at this point in the history
Signed-off-by: Krasi Georgiev <[email protected]>
  • Loading branch information
Krasi Georgiev committed May 11, 2018
1 parent f1cfeae commit 4462229
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions cmd/tsdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
"runtime/pprof"
Expand All @@ -31,6 +32,7 @@ import (
"time"

"github.com/go-kit/kit/log"
"github.com/oklog/ulid"
"github.com/pkg/errors"
"github.com/prometheus/tsdb"
"github.com/prometheus/tsdb/labels"
Expand Down Expand Up @@ -92,7 +94,10 @@ are safe to delete as long as you are sure that no other application is currentl
exitWithError(err)
}

for err, unreadable := range scanner.Scan() {
var unreadable []*tsdb.Block
for err, unreadable = range scanner.Scan() {
fmt.Printf("\nCorrupted blocks : %v \nDeleting these will remove all data in the listed time range.\n\n", err)

switch err.(type) {
case tsdb.ErrOverlap:
var biggestIndex int
Expand All @@ -106,15 +111,16 @@ are safe to delete as long as you are sure that no other application is currentl
// Don't delete the bigest block in the overlaps.
unreadable = append(unreadable[:biggestIndex], unreadable[biggestIndex+1:]...)

fmt.Printf("\n%v \nDeleting these will loose all data in the listed time ranges.\n\n", err)
fmt.Printf("\nBlock %v contains most samples is ommited from the list and it won't be deleted! \n\n", biggest)

default:
fmt.Printf("\nUnreadable blocks : %v \nDeleting these will loose all data in the listed time ranges.\n\n", err)

fmt.Printf("\nBlock %v contains most samples and is ommited from the deletion listgit ! \n\n", biggest)
}
promptDelete(unreadable, scanCmdHumanReadable)
}

fmt.Println("Scan complete!")
if len(unreadable) == 0 {
fmt.Println("Hooray! The db is clean(or the scan tool is broken).\U0001f638")
return
}
}
flag.CommandLine.Set("log.level", "debug")
}
Expand Down Expand Up @@ -144,9 +150,14 @@ func promptDelete(i interface{}, humanReadable *bool) {
s = strings.ToLower(s)

if s == "y" || s == "yes" {
for _, path := range paths {
if err := os.Remove(path); err != nil {
fmt.Printf("error deleting: %v, %v", path, err)
for _, p := range paths {
_, folder := path.Split(p)
if _, err := ulid.Parse(folder); err != nil {
exitWithError(fmt.Errorf("dir doesn't contain a valid ULID:%v", err))
}

if err := os.RemoveAll(p); err != nil {
fmt.Printf("error deleting: %v, %v", p, err)
}
}
return
Expand Down

0 comments on commit 4462229

Please sign in to comment.