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

db: avoid loading later files for a level in SeekPrefixGE #3615

Merged
merged 2 commits into from May 15, 2024

Conversation

jbowens
Copy link
Collaborator

@jbowens jbowens commented May 13, 2024

Don't load arbitrarily later files during levelIter.SeekPrefixGE. This avoids unnecessary IO and CPU overhead.

Close #3575.

@jbowens jbowens requested a review from a team as a code owner May 13, 2024 19:39
@jbowens jbowens requested a review from itsbilal May 13, 2024 19:39
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jbowens jbowens requested a review from sumeerbhola May 13, 2024 19:45
Copy link
Member

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


level_iter.go line 562 at r1 (raw file):

		// unnecessary. This has been observed in practice on slow shared
		// storage. See #3575.
		if l.prefix != nil && l.cmp(file.SmallestPointKey.UserKey[l.split(file.SmallestPointKey.UserKey):], l.prefix) > 0 {

The : looks in the wrong place here

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.

Reviewable status: 0 of 5 files reviewed, 2 unresolved discussions (waiting on @itsbilal, @RaduBerinde, and @sumeerbhola)


level_iter.go line 562 at r1 (raw file):

Previously, RaduBerinde wrote…

The : looks in the wrong place here

Ooof; fixed and added a test that I should've added to begin with


testdata/level_iter line 184 at r2 (raw file):

next
prev
prev

prevs removed because these are not actually permitted by the InternalIterator interface

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

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


level_iter.go line 562 at r1 (raw file):

Previously, jbowens (Jackson Owens) wrote…

Ooof; fixed and added a test that I should've added to begin with

I would add a Prefix(userKey []byte) []byte method on base.Split and change this and the other callsite to l.split.Prefix(file.SmallestPointKey.UserKey).

Copy link
Member

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


level_iter.go line 562 at r1 (raw file):

Previously, RaduBerinde wrote…

I would add a Prefix(userKey []byte) []byte method on base.Split and change this and the other callsite to l.split.Prefix(file.SmallestPointKey.UserKey).

If you want, I can make that change separately, there are probably many other call sites that would benefit.

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.

Reviewable status: 0 of 9 files reviewed, 2 unresolved discussions (waiting on @itsbilal, @RaduBerinde, and @sumeerbhola)


level_iter.go line 562 at r1 (raw file):

Previously, RaduBerinde wrote…

If you want, I can make that change separately, there are probably many other call sites that would benefit.

was working on it just now! pushed

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

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


level_iter.go line 562 at r1 (raw file):

Previously, jbowens (Jackson Owens) wrote…

was working on it just now! pushed

Nice, thanks!


internal/base/comparer.go line 128 at r3 (raw file):

// Prefix returns the prefix of the key k, using s to split the key.
func (s Split) Prefix(k []byte) []byte {
	return k[:s(k)]

[nit] Do you see any downside to doing k[:n:n] just to be safe?

Copy link
Collaborator

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


level_iter.go line 563 at r2 (raw file):

		// storage. See #3575.
		if l.prefix != nil && l.cmp(file.SmallestPointKey.UserKey[:l.split(file.SmallestPointKey.UserKey)], l.prefix) > 0 {
			return noFileLoaded

Does returning noFileLoaded have any implication on the SeekGEFlags based optimizations?

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 9 files reviewed, 4 unresolved discussions (waiting on @itsbilal, @RaduBerinde, and @sumeerbhola)


level_iter.go line 563 at r2 (raw file):

Previously, sumeerbhola wrote…

Does returning noFileLoaded have any implication on the SeekGEFlags based optimizations?

Not directly; added a comment discussing TrySeekUsingNext. Since the file hasn't been loaded, a subsequent seek with TrySeekUsingNext()=true will disable TrySeekUsingNext on the sstable iterator seek


internal/base/comparer.go line 128 at r3 (raw file):

Previously, RaduBerinde wrote…

[nit] Do you see any downside to doing k[:n:n] just to be safe?

I don't, done!

Copy link
Collaborator

@sumeerbhola sumeerbhola 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: 0 of 9 files reviewed, 5 unresolved discussions (waiting on @itsbilal, @jbowens, and @RaduBerinde)


level_iter.go line 563 at r5 (raw file):

		// storage. See #3575.
		if l.prefix != nil && l.cmp(l.split.Prefix(file.SmallestPointKey.UserKey), l.prefix) > 0 {
			// Note that because we don't update l.iter, a subsequent call to

nit: should this say "because l.iter will be nil, ..."

And there's no issue with the manifest.LevelIterator and the SeekGEFlags either because we've stopped earlier, yes?

Don't load arbitrarily later files during levelIter.SeekPrefixGE. This avoids
unnecessary IO and CPU overhead.

Close cockroachdb#3575.
Add a Prefix method to base.Split that returns the prefix of a user key, as
defined by the Split func.
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.

Reviewable status: 0 of 9 files reviewed, 5 unresolved discussions (waiting on @itsbilal, @RaduBerinde, and @sumeerbhola)


level_iter.go line 563 at r5 (raw file):

Previously, sumeerbhola wrote…

nit: should this say "because l.iter will be nil, ..."

And there's no issue with the manifest.LevelIterator and the SeekGEFlags either because we've stopped earlier, yes?

yes

@jbowens jbowens merged commit 89116b3 into cockroachdb:master May 15, 2024
11 checks passed
@jbowens jbowens deleted the seekprefixge-loadfile branch May 15, 2024 20:19
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.

db: avoid loading later files for a level in SeekPrefixGE
4 participants