@ -52,6 +52,9 @@ DEFINE_int32(seed, 0, "random number generator seed");
DEFINE_int32 ( should_deletes_per_run , 1 , " number of ShouldDelete calls per run " ) ;
DEFINE_int32 ( should_deletes_per_run , 1 , " number of ShouldDelete calls per run " ) ;
DEFINE_int32 ( add_tombstones_per_run , 1 ,
" number of AddTombstones calls per run " ) ;
namespace {
namespace {
struct Stats {
struct Stats {
@ -65,8 +68,9 @@ std::ostream& operator<<(std::ostream& os, const Stats& s) {
fmt_holder . copyfmt ( os ) ;
fmt_holder . copyfmt ( os ) ;
os < < std : : left ;
os < < std : : left ;
os < < std : : setw ( 25 )
os < < std : : setw ( 25 ) < < " AddTombstones: "
< < " AddTombstones: " < < s . time_add_tombstones / ( FLAGS_num_runs * 1.0e3 )
< < s . time_add_tombstones /
( FLAGS_add_tombstones_per_run * FLAGS_num_runs * 1.0e3 )
< < " us \n " ;
< < " us \n " ;
os < < std : : setw ( 25 ) < < " ShouldDelete (first): "
os < < std : : setw ( 25 ) < < " ShouldDelete (first): "
< < s . time_first_should_delete / ( FLAGS_num_runs * 1.0e3 ) < < " us \n " ;
< < s . time_first_should_delete / ( FLAGS_num_runs * 1.0e3 ) < < " us \n " ;
@ -133,17 +137,16 @@ struct TombstoneStartKeyComparator {
const Comparator * cmp ;
const Comparator * cmp ;
} ;
} ;
void AddTombstones ( RangeDelAggregator * range_del_agg ,
std : : unique_ptr < InternalIterator > MakeRangeDelIterator (
const std : : vector < PersistentRangeTombstone > & range_dels ) {
const std : : vector < PersistentRangeTombstone > & range_dels ) {
std : : vector < std : : string > keys , values ;
std : : vector < std : : string > keys , values ;
for ( const auto & range_del : range_dels ) {
for ( const auto & range_del : range_dels ) {
auto key_and_value = range_del . tombstone . Serialize ( ) ;
auto key_and_value = range_del . tombstone . Serialize ( ) ;
keys . push_back ( key_and_value . first . Encode ( ) . ToString ( ) ) ;
keys . push_back ( key_and_value . first . Encode ( ) . ToString ( ) ) ;
values . push_back ( key_and_value . second . ToString ( ) ) ;
values . push_back ( key_and_value . second . ToString ( ) ) ;
}
}
std : : unique_ptr < test : : VectorIterator > range_del_iter (
return std : : unique_ptr < test : : VectorIterator > (
new test : : VectorIterator ( keys , values ) ) ;
new test : : VectorIterator ( keys , values ) ) ;
range_del_agg - > AddTombstones ( std : : move ( range_del_iter ) ) ;
}
}
// convert long to a big-endian slice key
// convert long to a big-endian slice key
@ -171,32 +174,40 @@ int main(int argc, char** argv) {
std : : default_random_engine random_gen ( FLAGS_seed ) ;
std : : default_random_engine random_gen ( FLAGS_seed ) ;
std : : normal_distribution < double > normal_dist ( FLAGS_tombstone_width_mean ,
std : : normal_distribution < double > normal_dist ( FLAGS_tombstone_width_mean ,
FLAGS_tombstone_width_stddev ) ;
FLAGS_tombstone_width_stddev ) ;
std : : vector < rocksdb : : PersistentRangeTombstone > persistent_range_tombstones (
std : : vector < std : : vector < rocksdb : : PersistentRangeTombstone > >
FLAGS_num_range_tombstones ) ;
all_persistent_range_tombstones ( FLAGS_add_tombstones_per_run ) ;
auto mode =
for ( int i = 0 ; i < FLAGS_add_tombstones_per_run ; i + + ) {
FLAGS_use_collapsed
all_persistent_range_tombstones [ i ] =
? rocksdb : : RangeDelPositioningMode : : kForwardTraversal
std : : vector < rocksdb : : PersistentRangeTombstone > (
: rocksdb : : RangeDelPositioningMode : : kFullScan ;
FLAGS_num_range_tombstones ) ;
}
auto mode = FLAGS_use_collapsed
? rocksdb : : RangeDelPositioningMode : : kForwardTraversal
: rocksdb : : RangeDelPositioningMode : : kFullScan ;
for ( int i = 0 ; i < FLAGS_num_runs ; i + + ) {
for ( int i = 0 ; i < FLAGS_num_runs ; i + + ) {
auto icmp = rocksdb : : InternalKeyComparator ( rocksdb : : BytewiseComparator ( ) ) ;
auto icmp = rocksdb : : InternalKeyComparator ( rocksdb : : BytewiseComparator ( ) ) ;
rocksdb : : RangeDelAggregator range_del_agg ( icmp , { } /* snapshots */ ,
rocksdb : : RangeDelAggregator range_del_agg ( icmp , { } /* snapshots */ ,
FLAGS_use_collapsed ) ;
FLAGS_use_collapsed ) ;
// TODO(abhimadan): consider whether creating the range tombstones right
for ( auto & persistent_range_tombstones : all_persistent_range_tombstones ) {
// before AddTombstones is artificially warming the cache compared to
// TODO(abhimadan): consider whether creating the range tombstones right
// real workloads.
// before AddTombstones is artificially warming the cache compared to
for ( int j = 0 ; j < FLAGS_num_range_tombstones ; j + + ) {
// real workloads.
uint64_t start = rnd . Uniform ( FLAGS_tombstone_start_upper_bound ) ;
for ( int j = 0 ; j < FLAGS_num_range_tombstones ; j + + ) {
uint64_t end = start + std : : max ( 1.0 , normal_dist ( random_gen ) ) ;
uint64_t start = rnd . Uniform ( FLAGS_tombstone_start_upper_bound ) ;
persistent_range_tombstones [ j ] = rocksdb : : PersistentRangeTombstone (
uint64_t end = start + std : : max ( 1.0 , normal_dist ( random_gen ) ) ;
rocksdb : : Key ( start ) , rocksdb : : Key ( end ) , j ) ;
persistent_range_tombstones [ j ] = rocksdb : : PersistentRangeTombstone (
}
rocksdb : : Key ( start ) , rocksdb : : Key ( end ) , j ) ;
}
rocksdb : : StopWatchNano stop_watch_add_tombstones ( rocksdb : : Env : : Default ( ) ,
auto range_del_iter =
true /* auto_start */ ) ;
rocksdb : : MakeRangeDelIterator ( persistent_range_tombstones ) ;
rocksdb : : AddTombstones ( & range_del_agg , persistent_range_tombstones ) ;
rocksdb : : StopWatchNano stop_watch_add_tombstones ( rocksdb : : Env : : Default ( ) ,
stats . time_add_tombstones + = stop_watch_add_tombstones . ElapsedNanos ( ) ;
true /* auto_start */ ) ;
range_del_agg . AddTombstones ( std : : move ( range_del_iter ) ) ;
stats . time_add_tombstones + = stop_watch_add_tombstones . ElapsedNanos ( ) ;
}
rocksdb : : ParsedInternalKey parsed_key ;
rocksdb : : ParsedInternalKey parsed_key ;
parsed_key . sequence = FLAGS_num_range_tombstones / 2 ;
parsed_key . sequence = FLAGS_num_range_tombstones / 2 ;