Skip to content

test: contain shared CN state failures and attribute race UT stalls - #29043

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/ut-memory-attribution
Sep 17, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/ut-memory-attribution

Conversation

@XuPeng-SH

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:

Addresses the shared-CN contamination and resource-attribution parts of #29039.
Related to #28419. Keep #29039 open for attribution of the initial control-plane stalls.

What this PR does / why we need it:

In race UT job 105063157387, a Draining RPC failed before TestGroupConcatNamedTimeZoneRemoteOwner registered restoration. A later DML test observed the same CN still Draining. TestConvRowBasesRemoteFallback had the same cleanup gap. This is fixture contamination inside one package test process, not shared Go state across packages.

  • Route both consumers through the existing withCNDraining state/cleanup contract. An ambiguous write fails the test and invalidates the fixture without a potentially reordered compensating write. An acknowledged transition is restored and authoritatively verified during unwinding.
  • Discard invalid fixtures only after the shared callback releases its mutex. Always unwind client/row and runtime/plan state; omit database DROP only when fixture destruction owns cleanup.
  • Retain all existing two-row SQL, remote-plan, mixed-version fallback and prepared-query assertions. Add deterministic cancellation/panic coverage alongside existing ambiguous-write, Goexit and failed-restore controls.
  • Extend the existing heartbeat with top-eight PID/PPID/RSS/executable records (no arguments), selected memory fields, event/throttling counters and cumulative pressure totals. Test formatting with fake process/cgroup data and preserve heartbeat cancellation.

Performance and limits

No production code, package selection, scheduler parallelism, overall timeouts or normal-path cluster count changes. A healthy state mutation still uses two writes and two authoritative refreshes. Resource sampling stays on the existing 60-second cadence: one process snapshot/sort and up to six small cgroup-file reads, with no retained samples.

The two migrated callers explicitly adopt the existing helper's 30-second phase budget instead of the legacy API's 3-second write timeout. Stalled phases may therefore wait longer; discarding an uncertain fixture can also require shutdown and a later startup. This is containment, not a promise of identical failure-path latency or a suite speedup. No state writes or failed tests are retried; existing bounded authoritative-read polling is reused.

The historical 16 GiB peak does not prove a memory leak or explain the initial failures. RSS can double-count shared pages, memory fields overlap, process and cgroup scopes differ, and cumulative counters require timestamp deltas. Actual Ubuntu/x86 overhead and stall attribution remain unmeasured.

Validation

macOS/arm64, Go 1.26.4, isolated repository-native build:

  • Four real remote consumers before change: PASS, 15.473s. After change plus deterministic helper controls: PASS, 15.591s. This is a smoke comparison, not a statistical benchmark.
  • Full DML package normal mode: PASS, 30.888s.
  • Full optools package: PASS, 22.228s; DML/optools vet and shell syntax checks passed.
  • Full DML package race mode: PASS, 72.489s. Incremental golangci-lint on DML/optools: PASS, 0 issues.
  • Adaptive exact-test race controls (30-second measured test-body budget, capped at 100 invocations): cancellation/panic fake 100 times, Conv 34 times, GroupConcat 34 times, and Prepared 57 times all passed in their respective single-process runs. No failed-run retries.

No additional BVT is needed: only test infrastructure changes; the existing two-CN frontend tests retain the SQL/public-path oracles. Remote CI is pending and will not be waited on as part of this delivery.

@XuPeng-SH
XuPeng-SH requested a review from fengttt as a code owner September 17, 2026 06:02
@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 →

@mergify mergify Bot added kind/bug Something isn't working kind/enhancement kind/documentation Improvements or additions to documentation labels Sep 17, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 17, 2026
@mergify mergify Bot added the kind/test-ci label Sep 17, 2026

@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.

Force review for exact head edcbbaf.

Scope reviewed: all 6 changed files, the shared-CN work-state lifecycle, heartbeat/cgroup diagnostics, and the design evidence.

  • Both DML callers now use the existing withCNDraining contract. Restoration is registered before the state-changing RPC, uses a fresh bounded context, requires authoritative topology verification, and invalidates the shared fixture when the transition or restoration result is ambiguous. The callback cleanup order preserves database/client cleanup before fixture discard, including Goexit/panic paths.
  • Readiness now reports both admission-ready and normally discoverable CNs and retains the original peer-address/query assertions. The migrated tests keep the same two-row SQL, remote-plan, protocol-fallback, and time-zone result coverage; no production or SQL behavior is changed.
  • Heartbeat diagnostics add bounded PID/PPID/RSS/comm data without command arguments, and cgroup fields are reported individually with overlap caveats. Missing cgroup files are tolerated; there is no new polling worker, retry, timeout, scheduler, or test-selection behavior.
  • The new tests cover cgroup field filtering, heartbeat cancellation/formatting, and canceled-body restoration for both normal and panic unwinding.

The PR is mergeable without conflict and only behind the base branch. Required CI is still pending at review time, so this is a code/lifecycle conclusion rather than a green-CI conclusion.

No evidence-backed P0/P1/P2 blocker found. This is a comment-only review because the PR is authored by the review requester.

XuPeng-SH added a commit that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Follow-up to #28967 and #28969, already closed by #28976. Related to
#28419.

## What this PR does / why we need it:

In [PR #29043's race UT
failure](https://github.com/matrixorigin/matrixone/actions/runs/35188168237/job/105094781393),
`TestISCPExecutor7` exhausted its 10-second watermark wait while the
mock consumer was still creating its destination database. The
Running-status commit took 2.60 seconds, followed by a target-database
commit taking 7.21 seconds. Engine/heavy-wave isolation from #28976 was
already active. The iteration log printed during teardown is a deferred
producer-exit log, not evidence that the worker only started then.

Prepare empty sink tables before registration in Executor7/8 and
UpdateJobSpec, sharing the existing InvalidTimestamp setup pattern.
Batch database/table creation into one executor-owned transaction, with
rollback on statement errors. Keep the original watermark targets,
deadlines, deletion/job-type transitions and fault barriers. Extend
Executor7/8 with bidirectional source/sink data checks; retain
cold-start, non-system-tenant and cancellation integration controls.

Fresh CN mock consumers now check the target in a tenant-scoped metadata
transaction. An existing target bypasses two redundant DDL statements on
every iteration. Confirmed absence retains the original idempotent cold
DDL; lookup/commit/cancellation errors propagate. The lookup transaction
finishes before DDL, with no cache or readiness state shared across
consumer instances, so a later dropped target is checked again.

### Performance and limits

Warm initialization replaces two SQL DDL paths with one metadata
transaction. Cold initialization adds that lookup; the four prepared
fixtures still perform real schema creation with one fewer write commit
each. Executor7/8 add six read-only comparison queries in total. The
observed UpdateJobSpec target DDL count falls from six to two. No shard
concurrency, test timeout, retry, WAL durability or IndexSync consumer
behavior changes.

The CI trace establishes the delayed fixture DDL, not the underlying
cause of slow TN commits. This removes that avoidable dependency from
functional progress waits; it does not guarantee that arbitrary
status/data commit stalls cannot exceed the original deadline. Local
timings are smoke comparisons, not a prediction of total Ubuntu CI
duration.

### Validation

macOS/arm64, Go 1.26.4, isolated native build:

- Full `pkg/iscp` normal/race: PASS (0.928s / 2.336s).
- Twelve deterministic readiness/ownership/error scenarios, including
fresh warm consumers, cold/missing targets, drop between iterations,
tenant context, partial acquisition, lookup/commit/DDL failures and
cancellation: PASS; 100 exact-test race repetitions PASS.
- Deterministic negative control: overlay only the baseline consumer
source while retaining the new warm-target test. It fails with `a warm
target must not execute DDL`; the candidate passes 100 race repetitions.
This reproduces the redundant-DDL contract violation, not the historical
CI slow-commit timeout (the unmodified local Executor7 baseline also
passed).
- Eight real engine race controls (Executor1/6/7/8, UpdateJobSpec,
InvalidTimestamp, CancelIteration1/2): PASS. After the batching
refinement, all four affected controls pass again, totaling 7.13s versus
7.30s before, including the added data assertions.
- Same-process adaptive race controls: Executor7 x22, Executor8 x17,
UpdateJobSpec x10 and InvalidTimestamp x22 all PASS. Counts were fixed
before running from the measured test-body budget; no failed-test
retries.
- Full engine package normal: PASS, 136.009s versus 136.987s baseline.
An intermediate pre-batching run was 147.346s; single-run timing
variation is not a CI performance guarantee.
- Scoped formatting, default go-test vet, golangci-lint and diff checks:
PASS, zero lint issues.
- Full engine package race: PASS, 172.938s.

No new BVT: the changed consumer is the CN test consumer; existing real
engine integration supplies the data, transaction, tenant and recovery
oracles. CI will remain pending at delivery.

@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.

Deep review(Astra medium,head f498b01)

结论:未发现本次变更引入的可证实 P0/P1/P2 阻断问题。由于这是作者自有 PR,本次提交 COMMENT,不提交 APPROVE。

已检查全部 6 个 changed files(350 行新增、126 行删除)及相关 helper、共享 fixture、HAKeeper client 和清理路径:

  • 共享 CN 污染 containment 闭环完整:失败后标记 fixture 失效,避免继续查询/乱序补偿写;callback 清理并解锁,外层再销毁。
  • 正常返回、Goexit、panic 路径均恢复 context/状态并校验权威拓扑;未发现新的 double cleanup、owner 丢失或并发 map 访问。
  • Run 解锁后再销毁 fixture,避免同一 mutex 自锁;现有并发子场景在返回前 join。
  • run_ut.sh 的采样、取消、缺文件和资源边界检查未发现新增问题;schedule/heartbeat 路径也保持一致。

需要保留的限制:30 秒只是状态阶段 context 预算,不是整个 shutdown 的硬上限;本 PR 没有证明或宣称修复 #29039 的初始 UT stall。Linux 采样开销、stall 根因和性能改善仍缺因果证据,历史内存峰值也不能单独证明泄漏。

指定 head 的 race UT、CI Required、coverage 和相关 BVT 已通过:
https://github.com/matrixorigin/matrixone/actions/runs/35218080397

@XuPeng-SH
XuPeng-SH merged commit bc90a61 into matrixorigin:main Sep 17, 2026
21 of 25 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/ut-memory-attribution branch September 17, 2026 13:23

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/bug Something isn't working kind/documentation Improvements or additions to documentation kind/enhancement kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants