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: refactor Reader.Get #3507

Merged
merged 2 commits into from
Apr 12, 2024
Merged

db: refactor Reader.Get #3507

merged 2 commits into from
Apr 12, 2024

Conversation

jbowens
Copy link
Collaborator

@jbowens jbowens commented Apr 12, 2024

db: refactor Reader.Get

This commit refactors the implementation of getIter to be a little more
understandable and avoid the unnecessary use of levelIter. Current supported
format major versions guarantee that a user key is not split across sstables
within a level. This ensures that Get (which only retrieves one individual user
key) need only consult 1 sstable per level.

This is somewhat motivated by #2863. Removing getIter's dependency on levelIter
will make that refactor easier.

db: simplify levelIter skipEmptyFileForward

Apply a small simplification to levelIter.skipEmptyFileForward's condition for
when to interleave a synthetic boundary. Previously we needed to check whether
a file's largest point key was a range deletion to work around getIter's use of
the rangeDelIterPtr. Now that getIter no longer uses levelIter it's
unnecessary.

@jbowens jbowens requested review from a team and itsbilal April 12, 2024 16:20
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jbowens jbowens requested a review from RaduBerinde April 12, 2024 16:47
@jbowens jbowens force-pushed the get-refac branch 3 times, most recently from 4742d22 to 888bd84 Compare April 12, 2024 17:33
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: Awesome! Some minor comments.

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


get_iter.go line 77 at r1 (raw file):

}

func (g *getIter) Next() *base.InternalKV {

Do we ever call Next() on this iterator? It seems strange, since we'd only care about the first result.


get_iter.go line 243 at r1 (raw file):

}

func (g *getIter) getSSTableIterators(

This could use a comment - we are getting iterators for the one sstable that might contain the key.


get_iter.go line 255 at r1 (raw file):

	// the file doesn't actually contain any point keys equal to `key`. We next
	// to keep searching for a file that actually contains point keys ≥ key.
	if m.LargestPointKey.IsExclusiveSentinel() && g.comparer.Equal(m.LargestPointKey.UserKey, g.key) {

Not related to this change, but I think we should make SeekGE take a base.UserKeyBoundary

jbowens added 2 commits April 12, 2024 16:40
This commit refactors the implementation of getIter to be a little more
understandable and avoid the unnecessary use of levelIter. Current supported
format major versions guarantee that a user key is not split across sstables
within a level. This ensures that Get (which only retrieves one individual user
key) need only consult 1 sstable per level.

This is somewhat motivated by cockroachdb#2863. Removing getIter's dependency on levelIter
will make that refactor easier.
Apply a small simplification to levelIter.skipEmptyFileForward's condition for
when to interleave a synthetic boundary. Previously we needed to check whether
a file's largest point key was a range deletion to work around getIter's use of
the rangeDelIterPtr. Now that getIter no longer uses levelIter it's
unnecessary.
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 6 files reviewed, 2 unresolved discussions (waiting on @itsbilal and @RaduBerinde)


get_iter.go line 77 at r1 (raw file):

Previously, RaduBerinde wrote…

Do we ever call Next() on this iterator? It seems strange, since we'd only care about the first result.

yeah, but I think only in the case the first key is a MERGE. added a comment


get_iter.go line 243 at r1 (raw file):

Previously, RaduBerinde wrote…

This could use a comment - we are getting iterators for the one sstable that might contain the key.

Done.


get_iter.go line 255 at r1 (raw file):

Previously, RaduBerinde wrote…

Not related to this change, but I think we should make SeekGE take a base.UserKeyBoundary

yeah, makes sense

@jbowens jbowens merged commit 1eab9d6 into cockroachdb:master Apr 12, 2024
11 checks passed
@jbowens jbowens deleted the get-refac branch April 12, 2024 21:51
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