@@ -49,6 +49,7 @@ func main() {
4949 listCmdHumanReadable = listCmd .Flag ("human-readable" , "print human readable values" ).Short ('h' ).Bool ()
5050 listPath = listCmd .Arg ("db path" , "database path (default is benchout/storage)" ).Default ("benchout/storage" ).String ()
5151 scanCmd = cli .Command ("scan" , "scans the db and lists corrupted blocks" )
52+ scanCmdHumanReadable = scanCmd .Flag ("human-readable" , "print human readable values" ).Short ('h' ).Bool ()
5253 scanPath = scanCmd .Arg ("dir" , "database path (default is current dir ./)" ).Default ("./" ).ExistingDir ()
5354 )
5455
@@ -60,15 +61,16 @@ func main() {
6061 samplesFile : * benchSamplesFile ,
6162 }
6263 wb .run ()
64+
6365 case listCmd .FullCommand ():
6466 db , err := tsdb .Open (* listPath , nil , nil , nil )
6567 if err != nil {
6668 exitWithError (err )
6769 }
6870 printBlocks (db .Blocks (), listCmdHumanReadable )
69- case scanCmd .FullCommand ():
7071
71- // Scan for temporary files.
72+ case scanCmd .FullCommand ():
73+ fmt .Println ("Scanning for temporary files..." )
7274 var tmpFiles []string
7375 filepath .Walk (* scanPath , func (path string , f os.FileInfo , _ error ) error {
7476 if ! f .IsDir () {
@@ -80,48 +82,40 @@ func main() {
8082 })
8183 if len (tmpFiles ) > 0 {
8284 fmt .Println (`
83- Scanning found some temporary files!
8485These are usually caused by a crash or incomplete compaction and
85- are safe to delete as long as you are sure that no other application is currently using this database folder .` )
86+ are safe to delete as long as you are sure that no other application is currently using this database.` )
8687
87- promptDelete (tmpFiles )
88+ promptDelete (tmpFiles , scanCmdHumanReadable )
8889
8990 }
9091
91- useless , err := tsdb .Scan (* scanPath )
92+ scanner , err := tsdb .NewDBScanner (* scanPath )
9293 if err != nil {
9394 exitWithError (err )
9495 }
9596
96- if len (useless ) == 0 {
97- fmt .Println ("Hooray! The db has no corrupted blocks (or the scan tool is broken).\U0001f638 " )
98- return
99- }
100-
101- for err , paths := range useless {
102- fmt .Println (err )
103- for _ , path := range paths {
104- fmt .Println (path )
105- }
106- switch err .(type ) {
107- case tsdb.ErrorOpen :
108- fmt .Println (`
109- Scanning found some blocks that cannot be opened!
110- Deleting these will allow a clean startup, but you will loose all data in the listed time ranges.` )
111- case tsdb.ErrorSequence :
112- fmt .Println (`
113- Scanning found some overlapping blocks!
114- Deleting these will allow a clean startup, but you will loose all data in the listed time ranges.` )
115- }
116-
117- promptDelete (paths )
97+ for err , useless := range scanner .Scan () {
98+ fmt .Printf ("Deleting these will loose all data in the listed time ranges.%v" , err )
99+ promptDelete (useless , scanCmdHumanReadable )
118100 }
119101 }
120102 flag .CommandLine .Set ("log.level" , "debug" )
121103}
122104
123- func promptDelete (paths []string ) {
124- fmt .Println (paths )
105+ func promptDelete (i interface {}, humanReadable * bool ) {
106+ var paths []string
107+ switch i .(type ) {
108+ case []* tsdb.Block :
109+ blocks := i .([]* tsdb.Block )
110+ for _ , b := range blocks {
111+ paths = append (paths , b .Dir ())
112+ }
113+ printBlocks (blocks , humanReadable )
114+ case []string :
115+ paths = i .([]string )
116+ printTmps (paths , humanReadable )
117+ }
118+
125119 fmt .Printf ("Do you want to delete these (y/N)? " )
126120 var s string
127121 _ , err := fmt .Scanln (& s )
@@ -144,7 +138,7 @@ func promptDelete(paths []string) {
144138 return
145139 }
146140 fmt .Printf ("%v is not a valid answer \n " , s )
147- promptDelete (paths )
141+ promptDelete (i , humanReadable )
148142}
149143
150144type writeBenchmark struct {
@@ -425,6 +419,11 @@ func exitWithError(err error) {
425419 os .Exit (1 )
426420}
427421
422+ func printTmps (tmps []string , humanReadable * bool ) {
423+
424+ fmt .Println (tmps )
425+ }
426+
428427func printBlocks (blocks []* tsdb.Block , humanReadable * bool ) {
429428 tw := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
430429 defer tw .Flush ()
0 commit comments