| 543 | } |
| 544 | |
| 545 | void DBImpl::CompactMemTable() { |
| 546 | mutex_.AssertHeld(); |
| 547 | assert(imm_ != nullptr); |
| 548 | |
| 549 | // Save the contents of the memtable as a new Table |
| 550 | VersionEdit edit; |
| 551 | Version* base = versions_->current(); |
| 552 | base->Ref(); |
| 553 | Status s = WriteLevel0Table(imm_, &edit, base); |
| 554 | base->Unref(); |
| 555 | |
| 556 | if (s.ok() && shutting_down_.load(std::memory_order_acquire)) { |
| 557 | s = Status::IOError("Deleting DB during memtable compaction"); |
| 558 | } |
| 559 | |
| 560 | // Replace immutable memtable with the generated Table |
| 561 | if (s.ok()) { |
| 562 | edit.SetPrevLogNumber(0); |
| 563 | edit.SetLogNumber(logfile_number_); // Earlier logs no longer needed |
| 564 | s = versions_->LogAndApply(&edit, &mutex_); |
| 565 | } |
| 566 | |
| 567 | if (s.ok()) { |
| 568 | // Commit to the new state |
| 569 | imm_->Unref(); |
| 570 | imm_ = nullptr; |
| 571 | has_imm_.store(false, std::memory_order_release); |
| 572 | DeleteObsoleteFiles(); |
| 573 | } else { |
| 574 | RecordBackgroundError(s); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | void DBImpl::CompactRange(const Slice* begin, const Slice* end) { |
| 579 | int max_level_with_files = 1; |
nothing calls this directly
no test coverage detected