Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dumptsi path error handling. #9489

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 22 additions & 26 deletions cmd/influx_inspect/dumptsi/dumptsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,20 @@ func (cmd *Command) run() error {
return err
}

if cmd.showSeries {
if err := cmd.printSeries(sfile); err != nil {
return err
}
}

// If this is an ad-hoc fileset then process it and close afterward.
if fs != nil {
defer fs.Release()
defer fs.Close()
return cmd.printFileSet(sfile, fs)
if cmd.showSeries || cmd.showMeasurements {
return cmd.printMeasurements(sfile, fs)
}
return cmd.printFileSummaries(fs)
}

// Otherwise iterate over each partition in the index.
Expand All @@ -143,26 +152,15 @@ func (cmd *Command) run() error {
return err
}
defer fs.Release()
return cmd.printFileSet(sfile, fs)
}(); err != nil {
return err
}
}
return nil
}

func (cmd *Command) printFileSet(sfile *tsdb.SeriesFile, fs *tsi1.FileSet) error {
// Show either raw data or summary stats.
if cmd.showSeries || cmd.showMeasurements {
if err := cmd.printMerged(sfile, fs); err != nil {
return err
}
} else {
if err := cmd.printFileSummaries(fs); err != nil {
if cmd.showSeries || cmd.showMeasurements {
return cmd.printMeasurements(sfile, fs)
}
return cmd.printFileSummaries(fs)
}(); err != nil {
return err
}
}

return nil
}

Expand All @@ -173,6 +171,13 @@ func (cmd *Command) readFileSet(sfile *tsdb.SeriesFile) (*tsi1.Index, *tsi1.File
if err != nil {
return nil, nil, err
} else if fi.IsDir() {
// Verify directory is an index before opening it.
if ok, err := tsi1.IsIndexDir(cmd.paths[0]); err != nil {
return nil, nil, err
} else if !ok {
return nil, nil, fmt.Errorf("Not an index directory: %q", cmd.paths[0])
}

idx := tsi1.NewIndex(sfile,
"",
tsi1.WithPath(cmd.paths[0]),
Expand Down Expand Up @@ -218,15 +223,6 @@ func (cmd *Command) readFileSet(sfile *tsdb.SeriesFile) (*tsi1.Index, *tsi1.File
return nil, fs, nil
}

func (cmd *Command) printMerged(sfile *tsdb.SeriesFile, fs *tsi1.FileSet) error {
if err := cmd.printSeries(sfile); err != nil {
return err
} else if err := cmd.printMeasurements(sfile, fs); err != nil {
return err
}
return nil
}

func (cmd *Command) printSeries(sfile *tsdb.SeriesFile) error {
if !cmd.showSeries {
return nil
Expand Down
19 changes: 19 additions & 0 deletions tsdb/index/tsi1/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tsi1
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -880,3 +881,21 @@ func (i *Index) SetFieldName(measurement []byte, name string) {}

// Rebuild rebuilds an index. It's a no-op for this index.
func (i *Index) Rebuild() {}

// IsIndexDir returns true if directory contains at least one partition directory.
func IsIndexDir(path string) (bool, error) {
fis, err := ioutil.ReadDir(path)
if err != nil {
return false, err
}
for _, fi := range fis {
if !fi.IsDir() {
continue
} else if ok, err := IsPartitionDir(filepath.Join(path, fi.Name())); err != nil {
return false, err
} else if ok {
return true, nil
}
}
return false, nil
}
10 changes: 10 additions & 0 deletions tsdb/index/tsi1/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -1276,3 +1276,13 @@ const MaxIndexMergeCount = 2

// MaxIndexFileSize is the maximum expected size of an index file.
const MaxIndexFileSize = 4 * (1 << 30)

// IsPartitionDir returns true if directory contains a MANIFEST file.
func IsPartitionDir(path string) (bool, error) {
if _, err := os.Stat(filepath.Join(path, ManifestFileName)); os.IsNotExist(err) {
return false, nil
} else if err != nil {
return false, err
}
return true, nil
}