Skip to content

tests: fix weekly random DDL single stability#5417

Draft
asddongmen wants to merge 3 commits into
pingcap:masterfrom
asddongmen:codex/fix-weekly-rand-single
Draft

tests: fix weekly random DDL single stability#5417
asddongmen wants to merge 3 commits into
pingcap:masterfrom
asddongmen:codex/fix-weekly-rand-single

Conversation

@asddongmen

@asddongmen asddongmen commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Issue Number: ref #5040

Weekly random DDL single runs need reproducible coverage and stricter failure detection so dispatcher progress regressions are actionable. The runtime replay fixes in downstreamadapter and pkg/eventservice have been split out to #5422.

What is changed and how it works?

This PR keeps the maintainer-side barrier/operator/span changes and adds weekly random DDL runner coverage, MySQL suite entries for single, multi, failover, and slow lossy DDL cases, plus random DDL generator/log scanner tests.

Check List

Tests

  • Unit test
  • Integration test

Questions

Will it cause performance regression or break compatibility?

No. The remaining changes are maintainer-side bookkeeping and test coverage.

Do you need to update user documentation, design documentation or monitoring documentation?

No user documentation update is needed.

Release note

None

@ti-chi-bot

ti-chi-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jun 16, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hicqu for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 311d5be2-9163-4bbb-877c-c425f213435a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ti-chi-bot ti-chi-bot Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 16, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a robust random DDL/DML test runner alongside integration tests to address TiCDC replication stalls and timeouts, while updating core components (such as BasicDispatcher, BarrierEvent, SpanController, and EventScanner) to handle obsolete events, dispatcher recreations, and deleted tables correctly. The review feedback highlights several critical areas for improvement in the test runner and controller, including a potential memory leak in removedTableCheckpointTs, file descriptor leaks in the log scanner, inefficient autotune scaling, a data race on tbl.name, and a failure to restore the global tidb_enable_external_ts_read variable on downstream TiDB during syncpoint diff failures.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +73 to +76
// removedTableCheckpointTs records the highest checkpoint reported by removed dispatchers for each table.
// It prevents a stale add-table barrier from recreating a dispatcher below events already flushed by
// the previous dispatcher of the same physical table.
removedTableCheckpointTs map[int64]uint64

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The removedTableCheckpointTs map keeps track of the highest checkpoint reported by removed dispatchers for each table. However, since table IDs are unique and monotonically increasing, entries are never removed from this map. In a long-running changefeed with frequent table creations and drops (e.g., partition tables), this will lead to an unbounded memory leak.

Recommendation:
Since any newly created dispatcher will have a startTs greater than or equal to the global checkpoint, any entry in removedTableCheckpointTs where the recorded checkpoint is less than or equal to the current global checkpoint can be safely garbage collected. Consider implementing a periodic cleanup mechanism to purge obsolete entries from this map.

Comment on lines +55 to +59

for _, path := range files {
f, err := os.Open(path)
if err != nil {
return err

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Opening files inside a loop without a guaranteed cleanup mechanism (like defer) is risky. If an error occurs or the loop body is modified to include early returns, the file descriptor may leak.

To safely use defer inside a loop without accumulating open file descriptors, wrap the loop body's file processing in an immediately-invoked function literal.

Comment on lines +33 to +45
if sinceAdvance >= soft || successRate < 0.10 {
if nextDDL > 1 {
nextDDL--
return autoTuneResult{nextDML: nextDML, nextDDL: nextDDL}
}
if nextDML > 1 {
nextDML -= 8
if nextDML < 1 {
nextDML = 1
}
}
return autoTuneResult{nextDML: nextDML, nextDDL: nextDDL}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

When a stall is detected (sinceAdvance >= soft or successRate < 0.10), the autotune logic decrements nextDDL by 1 per step and returns immediately. It does not start reducing nextDML until nextDDL has been reduced to 1.

If nextDDL is high (e.g., 8), it will take 7 steps (70 seconds with a 10-second health interval) to reduce nextDDL to 1 before nextDML is even touched. During this time, the high DML concurrency (e.g., 128) will continue to overwhelm the system, wasting valuable time and potentially triggering the hard timeout (5 minutes) and failing the test.

Recommendation:
Consider reducing both DDL and DML concurrency simultaneously when a stall is detected, or scaling down more aggressively if the stall duration increases.

Comment on lines +97 to +101
rowID := startID + int64(i)
for _, c := range cols {
args = append(args, buildRandomValue(rand.New(rand.NewSource(rowID)), tbl, c, rowID))
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

In runBigInsertTxn, buildRandomValue is called without holding tbl.mu. Inside buildRandomValue, tbl.name is read concurrently:

	case "JSON":
		return fmt.Sprintf("{\"id\":%d,\"tbl\":\"%s\"}", rowID, tbl.name)

At the same time, a DDL worker executing rename_table can modify tbl.name under tbl.mu.Lock(). Even though rename_table currently only targets domainChurn tables and runBigInsertTxn targets domainSplit tables, relying on domain disjointness to prevent data races is extremely fragile and prone to future regression.

Recommendation:
Retrieve and copy tbl.name (and tbl.fqName()) into local variables while holding tbl.mu at the beginning of runBigInsertTxn, and pass the copied name to buildRandomValue or lock tbl.mu inside buildRandomValue when accessing mutable fields.

Comment on lines +386 to +408
original, err := queryGlobalExternalTSRead(ctx, downstream)
if err != nil {
return "", err
}
if err := setGlobalExternalTSRead(ctx, downstream, "OFF"); err != nil {
return "", err
}

diag, runErr := runSyncDiffInspector(ctx, confPath, logPath, retries)
if original == "OFF" {
return diag, runErr
}

restoreCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
restoreErr := setGlobalExternalTSRead(restoreCtx, downstream, original)
cancel()
if restoreErr != nil {
r.logger.Printf("syncpoint diff: failed to restore %s=%s: err=%v", tidbEnableExternalTSReadVar, original, restoreErr)
if runErr == nil {
return diag, restoreErr
}
}
return diag, runErr

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

If runSyncDiffInspector panics or if there is an early return, the global variable tidb_enable_external_ts_read will not be restored to its original value on the downstream TiDB. This can leave the downstream cluster in an inconsistent state and affect subsequent tests.

Recommendation:
Use defer to guarantee that the global variable is always restored when the function exits.

	original, err := queryGlobalExternalTSRead(ctx, downstream)
	if err != nil {
		return "", err
	}
	if err := setGlobalExternalTSRead(ctx, downstream, "OFF"); err != nil {
		return "", err
	}
	defer func() {
		if original != "OFF" {
			restoreCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
			defer cancel()
			if err := setGlobalExternalTSRead(restoreCtx, downstream, original); err != nil {
				r.logger.Printf("syncpoint diff: failed to restore %s=%s: err=%v", tidbEnableExternalTSReadVar, original, err)
			}
		}
	}()

	return runSyncDiffInspector(ctx, confPath, logPath, retries)

Signed-off-by: dongmen <414110582@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/needs-triage-completed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant