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.
1// Copyright (c) 2011 The LevelDB Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file. See the AUTHORS file for names of contributors.5#ifndef STORAGE_LEVELDB_DB_VERSION_EDIT_H_6#define STORAGE_LEVELDB_DB_VERSION_EDIT_H_8#include <set>9#include <utility>10#include <vector>12#include "db/dbformat.h"14namespace leveldb {16class VersionSet;18struct FileMetaData {19FileMetaData() : refs(0), allowed_seeks(1 << 30), file_size(0) {}21int refs;22int allowed_seeks; // Seeks allowed until compaction23uint64_t number;24uint64_t file_size; // File size in bytes25InternalKey smallest; // Smallest internal key served by table26InternalKey largest; // Largest internal key served by table27};29class VersionEdit {30public:31VersionEdit() { Clear(); }32~VersionEdit() = default;34void Clear();36void SetComparatorName(const Slice& name) {37has_comparator_ = true;38comparator_ = name.ToString();39}40void SetLogNumber(uint64_t num) {41has_log_number_ = true;42log_number_ = num;43}44void SetPrevLogNumber(uint64_t num) {45has_prev_log_number_ = true;46prev_log_number_ = num;47}48void SetNextFile(uint64_t num) {49has_next_file_number_ = true;50next_file_number_ = num;51}52void SetLastSequence(SequenceNumber seq) {53has_last_sequence_ = true;54last_sequence_ = seq;55}56void SetCompactPointer(int level, const InternalKey& key) {57compact_pointers_.push_back(std::make_pair(level, key));58}60// Add the specified file at the specified number.61// REQUIRES: This version has not been saved (see VersionSet::SaveTo)62// REQUIRES: "smallest" and "largest" are smallest and largest keys in file63void AddFile(int level, uint64_t file, uint64_t file_size,64const InternalKey& smallest, const InternalKey& largest) {65FileMetaData f;66f.number = file;67f.file_size = file_size;68f.smallest = smallest;69f.largest = largest;70new_files_.push_back(std::make_pair(level, f));71}73// Delete the specified "file" from the specified "level".74void DeleteFile(int level, uint64_t file) {75deleted_files_.insert(std::make_pair(level, file));76}78void EncodeTo(std::string* dst) const;79Status DecodeFrom(const Slice& src);81std::string DebugString() const;83private:84friend class VersionSet;86typedef std::set<std::pair<int, uint64_t>> DeletedFileSet;88std::string comparator_;89uint64_t log_number_;90uint64_t prev_log_number_;91uint64_t next_file_number_;92SequenceNumber last_sequence_;93bool has_comparator_;94bool has_log_number_;95bool has_prev_log_number_;96bool has_next_file_number_;97bool has_last_sequence_;99std::vector<std::pair<int, InternalKey>> compact_pointers_;100DeletedFileSet deleted_files_;101std::vector<std::pair<int, FileMetaData>> new_files_;102};104} // namespace leveldb106#endif // STORAGE_LEVELDB_DB_VERSION_EDIT_H_
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.