Skip to content

Fix DBWithTTL reads of values written after 2038-01-19 - #15827

Open
groeneai wants to merge 1 commit into
meta:mainfrom
groeneai:fix-ttl-y2038-main
Open

groeneai wants to merge 1 commit into
meta:mainfrom
groeneai:fix-ttl-y2038-main

Conversation

@groeneai

Copy link
Copy Markdown

Summary:
DBWithTTL appends the low 32 bits of the current time to each value (AppendTS, TtlMergeOperator), which is valid as an unsigned value until 2106. DBWithTTLImpl::SanityCheckTimestamp decodes it as int32_t, so from 2038-01-19T03:14:08Z every newly written value fails the kMinTimestamp check: Get and MultiGet return Corruption: Error: Timestamp < ttl feature release time!, KeyMayExist returns false, and TtlIterator::value() fails its assert in debug builds. Expiry in the compaction filter (IsStale) is not affected.

This decodes the timestamp as uint32_t. The on-disk format does not change, and values already written after 2038 become readable.

Not changed: TtlIterator::ttl_timestamp() also returns int32_t; only ldb uses it.

Fixes #15826. The same change is in ClickHouse's RocksDB fork (ClickHouse#37), where EmbeddedRocksDB tables with a TTL hit this with the clock shifted past 2038.

Test Plan:
Two new tests in utilities/ttl/ttl_test.cc use the existing mock clock. Without the fix, TtlTest.ReadAfterYear2038 passes at t=2147483647 and fails at t=2147483648, and TtlTest.CompactionAfterYear2038 fails reading a fresh value. With the fix, all 28 ttl_test cases pass (Debug, gcc 13) and the two new tests pass 5 times in a row. clang-format 21.1.2 reports no changes, and build_tools/check-sources.sh passes.

`AppendTS` and `TtlMergeOperator` store the low 32 bits of the current
time, which is correct as an unsigned value until 2106.
`SanityCheckTimestamp` read it back as `int32_t`, so from
2038-01-19T03:14:08Z every stored timestamp is negative and below
`kMinTimestamp`: `Get` and `MultiGet` return
`Corruption: Error: Timestamp < ttl feature release time!`,
`KeyMayExist` returns false, and `TtlIterator::value()` fails its
assert in debug builds.

Read the timestamp as `uint32_t`. The on-disk format does not change,
and values already written after 2038 become readable.

Fixes meta#15826

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@meta-cla

meta-cla Bot commented Nov 29, 2026

Copy link
Copy Markdown

Hi @groeneai!

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!

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DBWithTTL: reads return Corruption for values written after 2038-01-19 (Y2038)

1 participant