-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
libroach: prevent infinite loop in reverse-scan #35505
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)
c-deps/libroach/mvcc.h, line 552 at r1 (raw file):
// Since the iterator we're using here has its upper-bound set to `key`, // this seeks to the last key that is strictly less than `key`. assert(key.compare(iter_->upper_bound) == 0);
I'm not sure if this is safe. We also call iterSeekReverse
from prevKey
.
I see. Does that usage also rely on |
Yes, it does rely on |
I think it should land on the seek key if it exists in the DB and isn't excluded by iterate_upper_bound, e.g., https://github.com/facebook/rocksdb/blob/master/db/db_iter_test.cc#L2264-L2266 |
I'll look at the code in RocksDB later. Seems feasible to test this scenario and demonstrate a problem. |
Got it. Will attempt to expose a problem in a test case in mvcc_test.go. |
c45b129
to
3ad5fbb
Compare
Fun investigation. I added a test case and reverted the change to EDIT: But I did not solve the actual problem yet. |
SeekForPrev
usageFixed and added a test case for infinite loop leading to OOM in reverse-scan optimization to use `SeekForPrev()` after N `Prev()`s fail to find a new key. It could happen when that optimization was used on a key that also had a write intent. Release note: None
Well, definitely a bug. I wonder if we've ever hit this in practice. It requires reverse scans, and a number of versions for a key, which might be a rare combination. Glad you found this, though. |
3ad5fbb
to
31a8193
Compare
This is ready for review. |
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.
Can you run the MVCCReverseScan
benchmarks? I'm curious to see how this affected them, though I don't see an easy way to avoid this check.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @ajkr)
Sure, the benchmark looks the same more or less (https://gist.github.com/ajkr/c7059d4dd38e111d91908d7d1eb244b0), so I think this should be safe to land. |
bors r+ |
35505: libroach: prevent infinite loop in reverse-scan r=ajkr a=ajkr Fixed and added a test case for infinite loop leading to OOM in reverse-scan optimization to use `SeekForPrev()` after N `Prev()`s fail to find a new key. It could happen when that optimization was used on a key that also had a write intent. Release note: None Co-authored-by: Andrew Kryczka <[email protected]>
Build succeeded |
Fixed and added a test case for infinite loop leading to OOM in reverse-scan
optimization to use
SeekForPrev()
after NPrev()
s fail to find a newkey. It could happen when that optimization was used on a key that also
had a write intent.
Release note: None