Repository navigation
fix(datasync): honor cleanup cancellation and remove timing-based tests - #29673
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
There was a problem hiding this comment.
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_changedstill 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.
6fe2319 to
da90af8
Compare
What type of PR is this?
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 main23d8f61252f3017dff218b530817a240206fd762(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:
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.