Repository navigation
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed the lockservice orphan-cleanup path from first principles: CannotCommit ordering, remote/local timeout cleanup, stale bind heartbeat cleanup, waiter wake-up timestamp propagation, mixed empty-FenceTS fallback, and repeated CannotCommit races.
No blocking issues found. The change is directionally correct: orphan cleanup should not unlock with an empty commit timestamp after TN has only proven cannot-commit safety. Returning an allocator HLC upper-bound as a fence, and only unlocking when CannotCommit does not report the txn as committing, closes the unsafe stale-snapshot path while keeping normal commit/unlock behavior unchanged.
I also checked the unhappy paths: CannotCommit RPC errors keep the lock; committing txns are not unlocked; the second CannotCommit check in checkTxnTimeout avoids a race where the first check becomes stale; empty FenceTS falls back to a local clock value for compatibility instead of reintroducing empty unlocks.
This PR should be viewed as the lockservice orphan-unlock fix for #25553, not as standalone proof that the full TPCC chaos scenario is solved end-to-end. The code-level coverage is solid for this layer.
Local validation passed on the PR head:
- targeted fenced orphan/CannotCommit tests from the PR body
- broader orphan cleanup regressions including communication interruption, service restart, bind heartbeat missing, unstable network, and ValidTxn paths
CI is green across UT, Coverage, BVT, multi-CN, upgrade, and benchmark checks.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed the latest head 931748dd5 after the generation-aware cleanup changes.
The previous blocking stale-cleaner race is fixed correctly. The cleaner now captures a per-service generation watermark immediately before each GetActiveTxn request, and commitState creation/refresh/in-flight transitions advance the generation. Cleanup therefore only removes states that existed at or before the snapshot boundary and did not change while the RPC round was in flight. The new two-service interleaving test deterministically covers the original failure mode.
I also rechecked the surrounding state machine and unhappy paths:
- every successful lock-table
Validin the TN Commit handler is paired with deferredFinishCommit; - duplicate/concurrent Commit attempts remain protected by the in-flight reference count;
- CannotCommit cannot replace a live committing state;
- failed active-txn queries preserve tombstones, while disconnected-service expiry remains fail-closed for newer generations;
- generation overflow intentionally preserves state;
- the strict fence still dominates equal-physical/higher-logical timestamps, and missing/overflowed clocks produce no fence and no orphan unlock;
- waiter, timeout, local, remote, and stale-bind cleanup paths require both allocator proofs before unlocking.
Performance is non-blocking: the normal Commit path adds no RPC or I/O, state is removed on completion, and the extra operations are small allocator-local map/mutex operations. Valid already serialized bind validation under l.mu; the new cost is a low constant factor plus a per-service FinishCommit critical section.
Compatibility remains fail-closed in the safety-critical direction: a new CN talking to an older allocator receives an empty fence and skips exceptional unlock. An old CN does not gain the fenced behavior until it is upgraded, which is an expected rollout limitation rather than a new regression.
Local validation on the latest head:
go test ./pkg/lockservice -count=1
ok (124.063s)
go test -race ./pkg/lockservice -run generation/fence/in-flight tests -count=10
ok
go test ./pkg/txn/service -run ^TestCommitWithLockTables$ -count=10
ok
git diff --check and gofmt -l on touched Go files
clean
Approved. CI for the fresh head is still running and should remain the merge gate.
|
I found one remaining lifecycle gap in the latest head: the new commit reference is released too early on the 2PC path.
A concrete interleaving is:
This recreates the same unlock-before-commit-completion window that this PR is intended to close. The fence orders timestamps, but it does not make an asynchronously pending commit visible before the waiter proceeds. Please transfer ownership of the successful Operational scope: this is not reachable in a deployment that strictly guarantees |
What type of PR is this?
Which issue(s) this PR fixes:
fixes #25553
refs #22115
refs #22791
What this PR does / why we need it:
This PR prevents lockservice orphan cleanup from releasing a holder while its TN Commit can still finish, and ensures every exceptional orphan unlock carries a timestamp that fences stale waiters.
Root cause
The incident follows the single-TN-shard 1PC branch and is a race between the TN Commit handler and lockservice orphan cleanup:
LockTableAllocator.Validrecords the transaction as committing.cleanCommitStatefails to obtain the CN active transaction list and deletes the service's commit-control state.CannotCommitno longer sees the in-flight Commit and incorrectly reports that the holder is safe to unlock.The previous fence-only implementation also used the raw HLC upper bound. A timestamp such as
(110, 0)does not dominate(110, 7), so it was not a strict fence for all logical timestamps at the same physical time.Fix
Validincrements a per-transaction reference count.FinishCommitfor every successfulValid.GetActiveTxncall, cleaner captures that service's state-generation watermark and only applies the response to states at or below that watermark.cannotCommit, and a lateValidrejected by that tombstone, advances the generation so an older active-txn snapshot cannot delete it.cannotCommittombstones.CannotCommit.(upper.PhysicalTime + 1, 0), which dominates every logical timestamp at the current upper-bound physical time.Scope and risk
The normal Commit path adds only allocator-local state operations; it adds no RPC and removes state as soon as the final Commit attempt returns. Normal lock acquisition, isolation semantics, lock wait timeouts, and ordinary commit/unlock are unchanged. The fix does not introduce or depend on 2PC:
committing/cannotCommitare lockservice allocator arbitration states around the current 1PC Commit handler.The deployment invariant for this hotfix is one TN shard per transaction (
len(TNShards) == 1). The retained multi-TN asynchronous Commit branch is outside this PR's supported scope; this PR does not claim to fix that branch's commit-reference lifetime.If a TN Commit itself never returns, the holder remains protected. Unlocking it would be unsafe because that Commit may still become visible; TN recovery must resolve that condition. This PR does not turn an uncertain Commit into an early unlock.
Main changes
proto/lock.proto, generated lock protobufFenceTStoCannotCommitResponselock_table_allocator.goservice_cn_handler.goValidwith deferredFinishCommitValidation
go test ./pkg/lockservice -count=1go test -race ./pkg/lockservice -run 'Test(CannotCommitWaitsForAllCommitAttempts|CleanCommitStateKeepsInflightCommit|CleanerPreservesCannotCommitOnActiveTxnQueryError|CleanerDoesNotDeleteTombstoneCreatedAfterServiceSnapshot|CannotCommitGenerationRefresh|NewFenceTS)' -count=1go test ./pkg/txn/service -run TestCommitWithLockTables -count=1go vet ./pkg/lockservicego vet ./pkg/txn/servicego build ./pkg/lockservice