Skip to content

Fix Statistics population in CompactedDBImpl::Get and MultiGet - #15180

Open
harisawan-bit wants to merge 1 commit into
facebook:mainfrom
harisawan-bit:fix-compacted-db-statistics
Open

Fix Statistics population in CompactedDBImpl::Get and MultiGet#15180
harisawan-bit wants to merge 1 commit into
facebook:mainfrom
harisawan-bit:fix-compacted-db-statistics

Conversation

@harisawan-bit

Copy link
Copy Markdown

Summary:
When a database is opened read-only and qualifies for compacted DB mode (such as a single SST file or all files in a single level without merge operators), read operations are handled by CompactedDBImpl.

In CompactedDBImpl::Get and CompactedDBImpl::MultiGet, GetContext was being constructed with
ullptr passed for logger, statistics, and clock. Consequently, when callers open a database with options.statistics configured, ticker metrics such as BLOCK_CACHE_HIT, BLOCK_CACHE_MISS, BLOCK_CACHE_DATA_HIT, BLOCK_CACHE_DATA_MISS, and BLOCK_CACHE_BYTES_READ remained at 0 during reads through CompactedDBImpl.

This patch passes immutable_db_options_.logger, immutable_db_options_.stats, and immutable_db_options_.clock to GetContext in both CompactedDBImpl::Get and CompactedDBImpl::MultiGet, ensuring block cache metrics and logger/clock diagnostics are properly populated.

Fixes #15140

Test Plan:
Updated TEST_F(DBBasicTest, CompactedDB) in db/db_basic_test.cc to attach options.statistics = CreateDBStatistics() and assert that block cache data hits/misses are counted after Get and MultiGet calls on a CompactedDB instance.

Summary:
When a database is opened read-only and qualifies for compacted DB mode (such as a single SST file or all files in a single level without merge operators), read operations are handled by `CompactedDBImpl`.

In `CompactedDBImpl::Get` and `CompactedDBImpl::MultiGet`, `GetContext` was being constructed with `nullptr` passed for `logger`, `statistics`, and `clock`. Consequently, when callers open a database with `options.statistics` configured, ticker metrics such as `BLOCK_CACHE_HIT`, `BLOCK_CACHE_MISS`, `BLOCK_CACHE_DATA_HIT`, `BLOCK_CACHE_DATA_MISS`, and `BLOCK_CACHE_BYTES_READ` remained at 0 during reads through `CompactedDBImpl`.

This patch passes `immutable_db_options_.logger`, `immutable_db_options_.stats`, and `immutable_db_options_.clock` to `GetContext` in both `CompactedDBImpl::Get` and `CompactedDBImpl::MultiGet`, ensuring block cache metrics and logger/clock diagnostics are properly populated.

Fixes facebook#15140

Test Plan:
Updated `TEST_F(DBBasicTest, CompactedDB)` in `db/db_basic_test.cc` to attach `options.statistics = CreateDBStatistics()` and assert that block cache data hits/misses are counted after `Get` and `MultiGet` calls on a CompactedDB instance.
Copilot AI lite review requested due to automatic review settings September 4, 2026 02:47
@meta-cla

meta-cla Bot commented Sep 4, 2026

Copy link
Copy Markdown

Hi @harisawan-bit!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@meta-cla

meta-cla Bot commented Sep 4, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CompactedDBImpl::Get/MultiGet never populate Statistics (block cache hit/miss, memtable hit/miss, bytes read all stay 0)

3 participants