Skip to content

[Compatibility]: GET_LOCK timeout coercion differs from MySQL for NULL and fractional values #28250

Closed

Description

@Ariznawlll

问题描述

MatrixOne 的 GET_LOCK(name, timeout) 直接按浮点秒解释 timeout;MySQL 8.3 先把参数转换为整数秒。NULL timeout 在 MySQL 中等价于 0,而 MatrixOne 直接返回 NULL。小数 timeout 在 MySQL 中截断小数部分,MatrixOne 则等待完整小数秒。

这会让相同 SQL 的是否等待、等待时长和返回类型不同,可能改变应用的互斥与重试行为。

环境

  • MatrixOne latest main, commit e7bb0572235ec4bac81eb098eb0ad8900f0065ab
  • MySQL 8.3.0(对照)

NULL timeout

锁空闲时:

select get_lock('timeout_null_free', null);
  • MatrixOne 返回 NULL。
  • MySQL 返回 1 并获得锁。

另一个连接持有锁时:

-- connection A
select get_lock('timeout_null_busy',0);

-- connection B
select get_lock('timeout_null_busy',null);
  • MatrixOne 立即返回 NULL。
  • MySQL 立即返回 0,表现为 timeout=0。

小数 timeout

连接 A 持有锁,连接 B 执行:

select get_lock('timeout_fractional',1.2);
  • MatrixOne 在约 1.201 秒后返回 0。
  • MySQL 在约 1.006 秒后返回 0,即将 1.2 转换为整数 1。

同样地,timeout=0.2 在 MatrixOne 等待约 0.201 秒,MySQL 立即返回 0。

期望行为

为保持 MySQL 兼容,timeout 应采用 MySQL 的整数转换规则:NULL 转为 0,小数截断为整数秒。锁空闲时 timeout=0 仍可立即获得锁;锁占用时立即返回 0。

命名锁的其余生命周期已对照确认一致:同连接重入计数、其他连接不能释放、COMMIT 不释放、断连释放、IS_USED_LOCK 返回 connection ID。

Activity

  1. added this to the MO-202609 milestone on Sep 5, 2026
  2. added
    kind/bug
    on Sep 5, 2026
  3. added theissue type on Sep 5, 2026
  4. self-assigned this
    on Sep 5, 2026
  5. XuPeng-SH commented on Sep 12, 2026

    @XuPeng-SH
    Contributor

    Implemented with #28249 in PR #28783: #28783

    The timeout conversion is input-domain-sensitive: DOUBLE uses ties-to-even, while DECIMAL64/128/256 uses exact HALF_UP conversion (for example, DECIMAL 0.5 waits one second while explicit DOUBLE 0.5 is zero seconds). NULL timeout means zero; explicit CAST remains authoritative. Integer/string inputs retain MatrixOne's prior DOUBLE coercion, so this does not change global cast rules. Prepared bare markers are covered through the generic runtime specialization path.

    Incremental SCA passed (0 issues). Local UT/BVT runtime verification remains pending because the isolated worktree lacks provenance-stamped cgo/libmo.dylib and unrelated MatrixOne services are active. The PR body records the preflight cost and the fact that this does not make lock-service failures transactional; please keep this issue open until exact-head CI verifies the behavior.

  6. added a commit that references this issue on Sep 12, 2026
    078d077
  7. Ariznawlll commented on Sep 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:07b25969bfea9d4b76d3bf05d5b0497e4f36eba0
    • 部署:本地独立 1 CN / 1 TN / 1 LogService;每轮均重新启动服务后执行。
    • 执行:每项 SQL 回归连续 3 轮,输出逐轮一致。

    原问题验证

    • GET_LOCK timeout 对 NULL 与小数值的 coercion 与 MySQL 行为一致。

    Happy Path 覆盖

    • 覆盖空闲锁的 GET_LOCK(name,NULL) 与 RELEASE_LOCK,均返回 1。

    Unhappy Path 覆盖

    • 双连接覆盖已持有锁时 NULL 和 0.2 timeout,均返回 0;连续 3 轮一致。

    白盒验证

    • MOTR 覆盖空闲 NULL 路径;独立双连接回归覆盖 holder/contender 竞争。

    回归测试

    测试证据

    • 以上结果均在该 main commit 的独立环境获得;每轮无 stderr,三轮结果一致。

    测试结论

    测试通过。

  8. added 6 commits that reference this issue on Sep 17, 2026
    2bd8198
    8a2694d
    ce7e452
    f736ab3
    349a5a6
    af9d639
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions