summaryrefslogtreecommitdiff
path: root/db/db_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'db/db_impl.cc')
-rw-r--r--db/db_impl.cc23
1 files changed, 19 insertions, 4 deletions
diff --git a/db/db_impl.cc b/db/db_impl.cc
index c9c9023..90c1c81 100644
--- a/db/db_impl.cc
+++ b/db/db_impl.cc
@@ -608,8 +608,21 @@ void DBImpl::BackgroundCall() {
MutexLock l(&mutex_);
assert(bg_compaction_scheduled_);
if (!shutting_down_.Acquire_Load()) {
- BackgroundCompaction();
+ Status s = BackgroundCompaction();
+ if (!s.ok()) {
+ // Wait a little bit before retrying background compaction in
+ // case this is an environmental problem and we do not want to
+ // chew up resources for failed compactions for the duration of
+ // the problem.
+ bg_cv_.SignalAll(); // In case a waiter can proceed despite the error
+ Log(options_.info_log, "Waiting after background compaction error: %s",
+ s.ToString().c_str());
+ mutex_.Unlock();
+ env_->SleepForMicroseconds(1000000);
+ mutex_.Lock();
+ }
}
+
bg_compaction_scheduled_ = false;
// Previous compaction may have produced too many files in a level,
@@ -618,12 +631,11 @@ void DBImpl::BackgroundCall() {
bg_cv_.SignalAll();
}
-void DBImpl::BackgroundCompaction() {
+Status DBImpl::BackgroundCompaction() {
mutex_.AssertHeld();
if (imm_ != NULL) {
- CompactMemTable();
- return;
+ return CompactMemTable();
}
Compaction* c;
@@ -698,6 +710,7 @@ void DBImpl::BackgroundCompaction() {
}
manual_compaction_ = NULL;
}
+ return status;
}
void DBImpl::CleanupCompaction(CompactionState* compact) {
@@ -1263,6 +1276,8 @@ Status DBImpl::MakeRoomForWrite(bool force) {
WritableFile* lfile = NULL;
s = env_->NewWritableFile(LogFileName(dbname_, new_log_number), &lfile);
if (!s.ok()) {
+ // Avoid chewing through file number space in a tight loop.
+ versions_->ReuseFileNumber(new_log_number);
break;
}
delete log_;