MCPcopy Create free account
hub / github.com/ElementsProject/elements / BackgroundCompaction

Method BackgroundCompaction

src/leveldb/db/db_impl.cc:698–777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

696}
697
698void DBImpl::BackgroundCompaction() {
699 mutex_.AssertHeld();
700
701 if (imm_ != nullptr) {
702 CompactMemTable();
703 return;
704 }
705
706 Compaction* c;
707 bool is_manual = (manual_compaction_ != nullptr);
708 InternalKey manual_end;
709 if (is_manual) {
710 ManualCompaction* m = manual_compaction_;
711 c = versions_->CompactRange(m->level, m->begin, m->end);
712 m->done = (c == nullptr);
713 if (c != nullptr) {
714 manual_end = c->input(0, c->num_input_files(0) - 1)->largest;
715 }
716 Log(options_.info_log,
717 "Manual compaction at level-%d from %s .. %s; will stop at %s\n",
718 m->level, (m->begin ? m->begin->DebugString().c_str() : "(begin)"),
719 (m->end ? m->end->DebugString().c_str() : "(end)"),
720 (m->done ? "(end)" : manual_end.DebugString().c_str()));
721 } else {
722 c = versions_->PickCompaction();
723 }
724
725 Status status;
726 if (c == nullptr) {
727 // Nothing to do
728 } else if (!is_manual && c->IsTrivialMove()) {
729 // Move file to next level
730 assert(c->num_input_files(0) == 1);
731 FileMetaData* f = c->input(0, 0);
732 c->edit()->DeleteFile(c->level(), f->number);
733 c->edit()->AddFile(c->level() + 1, f->number, f->file_size, f->smallest,
734 f->largest);
735 status = versions_->LogAndApply(c->edit(), &mutex_);
736 if (!status.ok()) {
737 RecordBackgroundError(status);
738 }
739 VersionSet::LevelSummaryStorage tmp;
740 Log(options_.info_log, "Moved #%lld to level-%d %lld bytes %s: %s\n",
741 static_cast<unsigned long long>(f->number), c->level() + 1,
742 static_cast<unsigned long long>(f->file_size),
743 status.ToString().c_str(), versions_->LevelSummary(&tmp));
744 } else {
745 CompactionState* compact = new CompactionState(c);
746 status = DoCompactionWork(compact);
747 if (!status.ok()) {
748 RecordBackgroundError(status);
749 }
750 CleanupCompaction(compact);
751 c->ReleaseInputs();
752 DeleteObsoleteFiles();
753 }
754 delete c;
755

Callers

nothing calls this directly

Calls 15

LogFunction · 0.85
num_input_filesMethod · 0.80
PickCompactionMethod · 0.80
IsTrivialMoveMethod · 0.80
editMethod · 0.80
levelMethod · 0.80
AddFileMethod · 0.80
LogAndApplyMethod · 0.80
LevelSummaryMethod · 0.80
ReleaseInputsMethod · 0.80
CompactRangeMethod · 0.45
inputMethod · 0.45

Tested by

no test coverage detected