Repository navigation
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#15738xingbowang wants to merge 2 commits into
Conversation
|
@xingbowang has exported this pull request. If you are a Meta employee, you can view the originating Diff in D133307302. |
|
| 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]
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 1e93e03 SummaryLarge, 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 High-severity findings (1):
Full review (click to expand)Findings🔴 HIGHH1. Missing src.mk entries —
|
| 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, beforemu->Lock(). Reads only data the singleProcessManifestWritesthread 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
- Canonical encoding design: Shortest-form varints ensure equal rows produce equal bytes — essential for store comparison and checksumming.
- 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. - Error hierarchy: Clear separation between
Corruption,NotSupported, andInvalidArgumentmatching RocksDB conventions. - Two-phase debug check: Maximizes coverage while minimizing mutex hold time, correctly accounting for in-memory differences.
- All-open-paths test:
ManifestStoreOptionsAreCheckedAtOpencovers Open, both OpenForReadOnly overloads, OpenAsSecondary, and OpenAsFollower. - Release build safety:
TEST_SYNC_POINT_CALLBACKguard 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
1e93e03 to
5dc06ca
Compare
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 5dc06ca SummaryThis 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🟡 MEDIUMM1.
|
| 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 modifieswals_, 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
-
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.
-
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.
-
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) mirrorskCustomTagNonSafeIgnoreMaskfor forward compatibility. -
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.
-
Debug check design: The two-phase check in ProcessManifestWrites cleverly avoids holding the DB mutex during expensive comparisons while still verifying consistency after install.
-
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
… 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
5dc06ca to
eeaa3c7
Compare
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit eeaa3c7 SummaryWell-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 High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🟡 MEDIUMM1.
|
| 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, beforemu->Lock(). Readswals_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. OnlyCheckManifestStoreOptions()runs in release, which is a cold-path check at open time.
Behavioral Compatibility
- No behavior change for existing users. Default
manifest_storeis null and defaultmanifest_row_feature_versionis 1, both passCheckManifestStoreOptions(). - New OPTIONS file line:
manifest_row_feature_version=1appears in new OPTIONS files. An older binary withignore_unknown_optionsskips it. Withoutignore_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
ManifestStoreOptionsAreCheckedAtOpentest covers all 5 open function families and verifies bothNotSupported(store set) andInvalidArgument(bad feature version), plus the sync point bypass in debug builds. The test correctly checksStatus::Coderather thanASSERT_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
… 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
… 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
… 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
… 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
… 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
eeaa3c7 to
7502f27
Compare
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 7502f27 SummaryWell-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🟡 MEDIUMM1.
|
| 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:
CheckManifestStoreOptionsalways 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 callsBuildManifestRowChanges/ApplyManifestRowChangesbut 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(beforeValidateCompactionFilterOptions),OpenForReadOnly(both overloads, before existence check),OpenAsSecondary(before deferred SST opening logic),OpenAsFollower(beforeCreateDirIfMissing).
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
statisticspattern for shared_ptr options. - Truncation safety:
kMaxCompactCursorLevelandkFileNumberMaskchecks 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
7502f27 to
c3c9e61
Compare
… 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
… 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
c3c9e61 to
1ea7ff1
Compare
… 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
… 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
… 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
1ea7ff1 to
21bd5bb
Compare
… 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
… 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
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 21bd5bb SummaryThis 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🔴 HIGHNone. 🟡 MEDIUMM1.
|
| 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
-
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.
-
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. -
Build-time exhaustiveness: Switch statements in
ManifestRowFieldOfTag(),ManifestRowFieldOfNewFileTag(), and eachRead*Field()have no default case -- adding a new tag/field without handling it fails the build. -
Static assertions pin field IDs:
static_asserton the last field ID of each row type prevents silent renumbering. -
BytesMatchTheFieldTablestest: Hand-written expected bytes catch bugs that round-trip tests alone cannot (e.g., swapped field IDs, wrong byte order). -
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.
-
Clean separation of concerns: Internal rows vs public rows with well-defined converters. ManifestDbRowExtraFields cleanly separates RocksDB-owned from store-owned fields.
-
Options follow established patterns:
manifest_storemirrors thestatisticsregistration (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
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 6a6413f SummaryThis 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🔴 HIGHNone. 🟡 MEDIUMM1.
|
| 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:
ManifestRowFieldOfTagandManifestRowFieldOfNewFileTagswitches 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
… 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
… 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
… 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
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 020e4d9 SummaryWell-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):
Full review (click to expand)Findings🔴 HIGHH1. Verify
|
| 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:
CheckManifestStoreOptionsis a pure static function reading onlyconst DBOptions&, called before the DB is created or the mutex exists.- The new options
manifest_storeandmanifest_row_feature_versionare 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
-
Thorough open guards: All 5 DB open paths correctly call
CheckManifestStoreOptionsbefore any disk changes. The test covers all of them including thecreate_if_missing/kNotFoundcheck. -
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."
-
Well-documented format: The public header thoroughly documents the row encoding, field IDs, defaults, and schema evolution (must-understand bit).
-
Clean separation: Internal rows (
ManifestRows) vs public rows (ManifestRow) with explicit conversion functions. The FieldWriter pattern is clean. -
Build-time enforcement: Switch over field ID enums with no
defaultcase ensures-Wswitch -Werrorcatches missing handlers when new fields are added. -
Round-trip testing: Coverage includes encode-decode round trips and explicit VersionEdit tag-to-field mapping verification.
-
C API blocklist: New options correctly deferred.
-
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
020e4d9 to
9ce4bc3
Compare
… 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
… 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
… 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
9ce4bc3 to
1cfd5ac
Compare
… 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
… 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
… 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
… 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
1cfd5ac to
ded36c5
Compare
… 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
… 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
… 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
… 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
ded36c5 to
3cd9f2a
Compare
… 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
… 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
… 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
… 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
✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 3cd9f2a SummaryThis 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): Full review (click to expand)Findings🟡 MEDIUMM1. src.mk changes may be missing from the diff —
|
| 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
MockManifestStoreDataacross 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
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.halready 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.hdefines 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; aCommit()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) theManifestStoreinterface 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.include/rocksdb/manifest_store.hdefines:ParseManifestRowFields()andEncodeManifestRowFields();ManifestStoreinterface (aCustomizable):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, andDestroy()removes all rows.Open()andDestroy()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, butOpen()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. ForCommit()andWriteGeneration(), 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()andDestroy()list their own results at their declarations.ManifestStore::CreateFromString()creates a store from a registered class. RocksDB has no built-in store.db/manifest_rows.h:ManifestRowsToPublicRows()turnsManifestRowsinto public rows, andPublicRowsToManifestRows()turns them back. The comment ofPublicRowsToManifestRows()lists every NotSupported and Corruption case and their order.ManifestDbRowExtraFieldsholds the RocksDB-owned DB row fields thatManifestDbRowdoes not hold, other than the row format version, which the writer always writes askManifestRowFormatVersionLatest.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()andDB::OpenAndCompact()return NotSupported whenmanifest_storeis set, or InvalidArgument whenmanifest_storeis set andmanifest_row_feature_versionis not from 1 tokManifestRowFeatureVersionLatest. The check runs before the open changes anything on disk (for example beforecreate_if_missingcreates 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 oneMockManifestStoreData, 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 makeOpen(),Commit()andWriteGeneration()fail on purpose (the fault list is in the mock header).ReadDbRow(),Scan()andDestroy()fail only for the reasons that theManifestStorecomments give.Implementation:
db/manifest_rows.ccimplements the encoding functions, the two converters andManifestStore::CreateFromString()(withLoadSharedObject()), 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.EncodeUniqueIdBytes()andDecodeUniqueIdBytes()).DBImpl::CheckManifestStoreOptions()holds the open check.DBImpl::Open()calls it first (forDB::Open()), and so do bothDB::OpenForReadOnly()functions,DBImplSecondary::OpenAsSecondaryImpl()(whichDB::OpenAsSecondary()andDB::OpenAndCompact()use) andDB::OpenAsFollower().manifest_storeis registered likestatistics(AsCustomSharedPtr, withkCompareNever,kDontSerializeandkAllowNull).options.honly forward-declaresManifestStore.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**
tools/c_api_gen/auto_simple_bindings_blocklist.json), so this diff adds no C API function.MockManifestStorechecks 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:
include/rocksdb/manifest_store.h: the Background comment, the row types,ManifestRowKey, the field ID enums, then "Canonical encoding"; then indb/manifest_rows.cc(section "Public rows"):GetShortestVarint(),ParseManifestRowFields()andEncodeManifestRowFields().db/manifest_rows.h:ManifestDbRowExtraFieldsand the two converter declarations at the end;db/manifest_rows.cc:FieldWriter, theEncode*Row()functions andManifestRowsToPublicRows().db/manifest_rows.cc: the reader, bottom-up, as the "reader of public rows" comment maps it: theGet*Value()helpers,ReadRowFields(), theRead*Field()functions, theDecode*Row()functions andDecodeRow(), thenPublicRowsToManifestRows().include/rocksdb/manifest_store.h: the "store interface" part at the end (background, terms, call order, structs, result meanings,ManifestStore).include/rocksdb/options.h,options/db_options.h,options/db_options.ccandoptions/options_helper.ccfor the two options; thendb/db_impl/db_impl.handdb/db_impl/db_impl_open.cc:DBImpl::CheckManifestStoreOptions()and its call inDBImpl::Open(), then the other callers indb_impl_readonly.cc,db_impl_secondary.ccanddb_impl_follower.cc.test_util/mock_manifest_store.h, thentest_util/mock_manifest_store.cc.db/version_set_test.cc:ManifestRowFieldsTest, the public-row part ofVersionSetTest.ManifestRowsRoundTrip, andManifestPublicRowsTest.MockManifestStoreTestpart ofdb/version_set_test.cc,options/options_test.cc,options/options_settable_test.ccanddb/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.jsononly 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 amanifest_row_feature_versionline. An older binary that loads such a file skips the unknown line only when the caller setsignore_unknown_optionsand the file was written by a newer RocksDB release version, as for every new DB option.Known limitations:
db_stress,db_benchand the crash test have no flags formanifest_storeormanifest_row_feature_version. Every DB open function returns NotSupported whenmanifest_storeis 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