Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1501for (size_t i = 0; i < inputs_[which].size(); i++) {1502edit->DeleteFile(level_ + which, inputs_[which][i]->number);1503}1504}1505}1507bool Compaction::IsBaseLevelForKey(const Slice& user_key) {1508// Maybe use binary search to find right entry instead of linear search?1509const Comparator* user_cmp = input_version_->vset_->icmp_.user_comparator();1510for (int lvl = level_ + 2; lvl < config::kNumLevels; lvl++) {1511const std::vector<FileMetaData*>& files = input_version_->files_[lvl];1512while (level_ptrs_[lvl] < files.size()) {1513FileMetaData* f = files[level_ptrs_[lvl]];1514if (user_cmp->Compare(user_key, f->largest.user_key()) <= 0) {1515// We've advanced far enough1516if (user_cmp->Compare(user_key, f->smallest.user_key()) >= 0) {1517// Key falls in this file's range, so definitely not base level1518return false;1519}1520break;1521}1522level_ptrs_[lvl]++;1523}1524}1525return true;1526}1528bool Compaction::ShouldStopBefore(const Slice& internal_key) {1529const VersionSet* vset = input_version_->vset_;1530// Scan to find earliest grandparent file that contains key.1531const InternalKeyComparator* icmp = &vset->icmp_;1532while (grandparent_index_ < grandparents_.size() &&1533icmp->Compare(internal_key,1534grandparents_[grandparent_index_]->largest.Encode()) >15350) {1536if (seen_key_) {1537overlapped_bytes_ += grandparents_[grandparent_index_]->file_size;1538}1539grandparent_index_++;1540}1541seen_key_ = true;1543if (overlapped_bytes_ > MaxGrandParentOverlapBytes(vset->options_)) {1544// Too much overlap for current output; start new output1545overlapped_bytes_ = 0;1546return true;1547} else {1548return false;1549}1550}1552void Compaction::ReleaseInputs() {1553if (input_version_ != nullptr) {1554input_version_->Unref();1555input_version_ = nullptr;1556}1557}1559} // namespace leveldb
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.