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.
2251delete db;2252db = nullptr;2254Env* env = Env::Default();2256port::Mutex mu;2257MutexLock l(&mu);2259InternalKeyComparator cmp(BytewiseComparator());2260Options options;2261VersionSet vset(dbname, &options, nullptr, &cmp);2262bool save_manifest;2263ASSERT_OK(vset.Recover(&save_manifest));2264VersionEdit vbase;2265uint64_t fnum = 1;2266for (int i = 0; i < num_base_files; i++) {2267InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);2268InternalKey limit(MakeKey(2 * fnum + 1), 1, kTypeDeletion);2269vbase.AddFile(2, fnum++, 1 /* file size */, start, limit);2270}2271ASSERT_OK(vset.LogAndApply(&vbase, &mu));2273uint64_t start_micros = env->NowMicros();2275for (int i = 0; i < iters; i++) {2276VersionEdit vedit;2277vedit.DeleteFile(2, fnum);2278InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);2279InternalKey limit(MakeKey(2 * fnum + 1), 1, kTypeDeletion);2280vedit.AddFile(2, fnum++, 1 /* file size */, start, limit);2281vset.LogAndApply(&vedit, &mu);2282}2283uint64_t stop_micros = env->NowMicros();2284unsigned int us = stop_micros - start_micros;2285char buf[16];2286snprintf(buf, sizeof(buf), "%d", num_base_files);2287fprintf(stderr,2288"BM_LogAndApply/%-6s %8d iters : %9u us (%7.0f us / iter)\n", buf,2289iters, us, ((float)us) / iters);2290}2292} // namespace leveldb2294int main(int argc, char** argv) {2295if (argc > 1 && std::string(argv[1]) == "--benchmark") {2296leveldb::BM_LogAndApply(1000, 1);2297leveldb::BM_LogAndApply(1000, 100);2298leveldb::BM_LogAndApply(1000, 10000);2299leveldb::BM_LogAndApply(100, 100000);2300return 0;2301}2303return leveldb::test::RunAllTests();2304}
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.