@ -275,68 +275,6 @@ TEST_P(MergeOperatorPinningTest, OperandsMultiBlocks) {
VerifyDBFromMap ( true_data ) ;
VerifyDBFromMap ( true_data ) ;
}
}
TEST_P ( MergeOperatorPinningTest , Randomized ) {
do {
Options options = CurrentOptions ( ) ;
options . merge_operator = MergeOperators : : CreateMaxOperator ( ) ;
BlockBasedTableOptions table_options ;
table_options . no_block_cache = disable_block_cache_ ;
options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ;
DestroyAndReopen ( options ) ;
Random rnd ( 301 ) ;
std : : map < std : : string , std : : string > true_data ;
const int kTotalMerges = 5000 ;
// Every key gets ~10 operands
const int kKeyRange = kTotalMerges / 10 ;
const int kOperandSize = 20 ;
const int kNumPutBefore = kKeyRange / 10 ; // 10% value
const int kNumPutAfter = kKeyRange / 10 ; // 10% overwrite
const int kNumDelete = kKeyRange / 10 ; // 10% delete
// kNumPutBefore keys will have base values
for ( int i = 0 ; i < kNumPutBefore ; i + + ) {
std : : string key = Key ( rnd . Next ( ) % kKeyRange ) ;
std : : string value = RandomString ( & rnd , kOperandSize ) ;
ASSERT_OK ( db_ - > Put ( WriteOptions ( ) , key , value ) ) ;
true_data [ key ] = value ;
}
// Do kTotalMerges merges
for ( int i = 0 ; i < kTotalMerges ; i + + ) {
std : : string key = Key ( rnd . Next ( ) % kKeyRange ) ;
std : : string value = RandomString ( & rnd , kOperandSize ) ;
ASSERT_OK ( db_ - > Merge ( WriteOptions ( ) , key , value ) ) ;
if ( true_data [ key ] < value ) {
true_data [ key ] = value ;
}
}
// Overwrite random kNumPutAfter keys
for ( int i = 0 ; i < kNumPutAfter ; i + + ) {
std : : string key = Key ( rnd . Next ( ) % kKeyRange ) ;
std : : string value = RandomString ( & rnd , kOperandSize ) ;
ASSERT_OK ( db_ - > Put ( WriteOptions ( ) , key , value ) ) ;
true_data [ key ] = value ;
}
// Delete random kNumDelete keys
for ( int i = 0 ; i < kNumDelete ; i + + ) {
std : : string key = Key ( rnd . Next ( ) % kKeyRange ) ;
ASSERT_OK ( db_ - > Delete ( WriteOptions ( ) , key ) ) ;
true_data . erase ( key ) ;
}
VerifyDBFromMap ( true_data ) ;
} while ( ChangeOptions ( kSkipMergePut ) ) ;
}
class MergeOperatorHook : public MergeOperator {
class MergeOperatorHook : public MergeOperator {
public :
public :
explicit MergeOperatorHook ( std : : shared_ptr < MergeOperator > _merge_op )
explicit MergeOperatorHook ( std : : shared_ptr < MergeOperator > _merge_op )
@ -637,6 +575,86 @@ TEST_F(DBMergeOperatorTest, SnapshotCheckerAndReadCallback) {
db_ - > ReleaseSnapshot ( snapshot2 ) ;
db_ - > ReleaseSnapshot ( snapshot2 ) ;
}
}
class PerConfigMergeOperatorPinningTest
: public DBMergeOperatorTest ,
public testing : : WithParamInterface < std : : tuple < bool , int > > {
public :
PerConfigMergeOperatorPinningTest ( ) {
std : : tie ( disable_block_cache_ , option_config_ ) = GetParam ( ) ;
}
bool disable_block_cache_ ;
} ;
INSTANTIATE_TEST_CASE_P (
MergeOperatorPinningTest , PerConfigMergeOperatorPinningTest ,
: : testing : : Combine ( : : testing : : Bool ( ) ,
: : testing : : Range ( static_cast < int > ( DBTestBase : : kDefault ) ,
static_cast < int > ( DBTestBase : : kEnd ) ) ) ) ;
TEST_P ( PerConfigMergeOperatorPinningTest , Randomized ) {
if ( ShouldSkipOptions ( option_config_ , kSkipMergePut ) ) {
return ;
}
Options options = CurrentOptions ( ) ;
options . merge_operator = MergeOperators : : CreateMaxOperator ( ) ;
BlockBasedTableOptions table_options ;
table_options . no_block_cache = disable_block_cache_ ;
options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ;
DestroyAndReopen ( options ) ;
Random rnd ( 301 ) ;
std : : map < std : : string , std : : string > true_data ;
const int kTotalMerges = 5000 ;
// Every key gets ~10 operands
const int kKeyRange = kTotalMerges / 10 ;
const int kOperandSize = 20 ;
const int kNumPutBefore = kKeyRange / 10 ; // 10% value
const int kNumPutAfter = kKeyRange / 10 ; // 10% overwrite
const int kNumDelete = kKeyRange / 10 ; // 10% delete
// kNumPutBefore keys will have base values
for ( int i = 0 ; i < kNumPutBefore ; i + + ) {
std : : string key = Key ( rnd . Next ( ) % kKeyRange ) ;
std : : string value = RandomString ( & rnd , kOperandSize ) ;
ASSERT_OK ( db_ - > Put ( WriteOptions ( ) , key , value ) ) ;
true_data [ key ] = value ;
}
// Do kTotalMerges merges
for ( int i = 0 ; i < kTotalMerges ; i + + ) {
std : : string key = Key ( rnd . Next ( ) % kKeyRange ) ;
std : : string value = RandomString ( & rnd , kOperandSize ) ;
ASSERT_OK ( db_ - > Merge ( WriteOptions ( ) , key , value ) ) ;
if ( true_data [ key ] < value ) {
true_data [ key ] = value ;
}
}
// Overwrite random kNumPutAfter keys
for ( int i = 0 ; i < kNumPutAfter ; i + + ) {
std : : string key = Key ( rnd . Next ( ) % kKeyRange ) ;
std : : string value = RandomString ( & rnd , kOperandSize ) ;
ASSERT_OK ( db_ - > Put ( WriteOptions ( ) , key , value ) ) ;
true_data [ key ] = value ;
}
// Delete random kNumDelete keys
for ( int i = 0 ; i < kNumDelete ; i + + ) {
std : : string key = Key ( rnd . Next ( ) % kKeyRange ) ;
ASSERT_OK ( db_ - > Delete ( WriteOptions ( ) , key ) ) ;
true_data . erase ( key ) ;
}
VerifyDBFromMap ( true_data ) ;
}
} // namespace rocksdb
} // namespace rocksdb
int main ( int argc , char * * argv ) {
int main ( int argc , char * * argv ) {