-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
engine: Fix case where a pebbleBatchIterator is passed to ClearIterRange #41540
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ajkr, @itsbilal, @petermattis, and @sumeerbhola)
pkg/storage/engine/pebble.go, line 286 at r1 (raw file):
pebbleIter = i.iter case *pebbleBatchIterator: pebbleIter = i.iter
The type-switch is a bit of a code smell. Perhaps add a pebbleIter()
to the various pebble*Iterator
types. Then you can do something like:
type pebbleIterGetter interface { pebbleIter() *pebble.Iterator }
pebbleIter := iter.(pebbleIterGetter).pebbleIter()
Or perhaps better is to add a unsafeRawKey() []byte
method to the various pebble*Iterator
classes as it looks like that is why you're trying to get access to the *pebble.Iterator
.
pkg/storage/engine/pebble.go, line 306 at r1 (raw file):
} err = p.db.Delete(pebbleIter.Key(), pebble.Sync)
This passed my attention last time, but synchronously deleting each key is going to be horribly slow. What we want to do is build up a batch of deletes and commit the batch when it gets too large.
pkg/storage/engine/pebble_batch.go, line 200 at r1 (raw file):
} var pebbleIter *pebble.Iterator
This looks like a duplicate of the other clear range code. I think it could be unified.
pkg/storage/engine/pebble_batch.go, line 216 at r1 (raw file):
iter.SetUpperBound(end.Key) for ; ; iter.Next() {
Are you missing a call to iter.Seek()
here?
5269a41
to
93bb151
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ajkr, @petermattis, and @sumeerbhola)
pkg/storage/engine/pebble.go, line 286 at r1 (raw file):
Previously, petermattis (Peter Mattis) wrote…
The type-switch is a bit of a code smell. Perhaps add a
pebbleIter()
to the variouspebble*Iterator
types. Then you can do something like:type pebbleIterGetter interface { pebbleIter() *pebble.Iterator } pebbleIter := iter.(pebbleIterGetter).pebbleIter()
Or perhaps better is to add a
unsafeRawKey() []byte
method to the variouspebble*Iterator
classes as it looks like that is why you're trying to get access to the*pebble.Iterator
.
Did something similar, added an unsafeRawKey
and an inline interface to be able to call it. Thanks!
pkg/storage/engine/pebble.go, line 306 at r1 (raw file):
Previously, petermattis (Peter Mattis) wrote…
This passed my attention last time, but synchronously deleting each key is going to be horribly slow. What we want to do is build up a batch of deletes and commit the batch when it gets too large.
Done. This also lets us reuse pebbleBatch.ClearIterRange
since we can just create a new batch, call ClearIterRange
on it, then commit it.
pkg/storage/engine/pebble_batch.go, line 200 at r1 (raw file):
Previously, petermattis (Peter Mattis) wrote…
This looks like a duplicate of the other clear range code. I think it could be unified.
Done.
pkg/storage/engine/pebble_batch.go, line 216 at r1 (raw file):
Previously, petermattis (Peter Mattis) wrote…
Are you missing a call to
iter.Seek()
here?
Oops, good catch. Fixed.
93bb151
to
9dfe9e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ajkr, @itsbilal, and @sumeerbhola)
pkg/storage/engine/pebble.go, line 285 at r2 (raw file):
defer batch.Close() err := batch.ClearIterRange(iter, start, end)
Nit: if err := batch.ClearIterRange(...); err != nil { ... }
pkg/storage/engine/pebble_iterator.go, line 164 at r2 (raw file):
// unsafeRawKey returns the raw key from the underlying pebble.Iterator. func (p *pebbleIterator) unsafeRawKey() []byte { if valid, err := p.Valid(); err != nil || !valid {
I suspect this isn't necessary and you can just call p.iter.Key()
. Perhaps add a TODO to investigate.
Currently ClearIterRange expects a pebbleIterator to be passed in as the iterator. This isn't always the case; occasionally, we see a pebbleBatchIterator which currently errors out the method. Update that method in pebble and pebbleBatch to accept both types of iterators. Release note: None
9dfe9e8
to
25ab180
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! Will merge on green CI.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ajkr, @petermattis, and @sumeerbhola)
pkg/storage/engine/pebble_iterator.go, line 164 at r2 (raw file):
Previously, petermattis (Peter Mattis) wrote…
I suspect this isn't necessary and you can just call
p.iter.Key()
. Perhaps add a TODO to investigate.
It's pretty unnecessary in this case since ClearIterRange
does its own validity checks before calling this. Removed.
bors r+ |
PR fell off the bors list for some reason. bors r+ |
41540: engine: Fix case where a pebbleBatchIterator is passed to ClearIterRange r=itsbilal a=itsbilal Currently ClearIterRange expects a pebbleIterator to be passed in as the iterator. This isn't always the case; occasionally, we see a pebbleBatchIterator which currently errors out the method. Update that method in pebble and pebbleBatch to accept both types of iterators. Release note: None Co-authored-by: Bilal Akhtar <[email protected]>
Build succeeded |
Currently ClearIterRange expects a pebbleIterator to be passed in
as the iterator. This isn't always the case; occasionally, we see
a pebbleBatchIterator which currently errors out the method. Update
that method in pebble and pebbleBatch to accept both types of
iterators.
Release note: None