Skip to content

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

Merged
alexey-milovidov merged 1 commit into
ClickHouse:ClickHouse/v11.8.1from
groeneai:fix-ttl-y2038-v11.8.1
Nov 29, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:ClickHouse/v11.8.1from
groeneai:fix-ttl-y2038-v11.8.1

Conversation

@groeneai

@groeneai groeneai commented Nov 29, 2026 •

Copy link
Copy Markdown

DBWithTTL stores the low 32 bits of the current time after each value, which is correct as an unsigned value until 2106. DBWithTTLImpl::SanityCheckTimestamp read it back as int32_t, so from 2038-01-19T03:14:08Z every read of a newly written value fails: Get and MultiGet return Corruption: Error: Timestamp < ttl feature release time!, KeyMayExist returns false, and TtlIterator::value() fails its assert in debug builds. Expiry by the compaction filter was not affected.

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

ClickHouse's EmbeddedRocksDB uses DBWithTTL when a table has a TTL; 02416_rocksdb_delete_update fails this way with the clock shifted past 2038 (ClickHouse/ClickHouse#135354).

Tests: two new cases in utilities/ttl/ttl_test.cc use the existing mock clock. Without the fix, ReadAfterYear2038 passes at t=2147483647 and fails at t=2147483648, and CompactionAfterYear2038 fails reading a fresh value; with it, all 25 ttl_test cases pass (Debug, gcc 13).

Not changed: TtlIterator::ttl_timestamp() also returns int32_t; only ldb uses it, and ClickHouse does not build ldb.

Upstream report: meta#15826


Note

Low Risk
Small, localized type fix on read-path validation with new regression tests; no format or compaction semantics change.

Overview
Fixes DBWithTTL reads failing once system time passes the 32-bit signed boundary (2038-01-19). TTL values store the low 32 bits of Unix time as an unsigned field; SanityCheckTimestamp was decoding and comparing that suffix as int32_t, so newly written values looked “below” kMinTimestamp and Get, MultiGet, KeyMayExist, and iterators returned corruption or misses. The on-disk format is unchanged—decoded timestamps are now uint32_t with an unsigned compare.

Adds ReadAfterYear2038 (mock clock at 2037/2038/2039 exercises put/read paths) and CompactionAfterYear2038 (expired keys still drop after compaction post-2038).

Reviewed by Cursor Bugbot for commit f004392. Bugbot is set up for automated code reviews on this repo. Configure here.

`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.

Upstream report: meta#15826

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexey-milovidov
alexey-milovidov merged commit 8a970a0 into ClickHouse:ClickHouse/v11.8.1 Nov 29, 2026
1 check passed
gugulogs pushed a commit to gugulogs/ClickHouse that referenced this pull request Nov 30, 2026
DBWithTTLImpl::SanityCheckTimestamp decoded the stored 4-byte creation
timestamp as int32_t, so every value written after 2038-01-19 was reported
as Corruption ("Timestamp < ttl feature release time!") on Get/MultiGet and
hit the assert in TtlIterator::value(). The writers store the low 32 bits of
the Unix time, which is valid as an unsigned value until 2106; the reader now
decodes it as uint32_t.

Fork PR: ClickHouse/rocksdb#37
Upstream: meta/rocksdb#15826

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants