Skip to content

fix(datasync): honor cleanup cancellation and remove timing-based tests - #29673

Merged
XuPeng-SH merged 6 commits into
mainfrom
codex/quality-29249-datasync-20261007
Oct 9, 2026
Merged

XuPeng-SH merged 6 commits into
mainfrom
codex/quality-29249-datasync-20261007

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement
  • Test and CI

Which issue(s) this PR fixes:

Refs #29249

What this PR does / why we need it:

Failed consumer initialization enters cleanup. Previously cleanup ignored cancellation and could keep the admitted worker alive, preventing Stopper.Stop from completing. Its RPC wrappers captured the caller context but used the background-context retry helper. This defect was reproduced through Worker.Start and Stopper.Stop on the clean original base.

Cleanup now stops admitting retries after cancellation and uses a cancellable timer for its retry delay. All five datasync log-client retry wrappers use the existing fileservice.DoWithRetryContext owner. Successful retries, retry limits and partial LSN update ordering are preserved. No new state machine, storage or production test hook is introduced. The timer is allocated only after a cleanup error; successful cleanup has no new timer cost.

The original test improvements remain: role transitions capture the returned leader, prove initial consumption and initialization re-entry after demotion; async fixtures cancel and join before closing resources; queue draining retains its twenty-item and empty-queue checks. NewDataSync retires acquired children through its existing aggregate owner when startup is rejected. The transaction RPC regression observes the production retry wait before canceling and checks the exact error and one send. The resolved role-change review comment remains covered.

New regressions exercise actual consumer/Stopper termination at failed initialization and both cleanup RPC phases, cancellation during both cleanup retry waits, and all five real retry wrappers. They verify zero canceled-entry calls, exact attempts, preserved required/synced LSNs, successful retry and write retry limits.

Validation

Final head da90af8ff8c6451a4e2a551803807ff97800c7f0, rebased without conflicts onto main 23d8f61252f3017dff218b530817a240206fd762 (including #29676); all five original PR commits preserved.

Current-code local validation: Darwin arm64, Go 1.27.1, repository-supported CGo invocation with verified matching native artifacts, short/matrixone_test mode:

  • Complete datasync and txn/rpc packages passed normal and race, count=1: 189 test nodes in each mode. Normal: 9.188s / 3.496s; race: 9.735s / 4.892s.
  • Existing fileservice context-backoff cancellation regression passed normal and race with nonempty selection.
  • Three changed cancellation families each passed 100 race repetitions, using adaptive counts capped at 100 and a 30-second measured budget per family.
  • Independent Producer.Start probe verified one append, one item release, completed wait group and unchanged write LSN after cancellation.
  • External mutations restoring background retries, removing the cleanup entry guard, and restoring Sleep were rejected. These mutations are outside the PR; all tests retired without race reports or process alarms.
  • Formatting, diff checks, vet, pinned molint and configured incremental golangci-lint 2.14.0 passed for the complete two-package closure, with 0 lint issues.
  • Actual gpt-6.1-sol / xhigh design and final overall review passed for the complete ten-file delivery.

Earlier Linux CI evidence belongs to the previous head. CI for this head is pending.

Scope limitations: this fixes cancellation after it reaches cleanup and its shared RPC retries. The separate transaction-client TN discovery wait and existing client preparation delays are unchanged.

The overall review also identified an inherited service-ownership gap: standby datasync tasks use the global Stopper, whereas log-service Close stops its local Stopper before closing datasync dependencies. Consequently this PR does not establish drain-before-close for arbitrary Service.Close or constructor rollback with already admitted global tasks. This unchanged caller-ordering issue is retained as a separate service-ownership follow-up; the tests here prove actual cancellation followed by worker and Stopper completion. This PR does not claim all shutdown paths are fixed.

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

@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 of 223e6bf6dea1653164637f9e6850ec467bedd8d4 against f20f5ca147c44b012343d0f48dfcd84b6a5986a1.

Conclusion: changes needed for the refactored role-transition test; no newly introduced production defect identified. Submitted as COMMENT because the authenticated reviewer is the PR author.

The one-line constructor rollback belongs in the existing syncer owner and is appropriate: rejected task admission happens before the syncer's workers start, and Close retires the acquired children without stopping the borrowed stopper. No new state machine, persistence, SQL/data compatibility change, or hot-path work is introduced.

All seven changed files were inspected, including the unchanged consumer Start/loop/checkRole, queue, producer and truncation callers. This is a focused fix/test-maintenance change, not a major-refactor design gate. The important remaining issue is test-oracle quality, not line count: see the inline P2 finding.

Verification (Go 1.27.0, darwin/arm64, isolated worktree; repository CGo wrapper, GOMAXPROCS=4, -p=1):

  • Exact-head controls: TestTruncation_Start, TestConsumerStart, TestWaitPermission, TestSyncer_Create_StopperUnavailableCleansUp passed (package 2.279s).
  • Additional exact-head targeted race check for TestSyncer_Create_StopperUnavailableCleansUp, TestWaitPermission and TestConsumerStart passed (2.495s).
  • Independent mutation: preserve the real checkRole call/event, but change the loop's demotion condition to if !c.checkRole(ctx) && false. TestConsumerStart/role_changed still passes (0.996s). This disables the required exit while retaining the event being counted.
  • Separate coverage-boundary probe: removing Start's call to truncate also leaves TestTruncation_Start green (1.392s). The PR intentionally uses direct truncate for the success effect; credit that as an effect test, not proof of timer-to-worker dispatch. This is not an additional claimed production regression.
  • Fresh CI was green; no pre-existing human reviews or inline discussion threads required resolution. No source changes were pushed; mutations were isolated/restored.

Unhappy-path audit: construction cleanup ownership is closed; cancellation/join controls pass; queue capacity remains bounded. The role-transition behavioral proof remains open. The old sleep-based test was also weak: the finding is about the new test not delivering its stated deterministic transition contract, not a claim that this PR newly broke leader handling.

Comment thread pkg/datasync/consumer_test.go Resolved
@XuPeng-SH
XuPeng-SH force-pushed the codex/quality-29249-datasync-20261007 branch from 6fe2319 to da90af8 Compare October 9, 2026 01:44
@XuPeng-SH XuPeng-SH changed the title test(datasync): remove wall-clock waits fix(datasync): honor cleanup cancellation and remove timing-based tests Oct 9, 2026
@XuPeng-SH
XuPeng-SH merged commit 2726fb4 into main Oct 9, 2026
@XuPeng-SH
XuPeng-SH deleted the codex/quality-29249-datasync-20261007 branch October 9, 2026 03:06

This branch was previously deployed

1 inactive deployment
ci — da90af8f Deployed Oct 9, 2026 by XuPeng-SH
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/enhancement kind/refactor Code refactor kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants