@ -3,15 +3,17 @@
// COPYING file in the root directory) and Apache 2.0 License
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
// (found in the LICENSE.Apache file in the root directory).
# include "db/compaction/compaction_iterator.h"
# include <string>
# include <string>
# include <vector>
# include <vector>
# include "db/compaction/compaction_iterator .h"
# include "db/dbformat .h"
# include "port/port.h"
# include "port/port.h"
# include "test_util/testharness.h"
# include "test_util/testharness.h"
# include "test_util/testutil.h"
# include "test_util/testutil.h"
# include "util/string_util.h"
# include "util/string_util.h"
# include "util/vector_iterator.h"
# include "utilities/merge_operators.h"
# include "utilities/merge_operators.h"
namespace ROCKSDB_NAMESPACE {
namespace ROCKSDB_NAMESPACE {
@ -86,7 +88,7 @@ class FilterAllKeysCompactionFilter : public CompactionFilter {
const char * Name ( ) const override { return " AllKeysCompactionFilter " ; }
const char * Name ( ) const override { return " AllKeysCompactionFilter " ; }
} ;
} ;
class LoggingForwardVectorIterator : public Internal Iterator {
class LoggingForwardVectorIterator : public Vector Iterator {
public :
public :
struct Action {
struct Action {
enum class Type {
enum class Type {
@ -108,22 +110,19 @@ class LoggingForwardVectorIterator : public InternalIterator {
LoggingForwardVectorIterator ( const std : : vector < std : : string > & keys ,
LoggingForwardVectorIterator ( const std : : vector < std : : string > & keys ,
const std : : vector < std : : string > & values )
const std : : vector < std : : string > & values )
: keys_ ( keys ) , values_ ( values ) , current_ ( keys . size ( ) ) {
: VectorIterator ( keys , values ) {
assert ( keys_ . size ( ) = = value s_. size ( ) ) ;
current_ = key s_. size ( ) ;
}
}
bool Valid ( ) const override { return current_ < keys_ . size ( ) ; }
void SeekToFirst ( ) override {
void SeekToFirst ( ) override {
log . emplace_back ( Action : : Type : : SEEK_TO_FIRST ) ;
log . emplace_back ( Action : : Type : : SEEK_TO_FIRST ) ;
current_ = 0 ;
VectorIterator : : SeekToFirst ( ) ;
}
}
void SeekToLast ( ) override { assert ( false ) ; }
void SeekToLast ( ) override { assert ( false ) ; }
void Seek ( const Slice & target ) override {
void Seek ( const Slice & target ) override {
log . emplace_back ( Action : : Type : : SEEK , target . ToString ( ) ) ;
log . emplace_back ( Action : : Type : : SEEK , target . ToString ( ) ) ;
current_ = std : : lower_bound ( keys_ . begin ( ) , keys_ . end ( ) , target . ToString ( ) ) -
VectorIterator : : Seek ( target ) ;
keys_ . begin ( ) ;
}
}
void SeekForPrev ( const Slice & /*target*/ ) override { assert ( false ) ; }
void SeekForPrev ( const Slice & /*target*/ ) override { assert ( false ) ; }
@ -131,27 +130,20 @@ class LoggingForwardVectorIterator : public InternalIterator {
void Next ( ) override {
void Next ( ) override {
assert ( Valid ( ) ) ;
assert ( Valid ( ) ) ;
log . emplace_back ( Action : : Type : : NEXT ) ;
log . emplace_back ( Action : : Type : : NEXT ) ;
current_ + + ;
VectorIterator : : Next ( ) ;
}
}
void Prev ( ) override { assert ( false ) ; }
void Prev ( ) override { assert ( false ) ; }
Slice key ( ) const override {
Slice key ( ) const override {
assert ( Valid ( ) ) ;
assert ( Valid ( ) ) ;
return Slice ( keys_ [ current_ ] ) ;
return VectorIterator : : key ( ) ;
}
}
Slice value ( ) const override {
Slice value ( ) const override {
assert ( Valid ( ) ) ;
assert ( Valid ( ) ) ;
return Slice ( values_ [ current_ ] ) ;
return VectorIterator : : value ( ) ;
}
}
Status status ( ) const override { return Status : : OK ( ) ; }
std : : vector < Action > log ;
std : : vector < Action > log ;
private :
std : : vector < std : : string > keys_ ;
std : : vector < std : : string > values_ ;
size_t current_ ;
} ;
} ;
class FakeCompaction : public CompactionIterator : : CompactionProxy {
class FakeCompaction : public CompactionIterator : : CompactionProxy {
@ -244,7 +236,7 @@ class CompactionIteratorTest : public testing::TestWithParam<bool> {
bool key_not_exists_beyond_output_level = false ,
bool key_not_exists_beyond_output_level = false ,
const std : : string * full_history_ts_low = nullptr ) {
const std : : string * full_history_ts_low = nullptr ) {
std : : unique_ptr < InternalIterator > unfragmented_range_del_iter (
std : : unique_ptr < InternalIterator > unfragmented_range_del_iter (
new test : : VectorIterator ( range_del_ks , range_del_vs ) ) ;
new VectorIterator ( range_del_ks , range_del_vs , & icmp_ ) ) ;
auto tombstone_list = std : : make_shared < FragmentedRangeTombstoneList > (
auto tombstone_list = std : : make_shared < FragmentedRangeTombstoneList > (
std : : move ( unfragmented_range_del_iter ) , icmp_ ) ;
std : : move ( unfragmented_range_del_iter ) , icmp_ ) ;
std : : unique_ptr < FragmentedRangeTombstoneIterator > range_del_iter (
std : : unique_ptr < FragmentedRangeTombstoneIterator > range_del_iter (