Permalink
Browse files

Move the DB::Open pause code to new location so as to let foreground …

…processing of recovery logs properly post to version_set before starting background compactions.
  • Loading branch information...
1 parent 25000de commit 206b27719ba6eba377bd2f1317dc4008955604bf MatthewVon committed Jun 25, 2013
Showing with 54 additions and 38 deletions.
  1. +49 −38 db/db_impl.cc
  2. +5 −0 db/db_impl.h
View
@@ -457,51 +457,62 @@ Status DBImpl::Recover(VersionEdit* edit) {
}
}
- // Verify Riak 1.4 level sizing, run compactions to fix as necessary
- // (also recompacts hard repair of all files to level 0)
- if (s.ok())
- {
- bool log_flag, need_compaction;
+ return s;
+}
- log_flag=false;
- need_compaction=false;
- // loop on pending background compactions
- // reminder: mutex_ is held
- do
- {
- int level;
+void DBImpl::CheckCompactionState()
+{
+ mutex_.AssertHeld();
+ bool log_flag, need_compaction;
- // wait out executing compaction (Wait gives mutex to compactions)
- if (bg_compaction_scheduled_)
- bg_cv_.Wait();
+ // Verify Riak 1.4 level sizing, run compactions to fix as necessary
+ // (also recompacts hard repair of all files to level 0)
- for (level=0, need_compaction=false;
- level<config::kNumLevels && !need_compaction;
- ++level)
- {
- if (versions_->IsLevelOverlapped(level)
- && config::kL0_SlowdownWritesTrigger<=versions_->NumLevelFiles(level))
- {
- need_compaction=true;
- MaybeScheduleCompaction();
- if (!log_flag)
- {
- log_flag=true;
- Log(options_.info_log, "Cleanup compactions started ... DB::Open paused");
- } // if
- } //if
- } // for
+ log_flag=false;
+ need_compaction=false;
- } while(bg_compaction_scheduled_ && need_compaction);
+ // loop on pending background compactions
+ // reminder: mutex_ is held
+ do
+ {
+ int level;
- if (log_flag)
- Log(options_.info_log, "Cleanup compactions completed ... DB::Open continuing");
+ // wait out executing compaction (Wait gives mutex to compactions)
+ if (bg_compaction_scheduled_)
+ bg_cv_.Wait();
- } // if
+ for (level=0, need_compaction=false;
+ level<config::kNumLevels && !need_compaction;
+ ++level)
+ {
+ if (versions_->IsLevelOverlapped(level)
+ && config::kL0_SlowdownWritesTrigger<=versions_->NumLevelFiles(level))
+ {
+ need_compaction=true;
+ MaybeScheduleCompaction();
+ if (!log_flag)
+ {
+ log_flag=true;
+ Log(options_.info_log, "Cleanup compactions started ... DB::Open paused");
+ } // if
+ } //if
+ } // for
+
+ } while(bg_compaction_scheduled_ && need_compaction);
+
+ if (log_flag)
+ Log(options_.info_log, "Cleanup compactions completed ... DB::Open continuing");
+
+ // prior code only called this function instead of CheckCompactionState
+ // (duplicates original Google functionality)
+ else
+ MaybeScheduleCompaction();
+
+ return;
+
+} // DBImpl::CheckCompactionState()
- return s;
-}
Status DBImpl::RecoverLogFile(uint64_t log_number,
VersionEdit* edit,
@@ -1821,7 +1832,7 @@ Status DB::Open(const Options& options, const std::string& dbname,
}
if (s.ok()) {
impl->DeleteObsoleteFiles();
- impl->MaybeScheduleCompaction();
+ impl->CheckCompactionState();
}
}
impl->mutex_.Unlock();
View
@@ -77,6 +77,11 @@ class DBImpl : public DB {
// be made to the descriptor are added to *edit.
Status Recover(VersionEdit* edit);
+ // Riak routine: pause DB::Open if too many compactions
+ // stacked up immediately. Happens in some repairs and
+ // some Riak upgrades
+ void CheckCompactionState();
+
void MaybeIgnoreError(Status* s) const;
// Delete any unneeded files and stale in-memory entries.

0 comments on commit 206b277

Please sign in to comment.