VDB 1.0.2.1 Released:Radical Refactoring

VDB is a header-only modern C++23/26 embedded key-value database - storage engine(B+ tree, MVCC, page format, lock model, free list, spill, page, nested transactions) derived from LMDB, common interface layer for modern C++ encapsulation(RAII move-only handles,std::expected / std::error_code / std::span).

1.0.2.1 is the first modified version on the 1.0.2 baseline. This versionNo new features, no behavior changes, disk and lock format bytes have not been moved- Its whole content is a planned and verifiable radical equivalent reconstruction of the remnants of the pre-modernization traces of the engine.

Why it's worth publishing

The special feature of the header-only library is that :What users compile is your source codeEvery dead loop style in the engine. for (i = 0; i n; i++), every naked place memcpy(ptr, data, size), each int The returned error code will appear in the user's build log and static analysis.

The quality access control of VDB is a two-way deterministic regression:

  • golden return: Byte-by-byte comparison of sample library files ;
  • baseline hash regression: 5 operating modes to hash stdout and library files.

All changes in this reconstruction are based on the hard constraint of "two regressions pass as they are" - the final golden is consistent byte-by-byte, and all 5 schema hashes are consistent,C++23 / C++26 double standard 13/13 test passes , compilation zero warnings.

Major changes

Byte Handling: memcpy To the Type-safe view

New copy_bytes / move_bytes / fill_bytes / zero_bytes A set of span assistants ( internal is still memcpy/memmove guarantee production code ), put the engine in about 25 places memcpy/memmove/memset Inclusion. Key distinction:Non-overlapping copiesWithOverlapping and moving within the page(memmove semantics ) are now two names , call points are no longer possible to use memcpy to move overlapping areas.page_copy The (x + align-1) & -align The magic expression is replaced with a named alignment assistant.

Control Flow : Eliminate Handwritten Index Loops

About 30 remaining locations for (i = 0; i < n; i++) Convergence to std::views::iota / std::ranges:B+ Pointer table compression when tree nodes are deleted, cursor stack correction when page splitting, sublibrary directory search, cursor linked list traversal ( Unified intrusive_range).hash() The FNV-1a was rewritten as std::ranges::fold_left. .

Error Model:int → std::expected

env_map Migrating to status(std::expected<void, int>),dbi_open The error chain is changed to early-return Unexpected Form , library name copy from strdup + Handmade free changed to malloc_unique Exclusive buffer( Failure path is automatically released). Resource acquisition class functions now return consistently result<T> / status. .

Enumeration closing blocks spelling drift

  • Inside the engine VDB_cursor_op From naked enum Upgrade to enum class, and the public layer vdb::cursor_op The correspondence has been expanded from 4 sampling static_assert to 18 items**;
  • txn_state Completing the native bit operation , and txn_end_mode / page_search_mode Consistent Shape;
  • Public Position Sign Supplement operator^ / ~ / &= / ^=. .

C++23 deducing this: one part to replace two copies

Three pairs of const / non-const accessors with explicit object parameter parameters of C++23(VDB_node::key()/data(),DB_page::node_ptr(),node_range). Midway discovered GCC evaluation of trailing return type Self There are quirks , use if constexpr Branch derivation bypass , and leave a note in the comments.

Other improvements

  • mn_lo/mn_hi Four repeated bits are supposed to receive join_halves/split_halves A pair of assistants;
  • Error code table changed to X-macro:types.hpp New VDB_ERRC_LIST,enum errc Generate the same list as the engine error string - the new error code has only been changed in one place, "table order misalignment string words" has been mechanically eliminated;
  • New page_offset_as<T> The opening logic of the node/meta page accessor in the public skeleton is no longer repeated.

Changes for users

ZeroPublic APIs, ABIs, disk formats, lock file layouts, and error code values are all frozen. The upgrade does not affect any existing data files or any call codes.

For users of the typical use of source-level integration(header-only,The only perceptible change is that the code compiled into your project is more modern: run clang-tidy with one less batch bugprone-* / cppcoreguidelines-* Alerts, No more naked when reading code memcpy With for (i = 0; …). .

Related links

Leave a Comment