@ -2137,6 +2137,9 @@ TEST_F(ColumnFamilyTest, CreateAndDropRace) {
TEST_F ( ColumnFamilyTest , WriteStallSingleColumnFamily ) {
const uint64_t kBaseRate = 810000u ;
db_options_ . delayed_write_rate = kBaseRate ;
db_options_ . base_background_compactions = 2 ;
db_options_ . max_background_compactions = 6 ;
Open ( { " default " } ) ;
ColumnFamilyData * cfd =
static_cast < ColumnFamilyHandleImpl * > ( db_ - > DefaultColumnFamily ( ) ) - > cfd ( ) ;
@ -2162,6 +2165,7 @@ TEST_F(ColumnFamilyTest, WriteStallSingleColumnFamily) {
ASSERT_TRUE ( ! dbfull ( ) - > TEST_write_controler ( ) . IsStopped ( ) ) ;
ASSERT_TRUE ( dbfull ( ) - > TEST_write_controler ( ) . NeedsDelay ( ) ) ;
ASSERT_EQ ( kBaseRate , dbfull ( ) - > TEST_write_controler ( ) . delayed_write_rate ( ) ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > TEST_set_estimated_compaction_needed_bytes ( 400 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
@ -2169,6 +2173,7 @@ TEST_F(ColumnFamilyTest, WriteStallSingleColumnFamily) {
ASSERT_TRUE ( dbfull ( ) - > TEST_write_controler ( ) . NeedsDelay ( ) ) ;
ASSERT_EQ ( kBaseRate / 1.2 ,
dbfull ( ) - > TEST_write_controler ( ) . delayed_write_rate ( ) ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > TEST_set_estimated_compaction_needed_bytes ( 500 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
@ -2224,6 +2229,7 @@ TEST_F(ColumnFamilyTest, WriteStallSingleColumnFamily) {
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_TRUE ( dbfull ( ) - > TEST_write_controler ( ) . IsStopped ( ) ) ;
ASSERT_TRUE ( ! dbfull ( ) - > TEST_write_controler ( ) . NeedsDelay ( ) ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > TEST_set_estimated_compaction_needed_bytes ( 3001 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
@ -2248,6 +2254,7 @@ TEST_F(ColumnFamilyTest, WriteStallSingleColumnFamily) {
ASSERT_TRUE ( dbfull ( ) - > TEST_write_controler ( ) . NeedsDelay ( ) ) ;
ASSERT_EQ ( kBaseRate / 1.2 ,
dbfull ( ) - > TEST_write_controler ( ) . delayed_write_rate ( ) ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > set_l0_delay_trigger_count ( 101 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
@ -2320,6 +2327,73 @@ TEST_F(ColumnFamilyTest, WriteStallSingleColumnFamily) {
dbfull ( ) - > TEST_write_controler ( ) . delayed_write_rate ( ) ) ;
}
TEST_F ( ColumnFamilyTest , CompactionSpeedupSingleColumnFamily ) {
db_options_ . base_background_compactions = 2 ;
db_options_ . max_background_compactions = 6 ;
Open ( { " default " } ) ;
ColumnFamilyData * cfd =
static_cast < ColumnFamilyHandleImpl * > ( db_ - > DefaultColumnFamily ( ) ) - > cfd ( ) ;
VersionStorageInfo * vstorage = cfd - > current ( ) - > storage_info ( ) ;
MutableCFOptions mutable_cf_options (
Options ( db_options_ , column_family_options_ ) ,
ImmutableCFOptions ( Options ( db_options_ , column_family_options_ ) ) ) ;
// Speed up threshold = min(4 * 2, 4 + (36 - 4)/4) = 8
mutable_cf_options . level0_file_num_compaction_trigger = 4 ;
mutable_cf_options . level0_slowdown_writes_trigger = 36 ;
mutable_cf_options . level0_stop_writes_trigger = 50 ;
// Speedup threshold = 200 / 4 = 50
mutable_cf_options . soft_pending_compaction_bytes_limit = 200 ;
mutable_cf_options . hard_pending_compaction_bytes_limit = 2000 ;
vstorage - > TEST_set_estimated_compaction_needed_bytes ( 40 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 2 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > TEST_set_estimated_compaction_needed_bytes ( 50 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > TEST_set_estimated_compaction_needed_bytes ( 300 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > TEST_set_estimated_compaction_needed_bytes ( 45 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 2 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > set_l0_delay_trigger_count ( 7 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 2 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > set_l0_delay_trigger_count ( 9 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > set_l0_delay_trigger_count ( 6 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 2 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
// Speed up threshold = min(4 * 2, 4 + (12 - 4)/4) = 6
mutable_cf_options . level0_file_num_compaction_trigger = 4 ;
mutable_cf_options . level0_slowdown_writes_trigger = 16 ;
mutable_cf_options . level0_stop_writes_trigger = 30 ;
vstorage - > set_l0_delay_trigger_count ( 5 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 2 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > set_l0_delay_trigger_count ( 7 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > set_l0_delay_trigger_count ( 3 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 2 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
}
TEST_F ( ColumnFamilyTest , WriteStallTwoColumnFamilies ) {
const uint64_t kBaseRate = 810000u ;
db_options_ . delayed_write_rate = kBaseRate ;
@ -2401,6 +2475,74 @@ TEST_F(ColumnFamilyTest, WriteStallTwoColumnFamilies) {
ASSERT_EQ ( kBaseRate / 1.2 ,
dbfull ( ) - > TEST_write_controler ( ) . delayed_write_rate ( ) ) ;
}
TEST_F ( ColumnFamilyTest , CompactionSpeedupTwoColumnFamilies ) {
db_options_ . base_background_compactions = 2 ;
db_options_ . max_background_compactions = 6 ;
column_family_options_ . soft_pending_compaction_bytes_limit = 200 ;
column_family_options_ . hard_pending_compaction_bytes_limit = 2000 ;
Open ( ) ;
CreateColumnFamilies ( { " one " } ) ;
ColumnFamilyData * cfd =
static_cast < ColumnFamilyHandleImpl * > ( db_ - > DefaultColumnFamily ( ) ) - > cfd ( ) ;
VersionStorageInfo * vstorage = cfd - > current ( ) - > storage_info ( ) ;
ColumnFamilyData * cfd1 =
static_cast < ColumnFamilyHandleImpl * > ( handles_ [ 1 ] ) - > cfd ( ) ;
VersionStorageInfo * vstorage1 = cfd1 - > current ( ) - > storage_info ( ) ;
MutableCFOptions mutable_cf_options (
Options ( db_options_ , column_family_options_ ) ,
ImmutableCFOptions ( Options ( db_options_ , column_family_options_ ) ) ) ;
// Speed up threshold = min(4 * 2, 4 + (36 - 4)/4) = 8
mutable_cf_options . level0_file_num_compaction_trigger = 4 ;
mutable_cf_options . level0_slowdown_writes_trigger = 36 ;
mutable_cf_options . level0_stop_writes_trigger = 30 ;
// Speedup threshold = 200 / 4 = 50
mutable_cf_options . soft_pending_compaction_bytes_limit = 200 ;
mutable_cf_options . hard_pending_compaction_bytes_limit = 2000 ;
MutableCFOptions mutable_cf_options1 = mutable_cf_options ;
mutable_cf_options1 . level0_slowdown_writes_trigger = 16 ;
vstorage - > TEST_set_estimated_compaction_needed_bytes ( 40 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 2 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > TEST_set_estimated_compaction_needed_bytes ( 60 ) ;
cfd1 - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 2 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage1 - > TEST_set_estimated_compaction_needed_bytes ( 30 ) ;
cfd1 - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage1 - > TEST_set_estimated_compaction_needed_bytes ( 70 ) ;
cfd1 - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > TEST_set_estimated_compaction_needed_bytes ( 20 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage1 - > TEST_set_estimated_compaction_needed_bytes ( 3 ) ;
cfd1 - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 2 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > set_l0_delay_trigger_count ( 9 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage1 - > set_l0_delay_trigger_count ( 2 ) ;
cfd1 - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 6 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
vstorage - > set_l0_delay_trigger_count ( 0 ) ;
cfd - > RecalculateWriteStallConditions ( mutable_cf_options ) ;
ASSERT_EQ ( 2 , dbfull ( ) - > BGCompactionsAllowed ( ) ) ;
}
} // namespace rocksdb
int main ( int argc , char * * argv ) {