@@ -3020,6 +3020,75 @@ TEST_P(ColumnFamilyTest, CompactionSpeedupForCompactionDebt) {
3020
3020
}
3021
3021
}
3022
3022
3023
+ TEST_P (ColumnFamilyTest, CompactionSpeedupForMarkedFiles) {
3024
+ const int kParallelismLimit = 3 ;
3025
+ class AlwaysCompactTpc : public TablePropertiesCollector {
3026
+ public:
3027
+ Status Finish (UserCollectedProperties* /* properties */ ) override {
3028
+ return Status::OK ();
3029
+ }
3030
+
3031
+ UserCollectedProperties GetReadableProperties () const override {
3032
+ return UserCollectedProperties{};
3033
+ }
3034
+
3035
+ const char * Name () const override { return " AlwaysCompactTpc" ; }
3036
+
3037
+ bool NeedCompact () const override { return true ; }
3038
+ };
3039
+
3040
+ class AlwaysCompactTpcf : public TablePropertiesCollectorFactory {
3041
+ public:
3042
+ TablePropertiesCollector* CreateTablePropertiesCollector (
3043
+ TablePropertiesCollectorFactory::Context /* context */ ) override {
3044
+ return new AlwaysCompactTpc ();
3045
+ }
3046
+
3047
+ const char * Name () const override { return " AlwaysCompactTpcf" ; }
3048
+ };
3049
+
3050
+ column_family_options_.num_levels = 2 ;
3051
+ column_family_options_.table_properties_collector_factories .emplace_back (
3052
+ std::make_shared<AlwaysCompactTpcf>());
3053
+ db_options_.max_background_compactions = kParallelismLimit ;
3054
+ Open ();
3055
+
3056
+ // Make a nonempty last level. Only marked files in upper levels count.
3057
+ ASSERT_OK (db_->Put (WriteOptions (), " foo" , " bar" ));
3058
+ ASSERT_OK (db_->Flush (FlushOptions ()));
3059
+ WaitForCompaction ();
3060
+ AssertFilesPerLevel (" 0,1" , 0 /* cf */ );
3061
+
3062
+ // Block the compaction thread pool so marked files accumulate in L0.
3063
+ test::SleepingBackgroundTask sleeping_tasks[kParallelismLimit ];
3064
+ for (int i = 0 ; i < kParallelismLimit ; i++) {
3065
+ env_->Schedule (&test::SleepingBackgroundTask::DoSleepTask,
3066
+ &sleeping_tasks[i], Env::Priority::LOW);
3067
+ sleeping_tasks[i].WaitUntilSleeping ();
3068
+ }
3069
+
3070
+ // Zero marked upper-level files. No speedup.
3071
+ ASSERT_EQ (1 , dbfull ()->TEST_BGCompactionsAllowed ());
3072
+ AssertFilesPerLevel (" 0,1" , 0 /* cf */ );
3073
+
3074
+ // One marked upper-level file. No speedup.
3075
+ ASSERT_OK (db_->Put (WriteOptions (), " foo" , " bar" ));
3076
+ ASSERT_OK (db_->Flush (FlushOptions ()));
3077
+ ASSERT_EQ (1 , dbfull ()->TEST_BGCompactionsAllowed ());
3078
+ AssertFilesPerLevel (" 1,1" , 0 /* cf */ );
3079
+
3080
+ // Two marked upper-level files. Speedup.
3081
+ ASSERT_OK (db_->Put (WriteOptions (), " foo" , " bar" ));
3082
+ ASSERT_OK (db_->Flush (FlushOptions ()));
3083
+ ASSERT_EQ (kParallelismLimit , dbfull ()->TEST_BGCompactionsAllowed ());
3084
+ AssertFilesPerLevel (" 2,1" , 0 /* cf */ );
3085
+
3086
+ for (int i = 0 ; i < kParallelismLimit ; i++) {
3087
+ sleeping_tasks[i].WakeUp ();
3088
+ sleeping_tasks[i].WaitUntilDone ();
3089
+ }
3090
+ }
3091
+
3023
3092
TEST_P (ColumnFamilyTest, CreateAndDestroyOptions) {
3024
3093
std::unique_ptr<ColumnFamilyOptions> cfo (new ColumnFamilyOptions ());
3025
3094
ColumnFamilyHandle* cfh;
0 commit comments