@ -2298,6 +2298,70 @@ TEST_F(DBTest2, DirectIO) {
ASSERT_OK ( db_ - > CompactRange ( CompactRangeOptions ( ) , nullptr , nullptr ) ) ;
ASSERT_OK ( db_ - > CompactRange ( CompactRangeOptions ( ) , nullptr , nullptr ) ) ;
Reopen ( options ) ;
Reopen ( options ) ;
}
}
TEST_F ( DBTest2 , MemtableOnlyIterator ) {
Options options = CurrentOptions ( ) ;
CreateAndReopenWithCF ( { " pikachu " } , options ) ;
ASSERT_OK ( Put ( 1 , " foo " , " first " ) ) ;
ASSERT_OK ( Put ( 1 , " bar " , " second " ) ) ;
ReadOptions ropt ;
ropt . read_tier = kMemtableTier ;
std : : string value ;
Iterator * it = nullptr ;
// Before flushing
// point lookups
ASSERT_OK ( db_ - > Get ( ropt , handles_ [ 1 ] , " foo " , & value ) ) ;
ASSERT_EQ ( " first " , value ) ;
ASSERT_OK ( db_ - > Get ( ropt , handles_ [ 1 ] , " bar " , & value ) ) ;
ASSERT_EQ ( " second " , value ) ;
// Memtable-only iterator (read_tier=kMemtableTier); data not flushed yet.
it = db_ - > NewIterator ( ropt , handles_ [ 1 ] ) ;
int count = 0 ;
for ( it - > SeekToFirst ( ) ; it - > Valid ( ) ; it - > Next ( ) ) {
ASSERT_TRUE ( it - > Valid ( ) ) ;
count + + ;
}
ASSERT_TRUE ( ! it - > Valid ( ) ) ;
ASSERT_EQ ( 2 , count ) ;
delete it ;
Flush ( 1 ) ;
// After flushing
// point lookups
ASSERT_OK ( db_ - > Get ( ropt , handles_ [ 1 ] , " foo " , & value ) ) ;
ASSERT_EQ ( " first " , value ) ;
ASSERT_OK ( db_ - > Get ( ropt , handles_ [ 1 ] , " bar " , & value ) ) ;
ASSERT_EQ ( " second " , value ) ;
// nothing should be returned using memtable-only iterator after flushing.
it = db_ - > NewIterator ( ropt , handles_ [ 1 ] ) ;
count = 0 ;
for ( it - > SeekToFirst ( ) ; it - > Valid ( ) ; it - > Next ( ) ) {
ASSERT_TRUE ( it - > Valid ( ) ) ;
count + + ;
}
ASSERT_TRUE ( ! it - > Valid ( ) ) ;
ASSERT_EQ ( 0 , count ) ;
delete it ;
// Add a key to memtable
ASSERT_OK ( Put ( 1 , " foobar " , " third " ) ) ;
it = db_ - > NewIterator ( ropt , handles_ [ 1 ] ) ;
count = 0 ;
for ( it - > SeekToFirst ( ) ; it - > Valid ( ) ; it - > Next ( ) ) {
ASSERT_TRUE ( it - > Valid ( ) ) ;
ASSERT_EQ ( " foobar " , it - > key ( ) . ToString ( ) ) ;
ASSERT_EQ ( " third " , it - > value ( ) . ToString ( ) ) ;
count + + ;
}
ASSERT_TRUE ( ! it - > Valid ( ) ) ;
ASSERT_EQ ( 1 , count ) ;
delete it ;
}
} // namespace rocksdb
} // namespace rocksdb
int main ( int argc , char * * argv ) {
int main ( int argc , char * * argv ) {