Repository navigation
fix(frontend): validate SET GLOBAL time_zone before persisting it - #31830
Closed
MatrixAdventurer wants to merge 4 commits into
Closed
MatrixAdventurer wants to merge 4 commits into
MatrixAdventurer wants to merge 4 commits into
Conversation
SET GLOBAL time_zone stored any string, and every new session then failed to initialize with "unknown time zone", even after a restart. Extract the parsing of updateTimeZone into resolveTimeZone and call it from SetGlobalSysVar, so an unknown zone is rejected like SET SESSION does. Fixes matrixorigin#31714
MatrixAdventurer
requested review from
LeftHandCold and
aptend
as code owners
October 30, 2026 03:51
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Contributor
|
相关issue将根据优先级计划修复 |
2 of 7 tasks
mergify Bot
pushed a commit
that referenced
this pull request
Nov 14, 2026
…results, reject snapshot-qualified write targets (#32456) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes #31714 Fixes #31547 Fixes #31550 Fixes #31688 ## What this PR does / why we need it: 把此前被关闭、未合入的三个修复中影响最大的几项(锁死登录、进程崩溃、静默写错表)合成一个 PR,基于当前 main(`11d2e1ef`)重新整理。三项修复的代码互不重叠: 1. **#31714:`SET GLOBAL time_zone` 写入非法时区后,所有新连接都无法登录**(原 #31830) - 现状:`SET GLOBAL time_zone = 'Mars/Phobos'` 返回 OK 并持久化,之后每个新连接都报 `1815 unknown time zone`,重启也不能恢复。 - 修复:把 `updateTimeZone` 的校验抽成 `resolveTimeZone`,`SetGlobalSysVar` 在持久化 `time_zone` 之前先用它校验。非法值直接报错,和 `SET SESSION` 的行为一致。 - 文件:`pkg/frontend/variables.go`、`pkg/frontend/types.go` 2. **#31547 / #31550:`save_query_result = on` 时,`DATA BRANCH DIFF` 遇到 DATETIME/TIME 列会让服务进程崩溃;TIMESTAMP 丢精度、时区不对**(原 #31842) - 现状:DIFF 结果中的时间值是文本,保存结果时 `convertRowsIntoBatch` 对 `types.Datetime/Time/Date` 做类型断言,直接 panic,整个 CN 退出。 - 修复:DATE/TIME/DATETIME 同时接受原生值和文本(按列声明的 scale 解析);结果列保留 TIME/DATETIME/TIMESTAMP 的小数秒精度;TIMESTAMP 文本按会话时区解析,不再用进程时区。 - 文件:`pkg/frontend/util.go`、`pkg/frontend/query_result.go` 3. **#31688:对 `t{snapshot='sp'}` 执行 DML/DDL 会静默改动当前表**(原 #31854) - 现状:`INSERT/UPDATE/DELETE/ALTER/TRUNCATE/DROP ... t{snapshot='sp'}` 都返回成功,实际写进了当前表,快照不变,也没有任何提示。 - 修复:`BuildPlan` 入口新增 `rejectSnapshotQualifiedWriteTarget`。写入目标带快照/时间戳限定时,统一报 `not supported: <OP> on a snapshot-qualified table`。覆盖的语句有 INSERT、REPLACE、UPDATE(含多表)、DELETE(含多表)、ALTER、TRUNCATE、DROP TABLE、LOAD、INSERT ALL、CREATE/DROP INDEX、RENAME。带快照限定的表作为只读来源(`INSERT ... SELECT`、UPDATE/DELETE 的 JOIN 来源)不受影响。 - 文件:`pkg/sql/plan/build.go`、`pkg/sql/plan/snapshot_write_target.go` ## How this PR does it or why it needs it: - 在新分支上 cherry-pick 原 PR 的提交(a8dfd88d、4556f673、375cf9b9、768ace77),过程中没有冲突。 - 适配当前 main:`CompilerContext.Resolve` 现在多了一个 `*TableResolution` 参数,相应补上 `nil`。 - 为了把规模控制在 10 个文件以内,把两个 frontend 单测合并成 `pkg/frontend/time_zone_and_saved_temporal_test.go`,三组 BVT 合并成 `test/distributed/cases/util/priority_fixes_31547_31688_31714.{sql,result}`。用例内容不变,按 issue 分段注释。 - 规模:10 个文件,+790/-40。其中代码改动 6 个文件,其余 4 个是测试。 ## Evidence(本地,main `11d2e1ef` 对比本分支) - **端到端**(单机 launch,`unshare -rn` 隔离网络): - #31547:main 上执行 `DATA BRANCH DIFF c AGAINST b` 后客户端报 2013,服务进程退出;本分支正常返回 `c, UPDATE, 1, 2024-01-02 00:00:00.654321, 04:05:06.654321, ...`,服务存活。 - #31688:main 上 `INSERT INTO snap_t{snapshot='sp'} ...` 成功,当前表多出一行;本分支报 `20105 not supported: INSERT on a snapshot-qualified table 'snap_t'`,当前表不变。 - #31714:main 上 `SET GLOBAL time_zone='Mars/Phobos'` 成功,之后新连接报 `1815 unknown time zone Mars/Phobos`;本分支 SET 时直接报错,全局值仍是 `SYSTEM`,新连接正常。 - **BVT** `util/priority_fixes_31547_31688_31714.sql`:本分支 57/57 通过;main 13/57(DIFF 让进程崩溃后,后续 40 条全部 ABNORMAL)。 - **相关 BVT 目录**(本分支):`system_variable` 636/636,`git4data/branch/diff` 1976/1976,结果与 main 相同。`snapshot` 18389/18454:65 条失败全部在 `snapshot_restore_account_level.sql`,原因是本机资源准入报 `execution resource admission rejected ... cap=0`,与本改动无关,main 在同一目录也出现同类资源错误。全目录没有任何语句命中新的 snapshot-qualified 报错。 - **单测**:`go test ./pkg/frontend/ ./pkg/sql/plan/` 全部通过(含新增的 `TestSetGlobalTimeZoneRejectsUnknownZone`、`TestConvertRowsIntoBatchTemporalText` 和 snapshot write-target 用例)。 - **静态检查**:`go vet`、`molint check`、`golangci-lint v2.14.0 -c .golangci.yml --new-from-rev=origin/main`(`./pkg/frontend/...`、`./pkg/sql/plan/`)均无问题。 ## Special notes for your reviewer: - 这三项修复之前分别在 #31830、#31842、#31854 提交,2026-10-30 被关闭(“相关 issue 将根据优先级计划修复”)。这次按严重程度挑出:会锁死登录、会让进程崩溃、会静默写错表的三项,三个 issue 目前都还开着,也没有其他修复 PR。 - 非法时区的错误码沿用 SET SESSION 现有的行为(`unknown time zone ...`),没有改成 MySQL 的 1298,以免改变会话级的既有行为。 > 本操作由 LW 授权的 Grok Bot 智能体执行。 Approved-by: XuPeng-SH <[email protected]>
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #31714
What this PR does / why we need it:
SET GLOBAL time_zone = 'Mars/Phobos'succeeded and persisted the value. Every new connection then failed during session-variable initialization withunknown time zone Mars/Phobos, also after a restart, so a single typo locked out all new logins.SET SESSION time_zonealready rejects the same value.Cause: the zone is only parsed in
updateTimeZone, the session-scope update hook.Session.SetGlobalSysVarpersists the global value without calling it.Fix (
variables.go,types.go; +42/-26, mostly moving code): the parsing part ofupdateTimeZonebecomesresolveTimeZone(ctx, val) (stored, *time.Location, error)with the same rules (SYSTEM,[+-]HH:MMwithin ±14:00, UTC, IANA names).updateTimeZonecalls it, so session behavior is unchanged.SetGlobalSysVarcalls it fortime_zonebefore persisting, so an invalid zone returns the same error asSET SESSIONand the stored global value stays as it was.Not done here: the issue's "defense in depth" (session init falling back when a bad value is already persisted). Clusters that already stored a bad value still need it fixed manually.
Tests
global_time_zone_validate_test.go:Mars/Phobosand+25:00are rejected and the global staysSYSTEM;+08:00andUTCare stored. RED on main, GREEN here.go test ./pkg/frontend/passes.system_variable/set_global_time_zone_invalid.sql: on main the three badSET GLOBALs succeed and the rest of the run cannot connect (233 abnormal cases in the dir); on the PR, 624/624 pass insystem_variableand 488/488 inset.Merge Danger
Low.
SET GLOBAL time_zonewith a value thatSET SESSIONwould reject now fails instead of being stored. Valid values are stored with the same spelling as before.