Skip to content

Read create_time of a replication log entry correctly in the hour repeated at the end of DST - #127766

Open
groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:fix-replication-log-create-time-dst
Open

groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:fix-replication-log-create-time-dst

Conversation

@groeneai

@groeneai groeneai commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #76867
Related: #127758

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix create_time of replication log entries created in the hour repeated at the end of DST in the server time zone. It was read back one hour early, so system.replicas.absolute_delay reported 3600 seconds for an up-to-date replica and execute_merges_on_single_replica_time_threshold did not wait.

Description

On 26.3 and older releases, with a DST server time zone, a replication log entry created in the second pass of the hour repeated at the end of DST is read back one hour early: create_time is written as wall-clock text in the server time zone and makeDateTime resolves it to the first occurrence. system.replicas.absolute_delay then reports 3600 s while an insert is being replicated, and execute_merges_on_single_replica_time_threshold stops waiting. CI hit it on 2026-10-25 01:00-02:00 UTC (Europe/Amsterdam): 00563_insert_into_remote_and_zookeeper_long, 03080_incorrect_join_with_merge and 03008_deduplication_remote_insert_select with Local replica of shard 1 is stale (delay: 3600s.) (Fast test, PR 76867), and 01532_execute_merges_on_single_replica_long (PR 127758).

ReplicatedMergeTreeLogEntry::parse now replaces an ambiguous create_time with the znode creation time (stat.ctime) when the znode was created with the entry (a log znode or a barrier), so all replicas reading the log agree on it. Readers of queue znodes, whose creation time is the pull time, keep the previous reading: after a restart, an unprocessed entry from that hour still reads one hour early. The written format is unchanged: older replicas parse it strictly, and a new format would not fix entries they wrote. Mutation entries use the same encoding, for display only (system.mutations).

Validation: the new unit test fails on master and passes with the fix. On a Europe/Amsterdam server, a log entry injected with create_time: 2026-10-25 02:30:00 reads as its znode creation time with the fix (absolute_delay 0) and as 02:30 CEST on master.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/127766]

groeneai and others added 3 commits October 25, 2026 02:53
…eated at the end of DST

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eated at the end of DST

`ReplicatedMergeTreeLogEntryData` writes `create_time` as wall-clock time
of the server time zone and reads it back with `makeDateTime`, which
resolves a time inside the hour repeated at the end of DST to its first
occurrence. An entry created in the second occurrence therefore reads back
`amount_of_offset_change` (one hour) early on every replica, so
`system.replicas.absolute_delay` jumps by 3600 s while an insert is being
replicated (`Local replica of shard 1 is stale (delay: 3600s.)`, healthy
replicas skipped by distributed queries) and
`execute_merges_on_single_replica_time_threshold` stops waiting at once.
Seen in CI on 2026-10-25 01:00-02:00 UTC (Europe/Amsterdam) in
`00563_insert_into_remote_and_zookeeper_long`,
`03080_incorrect_join_with_merge`,
`03008_deduplication_remote_insert_select` and
`01532_execute_merges_on_single_replica_long`.

`ReplicatedMergeTreeLogEntry::parse` now replaces an ambiguous value with
the creation time of the znode (`stat.ctime`), which is unambiguous and the
same on every replica, when that znode was created together with the entry
(a `log` znode or a barrier). The format version 1 fallback already takes
`create_time` from the same place. Readers of `queue` znodes, whose
creation time is the time the entry was pulled or copied, pass
`znode_created_with_entry = false` and keep the previous reading.
Unambiguous values and the written format are unchanged: older replicas
parse the header strictly (fixed-width date-time, `assertEOF`), so an
unambiguous on-wire format would need a writer gate and would still not
fix entries written by older versions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the two new comments on create_time ambiguity and the znode_created_with_entry parameter to one line each.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review.

# Sev Finding Verdict Evidence / action
1 ⚠️ The unit test never calls parse with znode_created_with_entry = false, so the queue path could regress unnoticed (gtest_replicated_merge_tree_log_entry.cpp) DISAGREE A false case needs the 4-argument parse, which master lacks, so Bugfix validation (unit tests) would report XFAIL instead of reproducing the bug (ci/jobs/unit_tests_bugfix_validation_job.py:17-29). The false path was checked locally: a temporary 4-argument probe kept the first reading in 9 zones, and after DETACH/ATTACH a server reloads an injected entry as 02:30 CEST, as before.
2 💡 For a merge assigned in that hour, a replica that reloads the entry from its queue znode after a restart (or an older replica) evaluates TTL at the first reading, while replicas reading the log use ctime noted, not blocking Inherent to any reader-side fix. If a TTL expires inside that hour, the existing "not byte-identical" path (MergeFromLogEntryTask.cpp:435-474) fetches the merged part, as between replicas with different server time zones today.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261025-041500

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. unit_tests_dbms --gtest_filter='ReplicatedMergeTreeLogEntry*' fails on master every run: 02:30 CET (1792891800) reads back as 1792888200, 3600 s early; Australia/Lord_Howe 1800 s early.
b Root cause explained? create_time is written as wall-clock text in the server time zone; in the hour repeated at the end of DST that text names two instants and makeDateTime returns the first, so an entry from the second pass is one hour old on every replica (getAbsoluteDelay 3600 s, shouldMergeOnSingleReplica stops waiting).
c Fix matches root cause? Yes. The ambiguous value is resolved where it is decoded (ReplicatedMergeTreeLogEntry::parse), with the znode creation time that parse already uses for format version 1. No consumer special cases, no format change.
d Test intent preserved / new tests added? New gtest gtest_replicated_merge_tree_log_entry.cpp; it uses only the existing 3-argument parse, so it compiles on master sources. No existing test changed.
e Both directions demonstrated? Yes. gtest FAIL on master, PASS with the fix (50/50 with --gtest_shuffle). On a Europe/Amsterdam server, a log entry injected with create_time: 2026-10-25 02:30:00 gives absolute_delay 12971 on master and 0 with the fix.
f Fix is general across code paths? All 12 parse callers classified: log and barrier znodes use the znode time, the 3 readers of queue znodes (load, cloneReplica, the wait lookup) keep the previous reading. All 16 log- writers set create_time = time(nullptr) before the create.
g Fix generalizes across inputs (params/datatypes/wrappers)? Checked 9 zones: 60- and 30-minute shifts, changes at midnight (Asia/Beirut, America/Sao_Paulo), America/Havana, Australia/Sydney, Pacific/Chatham, US, EU; both occurrences; values outside the hour unchanged; ctime == 0 unchanged. Type wrappers N/A.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, no format version, no wire change. Older replicas keep their reading; if time_of_merge differs in that hour, the existing "not byte-identical" path fetches the merged part.
i Invariants and contracts preserved? A create_time parsed from a log znode is the creation instant of the entry and is the same on every replica of the same version; outside a repeated hour the written value is kept exactly; the format version 1 fallback is unchanged; no locks involved.

Session id: cron:clickhouse-impl-slot-5:20261025-025200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tavplubix @CheSema, could you review this and add the can be tested label so CI runs? create_time of a replication log entry is written as wall-clock text in the server time zone, so in the hour repeated at the end of DST it was read back one hour early (false 3600 s absolute_delay, execute_merges_on_single_replica_time_threshold not waiting); parse now takes the log znode ctime for such an ambiguous value, with no format change.

@clickhouse-gh

clickhouse-gh Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3e0d568]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) FAIL
Changed settings are not reflected in the settings changes history (see changed_settings.txt) FAIL cidb

AI Review

Summary

The PR disambiguates replication log create_time during backward DST transitions using the original znode's creation timestamp, without changing the stored format. Queue reloads retain the documented existing behavior. No actionable findings.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. labels Oct 25, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 25, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 3e0d568

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Upgrade check (amd_release) / Changed settings are not reflected in the settings changes history (see changed_settings.txt) not from this PR (it does not touch settings): v26.10.2.103-stable ships use_query_condition_cache_for_time_conditions = false after #127632, while the master this head was tested on still says its default became true in 26.10 (same 1 / 0 row on every PR since 2026-10-24 04:17Z). The fix merged at 11:26Z, after this run started, and is absent from the tested merge commit #127687 (mine, merged)
Mergeable Check, PR praktika rollups of the row above #127687 (the owner of the row above)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261025-133007

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

can be tested Allows running workflows for external contributors comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants