@ -3704,6 +3704,68 @@ TEST_F(DBCompactionTest, CompactionStatsTest) {
VerifyCompactionStats ( * cfd , * collector ) ;
VerifyCompactionStats ( * cfd , * collector ) ;
}
}
TEST_F ( DBCompactionTest , CompactFilesOutputRangeConflict ) {
// LSM setup:
// L1: [ba bz]
// L2: [a b] [c d]
// L3: [a b] [c d]
//
// Thread 1: Thread 2:
// Begin compacting all L2->L3
// Compact [ba bz] L1->L3
// End compacting all L2->L3
//
// The compaction operation in thread 2 should be disallowed because the range
// overlaps with the compaction in thread 1, which also covers that range in
// L3.
Options options = CurrentOptions ( ) ;
FlushedFileCollector * collector = new FlushedFileCollector ( ) ;
options . listeners . emplace_back ( collector ) ;
Reopen ( options ) ;
for ( int level = 3 ; level > = 2 ; - - level ) {
ASSERT_OK ( Put ( " a " , " val " ) ) ;
ASSERT_OK ( Put ( " b " , " val " ) ) ;
ASSERT_OK ( Flush ( ) ) ;
ASSERT_OK ( Put ( " c " , " val " ) ) ;
ASSERT_OK ( Put ( " d " , " val " ) ) ;
ASSERT_OK ( Flush ( ) ) ;
MoveFilesToLevel ( level ) ;
}
ASSERT_OK ( Put ( " ba " , " val " ) ) ;
ASSERT_OK ( Put ( " bz " , " val " ) ) ;
ASSERT_OK ( Flush ( ) ) ;
MoveFilesToLevel ( 1 ) ;
SyncPoint : : GetInstance ( ) - > LoadDependency ( {
{ " CompactFilesImpl:0 " ,
" DBCompactionTest::CompactFilesOutputRangeConflict:Thread2Begin " } ,
{ " DBCompactionTest::CompactFilesOutputRangeConflict:Thread2End " ,
" CompactFilesImpl:1 " } ,
} ) ;
SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
auto bg_thread = port : : Thread ( [ & ] ( ) {
// Thread 1
std : : vector < std : : string > filenames = collector - > GetFlushedFiles ( ) ;
filenames . pop_back ( ) ;
ASSERT_OK ( db_ - > CompactFiles ( CompactionOptions ( ) , filenames ,
3 /* output_level */ ) ) ;
} ) ;
// Thread 2
TEST_SYNC_POINT (
" DBCompactionTest::CompactFilesOutputRangeConflict:Thread2Begin " ) ;
std : : string filename = collector - > GetFlushedFiles ( ) . back ( ) ;
ASSERT_FALSE (
db_ - > CompactFiles ( CompactionOptions ( ) , { filename } , 3 /* output_level */ )
. ok ( ) ) ;
TEST_SYNC_POINT (
" DBCompactionTest::CompactFilesOutputRangeConflict:Thread2End " ) ;
bg_thread . join ( ) ;
}
INSTANTIATE_TEST_CASE_P ( DBCompactionTestWithParam , DBCompactionTestWithParam ,
INSTANTIATE_TEST_CASE_P ( DBCompactionTestWithParam , DBCompactionTestWithParam ,
: : testing : : Values ( std : : make_tuple ( 1 , true ) ,
: : testing : : Values ( std : : make_tuple ( 1 , true ) ,
std : : make_tuple ( 1 , false ) ,
std : : make_tuple ( 1 , false ) ,