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

Transaction::GetIterator does not honor ReadOptions #2343

Closed
graetzer opened this issue May 22, 2017 · 9 comments
Closed

Transaction::GetIterator does not honor ReadOptions #2343

graetzer opened this issue May 22, 2017 · 9 comments
Labels
up-for-grabs Up for grabs

Comments

@graetzer
Copy link
Contributor

graetzer commented May 22, 2017

The TransactionBaseImpl::GetIterator does not honor the prefix_same_as_start and iterate_upper_bound options for keys written in the current transaction.

The underlying WBWIIteratorImpl does not check these options. This means the iterator returns non-matching writes from the current transaction, which we did not expect to see based on the documentation.

This should either be documented or fixed, otherwise it leads to some frustrating bugs.

@adamretter
Copy link
Collaborator

@graetzer Interesting. Would you be willing to contribute unit tests for this?

@graetzer
Copy link
Contributor Author

graetzer commented Aug 4, 2017

@adamretter something like

rocksdb::Transaction* trx = tdb->BeginTransaction(wo, opts);
trx->Put("aaaa", "");
trx->Put("bbb", "");
trx->Put("ccc", "");
trx->Put("ddd", "");

std::string upper = "c";
rocksdb::ReadOptions ro;
ro.iterate_upper_bound = &upper;
auto it = trx->GetIterator(ro);
for (it->Seek("a"); it->Valid(); it->Next()) {
    assert(memcmp(it->key().data(), upper.data(), min(it->key().size(), upper.size())) < 0);
}

@gfosco
Copy link
Contributor

gfosco commented Jan 16, 2018

Closing this via automation due to lack of activity. If you'd like this to be re-opened, please just comment here and we'll open it back up.

@gfosco gfosco closed this as completed Jan 16, 2018
@evanmcc
Copy link

evanmcc commented Feb 13, 2019

I ran into this as well and produced this test script that shows the iterator_upper_bound issue:
https://gist.github.com/evanmcc/da9769290f32f0861f5f99b5caa9ede2

If this is valid and you can tell me where a corresponding unit test would go, I'd be happy to submit a PR to add (obviously failing) test.

@siying
Copy link
Contributor

siying commented Feb 13, 2019

@miasantreble worked upper bound support in transactions this in our last TechDebt week. We hit some problems and we haven't yet had time to finish it.

@siying siying reopened this Feb 13, 2019
@evanmcc
Copy link

evanmcc commented Feb 14, 2019

excellent. we can work around this for now, but it'd be lovely to have it over the longer term.

@gaoxiangxyz
Copy link

I meet this issue too.

@JayKickliter
Copy link

I ran into this bug as well. @evanmcc's reproduction is valid.

@adamretter
Copy link
Collaborator

See #7214

@ramvadiv ramvadiv added the up-for-grabs Up for grabs label Mar 24, 2021
ajkr pushed a commit that referenced this issue Oct 20, 2023
…ions in Transaction (#11680)

Summary:
Fix #11607
Fix #11679
Fix #11606
Fix #2343

Add bounds checking to `WBWIIteratorImpl`, which will be reflected in `BaseDeltaIterator::delta_iterator_::Valid()`, just like `BaseDeltaIterator::base_iterator_::Valid()`. In this way, the two sub itertors become more aligned from `BaseDeltaIterator`'s perspective. Like `DBIter`, the added bounds checking caps in either bound when seeking and disvalidates the `WBWIIteratorImpl` iterator when the lower bound is past or the upper bound is reached.

Pull Request resolved: #11680

Test Plan:
- A simple test added to write_batch_with_index_test.cc to exercise the bounds checking in `WBWIIteratorImpl`.
- A sophisticated test added to transaction_test.cc to assert that `Transaction` with different write policies honor bounds in `ReadOptions`. It should be so as long as the  `BaseDeltaIterator` is correctly coordinating the two sub iterators to perform iterating and bounds checking.

Reviewed By: ajkr

Differential Revision: D48125229

Pulled By: cbi42

fbshipit-source-id: c9acea52595aed1471a63d7ca6ef15d2a2af1367
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
up-for-grabs Up for grabs
Projects
None yet
9 participants