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

cli: Add 'pebble' debug command to run Pebble tool commands #40728

Merged
merged 1 commit into from
Sep 18, 2019

Conversation

itsbilal
Copy link
Member

@itsbilal itsbilal commented Sep 12, 2019

Command-ception: Add a debug pebble command similar to debug rocksdb that nests pebble commands like sstable scan, manifest
dump, etc right in the cockroach binary.

Also move the pebble.Compare definition to engine, which is a more
fitting place for it than bulk.

Fixes #40509

Release note: None

Release justification: Adds debug tools for internal use, no impact
on general operation.

@itsbilal itsbilal requested a review from a team as a code owner September 12, 2019 19:56
@itsbilal itsbilal self-assigned this Sep 12, 2019
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajkr, @itsbilal, and @petermattis)


pkg/cli/debug.go, line 765 at r1 (raw file):

var debugPebbleCmd = &cobra.Command{
	Use:   "pebble [command]",
	Short: "run a Pebble tool command",

Nit: s/Pebble tool/Pebble introspection tool/g


pkg/cli/debug.go, line 769 at r1 (raw file):

Allows the use of pebble tools, such as to introspect manifests, SSTables, etc.
'cockroach debug pebble' accepts the same arguments and flags as the 'pebble'
binary.

I'd leave out the bit about "the same arguments and flags as the 'pebble' binary". The user probably doesn't know about that binary.


pkg/cli/debug.go, line 1337 at r1 (raw file):

	pebbleTool := tool.New()
	merger := *pebble.DefaultMerger
	merger.Name = "cockroach_merge_operator"

This isn't correct and deserves a TODO(bilal). I'm guessing some point soon you'll have the cockroach merge operator ported from C++ back to Go. Also add a note that this means that any timeseries data will be displayed incorrectly (concatenated instead of "merged").


pkg/storage/engine/mvcc.go, line 1868 at r1 (raw file):

// comparator settings for use with Pebble.
//
// TODO(itsbilal): Move this to a new file pebble.go.

Might as well create pebble.go now, or are you worried about a conflict with something else?


pkg/storage/engine/mvcc.go, line 1878 at r1 (raw file):

		return pebble.DefaultComparer.AbbreviatedKey(key)
	},

Let's fill in Format. You should be able to do something like:

func(k []byte) fmt.Formatter {
  return roachpb.Key(k)
}

I think that should just work, but if it doesn't I can help figure out what needs to be done. Once this is done, can you check that pebble sstable scan --key=%s for a cockroach generated sstable pretty-prints the keys?

Copy link
Member Author

@itsbilal itsbilal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that cockroachdb/pebble#267 has landed, this can go through. PTAL!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajkr and @petermattis)


pkg/cli/debug.go, line 769 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

I'd leave out the bit about "the same arguments and flags as the 'pebble' binary". The user probably doesn't know about that binary.

Done.


pkg/cli/debug.go, line 1337 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

This isn't correct and deserves a TODO(bilal). I'm guessing some point soon you'll have the cockroach merge operator ported from C++ back to Go. Also add a note that this means that any timeseries data will be displayed incorrectly (concatenated instead of "merged").

Yep, I am doing the port as part of my work for #39674. For now I'll add a TODO describing that. Is that enough or are we going to need to update the command help strings to also mention the discrepancy?


pkg/storage/engine/mvcc.go, line 1868 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

Might as well create pebble.go now, or are you worried about a conflict with something else?

I could - really the only conflict is with my own work in #39674 when that lands soon.


pkg/storage/engine/mvcc.go, line 1878 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

Let's fill in Format. You should be able to do something like:

func(k []byte) fmt.Formatter {
  return roachpb.Key(k)
}

I think that should just work, but if it doesn't I can help figure out what needs to be done. Once this is done, can you check that pebble sstable scan --key=%s for a cockroach generated sstable pretty-prints the keys?

Done. Confirmed that the pretty-printing works, with --format=pretty.

@itsbilal itsbilal force-pushed the debug-pebble-tool branch 2 times, most recently from 9984c82 to 42d7b92 Compare September 17, 2019 14:07
Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo the comment on MVCCKey.Format.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajkr and @itsbilal)


pkg/storage/engine/mvcc.go, line 1868 at r1 (raw file):

Previously, itsbilal (Bilal Akhtar) wrote…

I could - really the only conflict is with my own work in #39674 when that lands soon.

Ack. Ok.


pkg/storage/engine/mvcc.go, line 130 at r2 (raw file):

// Format implements the fmt.Formatter interface.
func (k MVCCKey) Format(f fmt.State, c rune) {
	fmt.Fprintf(f, "%s/%s", keys.PrettyPrint(nil, k.Key), k.Timestamp)

Is the keys.PrettyPrint call necessary? I think you can pass k.Key to fmt.Fprintf and it will automatically call k.Key.String() which will in turn call PrettyPrint.

Copy link
Member Author

@itsbilal itsbilal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the fix (plus other linter-found issues). Thanks for the review!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajkr, @itsbilal, and @petermattis)


pkg/storage/engine/mvcc.go, line 130 at r2 (raw file):

Previously, petermattis (Peter Mattis) wrote…

Is the keys.PrettyPrint call necessary? I think you can pass k.Key to fmt.Fprintf and it will automatically call k.Key.String() which will in turn call PrettyPrint.

Yes, it's unnecessary. Removed it.

Command-ception: Add a `debug pebble` command similar to `debug
rocksdb` that nests pebble commands like sstable scan, manifest
dump, etc right in the cockroach binary.

Also move the pebble.Compare definition to engine, which is a more
fitting place for it than bulk.

Fixes cockroachdb#40509

Release note: None

Release justification: Adds debug tools for internal use, no impact
on general operation.
@itsbilal
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Sep 17, 2019

Build failed (retrying...)

@craig
Copy link
Contributor

craig bot commented Sep 17, 2019

Build failed

@itsbilal
Copy link
Member Author

Release justification copied to PR description.

bors r+

craig bot pushed a commit that referenced this pull request Sep 18, 2019
40728: cli: Add 'pebble' debug command to run Pebble tool commands r=itsbilal a=itsbilal

Command-ception: Add a `debug pebble` command similar to `debug
rocksdb` that nests pebble commands like sstable scan, manifest
dump, etc right in the cockroach binary.

Also move the pebble.Compare definition to engine, which is a more
fitting place for it than bulk.

Fixes #40509

Release note: None

Release justification: Adds debug tools for internal use, no impact
on general operation.

Co-authored-by: Bilal Akhtar <[email protected]>
@craig
Copy link
Contributor

craig bot commented Sep 18, 2019

Build succeeded

@craig craig bot merged commit 70cca6d into cockroachdb:master Sep 18, 2019
@petermattis
Copy link
Collaborator

@jseldess Do we document the cockroach debug rocksdb command? I couldn't find anything, but wanted to double-check. The new debug pebble commands are preferable from an ease of use standpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cli: integrate pebble debug tools
3 participants