-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat(inspect): add influx_inspect verify-tombstone tool #15952
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f7f19c5
refactor(storage): add tombstone extension
e-dard 92b9bde
feat(inspect): add verify-tombstone
e-dard b93bac1
fix: typo in error message
dgnorton 0fcb240
fix: use highest verbosity level specified
dgnorton fca2ee0
fix: update package comment
dgnorton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Package tombstone verifies integrity of tombstones. | ||
package tombstone | ||
|
||
import ( | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/influxdata/influxdb/tsdb/engine/tsm1" | ||
) | ||
|
||
// Command represents the program execution for "influx_inspect verify-tombstone". | ||
type Command struct { | ||
Stderr io.Writer | ||
Stdout io.Writer | ||
} | ||
|
||
// NewCommand returns a new instance of Command. | ||
func NewCommand() *Command { | ||
return &Command{ | ||
Stderr: os.Stderr, | ||
Stdout: os.Stdout, | ||
} | ||
} | ||
|
||
// Run executes the command. | ||
func (cmd *Command) Run(args ...string) error { | ||
runner := verifier{w: cmd.Stdout} | ||
fs := flag.NewFlagSet("verify-tombstone", flag.ExitOnError) | ||
fs.StringVar(&runner.path, "path", os.Getenv("HOME")+"/.influxdb", "path to find tombstone files") | ||
v := fs.Bool("v", false, "verbose: emit periodic progress") | ||
vv := fs.Bool("vv", false, "very verbose: emit every tombstone entry key and time range") | ||
vvv := fs.Bool("vvv", false, "very very verbose: emit every tombstone entry key and RFC3339Nano time range") | ||
|
||
fs.SetOutput(cmd.Stdout) | ||
|
||
if err := fs.Parse(args); err != nil { | ||
return err | ||
} | ||
|
||
if *v { | ||
runner.verbosity = verbose | ||
} | ||
if *vv { | ||
runner.verbosity = veryVerbose | ||
} | ||
if *vvv { | ||
runner.verbosity = veryVeryVerbose | ||
} | ||
|
||
return runner.Run() | ||
} | ||
|
||
const ( | ||
quiet = iota | ||
verbose | ||
veryVerbose | ||
veryVeryVerbose | ||
) | ||
|
||
type verifier struct { | ||
path string | ||
verbosity int | ||
|
||
w io.Writer | ||
files []string | ||
f string | ||
} | ||
|
||
func (v *verifier) loadFiles() error { | ||
return filepath.Walk(v.path, func(path string, f os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if filepath.Ext(path) == "."+tsm1.TombstoneFileExtension { | ||
v.files = append(v.files, path) | ||
} | ||
return nil | ||
}) | ||
} | ||
|
||
func (v *verifier) Next() bool { | ||
if len(v.files) == 0 { | ||
return false | ||
} | ||
|
||
v.f, v.files = v.files[0], v.files[1:] | ||
return true | ||
} | ||
|
||
func (v *verifier) Run() error { | ||
if err := v.loadFiles(); err != nil { | ||
return err | ||
} | ||
|
||
var failed bool | ||
start := time.Now() | ||
for v.Next() { | ||
if v.verbosity > quiet { | ||
fmt.Fprintf(v.w, "Verifying: %q\n", v.f) | ||
} | ||
|
||
tombstoner := tsm1.NewTombstoner(v.f, nil) | ||
if !tombstoner.HasTombstones() { | ||
fmt.Fprintf(v.w, "%s has no tombstone entries", v.f) | ||
continue | ||
} | ||
|
||
var totalEntries int64 | ||
err := tombstoner.Walk(func(t tsm1.Tombstone) error { | ||
totalEntries++ | ||
if v.verbosity > quiet && totalEntries%(10*1e6) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 10e6 or 1e7? |
||
fmt.Fprintf(v.w, "Verified %d tombstone entries\n", totalEntries) | ||
} else if v.verbosity > verbose { | ||
var min interface{} = t.Min | ||
var max interface{} = t.Max | ||
if v.verbosity > veryVerbose { | ||
min = time.Unix(0, t.Min) | ||
max = time.Unix(0, t.Max) | ||
} | ||
fmt.Printf("key: %q, min: %v, max: %v\n", t.Key, min, max) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
fmt.Fprintf(v.w, "%q failed to walk tombstone entries: %v. Last okay entry: %d\n", v.f, err, totalEntries) | ||
failed = true | ||
continue | ||
} | ||
|
||
fmt.Fprintf(v.w, "Completed verification for %q in %v.\nVerified %d entries\n\n", v.f, time.Since(start), totalEntries) | ||
} | ||
|
||
if failed { | ||
return errors.New("failed tombstone verification") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the complexity be simplified by checking
v
first, thenvv
, and finallyvvv
; using the most verbose option?Would allow removal of complicated if statements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or let higher verbosity levels override lower levels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I said, but in a terrible fashion :)