Skip to content

db: support configuring iterator during Clone#1766

Merged
jbowens merged 1 commit intocockroachdb:masterfrom
jbowens:clone-with-options
Jun 29, 2022
Merged

db: support configuring iterator during Clone#1766
jbowens merged 1 commit intocockroachdb:masterfrom
jbowens:clone-with-options

Conversation

@jbowens
Copy link
Copy Markdown
Contributor

@jbowens jbowens commented Jun 15, 2022

When creating an iterator through Clone, CockroachDB clones and then
immediately calls SetOptions. This adds unnecessary key comparisons to compute
the delta in the options, and if the options changed significantly, adds
unnecessary iterator stack construction.

Add a CloneOptions parameter to Clone that allows the user to optionally
specify IterOptions to construct the iterator with. Additionally, add a field
to support constructing the clone with a refreshed view of the indexed batch,
when cloning an iterator over an indexed batch.

Close #1712.

When creating an iterator through Clone, CockroachDB clones and then
immediately calls SetOptions. This adds unnecessary key comparisons to compute
the delta in the options, and if the options changed significantly, adds
unnecessary iterator stack construction.

Add a CloneOptions parameter to Clone that allows the user to optionally
specify IterOptions to construct the iterator with. Additionally, add a field
to support constructing the clone with a refreshed view of the indexed batch,
when cloning an iterator over an indexed batch.
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor 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 10 files reviewed, 1 unresolved discussion


iterator.go line 2118 at r1 (raw file):

// will cause an increase in memory and disk usage (use NewSnapshot for that
// purpose).
func (i *Iterator) Clone(opts CloneOptions) (*Iterator, error) {

I considered not changing this function's signature, and adding a new CloneWithOptions function, but we don't really provide any interface stability guarantees to external users. I'm a little wary of expanding the pebble public interface too much, but I don't feel strongly.

@jbowens jbowens requested review from a team and erikgrinaker June 15, 2022 21:24
@erikgrinaker
Copy link
Copy Markdown
Contributor

erikgrinaker commented Jun 16, 2022

Thanks! Overall API looks good. Gave this a spin over in cockroachdb/cockroach#82981, but seems like the latest Pebble master has a bug with batch writes. Specifically this bit here:

https://github.com/cockroachdb/cockroach/blob/1905d359aa2802da585a6c18f5e7a2e5b3b4d98d/pkg/storage/engine_test.go#L2012-L2023

When using a batch, the iterator constructed in scanRangeKeys does not see the RangeKeyUnset() laid down by ExperimentalClearMVCCRangeKey().

Will give this another go once master passes tests.

Copy link
Copy Markdown
Contributor

@erikgrinaker erikgrinaker 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 10 files reviewed, 1 unresolved discussion (waiting on @erikgrinaker and @jbowens)


iterator.go line 2118 at r1 (raw file):

Previously, jbowens (Jackson Owens) wrote…

I considered not changing this function's signature, and adding a new CloneWithOptions function, but we don't really provide any interface stability guarantees to external users. I'm a little wary of expanding the pebble public interface too much, but I don't feel strongly.

I think this is fine personally. It has the advantage of making the options and their implications very visible too.

@jbowens
Copy link
Copy Markdown
Contributor Author

jbowens commented Jun 16, 2022

seems like the latest Pebble master has a bug with batch writes

Ah, yeah, the fix is in #1753.

@jbowens jbowens requested review from itsbilal and nicktrav June 29, 2022 00:11
Copy link
Copy Markdown
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.

Nice one. :lgtm:

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

Copy link
Copy Markdown
Contributor 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: all files reviewed, 1 unresolved discussion (waiting on @itsbilal and @jbowens)

@jbowens jbowens merged commit 15565f7 into cockroachdb:master Jun 29, 2022
@jbowens jbowens deleted the clone-with-options branch June 29, 2022 23: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.

perf: consider Clone variant that accepts IterOptions

4 participants