Skip to content

Add the public row form, the ManifestStore interface and a test store for MANIFEST metadata stores - #15738

Open
xingbowang wants to merge 2 commits into
meta:mainfrom
xingbowang:export-D133307302
Open

xingbowang wants to merge 2 commits into
meta:mainfrom
xingbowang:export-D133307302

Conversation

@xingbowang

@xingbowang xingbowang commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary:
Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in db/manifest_rows.h already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of include/rocksdb/manifest_store.h defines epoch, claim, commit sequence, commit id and generation. The application must give each DB instance that takes over a DB a newer epoch than all earlier instances. Only such a claim fences the older instance; a claim with the same epoch fences nothing; a Commit() prepared before it gets Busy, because the claim raised the commit sequence.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal ManifestRows, (3) the ManifestStore interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.

  • The new public header include/rocksdb/manifest_store.h defines:
    • the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
    • the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
    • the canonical encoding of the fields of a row (see "Canonical encoding"), with ParseManifestRowFields() and EncodeManifestRowFields();
    • the ManifestStore interface (a Customizable): Open() claims the DB, Commit() applies one atomic change of rows, ReadDbRow() reads the DB row, Scan() reads all rows, WriteGeneration() installs a full replacement set of column family, SST, blob file and WAL rows and updates the DB row in the same atomic switch, and Destroy() removes all rows. Open() and Destroy() take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but Open() returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, Open() claims unconditionally. The claim of a DB open is designed to set both (step 2 of "Call order" in the header): read the DB row, check that it belongs to this DB, claim with the commit sequence and last commit id of that read, and read again and retry after Busy. For Commit() and WriteGeneration(), the comment above the class defines the meaning of each status, so that RocksDB can tell a request that the store did not apply (IOFenced, Busy, TryAgain, NotSupported) from a request with an unknown outcome, such as a timeout. Open() and Destroy() list their own results at their declarations. ManifestStore::CreateFromString() creates a store from a registered class. RocksDB has no built-in store.
  • Internal converters in db/manifest_rows.h: ManifestRowsToPublicRows() turns ManifestRows into public rows, and PublicRowsToManifestRows() turns them back. The comment of PublicRowsToManifestRows() lists every NotSupported and Corruption case and their order. ManifestDbRowExtraFields holds the RocksDB-owned DB row fields that ManifestDbRow does not hold, other than the row format version, which the writer always writes as kManifestRowFormatVersionLatest.
  • DBOptions::manifest_store (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
  • DBOptions::manifest_row_feature_version (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
  • DB::Open(), DB::OpenForReadOnly(), DB::OpenAsSecondary(), DB::OpenAsFollower() and DB::OpenAndCompact() return NotSupported when manifest_store is set, or InvalidArgument when manifest_store is set and manifest_row_feature_version is not from 1 to kManifestRowFeatureVersionLatest. The check runs before the open changes anything on disk (for example before create_if_missing creates the directory). Without a store, the feature version is not checked.
  • MockManifestStore (test_util/mock_manifest_store.h, test code only) keeps rows in memory. Several store objects share one MockManifestStoreData, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A request that the mock keeps pending after a timeout keeps the epoch of the object that made it, so it can still run after that object is destroyed. A test can make Open(), Commit() and WriteGeneration() fail on purpose (the fault list is in the mock header). ReadDbRow(), Scan() and Destroy() fail only for the reasons that the ManifestStore comments give.

Implementation:

  • db/manifest_rows.cc implements the encoding functions, the two converters and ManifestStore::CreateFromString() (with LoadSharedObject()), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
  • One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (EncodeUniqueIdBytes() and DecodeUniqueIdBytes()).
  • A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
  • The key length check runs after all rows are read, because a column family row may come after its file rows.
  • DBImpl::CheckManifestStoreOptions() holds the open check. DBImpl::Open() calls it first (for DB::Open()), and so do both DB::OpenForReadOnly() functions, DBImplSecondary::OpenAsSecondaryImpl() (which DB::OpenAsSecondary() and DB::OpenAndCompact() use) and DB::OpenAsFollower().
  • manifest_store is registered like statistics (AsCustomSharedPtr, with kCompareNever, kDontSerialize and kAllowNull). options.h only forward-declares ManifestStore.
  • The test of the VersionEdit tags (db/version_set_test.cc) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".
**Notable implementation details**
  • The C API generator skips both options (two "deferred" entries in tools/c_api_gen/auto_simple_bindings_blocklist.json), so this diff adds no C API function.
  • MockManifestStore checks the epoch and the expected commit sequence under one lock. WriteGeneration() writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). Scan() copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.

How to read this diff:

  1. include/rocksdb/manifest_store.h: the Background comment, the row types, ManifestRowKey, the field ID enums, then "Canonical encoding"; then in db/manifest_rows.cc (section "Public rows"): GetShortestVarint(), ParseManifestRowFields() and EncodeManifestRowFields().
  2. db/manifest_rows.h: ManifestDbRowExtraFields and the two converter declarations at the end; db/manifest_rows.cc: FieldWriter, the Encode*Row() functions and ManifestRowsToPublicRows().
  3. db/manifest_rows.cc: the reader, bottom-up, as the "reader of public rows" comment maps it: the Get*Value() helpers, ReadRowFields(), the Read*Field() functions, the Decode*Row() functions and DecodeRow(), then PublicRowsToManifestRows().
  4. include/rocksdb/manifest_store.h: the "store interface" part at the end (background, terms, call order, structs, result meanings, ManifestStore).
  5. include/rocksdb/options.h, options/db_options.h, options/db_options.cc and options/options_helper.cc for the two options; then db/db_impl/db_impl.h and db/db_impl/db_impl_open.cc: DBImpl::CheckManifestStoreOptions() and its call in DBImpl::Open(), then the other callers in db_impl_readonly.cc, db_impl_secondary.cc and db_impl_follower.cc.
  6. test_util/mock_manifest_store.h, then test_util/mock_manifest_store.cc.
  7. Row tests in db/version_set_test.cc: ManifestRowFieldsTest, the public-row part of VersionSetTest.ManifestRowsRoundTrip, and ManifestPublicRowsTest.
  8. Store and option tests: the MockManifestStoreTest part of db/version_set_test.cc, options/options_test.cc, options/options_settable_test.cc and db/db_basic_test.cc.
    The build files (src.mk, CMakeLists.txt, BUCK) only add the new test source file. tools/c_api_gen/auto_simple_bindings_blocklist.json only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, ManifestScanOptions::consistent, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a manifest_row_feature_version line. An older binary that loads such a file skips the unknown line only when the caller sets ignore_unknown_options and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:

  • The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
  • This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
  • db_stress, db_bench and the crash test have no flags for manifest_store or manifest_row_feature_version. Every DB open function returns NotSupported when manifest_store is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302

@meta-cla meta-cla Bot added the CLA Signed label Nov 19, 2026
@meta-codesync

meta-codesync Bot commented Nov 19, 2026

Copy link
Copy Markdown

@xingbowang has exported this pull request. If you are a Meta employee, you can view the originating Diff in D133307302.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

⚠️ clang-tidy: 10 warning(s) on changed lines

Completed in 639.0s.

Summary by check

Check Count
bugprone-argument-comment 7
performance-inefficient-vector-operation 3
Total 10

Details

db/version_set_test.cc (9 warning(s))
db/version_set_test.cc:1462:48: warning: argument name 'db_directory' in comment does not match parameter name 'dir_contains_current_file' [bugprone-argument-comment]
db/version_set_test.cc:3400:39: warning: argument name 'count' in comment does not match parameter name 'garbage_blob_count' [bugprone-argument-comment]
db/version_set_test.cc:3400:52: warning: argument name 'bytes' in comment does not match parameter name 'garbage_blob_bytes' [bugprone-argument-comment]
db/version_set_test.cc:3624:5: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation]
db/version_set_test.cc:3676:9: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation]
db/version_set_test.cc:4626:37: warning: argument name 'count' in comment does not match parameter name 'garbage_blob_count' [bugprone-argument-comment]
db/version_set_test.cc:4626:50: warning: argument name 'bytes' in comment does not match parameter name 'garbage_blob_bytes' [bugprone-argument-comment]
db/version_set_test.cc:4632:39: warning: argument name 'count' in comment does not match parameter name 'garbage_blob_count' [bugprone-argument-comment]
db/version_set_test.cc:4632:52: warning: argument name 'bytes' in comment does not match parameter name 'garbage_blob_bytes' [bugprone-argument-comment]
test_util/mock_manifest_store.cc (1 warning(s))
test_util/mock_manifest_store.cc:66:5: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation]

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Claude Code Review - OBSOLETE

Superseded by a newer AI review. Expand to see the original review.

✅ Claude Code Review

Auto-triggered after CI passed — reviewing commit 1e93e03


Summary

Large, well-structured PR that adds the foundation for an external MANIFEST metadata store: public row definitions, a store interface, row converters, two new DB options, option validation in all open paths, a mock store for testing, and debug checks in ProcessManifestWrites. The code is carefully designed with strong forward/backward compatibility rules and thorough error handling. Since nothing calls the store outside tests, the blast radius is limited.

High-severity findings (1):

  • [src.mk] db/manifest_rows.cc and test_util/mock_manifest_store.cc are missing from src.mk. The Make build (the primary build for git clones) will fail to link.
Full review (click to expand)

Findings

🔴 HIGH

H1. Missing src.mk entries — src.mk
  • Issue: The PR adds db/manifest_rows.cc to BUCK (line 93) and CMakeLists.txt (line 842), and test_util/mock_manifest_store.cc to both BUCK (lines 423, 453) and CMakeLists.txt (line 1465). However, src.mk is not updated. CLAUDE.md explicitly states: "When a new .cc file is added, update Makefile, CMakeLists.txt, src.mk, BUCK." The PR description claims "The build files (src.mk, CMakeLists.txt, BUCK) only add the new test source file" but src.mk has no changes in the diff.
  • Root cause: src.mk was overlooked. db/manifest_ops.cc is at line 82 of src.mk (LIB_SOURCES); test_util/mock_time_env.cc is at line 443 (TEST_LIB_SOURCES). Both manifest_rows.cc and mock_manifest_store.cc need corresponding entries.
  • Suggested fix: Add db/manifest_rows.cc after db/manifest_ops.cc in LIB_SOURCES of src.mk, and add test_util/mock_manifest_store.cc after test_util/mock_time_env.cc in TEST_LIB_SOURCES. Then run python3 buckifier/buckify_rocksdb.py to regenerate BUCK (or verify BUCK was already manually updated correctly).

🟡 MEDIUM

M1. DebugCheckRowsBeforeInstall reads wals_ without DB mutex — db/version_set.cc
  • Issue: The comment in the diff for DebugCheckRowsBeforeInstall says "This reads wals_ without the DB mutex. Only this thread changes wals_, when it installs a write." The safety relies on ProcessManifestWrites being single-threaded — only the manifest-write leader thread modifies wals_, and the read happens before the mutex is re-acquired. The read sees the state from the previous successful write, which is the correct baseline. While the reasoning is correct, it is subtle.
  • Suggested fix: No code change needed, but consider adding a brief note that this is safe specifically because ProcessManifestWrites serializes all MANIFEST writes (only one thread executes at a time), preventing concurrent modification of wals_.
M2. debug_manifest_rows_ initialization copies all file metadata under DB mutex — db/version_set.cc:6115-6118
  • Issue: The first call to ProcessManifestWrites initializes debug_manifest_rows_ by calling GetManifestRows(), which copies metadata of every live file while the DB mutex is held. For debug builds of large DBs (100K+ SST files), this could cause a noticeable mutex hold-time spike on the first MANIFEST write (typically during DB::Open()). This is acceptable for debug builds.
  • Suggested fix: Acceptable as-is for debug-only code. The comment at debug_manifest_rows_ already acknowledges the cost.
M3. BaseReferencedVersionBuilder::version() exposes previously-private Version* — db/version_builder.h
  • Issue: The diff adds a public version() accessor to BaseReferencedVersionBuilder. The member was previously private. The accessor is used only by DebugCheckRowsBeforeInstall in debug builds.
  • Suggested fix: Consider #ifndef NDEBUG-guarding the accessor, or making VersionSet::DebugCheckRowsBeforeInstall a friend. Since the class is internal, this is acceptable as-is.

🟢 LOW / NIT

L1. kMaxCompactCursorLevel = 1 << 16 sanity bound — db/manifest_rows.cc
  • Issue: 65536 levels with a vector of InternalKey would allocate significant memory from corrupt data. The increasing-level check in ReadCompactCursors (level < cursors->size() must be false) provides additional protection so that only one entry per level is possible. Acceptable.
L2. PR description inconsistency with src.mk — documentation
  • Issue: The PR description states "The build files (src.mk, CMakeLists.txt, BUCK) only add the new test source file" but src.mk has no changes in the diff. See H1.

Cross-Component Analysis

Context Does code execute? Assumptions hold? Action needed?
WritePreparedTxnDB NO (store not called) N/A None
ReadOnly DB YES (option check) YES Correct
SecondaryInstance YES (option check) YES Correct
Follower DB YES (option check) YES Correct
User-defined timestamps YES (key size check in converter) YES Correct
BlobDB YES (blob file rows) YES Correct
Concurrent writers NO (debug check is single-threaded) N/A None

DB Mutex Analysis:

  • Phase 1 (DebugCheckRowsBeforeInstall): Runs without the DB mutex after the MANIFEST write succeeds, before mu->Lock(). Reads only data the single ProcessManifestWrites thread owns.
  • Phase 2 (DebugCheckRowsAfterInstall): Runs with the DB mutex held after version installation. Cost is O(edits + live WALs + levels for added CF) — bounded and acceptable.

Feature-off cost: When manifest_store is null (default), CheckManifestStoreOptions does one uint32_t comparison and one null check — O(1), no allocation. The debug-only debug_manifest_rows_ has a one-time O(files) initialization. No production code path is affected.

Positive Observations

  1. Canonical encoding design: Shortest-form varints ensure equal rows produce equal bytes — essential for store comparison and checksumming.
  2. Forward/backward compatibility: The "must understand" bit (bit 6) mirrors the MANIFEST's kCustomTagNonSafeIgnoreMask. Row format version is checked first, ensuring unknown formats are rejected before parsing unknown fields.
  3. Error hierarchy: Clear separation between Corruption, NotSupported, and InvalidArgument matching RocksDB conventions.
  4. Two-phase debug check: Maximizes coverage while minimizing mutex hold time, correctly accounting for in-memory differences.
  5. All-open-paths test: ManifestStoreOptionsAreCheckedAtOpen covers Open, both OpenForReadOnly overloads, OpenAsSecondary, and OpenAsFollower.
  6. Release build safety: TEST_SYNC_POINT_CALLBACK guard ensures release builds cannot reach store code paths.

ℹ️ About this response

Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md

Limitations:

  • Claude may miss context from files not in the diff
  • Large PRs may be truncated
  • Always apply human judgment to AI suggestions

Commands:

  • /claude-review [context] — Request a code review
  • /claude-query <question> — Ask about the PR or codebase

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Claude Code Review - OBSOLETE

Superseded by a newer AI review. Expand to see the original review.

✅ Claude Code Review

Auto-triggered after CI passed — reviewing commit 5dc06ca


Summary

This PR adds the foundational building blocks for an external MANIFEST metadata store: a public header with row types and store interface, internal row conversion functions, two new DB options, and a mock store for testing. The code is well-structured, thoroughly documented, and carefully designed to have zero impact on existing users (store mode is rejected at open). The diff is large (~4900 lines) but the new code is entirely additive — no existing behavior changes.

High-severity findings (0):

No high-severity findings.

Full review (click to expand)

Findings

🟡 MEDIUM

M1. DebugCheckRowsBeforeInstall reads wals_ without DB mutex — relies on single-writer assumption — db/manifest_rows.cc
  • Issue: DebugCheckRowsBeforeInstall() runs without the DB mutex (phase 1) and reads wals_ via BuildManifestRowChanges(). The comment states "Only this thread changes wals_", which is true for the MANIFEST write thread, but wals_ is documented as "Protected by DB mutex" in version_set.h. The diff updates the comment to note this exception, but the assumption is fragile — if another thread ever modifies WALs outside ProcessManifestWrites, this becomes a data race.
  • Root cause: The debug check is split into two phases to avoid holding the mutex during expensive comparisons. WAL access in phase 1 relies on the invariant that only ProcessManifestWrites modifies WALs.
  • Suggested fix: The current approach is acceptable for a debug-only check since the single-writer invariant is well-established. The updated comment adequately documents this. No change needed, but flag if WAL modification paths ever change.
M2. FieldWriter::Bytes() asserts but does not enforce field ID ordering at runtime — db/manifest_rows.cc
  • Issue: FieldWriter::Bytes() uses assert(raw_id > last_id_) to enforce increasing field ID order, but this only fires in debug builds. In release builds, a programming error that passes out-of-order IDs would produce a silently malformed encoding. ParseManifestRowFields() correctly rejects out-of-order IDs on the read side, so corruption would be caught on round-trip, but only if the rows are actually read back.
  • Root cause: FieldWriter is an internal utility used only by the encode functions, which are structured to pass IDs in order. The assert catches bugs during development.
  • Suggested fix: Acceptable as-is since FieldWriter is internal and the read side validates. Consider adding a release-build check if FieldWriter is ever exposed more broadly.
M3. GetShortestVarint template correctness for edge cases — db/manifest_rows.cc
  • Issue: The GetShortestVarint template checks that the varint uses the minimum number of bytes. For the 32-bit case, the 5th byte must have its upper 4 bits clear (kUnusedBits = '\xF0'). For the 64-bit case, the 10th byte must have its upper 7 bits clear (kUnusedBits = '\xFE'). The logic (start[kMaxLength - 1] & kUnusedBits) != 0 is correct, but VarintLength(*value) returns the canonical length, so the final check length == VarintLength(*value) already catches overlong encodings. The two checks are redundant but both correct.
  • Root cause: Belt-and-suspenders validation — the unused-bits check catches a specific overflow case while VarintLength catches the general overlong case.
  • Suggested fix: No fix needed. The redundancy is a safety feature.
M4. kMaxCompactCursorLevel sanity limit may be too generous — db/manifest_rows.cc
  • Issue: kMaxCompactCursorLevel is set to 65536 (1 << 16). With a default of 7 levels and practical maximum of perhaps 100-200, allocating a vector of 65536 InternalKey objects (each ~32 bytes on a 64-bit system) would use ~2MB. While this is a sanity limit, it's large enough to be an effective resource exhaustion vector from crafted input.
  • Root cause: Intentionally generous limit to avoid rejecting unusual but valid configurations.
  • Suggested fix: Consider lowering to a few thousand (e.g., 4096), which is still far above any practical number of levels but limits allocation to ~128KB. However, this is data from a ManifestStore which is trusted code, so the current limit is acceptable.

🟢 LOW / NIT

L1. CheckManifestStoreOptions placement in DBImpl::Open — db/db_impl/db_impl_open.cc
  • Issue: In DBImpl::Open(), CheckManifestStoreOptions() is called before the loop that validates compaction filter options, but after the function signature. The PR description says "the check runs before the open changes anything on disk", which is correct — the check happens before any filesystem operations. However, CheckManifestStoreOptions() is called before ValidateOptions(), which means a user with both an invalid manifest_store and other invalid options will see the store error first. This is fine — it's a reasonable ordering.
  • Suggested fix: No change needed.
L2. BaseReferencedVersionBuilder::version() accessor exposes private member — db/version_builder.h
  • Issue: The new version() accessor makes version_ accessible. This is used by the debug check to get the base Version for each builder. The accessor is appropriately scoped and const-correct.
  • Suggested fix: No change needed.
L3. SameCfRow and SameFileRow use different comparison strategies — db/manifest_rows.cc
  • Issue: SameCfRow() compares fields directly via std::tie, while SameFileRow() compares through the encoded record representation. The comment explains this design choice — file rows are compared through encoding so that new fields are automatically included, while CF rows are compared field-by-field so that a round-trip test can detect dropped fields. This is intentional asymmetry.
  • Suggested fix: No change needed.

Cross-Component Analysis

Context Does code execute? Assumptions hold? Action needed?
WritePreparedTxnDB NO (store rejected at open) N/A Safe
ReadOnly DB YES (option check only) YES Safe — check runs before open
SecondaryInstance YES (option check only) YES Safe — check runs before open
CompactionService NO (store rejected at open) N/A Safe
User-defined timestamps YES (timestamp size in rows) YES Correctly handled
MemPurge NO (no store mode) N/A Safe
BlobDB YES (blob file rows) YES Correctly handled
Old snapshots NO (no store mode) N/A Safe

Key safety observation: Since every DB::Open*() variant rejects manifest_store != nullptr with Status::NotSupported, and manifest_row_feature_version is validated to be in [1, kManifestRowFeatureVersionLatest], no existing user is affected. The new code paths (row conversion, debug checks) run only in debug builds or tests.

DB Mutex Analysis

The debug check in ProcessManifestWrites() has two phases:

  • Phase 1 (no mutex): Reads wals_ and the new Versions' storage info. Safe because only ProcessManifestWrites modifies wals_, and the new Versions are not yet installed so no other thread accesses them.
  • Phase 2 (mutex held): Reads installed state (CFD log numbers, dropped status, etc.). Safe under the mutex.

GetManifestRows() requires the DB mutex (documented). It iterates all column families and copies all file metadata, so it's expensive but correctly used only for the initial fill of debug_manifest_rows_ (under mutex), not on the hot path.

No DB mutex regression in release builds. In debug builds, the phase 2 check is lightweight (compares a few scalar fields per CF in the batch).

Positive Observations

  1. Excellent documentation: The PR description, header comments, and inline comments are comprehensive and precise. The "How to read this diff" section is a model for large PRs.

  2. Zero feature-off cost: Existing users pay nothing — no new work under the DB mutex, no new per-file metadata, no new failure modes. The option check runs before any filesystem changes.

  3. Canonical encoding design: The field encoding ({varint32 id; varint32 size; value} in increasing ID order, defaults omitted, shortest varints) produces deterministic bytes for equal rows. The "must understand" bit (bit 6) mirrors kCustomTagNonSafeIgnoreMask for forward compatibility.

  4. Defensive parsing: The reader validates shortest-form varints, field ID ordering, required fields, timestamp key sizes, and blob file checksum completeness. Unknown fields without the "must understand" bit are silently dropped, enabling forward compatibility.

  5. Debug check design: The two-phase check in ProcessManifestWrites cleverly avoids holding the DB mutex during expensive comparisons while still verifying consistency after install.

  6. Build system completeness: All three build systems (Make/src.mk, CMake, BUCK) are updated consistently.

Note: The diff was truncated — the public header (include/rocksdb/manifest_store.h), mock store files, options infrastructure changes, and test files in version_set_test.cc were not available for review. A complete review would examine those files for API design, encoding correctness of all field types, mock store thread safety, options registration patterns, and test coverage completeness.


ℹ️ About this response

Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md

Limitations:

  • Claude may miss context from files not in the diff
  • Large PRs may be truncated
  • Always apply human judgment to AI suggestions

Commands:

  • /claude-review [context] — Request a code review
  • /claude-query <question> — Ask about the PR or codebase

xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 20, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. RocksDB does not call the store yet, so every DB open function refuses a store. The diff that adds store mode must also stop an older binary, which does not know the store, from creating a new DB over a DB whose metadata lives in a store.

Terms (the header defines them in full):
- Epoch: a number that the application gives each store object, one per DB instance that takes over the DB. The store refuses requests of an object with an older epoch.
- Claim: the call that makes the epoch of this object the stored epoch (`Open()`, or the commit that creates the DB row).
- Generation: one full set of all rows other than the DB row. `WriteGeneration()` replaces it at once.
- Authority: where the real metadata lives, the MANIFEST file or the store.
- Copy mode: whether RocksDB also writes a MANIFEST file copy when the store is the authority.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
- The new public header `include/rocksdb/manifest_store.h` defines the public rows and the store interface:
  - the row types (DB, column family, SST file, blob file, WAL) and the row key;
  - the authority and copy mode values that the DB row stores;
  - the field IDs of each row type, with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID). A reader drops an unknown field without the bit, and returns NotSupported for an unknown field with the bit. A MANIFEST file uses the same rule and the same bit for the custom fields of a new SST file record. The rows use this rule instead of a version bump for each new field. Each row is an independent record, and it holds a field only when the value is not the default. So an older reader fails only on a row that really holds a field it must understand. The row format version is kept for layout changes, such as a new row type;
  - the row format version and the feature version constants;
  - the canonical encoding of the fields of a row: `{varint32 field ID; varint32 value size; value}` in increasing ID order, with defaults left out and each varint in its shortest form, so equal rows give equal bytes. Every value encoding is defined byte by byte, so a store adapter can decode the values without RocksDB code;
  - `ParseManifestRowFields()` and `EncodeManifestRowFields()`. The parser rejects field ID 0, IDs out of order, and a field ID or a value size in a longer form than needed;
  - the `ManifestStore` interface (a `Customizable`) and its input and output structs. Its methods: `Open()` claims the DB for the epoch of the store object, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The header defines the result of each status code, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome" (any other error). `ManifestStore::CreateFromString()` creates a store from a registered class name or ID. RocksDB has no built-in store.
- `ManifestRowsToPublicRows()` (internal, `db/manifest_rows.h`) turns `ManifestRows` into public rows: the DB row first, then for each column family its row, its file rows and its blob file rows, then the WAL rows, including the rows of dropped column families. Each row holds its fields in the canonical encoding, without the fields that hold their default. It takes the feature version that the caller allows (1 to `kManifestRowFeatureVersionLatest`) and returns InvalidArgument outside that range. All fields of this release belong to feature version 1, so every valid value gives the same rows.
- `PublicRowsToManifestRows()` (internal) turns public rows back into `ManifestRows`. The rows other than the DB row may come in any order. It drops an unknown field without the "must understand" bit, and reads a temperature value that is not below `Temperature::kLastTemperature` as `Temperature::kUnknown`, as a MANIFEST file reader does. It returns NotSupported for rows that a newer binary wrote: a row format version above `kManifestRowFormatVersionLatest`, an unknown "must understand" field, or an unknown authority or copy mode. Field ID 1, the row format version, is read first, so a newer version gives NotSupported before any other field can give Corruption. A row whose field encoding cannot be parsed is still Corruption. It returns Corruption for:
  - a bad encoding, or a varint in a longer form than needed (also inside values);
  - a bad value, for example a path id above 3, a key with an unknown value type, a WAL synced size that means an unknown size, or a blob file with only one of checksum method and value;
  - a file number above the largest that a file descriptor can hold;
  - a key that is too short for the timestamp size of its column family;
  - a missing "always present" field, a repeated key, a key with parts that its row type does not use, a DB row among the other rows, an unknown row type, or a file or blob file row whose column family has no row.
- `ManifestDbRowExtraFields` (internal) holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold: row format version, authority, copy mode, copy file number and in-flight file number. They are not the store-owned values (`ManifestStoreDbState`).
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, and InvalidArgument when `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Unit tests of the store mode can turn off the NotSupported check with the sync point callback `DBImpl::CheckManifestStoreOptions:AllowStore`. Sync points exist only in debug builds, so a release build cannot reach store mode.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`. Each object has its own epoch, so a test can play two DB instances that take over the same DB, or no epoch, so a test can play a reader such as a secondary instance. A test can make the next call fail in each way that the interface allows: TryAgain, TimedOut without apply, TimedOut with apply, and TimedOut with a late apply at the next call (`WriteGeneration()` applies the switch before it returns TimedOut instead). For the TimedOut cases with apply, a test can read the real result of the hidden apply. For a generation switch, it can also lose one written row or change the bytes of one written row.

Implementation:
- `include/rocksdb/manifest_store.h` holds the types, the field ID enums (`enum class`, so that the names do not clash with the VersionEdit tags), the constants and the store interface.
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`). It has one encode function and one read function per row type. The encode functions use `FieldWriter`, whose `*UnlessDefault()` methods leave out a field that holds its default. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule. The authority and the copy mode share one reader, `GetEnumByte()`, which returns NotSupported for a value above the largest known one.
- One shortest-form varint reader reads field IDs, value sizes and value varints. A value varint in a longer form than needed is Corruption, so every accepted value varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels.
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`. The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field". Its checklist for a new tag gets one more step: add the public field ID.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then `db/manifest_rows.cc`: `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background with the planned call order, terms, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `ManifestStoreContractTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the default options pass the open check. No file format changes. The header is marked EXPERIMENTAL until store mode is supported. Once that is released, the row types, the authority and copy mode values, the field IDs and the encodings in the header cannot change. They are fixed in this diff, before any RocksDB code writes them. So stores and store tests can be written against the final format. This is why the header has values that no RocksDB code reads yet (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version). A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. The recovery code that later reads these rows does those checks.
- An older binary refuses to open a DB with options from an OPTIONS file whose feature version is above its `kManifestRowFeatureVersionLatest` (for example options that `LoadLatestOptions()` loaded, or the options that `DB::OpenAndCompact()` loads), as for an unknown `BlockBasedTableOptions::format_version`.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Claude Code Review - OBSOLETE

Superseded by a newer AI review. Expand to see the original review.

✅ Claude Code Review

Auto-triggered after CI passed — reviewing commit eeaa3c7


Summary

Well-structured foundational PR that adds public row types, encoding/decoding, ManifestStore interface, options, and comprehensive debug checks. The design is clean: nothing calls the store in production code, existing behavior is unchanged, and the debug check in ProcessManifestWrites validates correctness without release-build cost. The main concern is ensuring all open paths and build files are covered.

High-severity findings (0):

No high-severity findings.

Full review (click to expand)

Findings

🟡 MEDIUM

M1. src.mk must include db/manifest_rows.cc and test_util/mock_manifest_store.cc -- src.mk
  • Issue: The diff was truncated, so changes to src.mk are not visible for verification. Currently src.mk lists db/manifest_ops.cc (line 82) but not db/manifest_rows.cc, and lists test_util/mock_time_env.cc (line 443) but not test_util/mock_manifest_store.cc. The PR description says "The build files (src.mk, CMakeLists.txt, BUCK) only add the new test source file", which suggests db/manifest_rows.cc might be missing from src.mk as a production source, while mock_manifest_store.cc is correctly added as test-only. However, CMakeLists.txt and BUCK both add db/manifest_rows.cc to the main library. If src.mk is missing this file, make builds will fail.
  • Root cause: Truncated diff -- cannot verify completeness.
  • Suggested fix: Verify that src.mk has db/manifest_rows.cc in the LIB_SOURCES list (near db/manifest_ops.cc) and test_util/mock_manifest_store.cc in TEST_MAIN_SOURCES or the test lib list (near test_util/mock_time_env.cc). Run make check-sources and make -j$(nproc) all to confirm.
M2. RepairDB() does not check manifest store options -- db/repair.cc:829
  • Issue: RepairDB() accepts DBOptions but does not call CheckManifestStoreOptions(). If a user passes DBOptions with manifest_store set or an invalid manifest_row_feature_version, RepairDB will silently proceed. While RepairDB creates a new MANIFEST (it doesn't use the store), accepting invalid manifest_row_feature_version could lead to confusing behavior.
  • Root cause: RepairDB() is not one of the standard open paths and may have been overlooked.
  • Suggested fix: Consider adding CheckManifestStoreOptions() at the top of the RepairDB overloads, or at minimum validate manifest_row_feature_version range. If the store option is set, returning NotSupported is consistent with other open functions. This is medium rather than high because (a) manifest_store defaults to null and is unlikely to be set accidentally, and (b) RepairDB doesn't use the store.
M3. C API blocklist entries -- tools/c_api_gen/auto_simple_bindings_blocklist.json
  • Issue: The PR description says two "deferred" entries are added for manifest_store and manifest_row_feature_version. The diff was truncated, so this cannot be verified. If these entries are missing, the C API auto-generator may try to generate bindings for manifest_store (a shared_ptr<ManifestStore>) and fail or produce incorrect bindings.
  • Root cause: Truncated diff.
  • Suggested fix: Verify the blocklist JSON has entries like:
    {"field": "manifest_store", "policy": "deferred", "reason": "..."},
    {"field": "manifest_row_feature_version", "policy": "deferred", "reason": "..."}

🟢 LOW / NIT

L1. CheckManifestStoreOptions ordering in DBImpl::Open -- db/db_impl/db_impl_open.cc:2730
  • Issue: In DBImpl::Open(), CheckManifestStoreOptions() is called before ValidateCompactionFilterOptions(). This is correct (it runs before any disk changes), but it means a user who passes both an invalid manifest option and an invalid compaction filter will see the manifest error first. This is consistent with the PR's goal of "before it changes anything on disk" but worth noting for error message clarity.
  • Suggested fix: No action needed. The ordering is correct.
L2. BaseReferencedVersionBuilder::version() accessor -- db/version_builder.h:131
  • Issue: The PR adds a version() accessor to BaseReferencedVersionBuilder, exposing the private version_ member. This is used only by the debug check in DebugCheckRowsBeforeInstall(). The accessor is on an internal class (not in include/rocksdb/), so this is low risk.
  • Suggested fix: No action needed. The accessor is appropriately scoped.
L3. Test uses std::unique_ptr<DB> for open results -- db/db_basic_test.cc:159
  • Issue: The test ManifestStoreOptionsAreCheckedAtOpen declares std::unique_ptr<DB> db inside each lambda. When the open fails (which is the expected case), the unique_ptr is not set, which is correct. However, the test doesn't verify that db is still null after the failed open. The test does check the status code, which is sufficient.
  • Suggested fix: No action needed. The test is correct.
L4. Single-CF OpenForReadOnly check placement relative to CompactedDBImpl::Open -- db/db_impl/db_impl_readonly.cc:275
  • Issue: In the single-CF OpenForReadOnly, CheckManifestStoreOptions runs before CompactedDBImpl::Open() is tried. CompactedDBImpl::Open() itself does NOT call CheckManifestStoreOptions(). This is correct because the check is at the caller level. However, if someone adds a new call path to CompactedDBImpl::Open() that bypasses OpenForReadOnly, the check would be missing. CompactedDBImpl::Open() is currently only called from OpenForReadOnly.
  • Suggested fix: No immediate action needed. The current coverage is correct.

Cross-Component Analysis

Open Path Check Present? Notes
DBImpl::Open() YES Before ValidateCompactionFilterOptions
DB::OpenForReadOnly() (single-CF) YES Before CompactedDBImpl::Open() and OpenForReadOnlyCheckExistence()
DB::OpenForReadOnly() (multi-CF) YES Before OpenForReadOnlyCheckExistence()
DB::OpenAsSecondary() YES Via OpenAsSecondaryImpl()
DB::OpenAndCompact() YES Via OpenAsSecondaryImpl() (line 2345)
DB::OpenAsFollower() YES Before create_if_missing directory creation
CompactedDBImpl::Open() INDIRECT Called only from OpenForReadOnly which checks
RepairDB() NO See M2

DB Mutex Impact

The debug check code is entirely within #ifndef NDEBUG blocks:

  • Phase 1 (DebugCheckRowsBeforeInstall): runs WITHOUT DB mutex, after MANIFEST write, before mu->Lock(). Reads wals_ which the comment correctly notes is only modified by this thread.
  • Phase 2 (DebugCheckRowsAfterInstall): runs WITH DB mutex held, after version installation. Accesses installed state safely.
  • Fill step: runs WITH DB mutex held, calls GetManifestRows() which copies all file metadata. This is O(total files) work under the mutex, but it only happens once (first call) or after a rare WAL rejection, and only in debug builds.
  • Release builds: Zero impact. All hooks are in #ifndef NDEBUG. Only CheckManifestStoreOptions() runs in release, which is a cold-path check at open time.

Behavioral Compatibility

  • No behavior change for existing users. Default manifest_store is null and default manifest_row_feature_version is 1, both pass CheckManifestStoreOptions().
  • New OPTIONS file line: manifest_row_feature_version=1 appears in new OPTIONS files. An older binary with ignore_unknown_options skips it. Without ignore_unknown_options, older binaries reject unknown options from a newer release version.
  • New LOG dump lines: Two new lines in the options dump. No behavioral impact.

Positive Observations

  • Clean separation of concerns: The public header defines stable types and encodings, the internal header defines the in-memory model, and the implementation handles conversion. This is well-layered.
  • Thorough encoding validation: GetShortestVarint() rejects non-canonical varints, preventing ambiguous encodings. The "must understand" bit pattern is well-designed for forward compatibility.
  • Debug check design is sound: The two-phase approach (without mutex for file-level checks, with mutex for installed state) minimizes mutex contention while still catching row change bugs.
  • Test coverage: The ManifestStoreOptionsAreCheckedAtOpen test covers all 5 open function families and verifies both NotSupported (store set) and InvalidArgument (bad feature version), plus the sync point bypass in debug builds. The test correctly checks Status::Code rather than ASSERT_TRUE.
  • Safety: The PR explicitly prevents production use of store mode (NotSupported at open), with a debug-only sync point bypass for testing. This is a good pattern for staged rollout.

ℹ️ About this response

Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md

Limitations:

  • Claude may miss context from files not in the diff
  • Large PRs may be truncated
  • Always apply human judgment to AI suggestions

Commands:

  • /claude-review [context] — Request a code review
  • /claude-query <question> — Ask about the PR or codebase

xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 21, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. RocksDB does not call the store yet, so every DB open function refuses a store. The diff that adds store mode must also stop an older binary, which does not know the store, from creating a new DB over a DB whose metadata lives in a store.

Terms (the header defines them in full):
- Epoch: a number that the application gives each store object, one per DB instance that takes over the DB. The store refuses requests of an object with an older epoch.
- Claim: the call that makes the epoch of this object the stored epoch (`Open()`, or the commit that creates the DB row).
- Generation: one full set of all rows other than the DB row. `WriteGeneration()` replaces it at once.
- Authority: where the real metadata lives, the MANIFEST file or the store.
- Copy mode: whether RocksDB also writes a MANIFEST file copy when the store is the authority.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
- The new public header `include/rocksdb/manifest_store.h` defines the public rows and the store interface:
  - the row types (DB, column family, SST file, blob file, WAL) and the row key;
  - the authority and copy mode values that the DB row stores;
  - the field IDs of each row type, with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID). A reader drops an unknown field without the bit, and returns NotSupported for an unknown field with the bit. A MANIFEST file uses the same rule and the same bit for the custom fields of a new SST file record. The rows use this rule instead of a version bump for each new field. Each row is an independent record, and it holds a field only when the value is not the default. So an older reader fails only on a row that really holds a field it must understand. The row format version is kept for layout changes, such as a new row type;
  - the row format version and the feature version constants;
  - the canonical encoding of the fields of a row: `{varint32 field ID; varint32 value size; value}` in increasing ID order, with defaults left out and each varint in its shortest form, so equal rows give equal bytes. Every value encoding is defined byte by byte, so a store adapter can decode the values without RocksDB code;
  - `ParseManifestRowFields()` and `EncodeManifestRowFields()`. The parser rejects field ID 0, IDs out of order, and a field ID or a value size in a longer form than needed;
  - the `ManifestStore` interface (a `Customizable`) and its input and output structs. Its methods: `Open()` claims the DB for the epoch of the store object, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The header defines the result of each status code, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome" (any other error). `ManifestStore::CreateFromString()` creates a store from a registered class name or ID. RocksDB has no built-in store.
- `ManifestRowsToPublicRows()` (internal, `db/manifest_rows.h`) turns `ManifestRows` into public rows: the DB row first, then for each column family its row, its file rows and its blob file rows, then the WAL rows, including the rows of dropped column families. Each row holds its fields in the canonical encoding, without the fields that hold their default. It takes the feature version that the caller allows (1 to `kManifestRowFeatureVersionLatest`) and returns InvalidArgument outside that range. All fields of this release belong to feature version 1, so every valid value gives the same rows.
- `PublicRowsToManifestRows()` (internal) turns public rows back into `ManifestRows`. The rows other than the DB row may come in any order. It drops an unknown field without the "must understand" bit, and reads a temperature value that is not below `Temperature::kLastTemperature` as `Temperature::kUnknown`, as a MANIFEST file reader does. It returns NotSupported for rows that a newer binary wrote: a row format version above `kManifestRowFormatVersionLatest`, an unknown "must understand" field, or an unknown authority or copy mode. Field ID 1, the row format version, is read first, so a newer version gives NotSupported before any other field can give Corruption. A row whose field encoding cannot be parsed is still Corruption. It returns Corruption for:
  - a bad encoding, or a varint in a longer form than needed (also inside values);
  - a bad value, for example a path id above 3, a key with an unknown value type, a WAL synced size that means an unknown size, or a blob file with only one of checksum method and value;
  - a file number above the largest that a file descriptor can hold;
  - a key that is too short for the timestamp size of its column family;
  - a missing "always present" field, a repeated key, a key with parts that its row type does not use, a DB row among the other rows, an unknown row type, or a file or blob file row whose column family has no row.
- `ManifestDbRowExtraFields` (internal) holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold: row format version, authority, copy mode, copy file number and in-flight file number. They are not the store-owned values (`ManifestStoreDbState`).
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, and InvalidArgument when `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Unit tests of the store mode can turn off the NotSupported check with the sync point callback `DBImpl::CheckManifestStoreOptions:AllowStore`. Sync points exist only in debug builds, so a release build cannot reach store mode.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`. Each object has its own epoch, so a test can play two DB instances that take over the same DB, or no epoch, so a test can play a reader such as a secondary instance. A test can make the next call fail in each way that the interface allows: TryAgain, TimedOut without apply, TimedOut with apply, and TimedOut with a late apply at the next call (`WriteGeneration()` applies the switch before it returns TimedOut instead). For the TimedOut cases with apply, a test can read the real result of the hidden apply. For a generation switch, it can also lose one written row or change the bytes of one written row.

Implementation:
- `include/rocksdb/manifest_store.h` holds the types, the field ID enums (`enum class`, so that the names do not clash with the VersionEdit tags), the constants and the store interface.
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`). It has one encode function and one read function per row type. The encode functions use `FieldWriter`, whose `*UnlessDefault()` methods leave out a field that holds its default. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule. The authority and the copy mode share one reader, `GetEnumByte()`, which returns NotSupported for a value above the largest known one.
- One shortest-form varint reader reads field IDs, value sizes and value varints. A value varint in a longer form than needed is Corruption, so every accepted value varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels.
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`. The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field". Its checklist for a new tag gets one more step: add the public field ID.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then `db/manifest_rows.cc`: `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background with the planned call order, terms, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `ManifestStoreContractTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the default options pass the open check. No file format changes. The header is marked EXPERIMENTAL until store mode is supported. Once that is released, the row types, the authority and copy mode values, the field IDs and the encodings in the header cannot change. They are fixed in this diff, before any RocksDB code writes them. So stores and store tests can be written against the final format. This is why the header has values that no RocksDB code reads yet (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version). A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. The recovery code that later reads these rows does those checks.
- An older binary refuses to open a DB with options from an OPTIONS file whose feature version is above its `kManifestRowFeatureVersionLatest` (for example options that `LoadLatestOptions()` loaded, or the options that `DB::OpenAndCompact()` loads), as for an unknown `BlockBasedTableOptions::format_version`.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 21, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. RocksDB does not call the store yet, so every DB open function refuses a store. The diff that adds store mode must also stop an older binary, which does not know the store, from creating a new DB over a DB whose metadata lives in a store.

Terms (the header defines them in full):
- Epoch: a number that the application gives each store object, one per DB instance that takes over the DB. The store refuses requests of an object with an older epoch.
- Claim: the call that makes the epoch of this object the stored epoch (`Open()`, or the commit that creates the DB row).
- Generation: one full set of all rows other than the DB row. `WriteGeneration()` replaces it at once.
- Authority: where the real metadata lives, the MANIFEST file or the store.
- Copy mode: whether RocksDB also writes a MANIFEST file copy when the store is the authority.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
- The new public header `include/rocksdb/manifest_store.h` defines the public rows and the store interface:
  - the row types (DB, column family, SST file, blob file, WAL) and the row key;
  - the authority and copy mode values that the DB row stores;
  - the field IDs of each row type, with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID). A reader drops an unknown field without the bit, and returns NotSupported for an unknown field with the bit. A MANIFEST file uses the same rule and the same bit for the custom fields of a new SST file record. The rows use this rule instead of a version bump for each new field. Each row is an independent record, and it holds a field only when the value is not the default. So an older reader fails only on a row that really holds a field it must understand. The row format version is kept for layout changes, such as a new row type;
  - the row format version and the feature version constants;
  - the canonical encoding of the fields of a row: `{varint32 field ID; varint32 value size; value}` in increasing ID order, with defaults left out and each varint in its shortest form, so equal rows give equal bytes. Every value encoding is defined byte by byte, so a store adapter can decode the values without RocksDB code;
  - `ParseManifestRowFields()` and `EncodeManifestRowFields()`. The parser rejects field ID 0, IDs out of order, and a field ID or a value size in a longer form than needed;
  - the `ManifestStore` interface (a `Customizable`) and its input and output structs. Its methods: `Open()` claims the DB for the epoch of the store object, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The header defines the result of each status code, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome" (any other error). `ManifestStore::CreateFromString()` creates a store from a registered class name or ID. RocksDB has no built-in store.
- `ManifestRowsToPublicRows()` (internal, `db/manifest_rows.h`) turns `ManifestRows` into public rows: the DB row first, then for each column family its row, its file rows and its blob file rows, then the WAL rows, including the rows of dropped column families. Each row holds its fields in the canonical encoding, without the fields that hold their default. It takes the feature version that the caller allows (1 to `kManifestRowFeatureVersionLatest`) and returns InvalidArgument outside that range. All fields of this release belong to feature version 1, so every valid value gives the same rows.
- `PublicRowsToManifestRows()` (internal) turns public rows back into `ManifestRows`. The rows other than the DB row may come in any order. It drops an unknown field without the "must understand" bit, and reads a temperature value that is not below `Temperature::kLastTemperature` as `Temperature::kUnknown`, as a MANIFEST file reader does. It returns NotSupported for rows that a newer binary wrote: a row format version above `kManifestRowFormatVersionLatest`, an unknown "must understand" field, or an unknown authority or copy mode. Field ID 1, the row format version, is read first, so a newer version gives NotSupported before any other field can give Corruption. A row whose field encoding cannot be parsed is still Corruption. It returns Corruption for:
  - a bad encoding, or a varint in a longer form than needed (also inside values);
  - a bad value, for example a path id above 3, a key with an unknown value type, a WAL synced size that means an unknown size, or a blob file with only one of checksum method and value;
  - a file number above the largest that a file descriptor can hold;
  - a key that is too short for the timestamp size of its column family;
  - a missing "always present" field, a repeated key, a key with parts that its row type does not use, a DB row among the other rows, an unknown row type, or a file or blob file row whose column family has no row.
- `ManifestDbRowExtraFields` (internal) holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold: row format version, authority, copy mode, copy file number and in-flight file number. They are not the store-owned values (`ManifestStoreDbState`).
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, and InvalidArgument when `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Unit tests of the store mode can turn off the NotSupported check with the sync point callback `DBImpl::CheckManifestStoreOptions:AllowStore`. Sync points exist only in debug builds, so a release build cannot reach store mode.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`. Each object has its own epoch, so a test can play two DB instances that take over the same DB, or no epoch, so a test can play a reader such as a secondary instance. A test can make the next call fail in each way that the interface allows: TryAgain, TimedOut without apply, TimedOut with apply, and TimedOut with a late apply at the next call (`WriteGeneration()` applies the switch before it returns TimedOut instead). For the TimedOut cases with apply, a test can read the real result of the hidden apply. For a generation switch, it can also lose one written row or change the bytes of one written row.

Implementation:
- `include/rocksdb/manifest_store.h` holds the types, the field ID enums (`enum class`, so that the names do not clash with the VersionEdit tags), the constants and the store interface.
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`). It has one encode function and one read function per row type. The encode functions use `FieldWriter`, whose `*UnlessDefault()` methods leave out a field that holds its default. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule. The authority and the copy mode share one reader, `GetEnumByte()`, which returns NotSupported for a value above the largest known one.
- One shortest-form varint reader reads field IDs, value sizes and value varints. A value varint in a longer form than needed is Corruption, so every accepted value varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels.
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`. The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field". Its checklist for a new tag gets one more step: add the public field ID.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then `db/manifest_rows.cc`: `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background with the planned call order, terms, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `ManifestStoreContractTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the default options pass the open check. No file format changes. The header is marked EXPERIMENTAL until store mode is supported. Once that is released, the row types, the authority and copy mode values, the field IDs and the encodings in the header cannot change. They are fixed in this diff, before any RocksDB code writes them. So stores and store tests can be written against the final format. This is why the header has values that no RocksDB code reads yet (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version). A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. The recovery code that later reads these rows does those checks.
- An older binary refuses to open a DB with options from an OPTIONS file whose feature version is above its `kManifestRowFeatureVersionLatest` (for example options that `LoadLatestOptions()` loaded, or the options that `DB::OpenAndCompact()` loads), as for an unknown `BlockBasedTableOptions::format_version`.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 21, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. RocksDB does not call the store yet, so every DB open function refuses a store. The diff that adds store mode must also stop an older binary, which does not know the store, from creating a new DB over a DB whose metadata lives in a store.

Terms (the header defines them in full):
- Epoch: a number that the application gives each store object, one per DB instance that takes over the DB. The store refuses requests of an object with an older epoch.
- Claim: the call that makes the epoch of this object the stored epoch (`Open()`, or the commit that creates the DB row).
- Generation: one full set of all rows other than the DB row. `WriteGeneration()` replaces it at once.
- Authority: where the real metadata lives, the MANIFEST file or the store.
- Copy mode: whether RocksDB also writes a MANIFEST file copy when the store is the authority.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
- The new public header `include/rocksdb/manifest_store.h` defines the public rows and the store interface:
  - the row types (DB, column family, SST file, blob file, WAL) and the row key;
  - the authority and copy mode values that the DB row stores;
  - the field IDs of each row type, with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID). A reader drops an unknown field without the bit, and returns NotSupported for an unknown field with the bit. A MANIFEST file uses the same rule and the same bit for the custom fields of a new SST file record. The rows use this rule instead of a version bump for each new field. Each row is an independent record, and it holds a field only when the value is not the default. So an older reader fails only on a row that really holds a field it must understand. The row format version is kept for layout changes, such as a new row type;
  - the row format version and the feature version constants;
  - the canonical encoding of the fields of a row: `{varint32 field ID; varint32 value size; value}` in increasing ID order, with defaults left out and each varint in its shortest form, so equal rows give equal bytes. Every value encoding is defined byte by byte, so a store adapter can decode the values without RocksDB code;
  - `ParseManifestRowFields()` and `EncodeManifestRowFields()`. The parser rejects field ID 0, IDs out of order, and a field ID or a value size in a longer form than needed;
  - the `ManifestStore` interface (a `Customizable`) and its input and output structs. Its methods: `Open()` claims the DB for the epoch of the store object, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The header defines the result of each status code, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome" (any other error). `ManifestStore::CreateFromString()` creates a store from a registered class name or ID. RocksDB has no built-in store.
- `ManifestRowsToPublicRows()` (internal, `db/manifest_rows.h`) turns `ManifestRows` into public rows: the DB row first, then for each column family its row, its file rows and its blob file rows, then the WAL rows, including the rows of dropped column families. Each row holds its fields in the canonical encoding, without the fields that hold their default. It takes the feature version that the caller allows (1 to `kManifestRowFeatureVersionLatest`) and returns InvalidArgument outside that range. All fields of this release belong to feature version 1, so every valid value gives the same rows.
- `PublicRowsToManifestRows()` (internal) turns public rows back into `ManifestRows`. The rows other than the DB row may come in any order. It drops an unknown field without the "must understand" bit, and reads a temperature value that is not below `Temperature::kLastTemperature` as `Temperature::kUnknown`, as a MANIFEST file reader does. It returns NotSupported for rows that a newer binary wrote: a row format version above `kManifestRowFormatVersionLatest`, an unknown "must understand" field, or an unknown authority or copy mode. Field ID 1, the row format version, is read first, so a newer version gives NotSupported before any other field can give Corruption. A row whose field encoding cannot be parsed is still Corruption. It returns Corruption for:
  - a bad encoding, or a varint in a longer form than needed (also inside values);
  - a bad value, for example a path id above 3, a key with an unknown value type, a WAL synced size that means an unknown size, or a blob file with only one of checksum method and value;
  - a file number above the largest that a file descriptor can hold;
  - a key that is too short for the timestamp size of its column family;
  - a missing "always present" field, a repeated key, a key with parts that its row type does not use, a DB row among the other rows, an unknown row type, or a file or blob file row whose column family has no row.
- `ManifestDbRowExtraFields` (internal) holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold: row format version, authority, copy mode, copy file number and in-flight file number. They are not the store-owned values (`ManifestStoreDbState`).
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, and InvalidArgument when `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Unit tests of the store mode can turn off the NotSupported check with the sync point callback `DBImpl::CheckManifestStoreOptions:AllowStore`. Sync points exist only in debug builds, so a release build cannot reach store mode.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`. Each object has its own epoch, so a test can play two DB instances that take over the same DB, or no epoch, so a test can play a reader such as a secondary instance. A test can make the next call fail in each way that the interface allows: TryAgain, TimedOut without apply, TimedOut with apply, and TimedOut with a late apply at the next call (`WriteGeneration()` applies the switch before it returns TimedOut instead). For the TimedOut cases with apply, a test can read the real result of the hidden apply. For a generation switch, it can also lose one written row or change the bytes of one written row.

Implementation:
- `include/rocksdb/manifest_store.h` holds the types, the field ID enums (`enum class`, so that the names do not clash with the VersionEdit tags), the constants and the store interface.
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`). It has one encode function and one read function per row type. The encode functions use `FieldWriter`, whose `*UnlessDefault()` methods leave out a field that holds its default. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule. The authority and the copy mode share one reader, `GetEnumByte()`, which returns NotSupported for a value above the largest known one.
- One shortest-form varint reader reads field IDs, value sizes and value varints. A value varint in a longer form than needed is Corruption, so every accepted value varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels.
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`. The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field". Its checklist for a new tag gets one more step: add the public field ID.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then `db/manifest_rows.cc`: `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background with the planned call order, terms, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `ManifestStoreContractTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the default options pass the open check. No file format changes. The header is marked EXPERIMENTAL until store mode is supported. Once that is released, the row types, the authority and copy mode values, the field IDs and the encodings in the header cannot change. They are fixed in this diff, before any RocksDB code writes them. So stores and store tests can be written against the final format. This is why the header has values that no RocksDB code reads yet (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version). A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. The recovery code that later reads these rows does those checks.
- An older binary refuses to open a DB with options from an OPTIONS file whose feature version is above its `kManifestRowFeatureVersionLatest` (for example options that `LoadLatestOptions()` loaded, or the options that `DB::OpenAndCompact()` loads), as for an unknown `BlockBasedTableOptions::format_version`.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 21, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. RocksDB does not call the store yet, so every DB open function refuses a store. The diff that adds store mode must also stop an older binary, which does not know the store, from creating a new DB over a DB whose metadata lives in a store.

Terms (the header defines them in full):
- Epoch: a number that the application gives each store object, one per DB instance that takes over the DB. The store refuses requests of an object with an older epoch.
- Claim: the call that makes the epoch of this object the stored epoch (`Open()`, or the commit that creates the DB row).
- Generation: one full set of all rows other than the DB row. `WriteGeneration()` replaces it at once.
- Authority: where the real metadata lives, the MANIFEST file or the store.
- Copy mode: whether RocksDB also writes a MANIFEST file copy when the store is the authority.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
- The new public header `include/rocksdb/manifest_store.h` defines the public rows and the store interface:
  - the row types (DB, column family, SST file, blob file, WAL) and the row key;
  - the authority and copy mode values that the DB row stores;
  - the field IDs of each row type, with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID). A reader drops an unknown field without the bit, and returns NotSupported for an unknown field with the bit. A MANIFEST file uses the same rule and the same bit for the custom fields of a new SST file record. The rows use this rule instead of a version bump for each new field. Each row is an independent record, and it holds a field only when the value is not the default. So an older reader fails only on a row that really holds a field it must understand. The row format version is kept for layout changes, such as a new row type;
  - the row format version and the feature version constants;
  - the canonical encoding of the fields of a row: `{varint32 field ID; varint32 value size; value}` in increasing ID order, with defaults left out and each varint in its shortest form, so equal rows give equal bytes. Every value encoding is defined byte by byte, so a store adapter can decode the values without RocksDB code;
  - `ParseManifestRowFields()` and `EncodeManifestRowFields()`. The parser rejects field ID 0, IDs out of order, and a field ID or a value size in a longer form than needed;
  - the `ManifestStore` interface (a `Customizable`) and its input and output structs. Its methods: `Open()` claims the DB for the epoch of the store object, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The header defines the result of each status code, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome" (any other error). `ManifestStore::CreateFromString()` creates a store from a registered class name or ID. RocksDB has no built-in store.
- `ManifestRowsToPublicRows()` (internal, `db/manifest_rows.h`) turns `ManifestRows` into public rows: the DB row first, then for each column family its row, its file rows and its blob file rows, then the WAL rows, including the rows of dropped column families. Each row holds its fields in the canonical encoding, without the fields that hold their default. It takes the feature version that the caller allows (1 to `kManifestRowFeatureVersionLatest`) and returns InvalidArgument outside that range. All fields of this release belong to feature version 1, so every valid value gives the same rows.
- `PublicRowsToManifestRows()` (internal) turns public rows back into `ManifestRows`. The rows other than the DB row may come in any order. It drops an unknown field without the "must understand" bit, and reads a temperature value that is not below `Temperature::kLastTemperature` as `Temperature::kUnknown`, as a MANIFEST file reader does. It returns NotSupported for rows that a newer binary wrote: a row format version above `kManifestRowFormatVersionLatest`, an unknown "must understand" field, or an unknown authority or copy mode. Field ID 1, the row format version, is read first, so a newer version gives NotSupported before any other field can give Corruption. A row whose field encoding cannot be parsed is still Corruption. It returns Corruption for:
  - a bad encoding, or a varint in a longer form than needed (also inside values);
  - a bad value, for example a path id above 3, a key with an unknown value type, a WAL synced size that means an unknown size, or a blob file with only one of checksum method and value;
  - a file number above the largest that a file descriptor can hold;
  - a key that is too short for the timestamp size of its column family;
  - a missing "always present" field, a repeated key, a key with parts that its row type does not use, a DB row among the other rows, an unknown row type, or a file or blob file row whose column family has no row.
- `ManifestDbRowExtraFields` (internal) holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold: row format version, authority, copy mode, copy file number and in-flight file number. They are not the store-owned values (`ManifestStoreDbState`).
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, and InvalidArgument when `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Unit tests of the store mode can turn off the NotSupported check with the sync point callback `DBImpl::CheckManifestStoreOptions:AllowStore`. Sync points exist only in debug builds, so a release build cannot reach store mode.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`. Each object has its own epoch, so a test can play two DB instances that take over the same DB, or no epoch, so a test can play a reader such as a secondary instance. A test can make the next call fail in each way that the interface allows: TryAgain, TimedOut without apply, TimedOut with apply, and TimedOut with a late apply at the next call (`WriteGeneration()` applies the switch before it returns TimedOut instead). For the TimedOut cases with apply, a test can read the real result of the hidden apply. For a generation switch, it can also lose one written row or change the bytes of one written row.

Implementation:
- `include/rocksdb/manifest_store.h` holds the types, the field ID enums (`enum class`, so that the names do not clash with the VersionEdit tags), the constants and the store interface.
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`). It has one encode function and one read function per row type. The encode functions use `FieldWriter`, whose `*UnlessDefault()` methods leave out a field that holds its default. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule. The authority and the copy mode share one reader, `GetEnumByte()`, which returns NotSupported for a value above the largest known one.
- One shortest-form varint reader reads field IDs, value sizes and value varints. A value varint in a longer form than needed is Corruption, so every accepted value varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels.
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`. The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field". Its checklist for a new tag gets one more step: add the public field ID.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then `db/manifest_rows.cc`: `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background with the planned call order, terms, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `ManifestStoreContractTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the default options pass the open check. No file format changes. The header is marked EXPERIMENTAL until store mode is supported. Once that is released, the row types, the authority and copy mode values, the field IDs and the encodings in the header cannot change. They are fixed in this diff, before any RocksDB code writes them. So stores and store tests can be written against the final format. This is why the header has values that no RocksDB code reads yet (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version). A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. The recovery code that later reads these rows does those checks.
- An older binary refuses to open a DB with options from an OPTIONS file whose feature version is above its `kManifestRowFeatureVersionLatest` (for example options that `LoadLatestOptions()` loaded, or the options that `DB::OpenAndCompact()` loads), as for an unknown `BlockBasedTableOptions::format_version`.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 21, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. RocksDB does not call the store yet, so every DB open function refuses a store. The diff that adds store mode must also stop an older binary, which does not know the store, from creating a new DB over a DB whose metadata lives in a store.

Terms (the header defines them in full):
- Epoch: a number that the application gives each store object, one per DB instance that takes over the DB. The store refuses requests of an object with an older epoch.
- Claim: the call that makes the epoch of this object the stored epoch (`Open()`, or the commit that creates the DB row).
- Generation: one full set of all rows other than the DB row. `WriteGeneration()` replaces it at once.
- Authority: where the real metadata lives, the MANIFEST file or the store.
- Copy mode: whether RocksDB also writes a MANIFEST file copy when the store is the authority.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
- The new public header `include/rocksdb/manifest_store.h` defines the public rows and the store interface:
  - the row types (DB, column family, SST file, blob file, WAL) and the row key;
  - the authority and copy mode values that the DB row stores;
  - the field IDs of each row type, with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID). A reader drops an unknown field without the bit, and returns NotSupported for an unknown field with the bit. A MANIFEST file uses the same rule and the same bit for the custom fields of a new SST file record. The rows use this rule instead of a version bump for each new field. Each row is an independent record, and it holds a field only when the value is not the default. So an older reader fails only on a row that really holds a field it must understand. The row format version is kept for layout changes, such as a new row type;
  - the row format version and the feature version constants;
  - the canonical encoding of the fields of a row: `{varint32 field ID; varint32 value size; value}` in increasing ID order, with defaults left out and each varint in its shortest form, so equal rows give equal bytes. Every value encoding is defined byte by byte, so a store adapter can decode the values without RocksDB code;
  - `ParseManifestRowFields()` and `EncodeManifestRowFields()`. The parser rejects field ID 0, IDs out of order, and a field ID or a value size in a longer form than needed;
  - the `ManifestStore` interface (a `Customizable`) and its input and output structs. Its methods: `Open()` claims the DB for the epoch of the store object, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The header defines the result of each status code, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome" (any other error). `ManifestStore::CreateFromString()` creates a store from a registered class name or ID. RocksDB has no built-in store.
- `ManifestRowsToPublicRows()` (internal, `db/manifest_rows.h`) turns `ManifestRows` into public rows: the DB row first, then for each column family its row, its file rows and its blob file rows, then the WAL rows, including the rows of dropped column families. Each row holds its fields in the canonical encoding, without the fields that hold their default. It takes the feature version that the caller allows (1 to `kManifestRowFeatureVersionLatest`) and returns InvalidArgument outside that range. All fields of this release belong to feature version 1, so every valid value gives the same rows.
- `PublicRowsToManifestRows()` (internal) turns public rows back into `ManifestRows`. The rows other than the DB row may come in any order. It drops an unknown field without the "must understand" bit, and reads a temperature value that is not below `Temperature::kLastTemperature` as `Temperature::kUnknown`, as a MANIFEST file reader does. It returns NotSupported for rows that a newer binary wrote: a row format version above `kManifestRowFormatVersionLatest`, an unknown "must understand" field, or an unknown authority or copy mode. Field ID 1, the row format version, is read first, so a newer version gives NotSupported before any other field can give Corruption. A row whose field encoding cannot be parsed is still Corruption. It returns Corruption for:
  - a bad encoding, or a varint in a longer form than needed (also inside values);
  - a bad value, for example a path id above 3, a key with an unknown value type, a WAL synced size that means an unknown size, or a blob file with only one of checksum method and value;
  - a file number above the largest that a file descriptor can hold;
  - a key that is too short for the timestamp size of its column family;
  - a missing "always present" field, a repeated key, a key with parts that its row type does not use, a DB row among the other rows, an unknown row type, or a file or blob file row whose column family has no row.
- `ManifestDbRowExtraFields` (internal) holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold: row format version, authority, copy mode, copy file number and in-flight file number. They are not the store-owned values (`ManifestStoreDbState`).
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, and InvalidArgument when `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Unit tests of the store mode can turn off the NotSupported check with the sync point callback `DBImpl::CheckManifestStoreOptions:AllowStore`. Sync points exist only in debug builds, so a release build cannot reach store mode.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`. Each object has its own epoch, so a test can play two DB instances that take over the same DB, or no epoch, so a test can play a reader such as a secondary instance. A test can make the next call fail in each way that the interface allows: TryAgain, TimedOut without apply, TimedOut with apply, and TimedOut with a late apply at the next call (`WriteGeneration()` applies the switch before it returns TimedOut instead). For the TimedOut cases with apply, a test can read the real result of the hidden apply. For a generation switch, it can also lose one written row or change the bytes of one written row.

Implementation:
- `include/rocksdb/manifest_store.h` holds the types, the field ID enums (`enum class`, so that the names do not clash with the VersionEdit tags), the constants and the store interface.
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`). It has one encode function and one read function per row type. The encode functions use `FieldWriter`, whose `*UnlessDefault()` methods leave out a field that holds its default. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule. The authority and the copy mode share one reader, `GetEnumByte()`, which returns NotSupported for a value above the largest known one.
- One shortest-form varint reader reads field IDs, value sizes and value varints. A value varint in a longer form than needed is Corruption, so every accepted value varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels.
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`. The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field". Its checklist for a new tag gets one more step: add the public field ID.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then `db/manifest_rows.cc`: `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background with the planned call order, terms, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `ManifestStoreContractTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the default options pass the open check. No file format changes. The header is marked EXPERIMENTAL until store mode is supported. Once that is released, the row types, the authority and copy mode values, the field IDs and the encodings in the header cannot change. They are fixed in this diff, before any RocksDB code writes them. So stores and store tests can be written against the final format. This is why the header has values that no RocksDB code reads yet (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version). A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. The recovery code that later reads these rows does those checks.
- An older binary refuses to open a DB with options from an OPTIONS file whose feature version is above its `kManifestRowFeatureVersionLatest` (for example options that `LoadLatestOptions()` loaded, or the options that `DB::OpenAndCompact()` loads), as for an unknown `BlockBasedTableOptions::format_version`.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Claude Code Review - OBSOLETE

Superseded by a newer AI review. Expand to see the original review.

✅ Claude Code Review

Auto-triggered after CI passed — reviewing commit 7502f27


Summary

Well-structured foundational PR that adds the ManifestStore interface, public row format, and internal conversion machinery. The design is carefully layered: nothing outside tests calls the store or converters, the open-time guard prevents accidental use, and the debug checks in ProcessManifestWrites provide ongoing validation. The canonical encoding is well-defined with proper bounds checking and shortest-form varint enforcement.

High-severity findings (0):

No high-severity findings.

Full review (click to expand)

Findings

🟡 MEDIUM

M1. FieldWriter::Bytes assert-only ordering check — db/manifest_rows.cc (FieldWriter class)
  • Issue: FieldWriter::Bytes() uses assert(raw_id > last_id_) to enforce strictly increasing field IDs. In release builds, this assert is compiled out. If a caller violates the ordering contract in release, the encoded row would have out-of-order field IDs, which ParseManifestRowFields would reject as Corruption("Bad manifest row field ID order"). This is defense-in-depth: the reader catches what the writer's assert would catch in debug. However, a silently malformed row from a release-build writer bug would propagate to the store before being detected on read.
  • Root cause: The writer trusts callers to maintain field ordering, with only a debug-mode check.
  • Suggested fix: The current approach is consistent with RocksDB's debug-assert pattern and is acceptable given the round-trip test coverage. The reader-side validation provides the actual safety net. No change required.
M2. BuildManifestRowChanges defensive path gives zero values for missing column family — db/manifest_rows.cc
  • Issue: When base_cf == old_rows.cfs.end() (which should never happen per the documented invariant), the defensive path initializes log_number = 0 and ts_low = "". This could produce incorrect row data. Since this is debug-only code (called from DebugCheckRowsBeforeInstall under #ifndef NDEBUG), it only affects debug builds, and the assert on the line above would fire first.
  • Root cause: The invariant is documented (every column family in batch_versions existed before the batch), and the assert catches violations in debug.
  • Suggested fix: Acceptable as-is. The assert catches the invariant violation, and the defensive path prevents undefined behavior in release builds where asserts are disabled.
M3. Potential for large allocation from adversarial compact cursor level — db/manifest_rows.cc (ReadCompactCursors)
  • Issue: kMaxCompactCursorLevel = 1 << 16 = 65536 means an adversarial input with level=65535 could cause cursors->resize(65536), allocating ~65536 InternalKey objects. Each InternalKey contains a std::string, so this could be ~1-2MB from a single field in an untrusted row.
  • Root cause: Intentional design tradeoff between allowing flexibility and bounding memory.
  • Suggested fix: The bound is documented, far above real workloads, and prevents truly unbounded allocation. Acceptable as a sanity limit. If tighter bounds are desired, ColumnFamilyOptions::num_levels (default 7, max typically ~100) could inform a tighter limit, but that would require passing CF options context into the decoder.

🟢 LOW / NIT

L1. SameFileRow creates temporary VersionEdit objects for comparison — db/manifest_rows.cc
  • Issue: Creates two VersionEdits, encodes them to strings, and compares. Relatively expensive but intentionally designed for maintainability (auto-picks up new FileMetaData fields). Used only in debug checks and tests.
  • Suggested fix: None. Good maintainability tradeoff.
L2. EncodeCfRow checks cursor.size() != 0 while MakeManifestCfRow uses cursor.unset() — db/manifest_rows.cc
  • Issue: These should be semantically equivalent (an unset InternalKey has size 0), but using the same method in both places would improve consistency.
  • Suggested fix: Consider using !cursor.unset() in EncodeCfRow for consistency.
L3. GetShortestVarint could benefit from a static_assert on T — db/manifest_rows.cc
  • Issue: The template works for uint32_t and uint64_t but would silently produce wrong results for other types (e.g., uint16_t).
  • Suggested fix: Optional: add static_assert(sizeof(T) == 4 || sizeof(T) == 8, "Only uint32_t and uint64_t supported").
L4. Test ManifestStoreOptionsAreCheckedAtOpen doesn't test DB::Open without create_if_missing — db/db_basic_test.cc:137
  • Issue: The DB::Open case in the test sets create_if_missing = true to verify no directory is created on failure. It could additionally test that a store-less open with the existing DB works correctly after the failed attempts.
  • Suggested fix: The final section of the test (reopening without a store with a future feature version) covers this. Acceptable.

Cross-Component Analysis

Context Does code execute? Assumptions hold? Action needed?
WritePreparedTxnDB NO (store blocked at open) N/A None
ReadOnly DB NO (store blocked at open) N/A None
Secondary Instance NO (store blocked at open) N/A None
Follower Instance NO (store blocked at open) N/A None
OpenAndCompact NO (via secondary path) N/A None
User-defined timestamps YES (encoding/decoding) YES Handled correctly
BlobDB YES (blob file rows) YES BlobFileAddition round-tripped
Concurrent writers Debug checks only YES Mutex-aware design

DB Mutex Analysis:

  • Phase 1 (DebugCheckRowsBeforeInstall): Runs WITHOUT mutex. Accesses only immutable data (new Versions not yet installed, builder_guards holding base Versions). Safe because these objects are owned by the current ProcessManifestWrites call.
  • Phase 2 (DebugCheckRowsAfterInstall): Runs WITH mutex. Scans batch_edits and checks installed ColumnFamilyData state. Work is O(edits) with no I/O. No mutex-held regression.
  • Fill step (GetManifestRows): O(total files), runs once per debug_manifest_rows_ initialization, debug-only. Acceptable.

Assumption stress-test:

  • Claim: "Nothing in RocksDB calls the store or converters outside tests." Verified: CheckManifestStoreOptions always returns NotSupported when store is set, preventing any DB from opening with a store. The converter functions and ManifestStore methods are only called from test code. The debug check calls BuildManifestRowChanges/ApplyManifestRowChanges but these operate on internal rows, not the store.
  • Claim: "The open check runs before the open changes anything on disk." Verified for all 5 open paths: DB::Open (before ValidateCompactionFilterOptions), OpenForReadOnly (both overloads, before existence check), OpenAsSecondary (before deferred SST opening logic), OpenAsFollower (before CreateDirIfMissing).

Positive Observations

  • Canonical encoding design: The shortest-form varint requirement and strictly-increasing field IDs produce a unique encoding per row state, enabling byte-for-byte comparison.
  • Error ordering discipline: kRowFormatVersion (field ID 1) is always read first, giving clean NotSupported before any Corruption for newer formats.
  • Defense in depth: The reader independently validates all structure: field ordering, varint forms, required fields, key validity, file number bounds, and timestamp sizes.
  • Two-phase debug check: Before-install (no mutex, immutable data) and after-install (mutex held, installed state) with documented allowed differences is a thorough correctness verification.
  • Complete open-time guard: All DB open paths check before any disk changes, with test coverage for each path.
  • Consistent option registration: Follows the established statistics pattern for shared_ptr options.
  • Truncation safety: kMaxCompactCursorLevel and kFileNumberMask checks bound memory allocation from corrupt input.
  • Well-documented PR description: The "How to read this diff" section, error order documentation, and "Known limitations" section are exemplary.

ℹ️ About this response

Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md

Limitations:

  • Claude may miss context from files not in the diff
  • Large PRs may be truncated
  • Always apply human judgment to AI suggestions

Commands:

  • /claude-review [context] — Request a code review
  • /claude-query <question> — Ask about the PR or codebase

xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 22, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms (the same list as "Terms" in `include/rocksdb/manifest_store.h`, which defines them in full):
- Epoch (store epoch): a number that the application gives each store object, one per DB instance that takes over the DB. The store refuses requests of an object with an older epoch.
- Claim: the call that makes the epoch of this object the stored epoch (`Open()`, or the commit that creates the DB row).
- Commit sequence: a number in the DB row that grows by 1 with each successful commit or claim. A commit names the commit sequence it expects, so two writers cannot both apply a change on the same state.
- Commit id: a unique string that RocksDB gives each commit and claim. The store keeps the id of the last applied one, so after an unknown outcome RocksDB can learn whether its request applied.
- Generation: one full set of all rows other than the DB row. `WriteGeneration()` replaces it at once.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make the next call fail in each way that the interface allows; the fault list is in the mock header.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels.
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The row types, the authority and copy mode values, the field IDs and the encodings are fixed in this diff, before any RocksDB code writes them, so that stores and store tests can be written against the final format. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The values are chosen to be final, but the header stays EXPERIMENTAL until store mode is supported, so a later release may still change the format or the interface. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 22, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms (the same list as "Terms" in `include/rocksdb/manifest_store.h`, which defines them in full):
- Epoch (store epoch): a number that the application gives each store object, one per DB instance that takes over the DB. The store refuses requests of an object with an older epoch.
- Claim: the call that makes the epoch of this object the stored epoch (`Open()`, or the commit that creates the DB row).
- Commit sequence: a number in the DB row that grows by 1 with each successful commit or claim. A commit names the commit sequence it expects, so two writers cannot both apply a change on the same state.
- Commit id: a unique string that RocksDB gives each commit and claim. The store keeps the id of the last applied one, so after an unknown outcome RocksDB can learn whether its request applied.
- Generation: one full set of all rows other than the DB row. `WriteGeneration()` replaces it at once.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make the next call fail in each way that the interface allows; the fault list is in the mock header.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels.
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The row types, the authority and copy mode values, the field IDs and the encodings are fixed in this diff, before any RocksDB code writes them, so that stores and store tests can be written against the final format. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The values are chosen to be final, but the header stays EXPERIMENTAL until store mode is supported, so a later release may still change the format or the interface. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
@meta-codesync meta-codesync Bot changed the title Add the public row form, the ManifestStore interface and a test store for MANIFEST metadata stores Add the public row form, the ManifestStore interface and a test store for MANIFEST metadata stores (#15738) Nov 22, 2026
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 22, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms (the same list as "Terms" in `include/rocksdb/manifest_store.h`, which defines them in full):
- Epoch (store epoch): a number that the application gives each store object, one per DB instance that takes over the DB. The store refuses requests of an object with an older epoch.
- Claim: the call that makes the epoch of this object the stored epoch (`Open()`, or the commit that creates the DB row).
- Commit sequence: a number in the DB row that grows by 1 with each successful commit or claim. A commit names the commit sequence it expects, so two writers cannot both apply a change on the same state.
- Commit id: a unique string that RocksDB gives each commit and claim. The store keeps the id of the last applied one, so after an unknown outcome RocksDB can learn whether its request applied.
- Generation: one full set of all rows other than the DB row. `WriteGeneration()` replaces it at once.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make the next call fail in each way that the interface allows; the fault list is in the mock header.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels.
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The row types, the authority and copy mode values, the field IDs and the encodings are fixed in this diff, before any RocksDB code writes them, so that stores and store tests can be written against the final format. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The values are chosen to be final, but the header stays EXPERIMENTAL until store mode is supported, so a later release may still change the format or the interface. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 22, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms (the same list as "Terms" in `include/rocksdb/manifest_store.h`, which defines them in full):
- Epoch (store epoch): a number that the application gives each store object, one per DB instance that takes over the DB. The store refuses requests of an object with an older epoch.
- Claim: the call that makes the epoch of this object the stored epoch (`Open()`, or the commit that creates the DB row).
- Commit sequence: a number in the DB row that grows by 1 with each successful commit or claim. A commit names the commit sequence it expects, so two writers cannot both apply a change on the same state.
- Commit id: a unique string that RocksDB gives each commit and claim. The store keeps the id of the last applied one, so after an unknown outcome RocksDB can learn whether its request applied.
- Generation: one full set of all rows other than the DB row. `WriteGeneration()` replaces it at once.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make the next call fail in each way that the interface allows; the fault list is in the mock header.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels.
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The row types, the authority and copy mode values, the field IDs and the encodings are fixed in this diff, before any RocksDB code writes them, so that stores and store tests can be written against the final format. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The values are chosen to be final, but the header stays EXPERIMENTAL until store mode is supported, so a later release may still change the format or the interface. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 22, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms (the same list as "Terms" in `include/rocksdb/manifest_store.h`, which defines them in full):
- Epoch (store epoch): a number that the application gives each store object, one per DB instance that takes over the DB. The store refuses requests of an object with an older epoch.
- Claim: the call that makes the epoch of this object the stored epoch (`Open()`, or the commit that creates the DB row).
- Commit sequence: a number in the DB row that grows by 1 with each successful commit or claim. A commit names the commit sequence it expects, so two writers cannot both apply a change on the same state.
- Commit id: a unique string that RocksDB gives each commit and claim. The store keeps the id of the last applied one, so after an unknown outcome RocksDB can learn whether its request applied.
- Generation: one full set of all rows other than the DB row. `WriteGeneration()` replaces it at once.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make the next call fail in each way that the interface allows; the fault list is in the mock header.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels.
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The row types, the authority and copy mode values, the field IDs and the encodings are fixed in this diff, before any RocksDB code writes them, so that stores and store tests can be written against the final format. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The values are chosen to be final, but the header stays EXPERIMENTAL until store mode is supported, so a later release may still change the format or the interface. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
@meta-codesync meta-codesync Bot changed the title Add the public row form, the ManifestStore interface and a test store for MANIFEST metadata stores (#15738) Add the public row form, the ManifestStore interface and a test store for MANIFEST metadata stores Nov 23, 2026
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 23, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header fixes the full format now, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers), so that stores can be written against the final format. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The row types, the authority and copy mode values, the field IDs and the encodings are fixed in this diff, before any RocksDB code writes them, so that stores and store tests can be written against the final format. Fixing the format early is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The values are chosen to be final, but the header stays EXPERIMENTAL until store mode is supported, so a later release may still change the format or the interface. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 23, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header fixes the full format now, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers), so that stores can be written against the final format. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The row types, the authority and copy mode values, the field IDs and the encodings are fixed in this diff, before any RocksDB code writes them, so that stores and store tests can be written against the final format. Fixing the format early is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The values are chosen to be final, but the header stays EXPERIMENTAL until store mode is supported, so a later release may still change the format or the interface. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Claude Code Review - OBSOLETE

Superseded by a newer AI review. Expand to see the original review.

✅ Claude Code Review

Auto-triggered after CI passed — reviewing commit 21bd5bb


Summary

This is a well-structured foundational diff that adds the public row form, ManifestStore interface, and MockManifestStore for external MANIFEST metadata stores. The code is carefully designed with defensive checks, comprehensive test coverage, and clear documentation. No data-path or store-mode code is activated -- all DB open functions correctly refuse a store.

High-severity findings (0):

No high-severity findings.

Full review (click to expand)

Findings

🔴 HIGH

None.

🟡 MEDIUM

M1. EncodeManifestRowFields does not validate inputs at runtime -- manifest_rows.cc:1558
  • Issue: EncodeManifestRowFields() is a public function that takes a vector<ManifestRowField> and delegates to FieldWriter::Bytes(). The FieldWriter asserts raw_id > last_id_ and raw_id > 0 only via assert(), which is a no-op in release builds. If a caller passes field IDs out of order or with id 0, the output is silently malformed in release builds.
  • Root cause: The function documents "The IDs must be larger than 0 and in increasing order" as a precondition but does not enforce it in release mode.
  • Suggested fix: Since this is marked EXPERIMENTAL and the only current callers are internal (the encode functions and MockManifestStore's MergeFields), the assert-only approach is acceptable for now. Consider adding a runtime check if this becomes a stable API, or document that the caller is responsible for validation and the result is undefined otherwise.
M2. MockManifestStore::Open calls ApplyWithFault before checking has_db_row_ -- mock_manifest_store.cc:231
  • Issue: Open() takes the fault before the ApplyOpen() checks. So ApplyWithFault with kTimedOutApplied or kTimedOutLateApply calls ApplyOpen() which checks has_db_row_ and may return NotFound. The hidden-apply path then stores kNotFound as the hidden apply code. This is correct behavior per the fault design (the hidden code reflects what actually happened), but the indirection makes it easy to misread in tests.
  • Root cause: Fault injection wraps the entire apply, including pre-checks. This is by design for generality.
  • Suggested fix: No code change needed. The behavior is correct and the HiddenApplyCode() test helper makes the outcome observable. Consider a brief comment in the Fault enum docs noting that fault-wrapped calls report the actual outcome of the inner apply.
M3. compact_cursors size_t/uint32_t comparison in ReadCompactCursors -- manifest_rows.cc:1132
  • Issue: level < cursors->size() compares uint32_t with size_t. While safe given the kMaxCompactCursorLevel bound (65536), the implicit conversion could trigger warnings on some compilers.
  • Root cause: std::vector::size() returns size_t, and level is uint32_t.
  • Suggested fix: The comparison is safe given the kMaxCompactCursorLevel guard. Both types are unsigned so no sign issue. No change strictly needed.

🟢 LOW / NIT

L1. FieldWriter::Varint allocates a temporary string per value -- manifest_rows.cc:802
  • Issue: Varint() creates a temporary std::string buf, puts the varint into it, then passes it to Bytes() which copies it into encoded_. This is a minor inefficiency (small allocation per varint field).
  • Suggested fix: Acceptable as-is. This is not on a hot path (encoding happens during MANIFEST writes, which are infrequent). If it ever becomes hot, the varint could be written directly into encoded_ with a placeholder for the value size.
L2. CheckManifestStoreOptions returns InvalidArgument before NotSupported -- db_impl_open.cc:259
  • Issue: When manifest_store is set, the function checks the feature version range first, then returns NotSupported. The design rationale is documented: "It checks the feature version before it refuses the store, so that a bad value gives the same InvalidArgument now and after store mode is supported."
  • Suggested fix: No change needed. The ordering is intentional, well-documented, and tested.
L3. manifest_row_feature_version is not checked without a store -- db_impl_open.cc:256
  • Issue: Without manifest_store, the feature version is not validated. A DB opens fine with kManifestRowFeatureVersionLatest + 1 without a store, allowing OPTIONS files from later releases to work. By design and tested.
  • Suggested fix: No change needed.

Cross-Component Analysis

Context Does code execute? Assumptions hold? Action needed?
WritePreparedTxnDB NO (store refused at open) N/A None
ReadOnly DB YES (CheckManifestStoreOptions called) YES None
Secondary Instance YES (via OpenAsSecondaryImpl) YES None
OpenAndCompact YES (via OpenAsSecondaryImpl) YES None
OpenAsFollower YES (CheckManifestStoreOptions called) YES None
User-defined timestamps YES (CheckTimestampKeySizes validates) YES None

DB Mutex Analysis: The changed code does not execute under the DB mutex. CheckManifestStoreOptions() is a pure static function that reads option values. No mutex interaction.

Positive Observations

  1. Excellent defensive design: The row format version check runs first (field ID 1), so a newer binary's rows always give NotSupported before any Corruption. Carefully documented and tested.

  2. Comprehensive shortest-form varint validation: GetShortestVarint() rejects longer-than-necessary forms, ensuring deterministic encoding (equal rows give equal bytes). Critical for stores that compare or checksum encoded fields.

  3. Build-time exhaustiveness: Switch statements in ManifestRowFieldOfTag(), ManifestRowFieldOfNewFileTag(), and each Read*Field() have no default case -- adding a new tag/field without handling it fails the build.

  4. Static assertions pin field IDs: static_assert on the last field ID of each row type prevents silent renumbering.

  5. BytesMatchTheFieldTables test: Hand-written expected bytes catch bugs that round-trip tests alone cannot (e.g., swapped field IDs, wrong byte order).

  6. MockManifestStore is well-designed: Scan copies rows under the lock then calls the visitor without it (consistent snapshots). WriteGeneration writes in chunks with epoch checks. Fault injection covers unknown-outcome scenarios thoroughly.

  7. Clean separation of concerns: Internal rows vs public rows with well-defined converters. ManifestDbRowExtraFields cleanly separates RocksDB-owned from store-owned fields.

  8. Options follow established patterns: manifest_store mirrors the statistics registration (kDontSerialize, kCompareNever, kAllowNull). C API blocklist entries are properly deferred.


ℹ️ About this response

Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md

Limitations:

  • Claude may miss context from files not in the diff
  • Large PRs may be truncated
  • Always apply human judgment to AI suggestions

Commands:

  • /claude-review [context] — Request a code review
  • /claude-query <question> — Ask about the PR or codebase

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Claude Code Review - OBSOLETE

Superseded by a newer AI review. Expand to see the original review.

✅ Claude Code Review

Auto-triggered after CI passed — reviewing commit 6a6413f


Summary

This is a well-structured, carefully designed foundational diff that adds the public row form for MANIFEST metadata, the ManifestStore interface, and a test store. The code is defensive (all open paths reject the store, format is EXPERIMENTAL), thoroughly documented, and extensively tested. The implementation follows existing RocksDB conventions closely.

High-severity findings (0):

No high-severity findings.

Full review (click to expand)

Findings

🔴 HIGH

None.

🟡 MEDIUM

M1. EncodeManifestRowFields does not validate field ID ordering or zero IDs in release builds -- db/manifest_rows.cc:1557
  • Issue: The public EncodeManifestRowFields() function's documentation states "The IDs must be larger than 0 and in increasing order," but the FieldWriter::Bytes() method only enforces this via assert(raw_id > last_id_), which is stripped in release builds. A caller passing misordered or zero IDs would produce silently invalid encoding that ParseManifestRowFields() would later reject with Corruption.
  • Root cause: The FieldWriter relies on debug assertions rather than runtime checks for a public API function.
  • Suggested fix: Since this is a public API, consider adding a runtime check or documenting that the behavior is undefined for invalid input (similar to how PutVarint32 doesn't validate). The current approach is consistent with RocksDB's style where callers are responsible, and ParseManifestRowFields catches bad output on the read side. This is medium because (a) the function is currently only called internally and by MockManifestStore, and (b) the round-trip through Parse catches errors. If the function is intended for external store adapters to use directly, a runtime check would be more robust.
M2. MergeFields in MockManifestStore uses Slice values pointing into source strings -- test_util/mock_manifest_store.cc:43
  • Issue: MergeFields stores Slice values in merged that point into *fields and updates. When EncodeManifestRowFields(out) is called, the out vector's Slice values still reference the original strings. The assignment *fields = EncodeManifestRowFields(out) overwrites *fields only after encoding completes, so this is safe in practice. However, if EncodeManifestRowFields were ever changed to build incrementally or if the assignment order changed, this would become a use-after-free.
  • Root cause: Implicit lifetime dependency between Slice values and their backing strings.
  • Suggested fix: This is test-only code and the current implementation is correct. A defensive improvement would be to ToString() the values when building out, but this is a minor style point for test code.

🟢 LOW / NIT

L1. GetShortestVarint template constraint could be more explicit -- db/manifest_rows.cc (line ~750)
  • Issue: The template works for uint32_t (sizeof 4) and uint64_t (sizeof 8), but the constexpr branches use sizeof(T) == 4 to distinguish. If someone instantiated with a different 4-byte or 8-byte type, it would compile but might behave unexpectedly.
  • Suggested fix: No change needed -- the function is in an anonymous namespace and only called with uint32_t and uint64_t. A static_assert could document the constraint if desired.
L2. ManifestRowsToRecords always emits a DeleteWalsBefore record -- db/manifest_rows.cc:570
  • Issue: Even when db.min_log_number_to_keep is 0, a DeleteWalsBefore(0) record is emitted. This is harmless (no-op during recovery) but adds an unnecessary record.
  • Suggested fix: Could wrap in if (db.min_log_number_to_keep != 0), but cosmetic only.
L3. kMaxCompactCursorLevel sentinel value only in .cc file -- db/manifest_rows.cc
  • Issue: The 65536 bound is documented in the public header comment but the constant is only in the .cc file. A store implementation generating cursors would need to know this limit.
  • Suggested fix: The public header comment already states "A level is at most 65536." No change needed for now since stores don't generate cursors.

Cross-Component Analysis

DB Open Path Coverage: All six DB open entry points are covered by CheckManifestStoreOptions():

Entry Point Location Covered
DB::Open db_impl_open.cc:2728 YES
DB::OpenForReadOnly (simple) db_impl_readonly.cc:275 YES
DB::OpenForReadOnly (with CFs) db_impl_readonly.cc:314 YES
DB::OpenAsSecondary db_impl_secondary.cc:1243 (via OpenAsSecondaryImpl) YES
DB::OpenAsFollower db_impl_follower.cc:267 YES
DB::OpenAndCompact via OpenAsSecondaryImpl YES (transitive)

Options Registration: Follows the exact same pattern as statistics (kCompareNever, kDontSerialize, kAllowNull). manifest_row_feature_version is correctly serialized to OPTIONS files.

DB Mutex Impact: Zero cost in release builds (#ifndef NDEBUG). Debug-only fill step runs under mutex but only on first call. Phase 1 without mutex; Phase 2 under mutex with O(edits) + O(WALs) cost for added CFs. No regression.

Alternative Execution Contexts: All contexts are safe because every open path rejects the store.

Format Safety: EXPERIMENTAL header, no DB code writes store data, forward-compatible must-understand bit pattern.

Serialization Correctness: Canonical encoding is fully deterministic. GetShortestVarint correctly rejects non-canonical varints. ParseManifestRowFields enforces strictly increasing IDs, non-zero IDs. Reader switches have no default case, enforcing build-time coverage of new field IDs. Temperature values above kLastTemperature are silently read as kUnknown, matching MANIFEST file reader behavior.

Positive Observations

  • Excellent documentation quality throughout all new files, with precise invariant documentation and thorough edge-case analysis.
  • Build-time guardrails: ManifestRowFieldOfTag and ManifestRowFieldOfNewFileTag switches with no default case force updates when new VersionEdit tags are added.
  • Byte-level test verification (BytesMatchTheFieldTables) against hand-computed encodings catches shared encoder/decoder bugs that round-trip tests cannot.
  • Thread safety analysis at debug_manifest_rows_ is meticulous, with per-object justification for mutex-free access.
  • MockManifestStore fault injection (TimedOut with hidden apply, late apply, lost/corrupted generation rows) enables thorough testing of unknown-outcome scenarios critical for distributed stores.
  • Clean separation between internal rows (db/manifest_rows.h) and public rows (include/rocksdb/manifest_store.h), with explicit converters.

ℹ️ About this response

Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md

Limitations:

  • Claude may miss context from files not in the diff
  • Large PRs may be truncated
  • Always apply human judgment to AI suggestions

Commands:

  • /claude-review [context] — Request a code review
  • /claude-query <question> — Ask about the PR or codebase

xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 23, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header fixes the full format now, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers), so that stores can be written against the final format. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The row types, the authority and copy mode values, the field IDs and the encodings are fixed in this diff, before any RocksDB code writes them, so that stores and store tests can be written against the final format. Fixing the format early is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The values are chosen to be final, but the header stays EXPERIMENTAL until store mode is supported, so a later release may still change the format or the interface. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 23, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header fixes the full format now, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers), so that stores can be written against the final format. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The row types, the authority and copy mode values, the field IDs and the encodings are fixed in this diff, before any RocksDB code writes them, so that stores and store tests can be written against the final format. Fixing the format early is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The values are chosen to be final, but the header stays EXPERIMENTAL until store mode is supported, so a later release may still change the format or the interface. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 23, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header fixes the full format now, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers), so that stores can be written against the final format. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The row types, the authority and copy mode values, the field IDs and the encodings are fixed in this diff, before any RocksDB code writes them, so that stores and store tests can be written against the final format. Fixing the format early is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The values are chosen to be final, but the header stays EXPERIMENTAL until store mode is supported, so a later release may still change the format or the interface. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Claude Code Review - OBSOLETE

Superseded by a newer AI review. Expand to see the original review.

✅ Claude Code Review

Auto-triggered after CI passed — reviewing commit 020e4d9


Summary

Well-structured foundational PR that adds the ManifestStore interface, public row encoding/decoding, and a mock store for testing. The code is defensive (store mode is refused at open), extensively documented, and follows existing RocksDB patterns. The diff is truncated so some files cannot be fully reviewed.

High-severity findings (1):

  • [src.mk] db/manifest_rows.cc and test_util/mock_manifest_store.cc may be missing from src.mk -- the diff is truncated and cannot confirm, but current src.mk on main does not contain them.
Full review (click to expand)

Findings

🔴 HIGH

H1. Verify src.mk includes new source files -- src.mk
  • Issue: The CLAUDE.md build system guidance states: "When a new .cc file is added, update Makefile, CMakeLists.txt, src.mk, BUCK." The diff shows updates to BUCK and CMakeLists.txt but is truncated before src.mk changes are visible. The PR description claims src.mk is updated. Current src.mk on main does NOT contain db/manifest_rows.cc in LIB_SOURCES (should be after db/manifest_ops.cc at line 82) or test_util/mock_manifest_store.cc in TEST_LIB_SOURCES (should be near test_util/mock_time_env.cc at line 443).
  • Root cause: Diff truncation prevents verification. If the PR omits these additions, make builds will fail to link.
  • Suggested fix: Confirm that the full diff includes db/manifest_rows.cc in LIB_SOURCES and test_util/mock_manifest_store.cc in TEST_LIB_SOURCES of src.mk. After updating src.mk, run /usr/local/bin/python3 buckifier/buckify_rocksdb.py to regenerate BUCK (though BUCK changes are already in the diff, so this may already be done).

🟡 MEDIUM

M1. CheckManifestStoreOptions ordering relative to ValidateOptions -- db/db_impl/db_impl_open.cc:2728
  • Issue: In DBImpl::Open(), CheckManifestStoreOptions() is called first, then ValidateCompactionFilterOptions(), ValidateOptionsByTable(), and ValidateOptions(). This means a manifest_store with an invalid feature version returns InvalidArgument before other option validation errors. The PR description says "The check runs before the open changes anything on disk" which is correct. However, the check semantics are: InvalidArgument (bad version) takes priority over NotSupported (store present but not yet supported). If a user has both a bad feature version AND other invalid options, they'll see the manifest store error first. This is intentional per the PR description but worth noting.
  • Root cause: Intentional design choice documented in the comment.
  • Suggested fix: No action needed, but the ordering should be verified to remain stable across the other open paths (ReadOnly, Secondary, Follower) which all call CheckManifestStoreOptions first.
M2. OpenForReadOnly single-CF overload: CompactedDBImpl::Open bypasses check -- db/db_impl/db_impl_readonly.cc:275-283
  • Issue: In the single-CF OpenForReadOnly, the check is added before OpenForReadOnlyCheckExistence, which is correct. CompactedDBImpl::Open() is then called. If a user sets manifest_store on options, the check correctly returns NotSupported before CompactedDBImpl::Open() runs. However, if CompactedDBImpl::Open() were ever called from another path that doesn't check, it could bypass the guard. Currently there's no such path.
  • Root cause: N/A -- currently safe, noting for future awareness.
  • Suggested fix: No action needed now.
M3. Feature version not validated without a store -- db/db_impl/db_impl_open.cc:258-266
  • Issue: CheckManifestStoreOptions() returns OK immediately when manifest_store is null, without checking manifest_row_feature_version. The test ManifestStoreOptionsAreCheckedAtOpen explicitly tests that "Without a store, the feature version is not checked" and that a DB opens with a future version value. This is intentional. However, this means manifest_row_feature_version is written to the OPTIONS file even with invalid values (e.g., 0 or future values), which could confuse users who inspect OPTIONS files.
  • Root cause: Intentional design -- the feature version only matters with a store.
  • Suggested fix: Consider documenting in the option comment that the value is not validated without a store, or add a note that it's only meaningful when manifest_store is set.
M4. kMaxCompactCursorLevel sanity limit allows ~2MB allocation from untrusted input -- db/manifest_rows.cc
  • Issue: A corrupt compaction cursor level up to 65536 causes a vector resize to 65537 entries (~2MB). The comment acknowledges this. For a metadata store that processes external data, this is a DoS vector if many corrupt rows are processed. The bound is reasonable for a single row, but a batch of corrupt rows could multiply this.
  • Root cause: Intentional sanity limit, documented in comments.
  • Suggested fix: Consider whether PublicRowsToManifestRows should have a total memory budget, or note in the ManifestStore interface that the caller is responsible for input validation.

🟢 LOW / NIT

L1. CheckManifestStoreOptions error message doesn't include the actual value -- db/db_impl/db_impl_open.cc:261-263
  • Issue: The InvalidArgument message says "manifest_row_feature_version must be from 1 to N" but doesn't include the actual bad value. Including it would help debugging.
  • Suggested fix: Add the actual value: "manifest_row_feature_version " + std::to_string(db_options.manifest_row_feature_version) + " must be from 1 to " + ...
L2. GetShortestVarint template for uint32_t/uint64_t only -- db/manifest_rows.cc
  • Issue: The template uses sizeof(T) checks for 4 and 8. If called with another type, the behavior would be incorrect.
  • Suggested fix: Add static_assert(sizeof(T) == 4 || sizeof(T) == 8) at the top of the template.
L3. EncodeCfRow uses uint32_t for level in compact cursors loop -- db/manifest_rows.cc
  • Issue: cf.compact_cursors.size() returns size_t. The loop variable is uint32_t. On 64-bit systems, if compact_cursors.size() > UINT32_MAX, this would wrap. In practice, kMaxCompactCursorLevel is 65536, so this can never happen.
  • Suggested fix: No action needed, but could use size_t for consistency.

Cross-Component Analysis

Context Does code execute? Assumptions hold? Action needed?
WritePreparedTxnDB YES (open check) YES Safe -- check runs before any transaction setup
ReadOnly DB YES (open check) YES Both single-CF and multi-CF overloads checked
SecondaryInstance YES (open check) YES OpenAsSecondaryImpl checked, covers OpenAndCompact
FollowerInstance YES (open check) YES OpenAsFollower checked
CompactedDBImpl NO (bypassed by prior check) N/A Single-CF ReadOnly checks before CompactedDBImpl::Open
Remote compaction YES (via OpenAsSecondaryImpl) YES OpenAndCompact goes through checked path

DB Mutex Analysis

The changes in this PR do NOT affect DB mutex behavior:

  • CheckManifestStoreOptions is a pure static function reading only const DBOptions&, called before the DB is created or the mutex exists.
  • The new options manifest_store and manifest_row_feature_version are immutable and read only during open validation.
  • The DebugCheckRows* functions are debug-only (#ifndef NDEBUG) and the diff documents their threading model relative to the mutex.
  • No new code runs under the DB mutex in production builds.

Positive Observations

  1. Thorough open guards: All 5 DB open paths correctly call CheckManifestStoreOptions before any disk changes. The test covers all of them including the create_if_missing / kNotFound check.

  2. Defensive error ordering: Feature version is validated BEFORE refusing the store, so "a bad value gives the same InvalidArgument now and after store mode is supported."

  3. Well-documented format: The public header thoroughly documents the row encoding, field IDs, defaults, and schema evolution (must-understand bit).

  4. Clean separation: Internal rows (ManifestRows) vs public rows (ManifestRow) with explicit conversion functions. The FieldWriter pattern is clean.

  5. Build-time enforcement: Switch over field ID enums with no default case ensures -Wswitch -Werror catches missing handlers when new fields are added.

  6. Round-trip testing: Coverage includes encode-decode round trips and explicit VersionEdit tag-to-field mapping verification.

  7. C API blocklist: New options correctly deferred.

  8. EXPERIMENTAL marking: Preserves ability to change format before store mode is supported.


ℹ️ About this response

Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md

Limitations:

  • Claude may miss context from files not in the diff
  • Large PRs may be truncated
  • Always apply human judgment to AI suggestions

Commands:

  • /claude-review [context] — Request a code review
  • /claude-query <question> — Ask about the PR or codebase

@meta-codesync meta-codesync Bot changed the title Add the public row form, the ManifestStore interface and a test store for MANIFEST metadata stores (#15738) Add the public row form, the ManifestStore interface and a test store for MANIFEST metadata stores Nov 24, 2026
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 24, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally, which is the normal claim at the open of a DB. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 24, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally, which is the normal claim at the open of a DB. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 24, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally, which is the normal claim at the open of a DB. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
@meta-codesync meta-codesync Bot changed the title Add the public row form, the ManifestStore interface and a test store for MANIFEST metadata stores Add the public row form, the ManifestStore interface and a test store for MANIFEST metadata stores (#15738) Nov 24, 2026
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 24, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally, which is the normal claim at the open of a DB. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 24, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally, which is the normal claim at the open of a DB. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 24, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally, which is the normal claim at the open of a DB. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 24, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally, which is the normal claim at the open of a DB. The comment above the class defines the meaning of each status, so that RocksDB can tell "not applied" (IOFenced, Busy, TryAgain) from "unknown outcome". `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
@meta-codesync meta-codesync Bot changed the title Add the public row form, the ManifestStore interface and a test store for MANIFEST metadata stores (#15738) Add the public row form, the ManifestStore interface and a test store for MANIFEST metadata stores Nov 25, 2026
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 25, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally, which is the normal claim at the open of a DB. For `Commit()` and `WriteGeneration()`, the comment above the class defines the meaning of each status, so that RocksDB can tell a request that the store did not apply (IOFenced, Busy, TryAgain, NotSupported) from a request with an unknown outcome, such as a timeout. `Open()` and `Destroy()` list their own results at their declarations. `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 25, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally, which is the normal claim at the open of a DB. For `Commit()` and `WriteGeneration()`, the comment above the class defines the meaning of each status, so that RocksDB can tell a request that the store did not apply (IOFenced, Busy, TryAgain, NotSupported) from a request with an unknown outcome, such as a timeout. `Open()` and `Destroy()` list their own results at their declarations. `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 25, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally, which is the normal claim at the open of a DB. For `Commit()` and `WriteGeneration()`, the comment above the class defines the meaning of each status, so that RocksDB can tell a request that the store did not apply (IOFenced, Busy, TryAgain, NotSupported) from a request with an unknown outcome, such as a timeout. `Open()` and `Destroy()` list their own results at their declarations. `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 25, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` replaces all rows other than the DB row, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally, which is the normal claim at the open of a DB. For `Commit()` and `WriteGeneration()`, the comment above the class defines the meaning of each status, so that RocksDB can tell a request that the store did not apply (IOFenced, Busy, TryAgain, NotSupported) from a request with an unknown outcome, such as a timeout. `Open()` and `Destroy()` list their own results at their declarations. `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
meta#15734)

Summary:
Pull Request resolved: meta#15734

Background
A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows.

The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks.

Previous behavior
RocksDB has no row form of the MANIFEST state.

New behavior
No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes and applies them to a debug copy of the rows. The check then compares the number and level of every SST in each new Version, and the persisted SST fields of the files whose rows the write adds or updates. The phase table at `debug_manifest_rows_` in `db/version_set.h` lists the column family, blob file, DB and WAL checks. "In-memory differences" in `db/manifest_rows.h` lists the differences that the check allows. A mismatch stops the process with an assert.

Implementation
Key choices:
- The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`.
- The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, a compare of the WAL rows with the live WAL set in place (O(live WALs), with no copy), and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row.
- When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds.
- Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values.

Safety
No format change, no public API change and no behavior change in release builds.
- `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path.
- In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The cost of this copy was not measured. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`.
- On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, an in-place compare of the WAL rows (O(live WALs), with no copy), and O(levels) for a column family that the write adds.
- Secondary and follower instances do not write the MANIFEST, so they never run the check.

Known limitations:
- `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given.
- Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows.
- Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen.

Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit.

How to read this diff
1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram.
2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`.
3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`.
4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version.
5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`.
6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file.

Differential Revision: D133208529
… for MANIFEST metadata stores

Summary:
Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation. The application must give each DB instance that takes over a DB a newer epoch than all earlier instances. Only such a claim fences the older instance; a claim with the same epoch fences nothing; a `Commit()` prepared before it gets Busy, because the claim raised the commit sequence.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` installs a full replacement set of column family, SST, blob file and WAL rows and updates the DB row in the same atomic switch, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally. The claim of a DB open is designed to set both (step 2 of "Call order" in the header): read the DB row, check that it belongs to this DB, claim with the commit sequence and last commit id of that read, and read again and retry after Busy. For `Commit()` and `WriteGeneration()`, the comment above the class defines the meaning of each status, so that RocksDB can tell a request that the store did not apply (IOFenced, Busy, TryAgain, NotSupported) from a request with an unknown outcome, such as a timeout. `Open()` and `Destroy()` list their own results at their declarations. `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A request that the mock keeps pending after a timeout keeps the epoch of the object that made it, so it can still run after that object is destroyed. A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 25, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation. The application must give each DB instance that takes over a DB a newer epoch than all earlier instances. Only such a claim fences the older instance; a claim with the same epoch fences nothing; a `Commit()` prepared before it gets Busy, because the claim raised the commit sequence.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` installs a full replacement set of column family, SST, blob file and WAL rows and updates the DB row in the same atomic switch, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally. The claim of a DB open is designed to set both (step 2 of "Call order" in the header): read the DB row, check that it belongs to this DB, claim with the commit sequence and last commit id of that read, and read again and retry after Busy. For `Commit()` and `WriteGeneration()`, the comment above the class defines the meaning of each status, so that RocksDB can tell a request that the store did not apply (IOFenced, Busy, TryAgain, NotSupported) from a request with an unknown outcome, such as a timeout. `Open()` and `Destroy()` list their own results at their declarations. `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A request that the mock keeps pending after a timeout keeps the epoch of the object that made it, so it can still run after that object is destroyed. A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 25, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation. The application must give each DB instance that takes over a DB a newer epoch than all earlier instances. Only such a claim fences the older instance; a claim with the same epoch fences nothing; a `Commit()` prepared before it gets Busy, because the claim raised the commit sequence.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` installs a full replacement set of column family, SST, blob file and WAL rows and updates the DB row in the same atomic switch, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally. The claim of a DB open is designed to set both (step 2 of "Call order" in the header): read the DB row, check that it belongs to this DB, claim with the commit sequence and last commit id of that read, and read again and retry after Busy. For `Commit()` and `WriteGeneration()`, the comment above the class defines the meaning of each status, so that RocksDB can tell a request that the store did not apply (IOFenced, Busy, TryAgain, NotSupported) from a request with an unknown outcome, such as a timeout. `Open()` and `Destroy()` list their own results at their declarations. `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A request that the mock keeps pending after a timeout keeps the epoch of the object that made it, so it can still run after that object is destroyed. A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 25, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation. The application must give each DB instance that takes over a DB a newer epoch than all earlier instances. Only such a claim fences the older instance; a claim with the same epoch fences nothing; a `Commit()` prepared before it gets Busy, because the claim raised the commit sequence.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` installs a full replacement set of column family, SST, blob file and WAL rows and updates the DB row in the same atomic switch, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally. The claim of a DB open is designed to set both (step 2 of "Call order" in the header): read the DB row, check that it belongs to this DB, claim with the commit sequence and last commit id of that read, and read again and retry after Busy. For `Commit()` and `WriteGeneration()`, the comment above the class defines the meaning of each status, so that RocksDB can tell a request that the store did not apply (IOFenced, Busy, TryAgain, NotSupported) from a request with an unknown outcome, such as a timeout. `Open()` and `Destroy()` list their own results at their declarations. `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A request that the mock keeps pending after a timeout keeps the epoch of the object that made it, so it can still run after that object is destroyed. A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 25, 2026
… for MANIFEST metadata stores (meta#15738)

Summary:
Pull Request resolved: meta#15738

Background: RocksDB keeps its metadata (the live files of each level, the column families, the WAL state and counters such as the next file number) in the MANIFEST file. An application may want to keep the same metadata in its own database instead, an external metadata store. The store then holds structured rows: one DB row, one row per column family, SST file, blob file and WAL. Each row has a key and a set of fields, and each field has a stable small integer, its field ID. The internal row model in `db/manifest_rows.h` already holds these rows in memory. A store needs three more things: a public, stable description of the rows and their bytes; an interface to implement; and an option to give its store object to RocksDB. Unit tests also need a store that keeps rows in memory and can fail on purpose. This diff adds these building blocks. The header defines the field IDs, values and byte encodings that store authors can implement and test against, including values that no DB code path writes in this diff (the authority, the copy mode, and the copy and in-flight file numbers). The format and the interface stay experimental and may change. RocksDB does not support store mode (a DB whose metadata lives in a store) at this diff, so every DB open function refuses a store.

Terms: the "Terms" list in the store interface part of `include/rocksdb/manifest_store.h` defines epoch, claim, commit sequence, commit id and generation. The application must give each DB instance that takes over a DB a newer epoch than all earlier instances. Only such a claim fences the older instance; a claim with the same epoch fences nothing; a `Commit()` prepared before it gets Busy, because the claim raised the commit sequence.

Previous behavior: RocksDB has no public description of its metadata as rows, no store interface and no store options.

New behavior:
This diff adds four things: (1) a public row form of MANIFEST metadata with a fixed byte encoding, (2) converters between it and the internal `ManifestRows`, (3) the `ManifestStore` interface and two DB options, and (4) a test store. Nothing in RocksDB calls the store in this diff, and every DB open function refuses a store.
- The new public header `include/rocksdb/manifest_store.h` defines:
  - the public rows: the row types and keys, the authority values (where the real metadata lives, the MANIFEST file or the store) and copy mode values (whether RocksDB also writes a MANIFEST file copy when the store is the authority), and the field IDs of each row type with the value encoding and the default of each field;
  - the "must understand" bit (bit 6 of a field ID), the same rule and bit that a MANIFEST file uses for the custom fields of a new SST file record (see "Schema evolution" at the top of the header for why the rows use it instead of a version bump per field);
  - the canonical encoding of the fields of a row (see "Canonical encoding"), with `ParseManifestRowFields()` and `EncodeManifestRowFields()`;
  - the `ManifestStore` interface (a `Customizable`): `Open()` claims the DB, `Commit()` applies one atomic change of rows, `ReadDbRow()` reads the DB row, `Scan()` reads all rows, `WriteGeneration()` installs a full replacement set of column family, SST, blob file and WAL rows and updates the DB row in the same atomic switch, and `Destroy()` removes all rows. `Open()` and `Destroy()` take an optional expected commit sequence: when it is set and the stored commit sequence differs, the call returns Busy and changes nothing. A missing DB row has commit sequence 0, but `Open()` returns NotFound first when there is no DB row, and a fenced object gets IOFenced before this check. They also take an expected last commit id: when it is not empty, the stored last_commit_id must equal it too, else the call returns Busy. The commit sequence alone cannot tell the read DB row from a row that was destroyed and created again and reached the same commit sequence; the new row never has the same last commit id, because commit ids are unique. A caller uses both to claim or destroy a DB only if the DB row is still the one it read and checked, so that it does not fence another writer that changed the row after that read. Without either precondition, `Open()` claims unconditionally. The claim of a DB open is designed to set both (step 2 of "Call order" in the header): read the DB row, check that it belongs to this DB, claim with the commit sequence and last commit id of that read, and read again and retry after Busy. For `Commit()` and `WriteGeneration()`, the comment above the class defines the meaning of each status, so that RocksDB can tell a request that the store did not apply (IOFenced, Busy, TryAgain, NotSupported) from a request with an unknown outcome, such as a timeout. `Open()` and `Destroy()` list their own results at their declarations. `ManifestStore::CreateFromString()` creates a store from a registered class. RocksDB has no built-in store.
- Internal converters in `db/manifest_rows.h`: `ManifestRowsToPublicRows()` turns `ManifestRows` into public rows, and `PublicRowsToManifestRows()` turns them back. The comment of `PublicRowsToManifestRows()` lists every NotSupported and Corruption case and their order. `ManifestDbRowExtraFields` holds the RocksDB-owned DB row fields that `ManifestDbRow` does not hold, other than the row format version, which the writer always writes as `kManifestRowFormatVersionLatest`.
- `DBOptions::manifest_store` (default null) holds the store object. It is not written to the OPTIONS file, because the object belongs to one DB instance, and it is never compared with a reloaded OPTIONS file.
- `DBOptions::manifest_row_feature_version` (default 1) is the newest feature version of the rows that RocksDB may write. It is an immutable option and is written to the OPTIONS file. In this diff 1 is its only valid value, and it changes nothing; it exists so that a later release can add row fields under a higher value.
- `DB::Open()`, `DB::OpenForReadOnly()`, `DB::OpenAsSecondary()`, `DB::OpenAsFollower()` and `DB::OpenAndCompact()` return NotSupported when `manifest_store` is set, or InvalidArgument when `manifest_store` is set and `manifest_row_feature_version` is not from 1 to `kManifestRowFeatureVersionLatest`. The check runs before the open changes anything on disk (for example before `create_if_missing` creates the directory). Without a store, the feature version is not checked.
- `MockManifestStore` (`test_util/mock_manifest_store.h`, test code only) keeps rows in memory. Several store objects share one `MockManifestStoreData`, each with its own epoch (two DB instances that take over the same DB) or no epoch (a read-only object, for example for a secondary instance). A request that the mock keeps pending after a timeout keeps the epoch of the object that made it, so it can still run after that object is destroyed. A test can make `Open()`, `Commit()` and `WriteGeneration()` fail on purpose (the fault list is in the mock header). `ReadDbRow()`, `Scan()` and `Destroy()` fail only for the reasons that the `ManifestStore` comments give.

Implementation:
- `db/manifest_rows.cc` implements the encoding functions, the two converters and `ManifestStore::CreateFromString()` (with `LoadSharedObject()`), in a "Public rows" section after the internal row code. It has one encode function and one read function per row type. Each read function has a switch over the field ID enum of its row type with no default case, so the build fails when a field ID is added without a reader. A field ID that is not in the enum falls through to the unknown-field rule.
- One shortest-form varint reader reads field IDs, value sizes and value varints, so every accepted varint has one byte form. The unique id uses the same helpers as a MANIFEST file (`EncodeUniqueIdBytes()` and `DecodeUniqueIdBytes()`).
- A compaction cursor level above 65536 is rejected as Corruption. The internal row keeps cursors in a vector indexed by level, so a corrupt level must not make the reader allocate a huge vector. The bound is a sanity limit, far above any real number of levels; at the bound the vector takes about 2 MB (an estimate).
- The key length check runs after all rows are read, because a column family row may come after its file rows.
- `DBImpl::CheckManifestStoreOptions()` holds the open check. `DBImpl::Open()` calls it first (for `DB::Open()`), and so do both `DB::OpenForReadOnly()` functions, `DBImplSecondary::OpenAsSecondaryImpl()` (which `DB::OpenAsSecondary()` and `DB::OpenAndCompact()` use) and `DB::OpenAsFollower()`.
- `manifest_store` is registered like `statistics` (`AsCustomSharedPtr`, with `kCompareNever`, `kDontSerialize` and `kAllowNull`). `options.h` only forward-declares `ManifestStore`.
- The test of the VersionEdit tags (`db/version_set_test.cc`) names, for each tag and each custom field of a new file record, the public field ID that holds it, or "no row field".

<details><summary>**Notable implementation details**</summary>

- The C API generator skips both options (two "deferred" entries in `tools/c_api_gen/auto_simple_bindings_blocklist.json`), so this diff adds no C API function.
- `MockManifestStore` checks the epoch and the expected commit sequence under one lock. `WriteGeneration()` writes the rows in chunks of 2 rows, so that tests with a few rows get several chunks. Each chunk checks the epoch, and the switch checks the row count and a checksum of the rows (a sum of row hashes). `Scan()` copies the rows under the lock and calls the visitor without it, so every scan returns the rows of one commit.
</details>

How to read this diff:
1. `include/rocksdb/manifest_store.h`: the Background comment, the row types, `ManifestRowKey`, the field ID enums, then "Canonical encoding"; then in `db/manifest_rows.cc` (section "Public rows"): `GetShortestVarint()`, `ParseManifestRowFields()` and `EncodeManifestRowFields()`.
2. `db/manifest_rows.h`: `ManifestDbRowExtraFields` and the two converter declarations at the end; `db/manifest_rows.cc`: `FieldWriter`, the `Encode*Row()` functions and `ManifestRowsToPublicRows()`.
3. `db/manifest_rows.cc`: the reader, bottom-up, as the "reader of public rows" comment maps it: the `Get*Value()` helpers, `ReadRowFields()`, the `Read*Field()` functions, the `Decode*Row()` functions and `DecodeRow()`, then `PublicRowsToManifestRows()`.
4. `include/rocksdb/manifest_store.h`: the "store interface" part at the end (background, terms, call order, structs, result meanings, `ManifestStore`).
5. `include/rocksdb/options.h`, `options/db_options.h`, `options/db_options.cc` and `options/options_helper.cc` for the two options; then `db/db_impl/db_impl.h` and `db/db_impl/db_impl_open.cc`: `DBImpl::CheckManifestStoreOptions()` and its call in `DBImpl::Open()`, then the other callers in `db_impl_readonly.cc`, `db_impl_secondary.cc` and `db_impl_follower.cc`.
6. `test_util/mock_manifest_store.h`, then `test_util/mock_manifest_store.cc`.
7. Row tests in `db/version_set_test.cc`: `ManifestRowFieldsTest`, the public-row part of `VersionSetTest.ManifestRowsRoundTrip`, and `ManifestPublicRowsTest`.
8. Store and option tests: the `MockManifestStoreTest` part of `db/version_set_test.cc`, `options/options_test.cc`, `options/options_settable_test.cc` and `db/db_basic_test.cc`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new test source file. `tools/c_api_gen/auto_simple_bindings_blocklist.json` only adds the two options.

Safety: Nothing in RocksDB calls the store or the converters outside tests. Existing DBs open as before, because the open check passes without a store. No file format changes. The header is marked EXPERIMENTAL. The header defines the row types, the authority and copy mode values, the field IDs and the encodings before any RocksDB code writes them, so that store authors can implement and test against them. This is why the header has values that no DB code path uses in this diff (the authority and copy mode values, the copy and in-flight file numbers, `ManifestScanOptions::consistent`, and the feature version); only the converters, the open check and tests read them. The format and the interface stay experimental and may change until store mode is supported. A new OPTIONS file has a `manifest_row_feature_version` line. An older binary that loads such a file skips the unknown line only when the caller sets `ignore_unknown_options` and the file was written by a newer RocksDB release version, as for every new DB option.

Known limitations:
- The converter checks each row, the links from file and blob file rows to their column family, and the key length against the timestamp size of the column family. It does not check other meaning across rows: for example, that file numbers are below the next file number, that file keys are in order under the comparator, or that a blob file that a file refers to exists. A caller that reads these rows must do those checks.
- This diff writes no store data. So no DB has its metadata in a store, and an older binary that does not know the store cannot meet such a DB.
- `db_stress`, `db_bench` and the crash test have no flags for `manifest_store` or `manifest_row_feature_version`. Every DB open function returns NotSupported when `manifest_store` is set, so these tools cannot test store mode.

Changes visible to existing users: the new public header, the two new options, the new line in the OPTIONS file, and two new lines in the LOG options dump. No other behavior change.

Differential Revision: D133307302
@github-actions

Copy link
Copy Markdown

✅ Claude Code Review

Auto-triggered after CI passed — reviewing commit 3cd9f2a


Summary

This is a well-structured building-block PR that adds the public row form, ManifestStore interface, and MockManifestStore for external MANIFEST metadata stores. The design follows RocksDB conventions for options registration, Customizable subclasses, and DB open validation. No high-severity issues were found. The "refuse all stores" approach (NotSupported) is a safe and appropriate strategy for introducing these building blocks before the actual store mode is implemented.

High-severity findings (0):
No high-severity findings.

Full review (click to expand)

Findings

🟡 MEDIUM

M1. src.mk changes may be missing from the diff — src.mk
  • Issue: The diff is truncated ("Diff truncated due to size") and the visible portion does not include src.mk changes. The PR description says "The build files (src.mk, CMakeLists.txt, BUCK) only add the new test source file" but db/manifest_rows.cc is a production source file that must also be added to LIB_SOURCES in src.mk. CMakeLists.txt and BUCK both correctly add it to their main library targets.
  • Root cause: Possibly a documentation inaccuracy in the PR description, or the src.mk change is in the truncated portion.
  • Suggested fix: Verify that src.mk adds db/manifest_rows.cc to LIB_SOURCES (after db/manifest_ops.cc) and test_util/mock_manifest_store.cc to TEST_LIB_SOURCES (near test_util/mock_time_env.cc). After updating src.mk, run python3 buckifier/buckify_rocksdb.py to regenerate BUCK.
M2. DebugCheckRowsAfterInstall does allocations under DB mutex — db/manifest_rows.cc
  • Issue: DebugCheckRowsAfterInstall() runs under the DB mutex (Phase 2 of the debug check). It creates ManifestRows expected and ManifestRows actual local variables, calls MakeManifestCfRow() for new column families, and calls AssertManifestRowsEqual(). These involve std::map operations and string allocations. While this is debug-only (#ifndef NDEBUG), it adds work under the DB mutex in debug builds.
  • Root cause: The debug check needs to verify row consistency after installation, which requires the mutex to read installed state.
  • Suggested fix: Acceptable for debug builds since it only fires for column family adds (the IsColumnFamilyAdd() path) and the allocations are small. The heavy lifting (file row comparison) is done in Phase 1 without the mutex. Worth noting that Phase 2 mutex-held work is bounded by the number of edits in the batch, not the total file count.
M3. PR description inaccuracy about build files — documentation
  • Issue: The PR description states "The build files (src.mk, CMakeLists.txt, BUCK) only add the new test source file." This is misleading because all three build files must also add db/manifest_rows.cc to their main library targets, as the CMakeLists.txt and BUCK diffs demonstrate.
  • Suggested fix: Update the description to say the build files add both db/manifest_rows.cc to the main library and test_util/mock_manifest_store.cc to the test library.

🟢 LOW / NIT

L1. All DB open paths are correctly covered — verification
  • Issue: None — positive observation. All DB open entry points are covered:
    • DBImpl::Open() — check at top (db_impl_open.cc)
    • DB::OpenForReadOnly() — both overloads check before OpenForReadOnlyCheckExistence (db_impl_readonly.cc)
    • DBImplSecondary::OpenAsSecondaryImpl() — check after *dbptr = nullptr (db_impl_secondary.cc)
    • DB::OpenAsFollower() — check after dbptr->reset(), before filesystem ops (db_impl_follower.cc)
    • DB::OpenAndCompact() — goes through OpenAsSecondaryImpl (covered)
    • DB::OpenAndTrimHistory() — goes through DB::Open (covered)
    • TransactionDB::Open() — goes through DBImpl::Open (covered)
    • OptimisticTransactionDB::Open() — goes through DB::Open (covered)
    • CompactedDBImpl::Open() — only called from OpenForReadOnly after the check (covered)
L2. CheckManifestStoreOptions ordering is intentionally correct — db_impl_open.cc:255-268
  • Issue: None — the function checks the feature version before returning NotSupported. This ensures an invalid feature version gives InvalidArgument both now and when store mode is supported, providing stable error behavior across releases.
L3. Test correctly covers all open functions except OpenAndCompact — db_basic_test.cc
  • Issue: The test comment correctly explains that OpenAndCompact is excluded (loads options from OPTIONS file; manifest_store is kDontSerialize). The test covers Open, OpenForReadOnly (both overloads), OpenAsSecondary, and OpenAsFollower.
L4. manifest_row_feature_version not checked without a store — by design
  • Issue: When manifest_store is null, manifest_row_feature_version is not validated. This is intentional (documented in function comment and PR description) — an OPTIONS file with a future feature version doesn't block opening without a store.
L5. Options registration follows established patterns
  • Issue: None — manifest_store uses AsCustomSharedPtr<ManifestStore> with kCompareNever | kDontSerialize | kAllowNull, matching the statistics pattern. manifest_row_feature_version is an immutable uint32_t serialized to OPTIONS file.
L6. Canonical encoding uses shortest-form varint validation
  • Issue: None — GetShortestVarint() prevents ambiguous encodings. Same data always encodes the same way. Good defensive design.
L7. Temperature handling matches MANIFEST reader
  • Issue: None — keeps kUnknown for unrecognized temperature values, matching MANIFEST file reader behavior for forward compatibility.

Cross-Component Analysis

Context Covered? Notes
DB::Open (primary) YES First check in DBImpl::Open
OpenForReadOnly (both) YES Before CompactedDBImpl::Open and OpenForReadOnlyCheckExistence
OpenAsSecondary YES In OpenAsSecondaryImpl
OpenAsFollower YES Before filesystem ops
OpenAndCompact YES Via OpenAsSecondaryImpl (store always null from OPTIONS)
OpenAndTrimHistory YES Via DB::Open
TransactionDB::Open YES Via DBImpl::Open
OptimisticTransactionDB YES Via DB::Open
CompactedDBImpl::Open YES Called after check in OpenForReadOnly
SetDBOptions N/A manifest_store not in MutableDBOptions

Positive Observations

  • Clean separation: Public header defines row format and store interface without depending on internal headers.
  • Defensive "refuse store": NotSupported for all stores makes this PR safe to land without risk to existing DB operations.
  • Two-phase debug check: Phase 1 (heavy, no mutex) vs Phase 2 (lightweight, with mutex) is well-designed.
  • Schema evolution: Must-understand bit (bit 6) matches MANIFEST custom field tag convention.
  • Canonical encoding: Shortest-form varint validation + strictly-increasing field IDs ensure deterministic encoding.
  • MockManifestStore design: Shared MockManifestStoreData across store objects with different epochs enables testing fencing and concurrent access.

ℹ️ About this response

Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md

Limitations:

  • Claude may miss context from files not in the diff
  • Large PRs may be truncated
  • Always apply human judgment to AI suggestions

Commands:

  • /claude-review [context] — Request a code review
  • /claude-query <question> — Ask about the PR or codebase

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant