@ -18,6 +18,7 @@
# include "rocksdb/perf_context.h"
# include "table/block_based/flush_block_policy.h"
# include "util/random.h"
# include "utilities/merge_operators/string_append/stringappend2.h"
namespace ROCKSDB_NAMESPACE {
@ -619,6 +620,40 @@ TEST_P(DBIteratorTest, IterReseek) {
delete iter ;
}
TEST_F ( DBIteratorTest , ReseekUponDirectionChange ) {
Options options = GetDefaultOptions ( ) ;
options . create_if_missing = true ;
options . prefix_extractor . reset ( NewFixedPrefixTransform ( 1 ) ) ;
options . statistics = ROCKSDB_NAMESPACE : : CreateDBStatistics ( ) ;
options . merge_operator . reset (
new StringAppendTESTOperator ( /*delim_char=*/ ' ' ) ) ;
DestroyAndReopen ( options ) ;
ASSERT_OK ( Put ( " foo " , " value " ) ) ;
ASSERT_OK ( Put ( " bar " , " value " ) ) ;
{
std : : unique_ptr < Iterator > it ( db_ - > NewIterator ( ReadOptions ( ) ) ) ;
it - > SeekToLast ( ) ;
it - > Prev ( ) ;
it - > Next ( ) ;
}
ASSERT_EQ ( 1 ,
options . statistics - > getTickerCount ( NUMBER_OF_RESEEKS_IN_ITERATION ) ) ;
const std : : string merge_key ( " good " ) ;
ASSERT_OK ( Put ( merge_key , " orig " ) ) ;
ASSERT_OK ( Merge ( merge_key , " suffix " ) ) ;
{
std : : unique_ptr < Iterator > it ( db_ - > NewIterator ( ReadOptions ( ) ) ) ;
it - > Seek ( merge_key ) ;
ASSERT_TRUE ( it - > Valid ( ) ) ;
const uint64_t prev_reseek_count =
options . statistics - > getTickerCount ( NUMBER_OF_RESEEKS_IN_ITERATION ) ;
it - > Prev ( ) ;
ASSERT_EQ ( prev_reseek_count + 1 , options . statistics - > getTickerCount (
NUMBER_OF_RESEEKS_IN_ITERATION ) ) ;
}
}
TEST_P ( DBIteratorTest , IterSmallAndLargeMix ) {
do {
CreateAndReopenWithCF ( { " pikachu " } , CurrentOptions ( ) ) ;
@ -2997,18 +3032,18 @@ TEST_P(DBIteratorTest, Blob) {
iter - > Prev ( ) ;
ASSERT_EQ ( TestGetTickerCount ( options , NUMBER_OF_RESEEKS_IN_ITERATION ) , 5 ) ;
iter - > Next ( ) ;
ASSERT_EQ ( TestGetTickerCount ( options , NUMBER_OF_RESEEKS_IN_ITERATION ) , 5 ) ;
ASSERT_EQ ( TestGetTickerCount ( options , NUMBER_OF_RESEEKS_IN_ITERATION ) , 6 ) ;
ASSERT_EQ ( IterStatus ( iter ) , " b->vb3 " ) ;
// Switch from forward to reverse
iter - > SeekToFirst ( ) ;
ASSERT_EQ ( TestGetTickerCount ( options , NUMBER_OF_RESEEKS_IN_ITERATION ) , 5 ) ;
iter - > Next ( ) ;
ASSERT_EQ ( TestGetTickerCount ( options , NUMBER_OF_RESEEKS_IN_ITERATION ) , 5 ) ;
ASSERT_EQ ( TestGetTickerCount ( options , NUMBER_OF_RESEEKS_IN_ITERATION ) , 6 ) ;
iter - > Next ( ) ;
ASSERT_EQ ( TestGetTickerCount ( options , NUMBER_OF_RESEEKS_IN_ITERATION ) , 6 ) ;
iter - > Prev ( ) ;
iter - > Next ( ) ;
ASSERT_EQ ( TestGetTickerCount ( options , NUMBER_OF_RESEEKS_IN_ITERATION ) , 7 ) ;
iter - > Prev ( ) ;
ASSERT_EQ ( TestGetTickerCount ( options , NUMBER_OF_RESEEKS_IN_ITERATION ) , 8 ) ;
ASSERT_EQ ( IterStatus ( iter ) , " b->vb3 " ) ;
}