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

internal/manifest: rework printing and parsing #1558

Merged
merged 4 commits into from
Mar 7, 2022

Conversation

nicktrav
Copy link
Contributor

@nicktrav nicktrav commented Mar 3, 2022

Addresses a number of TODOs by supporting range keys in various printing and parsing methods in manifest.

I opted to split the refactor up into four parts. Each commit is best reviewed in isolation but applies / tests cleanly. This should make reviewing the refactor much easier.

internal/manifest: format bounds consistently

Use the format $filename:[$smallest-$largest] when formatting bounds
for a table. This allows for better code reuse elsewhere.

Update affected test fixtures.

internal/manifest: remove (*Version).Pretty in favor of DebugString

Currently, (*Version).Pretty and (*Version).DebugString are almost
identical, except for the way in which the key is formatted. Remove the
Pretty variant in favor of DebugString, which removes some duplicate
code.

internal/manifest: add file metadata debug string and parser

Add the manifest.(*FileMetadata).DebugString() method that operates in
a similar fashion to manifest.(*Version).DebgString(), printing the
file number and overall bounds for the table. When verbose is set to
true, the point and range key bound are printed, depending on what
type of keys are present in the table (point keys, range keys or both).

Add the manifest.ParseFileMetadataDebug function that operates in a
similar fashion to ParseVersionDebug, parsing the inverse of the debug
string representation of a FileMetadata.

Move the metadata parsing out of ParseVersionDebug and instead rely on
the new function.

Update existing test cases that rely on file metadata parsing to use the
new function.

internal/manifest: consolidate string printing methods

Add a verbose parameter to manifest.(*Version).DebugString that when
set to true prints the verbose representation of each FileMetadata
in each level.

Further consolidate string printing for manifest.Version by having
manifest.(*Version).String use existing code to print the string
representation of a version, with each FileMetadata being printed in
non-verbose mode.

Update existing calls sites in various tests to call String, which is
essentially an alias for DebugString(..., false), which ensures
existing tests do not need to be updated.

nicktrav added 2 commits March 3, 2022 14:26
Use the format `$filename:[$smallest-$largest]` when formatting bounds
for a table. This allows for better code reuse elsewhere.

Update affected test fixtures.
Currently, `(*Version).Pretty` and `(*Version).DebugString` are almost
identical, except for the way in which the key is formatted. Remove the
`Pretty` variant in favor of `DebugString`, which removes some duplicate
code.
@nicktrav nicktrav requested review from itsbilal and jbowens March 3, 2022 22:38
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@jbowens jbowens left a comment

Choose a reason for hiding this comment

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

:LGTM:

Looks great, thanks for doing this!

Reviewed 4 of 4 files at r1, 4 of 4 files at r2, 5 of 5 files at r3, 15 of 15 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @itsbilal and @nicktrav)


internal/manifest/version.go, line 268 at r3 (raw file):

	}
	for len(fields) > 0 {
		prefix := strings.TrimSpace(fields[0])

nit: could use return unicode.IsSpace(c) in the FieldsFunc default case to strip whitespace upfront


internal/manifest/version.go, line 291 at r3 (raw file):

	// By default, when the parser sees just the overall bounds, we set the point
	// keys. This preserves backwards compatability with existing test cases that
	// specify only the overall bounds.

nice

@nicktrav nicktrav mentioned this pull request Mar 7, 2022
29 tasks
nicktrav added 2 commits March 7, 2022 13:28
Add the `manifest.(*FileMetadata).DebugString()` method that operates in
a similar fashion to `manifest.(*Version).DebgString()`, printing the
file number and overall bounds for the table. When `verbose` is set to
`true`, the point and range key bound are printed, depending on what
type of keys are present in the table (point keys, range keys or both).

Add the `manifest.ParseFileMetadataDebug` function that operates in a
similar fashion to `ParseVersionDebug`, parsing the inverse of the debug
string representation of a `FileMetadata`.

Move the metadata parsing out of `ParseVersionDebug` and instead rely on
the new function.

Update existing test cases that rely on file metadata parsing to use the
new function.
Add a `verbose` parameter to `manifest.(*Version).DebugString` that when
set to `true` prints the verbose representation of each `FileMetadata`
in each level.

Further consolidate string printing for `manifest.Version` by having
`manifest.(*Version).String` use existing code to print the string
representation of a version, with each `FileMetadata` being printed in
non-verbose mode.

Update existing calls sites in various tests to call `String`, which is
essentially an alias for `DebugString(..., false)`, which ensures
existing tests do not need to be updated.
@nicktrav nicktrav force-pushed the nickt.range-key-debug-parse branch from 58fc86a to 69da2f9 Compare March 7, 2022 21:29
Copy link
Contributor Author

@nicktrav nicktrav 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: 8 of 23 files reviewed, 1 unresolved discussion (waiting on @itsbilal, @jbowens, and @nicktrav)


internal/manifest/version.go, line 268 at r3 (raw file):

Previously, jbowens (Jackson Owens) wrote…

nit: could use return unicode.IsSpace(c) in the FieldsFunc default case to strip whitespace upfront

Nice. Done.

@nicktrav
Copy link
Contributor Author

nicktrav commented Mar 7, 2022

TFTR!

@nicktrav nicktrav merged commit 26d3995 into cockroachdb:master Mar 7, 2022
@nicktrav nicktrav deleted the nickt.range-key-debug-parse branch March 7, 2022 21:40
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.

3 participants