@@ -142,6 +142,9 @@ Options SanitizeOptions(const std::string& dbname,
142
142
DBOptions SanitizeOptions (const std::string& dbname, const DBOptions& src) {
143
143
DBOptions result = src;
144
144
ClipToRange (&result.max_open_files , 20 , 1000000 );
145
+ if (result.max_background_flushes == 0 ) {
146
+ result.max_background_flushes = 1 ;
147
+ }
145
148
146
149
if (result.info_log == nullptr ) {
147
150
Status s = CreateLoggerFromOptions (dbname, result.db_log_dir , src.env ,
@@ -1704,11 +1707,15 @@ void DBImpl::MaybeScheduleFlushOrCompaction() {
1704
1707
is_flush_pending = true ;
1705
1708
}
1706
1709
}
1707
- if (is_flush_pending &&
1708
- (bg_flush_scheduled_ < options_.max_background_flushes )) {
1710
+ if (is_flush_pending) {
1709
1711
// memtable flush needed
1710
- bg_flush_scheduled_++;
1711
- env_->Schedule (&DBImpl::BGWorkFlush, this , Env::Priority::HIGH);
1712
+ // max_background_compactions should not be 0, because that means
1713
+ // flush will never get executed
1714
+ assert (options_.max_background_flushes != 0 );
1715
+ if (bg_flush_scheduled_ < options_.max_background_flushes ) {
1716
+ bg_flush_scheduled_++;
1717
+ env_->Schedule (&DBImpl::BGWorkFlush, this , Env::Priority::HIGH);
1718
+ }
1712
1719
}
1713
1720
bool is_compaction_needed = false ;
1714
1721
for (auto cfd : *versions_->GetColumnFamilySet ()) {
@@ -1718,12 +1725,10 @@ void DBImpl::MaybeScheduleFlushOrCompaction() {
1718
1725
}
1719
1726
}
1720
1727
1721
- // Schedule BGWorkCompaction if there's a compaction pending (or a memtable
1722
- // flush, but the HIGH pool is not enabled). Do it only if
1723
- // max_background_compactions hasn't been reached and, in case
1728
+ // Schedule BGWorkCompaction if there's a compaction pending
1729
+ // Do it only if max_background_compactions hasn't been reached and, in case
1724
1730
// bg_manual_only_ > 0, if it's a manual compaction.
1725
- if ((manual_compaction_ || is_compaction_needed ||
1726
- (is_flush_pending && (options_.max_background_flushes <= 0 ))) &&
1731
+ if ((manual_compaction_ || is_compaction_needed) &&
1727
1732
bg_compaction_scheduled_ < options_.max_background_compactions &&
1728
1733
(!bg_manual_only_ || manual_compaction_)) {
1729
1734
@@ -1868,41 +1873,14 @@ Status DBImpl::BackgroundCompaction(bool* madeProgress,
1868
1873
*madeProgress = false ;
1869
1874
mutex_.AssertHeld ();
1870
1875
1876
+ unique_ptr<Compaction> c;
1871
1877
bool is_manual = (manual_compaction_ != nullptr ) &&
1872
1878
(manual_compaction_->in_progress == false );
1873
- if (is_manual) {
1874
- // another thread cannot pick up the same work
1875
- manual_compaction_->in_progress = true ;
1876
- }
1877
-
1878
- // TODO: remove memtable flush from formal compaction
1879
- for (auto cfd : *versions_->GetColumnFamilySet ()) {
1880
- while (cfd->imm ()->IsFlushPending ()) {
1881
- Log (options_.info_log ,
1882
- " BackgroundCompaction doing FlushMemTableToOutputFile with column "
1883
- " family %d, compaction slots available %d" ,
1884
- cfd->GetID (),
1885
- options_.max_background_compactions - bg_compaction_scheduled_);
1886
- Status stat =
1887
- FlushMemTableToOutputFile (cfd, madeProgress, deletion_state);
1888
- if (!stat.ok ()) {
1889
- if (is_manual) {
1890
- manual_compaction_->status = stat;
1891
- manual_compaction_->done = true ;
1892
- manual_compaction_->in_progress = false ;
1893
- manual_compaction_ = nullptr ;
1894
- }
1895
- return stat;
1896
- }
1897
- }
1898
- }
1899
-
1900
- unique_ptr<Compaction> c;
1901
1879
InternalKey manual_end_storage;
1902
1880
InternalKey* manual_end = &manual_end_storage;
1903
1881
if (is_manual) {
1904
1882
ManualCompaction* m = manual_compaction_;
1905
- assert ( m->in_progress ) ;
1883
+ m->in_progress = true ;
1906
1884
c.reset (m->cfd ->CompactRange (m->input_level , m->output_level , m->begin ,
1907
1885
m->end , &manual_end));
1908
1886
if (!c) {
@@ -2299,20 +2277,6 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
2299
2277
}
2300
2278
2301
2279
for (; input->Valid () && !shutting_down_.Acquire_Load (); ) {
2302
- // Prioritize immutable compaction work
2303
- // TODO: remove memtable flush from normal compaction work
2304
- if (cfd->imm ()->imm_flush_needed .NoBarrier_Load () != nullptr ) {
2305
- const uint64_t imm_start = env_->NowMicros ();
2306
- LogFlush (options_.info_log );
2307
- mutex_.Lock ();
2308
- if (cfd->imm ()->IsFlushPending ()) {
2309
- FlushMemTableToOutputFile (cfd, nullptr , deletion_state);
2310
- bg_cv_.SignalAll (); // Wakeup MakeRoomForWrite() if necessary
2311
- }
2312
- mutex_.Unlock ();
2313
- imm_micros += (env_->NowMicros () - imm_start);
2314
- }
2315
-
2316
2280
Slice key = input->key ();
2317
2281
Slice value = input->value ();
2318
2282
0 commit comments