Add flags for dumping only index, block or all data

pull/4445/head
Jason Wilder 2015-10-13 17:47:37 -06:00
parent 1a3f8c403e
commit 467ada073a
2 changed files with 35 additions and 14 deletions

View File

@ -57,11 +57,20 @@ func main() {
}
cmdInfo(path)
case "dumptsm":
var file string
var dumpAll bool
opts := &tsdmDumpOpts{}
fs := flag.NewFlagSet("file", flag.ExitOnError)
fs.BoolVar(&opts.dumpIndex, "dump-index", false, "Dump raw index data")
fs.BoolVar(&opts.dumpBlocks, "dump-blocks", false, "Dump raw block data")
fs.BoolVar(&dumpAll, "dump-all", false, "Dump all data. Caution: This may print a lot of information")
fs.Usage = func() {
println("Usage: influx_inspect dumptsm [options] <path>\n\n Dumps low-level details about tsm1 files.")
println()
println("Options:")
fs.PrintDefaults()
os.Exit(0)
}
if err := fs.Parse(flag.Args()[1:]); err != nil {
@ -75,8 +84,10 @@ func main() {
fs.PrintDefaults()
os.Exit(1)
}
file = fs.Args()[0]
dumpTsm1(file)
opts.path = fs.Args()[0]
opts.dumpBlocks = opts.dumpBlocks || dumpAll
opts.dumpIndex = opts.dumpIndex || dumpAll
dumpTsm1(opts)
return
default:

View File

@ -17,6 +17,12 @@ import (
"github.com/influxdb/influxdb/tsdb/engine/tsm1"
)
type tsdmDumpOpts struct {
dumpIndex bool
dumpBlocks bool
path string
}
type tsmIndex struct {
series int
offset int64
@ -211,10 +217,10 @@ func readIndex(f *os.File) *tsmIndex {
return index
}
func dumpTsm1(path string) {
func dumpTsm1(opts *tsdmDumpOpts) {
var errors []error
f, err := os.Open(path)
f, err := os.Open(opts.path)
if err != nil {
println(err.Error())
os.Exit(1)
@ -236,7 +242,7 @@ func dumpTsm1(path string) {
os.Exit(1)
}
ids, err := readIds(filepath.Dir(path))
ids, err := readIds(filepath.Dir(opts.path))
if err != nil {
println("Failed to read series:", err.Error())
os.Exit(1)
@ -251,7 +257,7 @@ func dumpTsm1(path string) {
blockStats := &blockStats{}
println("Summary:")
fmt.Printf(" File: %s\n", path)
fmt.Printf(" File: %s\n", opts.path)
fmt.Printf(" Time Range: %s - %s\n",
index.minTime.UTC().Format(time.RFC3339Nano),
index.maxTime.UTC().Format(time.RFC3339Nano),
@ -261,7 +267,6 @@ func dumpTsm1(path string) {
fmt.Printf(" File Size: %d\n", stat.Size())
println()
println("Index:")
tw := tabwriter.NewWriter(os.Stdout, 8, 8, 1, '\t', 0)
fmt.Fprintln(tw, " "+strings.Join([]string{"Pos", "ID", "Ofs", "Key", "Field"}, "\t"))
for i, block := range index.blocks {
@ -297,9 +302,12 @@ func dumpTsm1(path string) {
}, "\t"))
}
tw.Flush()
println()
println("Blocks:")
if opts.dumpIndex {
println("Index:")
tw.Flush()
println()
}
tw = tabwriter.NewWriter(os.Stdout, 8, 8, 1, '\t', 0)
fmt.Fprintln(tw, " "+strings.Join([]string{"Blk", "Ofs", "Len", "ID", "Type", "Min Time", "Points", "Enc [T/V]", "Len [T/V]"}, "\t"))
@ -368,9 +376,11 @@ func dumpTsm1(path string) {
i += (12 + int64(length))
blockCount += 1
}
tw.Flush()
println()
if opts.dumpBlocks {
println("Blocks:")
tw.Flush()
println()
}
fmt.Printf("Statistics\n")
fmt.Printf(" Blocks:\n")