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/testkeys: new package #1367

Merged
merged 1 commit into from
Nov 16, 2021
Merged

Conversation

jbowens
Copy link
Collaborator

@jbowens jbowens commented Nov 10, 2021

Add an internal testkeys package for generating and comparing human-readable
test keys. These test keys may be suffixed with an integer timestamp. The
testkeys package exposes its own Comparer implementation that compares
timestamps based on their logical value, rather than their byte encoding.

As Pebble introduces new suffix-aware features, like range keys, we will
increasingly have a need for human-readable suffixed keys.

The key generation facilities in this package support generating keys of
varying lengths interleaved. This is anticipated to be useful when testing or
benchmarking compactions, where a subset of keys are overwritten and a subset
are new.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jbowens jbowens requested review from sumeerbhola and a team November 10, 2021 17:17
Copy link
Contributor

@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.

Reviewed 2 of 4 files at r1, all commit messages.
Reviewable status: 2 of 4 files reviewed, 1 unresolved discussion (waiting on @jbowens and @sumeerbhola)


go.mod, line 11 at r1 (raw file):

	github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9
	github.com/golang/snappy v0.0.3
	github.com/klauspost/compress v1.12.3

I presume these are from adding strutil?

Wondering if we can could just inline the function (with appropriate attribution), rather than pulling in another dep (looks like it has a ton of transitive deps, based on the go.sum diff)? Given we're adding a "test-only" package, it seems heavy handed to pull in all these other dependencies.

With that to one side, if we take the path of adding the new dep, do we need to regen the vendor directory?

Copy link
Contributor

@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: 2 of 4 files reviewed, 2 unresolved discussions (waiting on @jbowens and @sumeerbhola)


internal/testkeys/testkeys.go, line 137 at r1 (raw file):

	// Slice returns the sub-keyspace from index i, inclusive, to index j
	// exclusive.
	Slice(i, j int) Keyspace

nit: Wondering if these doc strings should indicate that a new Keyspace is returned (for Slice and EveryN)?

Looks like alphabet returns a mutated copy of the receiver. I guess you could also have a implementation that returns a pointer to self and mutates, though that would seem weird.

Add an internal testkeys package for generating and comparing human-readable
test keys. These test keys may be suffixed with an integer timestamp. The
testkeys package exposes its own Comparer implementation that compares
timestamps based on their logical value, rather than their byte encoding.

As Pebble introduces new suffix-aware features, like range keys, we will
increasingly have a need for human-readable suffixed keys.

The key generation facilities in this package support generating keys of
varying lengths interleaved. This is anticipated to be useful when testing or
benchmarking compactions, where a subset of keys are overwritten and a subset
are new.
Copy link
Contributor

@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.

Neat. Just some nits. :lgtm:

Reviewable status: 0 of 5 files reviewed, 3 unresolved discussions (waiting on @jbowens, @nicktrav, and @sumeerbhola)


internal/testkeys/testkeys.go, line 226 at r2 (raw file):

}

func keyCount(n, l int) int {

nit: could this be uint64 to squeeze as much out of the range as possible?

Also - does it make sense if l > n? In that case, do we need to cap l to be min(l, n)? Or is it a programmer error if l > n, in which case panic.

Copy link
Collaborator Author

@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.

TFTR!

Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion (waiting on @nicktrav and @sumeerbhola)


internal/testkeys/testkeys.go, line 226 at r2 (raw file):

Previously, nicktrav (Nick Travers) wrote…

nit: could this be uint64 to squeeze as much out of the range as possible?

Also - does it make sense if l > n? In that case, do we need to cap l to be min(l, n)? Or is it a programmer error if l > n, in which case panic.

Yeah, it does still make sense if l > n, because l controls the maximum number of slots and n controls the number of characters that can fill a slot.

@jbowens jbowens merged commit 1adc45d into cockroachdb:master Nov 16, 2021
@jbowens jbowens deleted the testkeys branch November 16, 2021 19:54
@jbowens jbowens mentioned this pull request Nov 30, 2021
29 tasks
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