Repository navigation
fix(disttae): fence PK checks on table subscription readiness - #25888
mergify[bot] merged 10 commits into
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? |
4255f50 to
d0d509a
Compare
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
The readiness fence fixes the intended subscribed path, but it drops the pre-existing snapshot-read terminal path and can leave a lock-holding PK check looping until its context expires. Existing PR reviews/threads were empty; focused local tests could not run because this checkout has no go executable.
P1 - Preserve the successful snapshot-read fallback instead of re-subscribing forever (pkg/vm/engine/disttae/txn_table.go:3021)
getPartitionState deliberately converts a SubRspTableNotExist subscription result into a historical snapshot read and can return a non-nil partition state with no error (lines 2502-2553). This new loop discards that successful result. toSubscribeTable clears the subscription entry on that response (logtail_consumer.go:517-519), so the next iteration sees Unsubscribed, invokes getPartitionState again, and repeats the subscription/snapshot-read cycle until the statement context ends. This is a regression for the existing missing-table/snapshot-read path and is especially harmful here because PrimaryKeysMayBeModified runs after LockOp has acquired its row lock. Consume/return the valid fallback state (with an appropriate readiness decision) or return a terminal error, and add a regression test for a NoSuchTable subscription followed by a successful snapshot read.
XuPeng-SH
left a comment
There was a problem hiding this comment.
The reconnect generation fence, pending-update ordering, cancellation wakeup, and rolling-restart rollback propagation are sound on the covered paths. However, the new PK-check state machine still has a reachable non-terminating path after the caller has acquired its row lock: a successful historical snapshot fallback is discarded after SubRspTableNotExist. This must be fixed before merge. Please make the fallback a terminal outcome and add a deterministic regression test that proves there is no repeated subscribe/snapshot-read cycle.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed the latest head (aaa17ec0). The previous blocker is closed: a finite historical partition returned after SubRspTableNotExist is now a terminal outcome, it is accepted only when its physical range covers the PK-check upper timestamp, and the new regression test proves both the in-range and conservative out-of-range paths perform one snapshot read with no repeated subscribe cycle.
I also re-checked the full lifecycle: reconnect closes admission before resetting the subscription map; the PK snapshot is fenced before and after capture under the subscription generation; pending-table apply is recaptured; subscriber cancellation wakes the condition wait; and the sharded-read path preserves the concrete rolling-restart error so frontend performs a whole-transaction rollback and releases acquired locks.
Fresh local validation on this head passed:
- focused concurrency regressions with
-race -count=100; - full
./pkg/vm/engine/disttaetests, with and without-race; - dependent
./pkg/sql/colexec/lockopand./pkg/frontendtests; go buildandgo vetfordisttaewith the repository CGo environment.
No remaining correctness, performance, hang, or resource-lifecycle blocker found. CI is still in progress at review time.
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
No concrete correctness, compatibility, concurrency, resource, performance, or coverage regressions found. The prior historical-snapshot fallback blocker is fixed; applicable CI checks pass. Local focused execution was blocked by missing CGo artifacts.
Merge Queue Status
This pull request spent 1 hour 10 minutes 41 seconds in the queue, including 1 hour 10 minutes 15 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #25704
What this PR does / why we need it:
During a long-running
SELECT ... FOR UPDATE, a table scan can produce a batchbefore
LockOpwaits for a conflicting transaction. If the CN logtail clientreconnects while the lock is waiting, reconnect rebuilds the table subscription
and latest in-memory partition state.
After the lock is granted,
LockOpcallsPrimaryKeysMayBeModifiedto decidewhether the pre-lock batch must be retried. The old implementation called
LazyLoadLatestCkpdirectly and could inspect an empty partition while thetable was still
Subscribing. It then returned unchanged before thesubscription response was applied. In TPCC NewOrder this can reuse a committed
d_next_o_idand surface as a duplicatebmsql_oorderkey.This change makes the PK modification check use the existing subscription state
machine and the per-table applied fence:
SubscribingandSubRspReceivedwait until checkpoint loading completesinstead of treating an incomplete state as unchanged;
holding the subscription generation, so reconnect cannot make a snapshot from
the old generation appear ready;
reconnect closes this gate before it clears the old subscription map, covering
that otherwise-stale intermediate window;
ErrRetryForCNRollingRestartsofrontend rolls back the whole transaction and releases the already-acquired
row lock instead of retaining locks until the 24-hour default session timeout;
shardservice'serrors.Joinboundaryfor remotely sharded tables, without changing other replica-read errors;
upper timestamp, then recaptures the current state before checking PKs;
SubRspTableNotExistmay still resolve an old transaction snapshot fromfinite historical checkpoints; that fallback is terminal instead of entering
another subscribe/snapshot-read cycle, and it is accepted only when its
physical
[start,end]range covers the PK-check upper timestamp;logTailSubscriber.waitReady, so a statement canceledduring reconnect does not remain blocked after it has acquired a row lock;
behavior;
PrimaryKeysMayBeUpsertedkeeps its existing lazy-check semantics.An earlier revision returned
changed=trueimmediately for an incompletesubscription. Pessimistic BVT exposed that this retries an entire LOAD DATA
statement after auto-increment values have already been allocated. Since
auto-increment allocation is non-transactional, the retry consumed a second
range and changed expected values (for example 4/5/6 became 7/8/9). The current
revision waits for the already-running subscription and performs one definitive
PK check, so it does not create a statement retry merely because first-table
subscription is in flight.
The normal
Subscribedpath issues no RPC, creates no timer, and captures onepartition snapshot. Waiting is limited to first subscription or a known pending
per-table apply. Every wait observes the statement context; a reconnect fails
the affected transaction through an existing whole-transaction rollback error.
The snapshot method refreshes the existing subscription-GC timestamp, so
write-only tables retain the same GC behavior as
isSubscribed. No wire format,lock ownership, transaction protocol, or configuration semantics change.
Regression tests cover:
SubscribingandSubRspReceivedwithout retrying ano-conflict statement;
admission but the old subscription entry is still present;
multi-replica error wrappers;
checkpoint range covers the PK-check timestamp and when it must conservatively
report
changedbecause it does not;the logtail subscriber itself is not ready;
unchanged auto-increment upsert semantics.
Test
.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m ./pkg/vm/engine/disttae.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=15m ./pkg/vm/engine/disttae.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -timeout=5m -run 'TestPKCheckHistoricalSnapshotFallbackIsTerminal|TestNormalizePKCheckErrorPreservesRollingRestart|TestPKCheckSnapshot|TestLogTailSubscriberWaitReadyReturnsOnContextCancel|TestPrimaryKeysMayBeModified' ./pkg/vm/engine/disttae.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m ./pkg/sql/colexec/lockop ./pkg/frontendgo build ./pkg/vm/engine/disttaego vet ./pkg/vm/engine/disttae