Skip to content

refactor(schedule): expose bounded statement scheduling trace - #25581

Merged
XuPeng-SH merged 12 commits into
matrixorigin:mainfrom
XuPeng-SH:refactor_schedule_phase7_0710
Jul 11, 2026
Merged

XuPeng-SH merged 12 commits into
matrixorigin:mainfrom
XuPeng-SH:refactor_schedule_phase7_0710

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #25451

What this PR does / why we need it:

Separates AP multi-CN scheduling into explicit candidate discovery, tenant/label pool resolution, and pure worker placement. The new engine capability preserves the legacy Engine.Nodes path for engines that have not adopted both provider interfaces.

Adds a bounded, ownership-safe per-statement scheduling trace:

  • records query, scan, stage, retry, and failure decisions;
  • exports exceptional/distributed traces without amplifying normal local statement records;
  • shows a best-effort, independently timed preview in EXPLAIN.

The change keeps discovery cancellation-aware, carries one cluster snapshot through current-CN state and pool resolution, validates selected worker routes, and bounds trace/EXPLAIN memory and output.

Verification

  • go test -count=1 ./pkg/sql/schedule ./pkg/clusterservice ./pkg/vm/engine/disttae/route
  • With the repository CGo test environment and -mod=mod: pkg/sql/compile, pkg/frontend, pkg/vm/engine/disttae, pkg/vm/engine/memoryengine, and pkg/util/trace/impl/motrace
  • Targeted -race coverage for schedule/compile/frontend/clusterservice/route.
  • go vet -mod=mod -tags matrixone_test across affected packages.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Comment thread pkg/frontend/computation_wrapper.go Resolved

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前 head aeb2b92d41 仍有 merge blocker,提交 REQUEST_CHANGES。

  1. 已有的默认 EXPLAIN 兼容性问题尚未修复:普通 EXPLAIN、EXPLAIN ANALYZE、EXPLAIN PHYPLAN 仍无条件追加包含动态 CN 信息的 scheduling 块,且没有对应 test/distributed golden 变更。当前 CI 的 Compose optimistic/pessimistic、Standalone optimistic/pessimistic/proxy 共 5 条 BVT 均失败。请优先改为显式 option/session 开关;若产品决定修改默认输出,则必须完成动态值归一化、兼容性决策和全部 BVT 更新。

  2. 新增 inline blocker:短 TP/AP-one-CN 明知最终不会持久化,仍无条件 record + Snapshot + Clone scheduling trace。当前实现的等价 microbenchmark 是 1232 B/op, 8 allocs/op,会给所有本地短语句增加 GC 压力。请增加 normal-local 的低/零分配 fast path 和 allocation 回归覆盖。

已确认上一轮的两个问题在本 head 上有实质修复:持久化 trace 不再包含 pipeline address,pool/candidate 迭代也增加了 cancellation check。

本地验证:

  • git diff --check 通过
  • go test -race -count=1 ./pkg/sql/schedule ./pkg/clusterservice ./pkg/vm/engine/disttae/route 通过
  • 按仓库 CGo 配置,pkg/sql/compile、pkg/frontend、pkg/vm/engine/disttae、pkg/vm/engine/memoryengine、pkg/util/trace/impl/motrace 全包测试通过
  • 相关 go vet 通过

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

已更新到 54ad85579。

  1. 默认 EXPLAIN 输出兼容性

新增 session 变量 enable_explain_scheduling,默认值为 0。普通 EXPLAIN、EXPLAIN ANALYZE 和 EXPLAIN PHYPLAN 默认不再执行/输出 scheduling;显式执行 SET enable_explain_scheduling = 1 后才输出。相关默认关闭、开启和三条输出路径的单测已补齐。

  1. prepared statement attempt

重新沿完整调用链核对后,正常复用路径是:

TxnComputationWrapper.Compile -> retComp.Reset -> retComp.Run

该路径不会再次调用 Compile.Compile;只有首次构建或运行时 retry 创建的新 Compile 才进入 Compile.Compile。每次 EXECUTE 也会新建 TxnComputationWrapper 及其 TraceRecorder。因此 Reset 中记录 cached placement 是本次执行唯一的正常 attempt;删除它会让正常 prepared reuse 完全没有 scheduling trace。

已新增连续 10 次 prepared reuse 的回归测试:每次 fresh recorder 都只有 1 个 reused-placement attempt;模拟 retry 后才出现第 2 个 retry-placement attempt,并在代码中补充该生命周期契约说明。

验证通过:

  • 完整 ./pkg/sql/compile、./pkg/frontend 单测
  • 新增测试定向 -race
  • go vet
  • go build

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

@LeftHandCold 逐项回复最新 review:

  1. 默认 EXPLAIN 兼容性:已在后续 commit 54ad85579 修复。新增 session-only bool enable_explain_scheduling,默认 0;普通 EXPLAIN、EXPLAIN ANALYZE、EXPLAIN PHYPLAN 三条路径默认均不执行/输出 scheduling,显式 SET 为 1 后才启用。完整 frontend/compile UT、定向 race、vet、build 已通过,等待 Standalone/Compose BVT 在新 head 上重跑确认。

  2. 短 TP/AP-one-CN trace 分配:确认成立,54ad85579 尚未处理。当前 RecordExecPlan 确实仍会先 Snapshot,再由 WithSchedulingTrace Clone,最后短本地语句返回 sqlQueryIgnoreExecPlan。我已在 inline thread 单独回复,并会在当前 PR 中补 normal-local fast path 与 allocation 回归测试。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed latest head 77baac8bca across scheduling semantics, candidate discovery/pool resolution compatibility, current-CN routing, prepared/retry lifecycle, bounded trace ownership and persistence, EXPLAIN opt-in behavior, cancellation, concurrency, resource bounds, and hot-path allocation.

No blocking correctness, robustness, leak/hang/OOM, compatibility, or performance issue found. The feature patch after merging current main is content-equivalent to the previously reviewed patch; only a hunk line offset changed in pkg/sql/compile/compile.go.

Local verification passed:

  • go test -race -count=1 ./pkg/sql/schedule ./pkg/clusterservice ./pkg/vm/engine/disttae/route
  • go test -count=1 ./pkg/sql/compile ./pkg/frontend
  • go vet on all affected production packages
  • git diff --check
  • BenchmarkTraceRecorderNormalLocalExport: 0 B/op, 0 allocs/op (46-56 ns/op locally)

The new GitHub Actions run for the merge commit is still in progress. This is a COMMENT review because the authenticated account is also the PR author and GitHub does not permit self-approval.

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed latest head 77baac8bca.

No blocking issue found.

  • Default EXPLAIN remains stable; scheduling preview is explicit opt-in.
  • Candidate discovery/pool resolution share a snapshot and propagate cancellation through routing loops.
  • Persisted trace avoids pipeline-address exposure; normal local export remains allocation-free.
  • Prepared-statement reuse and retry attempt lifecycles have regression coverage.

Verified locally: go test -count=1 ./pkg/sql/schedule ./pkg/clusterservice ./pkg/vm/engine/disttae/route. Latest CI, including Standalone/Compose BVT and upgrade compatibility, is green. Local pkg/sql/compile and pkg/frontend builds are blocked only by missing usearch.h, roaring.h, and xxhash.h; their PR CI checks passed.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement kind/refactor Code refactor size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants