Skip to content

[Bug]: Data Branch snapshot metadata changes backslashes in quoted object names #26073

Closed

Description

@Ariznawlll

Description

DATA BRANCH CREATE TABLE stores a branch-protection snapshot whose database_name and table_name no longer match the source object when a legal quoted identifier contains a backslash.

The source catalog preserves the backslash byte (5C), while the snapshot insert treats it as part of a SQL string escape. For example, g4d\db becomes g4ddb, and src\t becomes src<TAB> (09) in mo_snapshots.

Version

  • Branch: main
  • Commit: 2eb7f523e5a10f352d3e258183ed8440510388de

Reproduction

drop database if exists `g4d\db`;
create database `g4d\db`;
use `g4d\db`;

create table `src\t`(id int primary key);
insert into `src\t` values (1);
data branch create table `dst\t` from `src\t`;

select reldatabase, hex(reldatabase), relname, hex(relname), rel_id
from mo_catalog.mo_tables
where reldatabase like 'g4d%';

select sname, database_name, hex(database_name),
       table_name, hex(table_name), obj_id, kind
from mo_catalog.mo_snapshots
where kind = 'branch' and database_name like 'g4d%';

This was reproduced 3 out of 3 runs.

Actual result

The object catalog contains:

database: g4d\db   hex=6734645C6462
table:    src\t    hex=7372635C74

The matching branch snapshot contains:

database_name: g4ddb    hex=6734646462
table_name:    src<TAB> hex=73726309

Expected result

The branch snapshot should preserve the exact source database and table names stored in the catalog.

Code path

createBranchProtectSnapshot interpolates receipt.srcDb and receipt.srcTbl directly into single-quoted SQL literals. Backslashes are therefore interpreted again when the generated INSERT is parsed.

The values should be encoded with the same SQL-literal helper used by other Data Branch generated statements.

Activity

  1. added this to the MO-202607 milestone on Jul 23, 2026
  2. added
    kind/bug
    on Jul 23, 2026
  3. added theissue type on Jul 23, 2026
  4. added
    severity/s0
    and removed on Jul 27, 2026
  5. added a commit that references this issue on Jul 28, 2026
    ca4a91c
  6. added and removed
    severity/s0
    on Jul 29, 2026
  7. Ariznawlll commented on Jul 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新 main 分支完成黑盒验证。

    测试版本:52ea9f874f492c368a20efef16b46ab8ced2de37
    测试拓扑:Proxy + 2 CN
    重复次数:3 轮

    测试过程:

    1. 创建数据库名和表名均包含反斜杠的源对象。
    2. 写入数据并创建 Data Branch。
    3. 查询 branch snapshot/protection 元数据。
    4. 同时读取名称文本和 HEX(name),与原始输入逐字节比较。
    5. 检查同一个对象是否生成重复 snapshot 元数据记录。

    测试结果:

    • Data Branch 创建和数据读取均成功。
    • 数据库名、表名中的反斜杠在 snapshot 元数据中保持原始 5C 字节,没有转换成控制字符。
    • 对象 ID 与源对象一致。
    • 每轮仅生成预期的一条对象元数据,没有缺失或重复。
    • 连续 3 轮结果一致。

    结论:该问题在上述最新 main commit 上验证通过。

  8. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在 main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c 完成扩展黑盒验证。

    黑盒验证:

    • MOTR 用例:issue_26073_data_branch_backslash_metadata.test
    • 使用普通数据库/表名作为控制组。
    • 创建数据库名和表名均包含反斜杠的合法 quoted identifier。
    • 对比 mo_tables 与 branch protection snapshot 中数据库名、表名的 HEX 值,确认 5C 字节未被二次解释为转义字符。
    • 通过 DIFF 消费生成的 branch ancestry/protection metadata。
    • 删除目标表后检查 active branch metadata 和 protection snapshot 均清零,同时源表仍可读取。

    结果:该 case 20/20 条 SQL/断言通过;本轮 Data Branch 全集 13/13 case、280/280 条 SQL/断言通过。

    白盒边界说明:

    Unhappy path / 数据一致性边界:

    • 使用 \t 等可能被 SQL parser 二次解释的反斜杠组合,直接比较 catalog 和 snapshot 的十六进制字节。
    • 不只检查 branch 创建成功,还通过 DIFF 使用生成的错误敏感 metadata。
    • 删除目标后检查 active metadata 和 protection snapshot 均为 0,避免转义错误造成无法匹配和孤儿保护记录。
    • 清理后源对象仍可读,证明目标清理没有误删源数据。

    结论:反斜杠 identifier 的 metadata 字节保持和清理路径在上述提交验证通过,回归已加入 motr#69。

  9. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    Unhappy Path / 数据一致性专项验证

    测试版本:main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c

    该问题的异常路径不是 SQL 返回错误,而是“语句成功但 metadata 字节被静默改变”,因此专项检查如下:

    1. 数据库名和表名使用包含反斜杠的合法 quoted identifier。
    2. 选取 \t 等可能被 SQL parser 二次解释的组合。
    3. 对比 mo_tables 与 branch protection snapshot 中名称的 HEX 字节。
    4. 执行 DIFF,确认生成的 ancestry/protection metadata 实际可被后续操作使用。
    5. 删除目标后检查 active metadata 和 protection snapshot 均为 0。
    6. 清理后回读源对象,确认没有误删源数据。

    结果:反斜杠字节保持为 5C,未变成 TAB 或被吞掉;无孤儿 metadata/snapshot,源数据保持可读。专项用例 20/20 条 SQL/断言通过。

  10. added 3 commits that reference this issue on Sep 17, 2026
    7c68236
    954a60b
    9641466
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