Skip to content

[Bug]: Concurrent DUMP TABLE to the same Stage path can report success for the wrong source table #29759

Closed

Description

@Ariznawlll

现象

同一个全新 Stage 子路径上,两台 CN 同时执行不同源表的 DUMP TABLE。其中一个 DUMP 返回成功,但随后 LOAD TABLE 从该路径恢复出的却是另一个源表的数据。另一次独立运行中,两个 DUMP 都返回成功,但同一份归档只能对应其中一张表。

这会让调用方在收到成功结果后误以为备份了指定源表,实际归档内容却不属于该表。

复现

在最新 main aee2a0b3764781a8ca908618548dfef75e336263 的双 CN embedded cluster 中:

  1. 创建两个相同 schema 的表 left_src(id INT PRIMARY KEY, marker INT) 与 right_src(...),各插入 2000 行,marker 分别固定为 1 和 2,并 flush。
  2. 创建指向本地私有目录的 Stage。先分别在不同路径顺序 DUMP/LOAD,确认左表恢复为 2000 行 marker=1,右表恢复为 2000 行 marker=2。
  3. 用两台 CN 同时向同一个此前不存在的路径执行:
    • CN0: DUMP TABLE left_src TO 'stage://s/race_00'
    • CN1: DUMP TABLE right_src TO 'stage://s/race_00'
  4. 对返回成功的一侧,创建同 schema 空表,再 LOAD TABLE ... FROM 'stage://s/race_00' 并查询 COUNT(*), MIN(marker), MAX(marker)。

3 次独立复现均发生成功侧归档归属错误:例如 CN1 DUMP 成功,CN0 报 READY already exists,但 CN1 随后 LOAD 得到 2000 行 marker=1;另一次两个 DUMP 均成功,CN0 LOAD 得到 marker=2。每次使用全新的临时 Stage 根目录,排除旧文件污染。

预期

并发写同一路径可以拒绝其中一方,但任何返回成功的 DUMP 必须保证该路径发布的 manifest/READY 与自己指定的源表一致;不能返回成功却恢复出另一张表。

初步定位

pkg/frontend/table_dump.go 的 handleDumpTable 依次复制对象、写共享 manifest.json、再写共享 READY,没有对整个路径取得排他发布权。两台 CN 可以交错写入;仅凭各自最后的文件写入结果无法确认最终 manifest 的所有权。

这是 MO 特有的 DUMP/LOAD 正确性问题,不是 MySQL 兼容性差异。测试证据保留在本地探索脚本 evidence/stage_dump/same_path_test.go;尚未加入正式回归套件。

Activity

  1. added
    kind/bug
    on Oct 9, 2026
  2. Ariznawlll commented on Oct 9, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充定位:新一轮独立复现中,left_src 的 DUMP 返回成功,right_src 报 READY already exists;但归档的 manifest.json 中 source_table=right_src,LOAD 后的 2000 行也都是右表标记 2。顺序对照中,对已发布路径二次 DUMP 会在 manifest.json already exists 处拒绝。因此失败点是并发发布时 manifest 与 READY 的所有权被拆开,不是 LOAD 误解码。

  3. Ariznawlll commented on Oct 9, 2026

    @Ariznawlll
    CollaboratorAuthor

    将并发复现扩展为 10 个互不复用的 Stage 子路径后,10/10 路径都至少有一条成功返回的 DUMP 与最终 manifest.source_table/LOAD 数据不一致;其中 4/10 路径的两条 DUMP 均返回成功。各路径创建前不存在,顺序对照仍正常。

  4. added this to the MO-202610 milestone on Oct 9, 2026
  5. added theissue type on Oct 9, 2026
  6. slyunnn commented on Oct 22, 2026

    @slyunnn

    Regression and extended verification for #29759 (2026-10-22)

    Verification Environment

    • Latest fetched origin/main: 6495ce997486c2445994081c1d85c39802f7049b — fix: preserve view authorization across index joins and replacement (#30799).
    • Rebuilt and restarted the actual runtime from this commit (TYPECHECK=1, Linux/arm64). Binary version and git_version() on all endpoints confirmed 6495ce9974.
    • Full local topology: 2 CN / 1 TN / 1 Log service / Proxy, co-located in one service process/container with shared local archive storage; not a physical multi-host deployment.
    • Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001, CN2 127.0.0.1:16002: all connected and actually executed DUMP TABLE / LOAD TABLE. Public SQL used PyMySQL COM_QUERY with independent connections; the existing integration test uses Go database/sql and the MySQL driver.

    What Was Covered

    • OK — Original flushed source tables, each with 2,000 rows and distinct markers: sequential controls and 10 fresh-path CN1/CN2 races. Every race had exactly 1 successful publisher; manifest source, READY, and every restored (id, marker) matched that publisher.
    • OK — Additional Proxy/CN and Proxy/Proxy races, same-source competition, different-path concurrent success, published-path replacement rejection, and empty archives. Across public SQL scenarios, 183 successful restores were checked row-for-row through all 3 endpoints.
    • OK — Deterministic pre-manifest barriers for CN1/CN2, Proxy/CN1 and Proxy/CN2: observed both publishers blocked before release. Together with the original/extended races, 25 same-path competitions passed. Rejected writers returned 20406 (already exists) without changing the winning archive.
    • OK — Cancellation after manifest publication through each endpoint returned 1317; all 9 incomplete-archive LOAD TABLE attempts were rejected with READY marker is missing, leaving empty targets. Competing publication was rejected; same-connection retry to a fresh path and subsequent restores passed.
    • OK — Existing TestTableDumpConcurrentPublication passed normally and under -race: 1 measurement run plus 3 consecutive repetitions in one process, with no race report. Existing storage/provider/allocator regressions also passed (8 top-level component tests).
    • OK — Test databases and stages were removed, connections remained healthy, and injected fault points were removed with the original disabled state restored. Source checkout remained clean.
    • Not covered — Real S3/MinIO services, physical multi-host deployment, live TN process restart, mixed-version/external writers, or performance benchmarks. HTTP provider controls and allocator binding-loss component tests are not substitutes for those environments.

    Findings

    The original wrong-source success and double-success behavior did not reproduce. PR #29808, fix(frontend): publish DUMP archives with create-only storage writes, merged as 04fe057bd73520cdf30754f79f66f6505060ad1f and is included in the tested main. It makes manifest/READY publication storage-level create-only, preventing a losing publisher from replacing the winner's metadata. Cancellation leaves an incomplete archive that fails closed.

    MOTR / BVT Coverage

    Reused the existing deterministic SQL integration regression, including filesystem aliases, cancellation and retry, plus the existing storage and allocator tests. The permanent regression needs only 2 rows per source table.

    No new MOTR coverage gap was identified, so no duplicate case, recording/replay, commit, push or weekly PR update was necessary. Actual concurrent server requests and publication barriers were verified; this is not a MOTR -j scheduling claim.

    Final Conclusion

    Fixed for the original concurrent same-path local Stage publication issue on the tested main.

    Additional large-data regression is not required: this is publication ownership under concurrency, not a row-count, block/batch, memory or spill boundary. The original 2,000-row reproduction and deterministic minimal-data concurrency tests cover the relevant boundary; increasing data volume would not strengthen that assertion.

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