You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by "leborchuk (via GitHub)" <gi...@apache.org> on 2026/10/02 09:06:48 UTC
Re: [PR] Fix distributed snapshot race during commit [cloudberry]
leborchuk commented on PR #1884:
URL: https://github.com/apache/cloudberry/pull/1884#issuecomment-5948780731
Sorry (for the straightforward answer, I really appreciate your efforts and want to say a big thanks), but I do not think it will work that way.
There are two issues with proposed approach:
1. High CPU usage for "spinning". There are no direct while-loop cycle eating CPU cycles, but the whole approach leads to high CPU consumption:
- needDistributedSnapshot is true for everything except single-slice direct-dispatch SELECTs outside a transaction block (pquery.c:612-620). So every statement in a transaction block, all DML, all multi-slice SELECTs go through the new path. This is the hot path, not an edge case.
- It adds a third proc-array pass per snapshot, over allTmGxact[] — a different array from ProcGlobal->xids, so it's extra cache misses that GetSnapshotData's careful dense-array layout was designed to avoid.
- markDtxCommitInProgress() adds a second ProcArrayLock LW_EXCLUSIVE acquisition per distributed commit. At high TPS, doubling exclusive acquisitions on the single hottest LWLock is its own throughput problem, independent of the waiting.
- When it does wait, a reader now takes a lock-manager entry for the gxid tag. N concurrent readers waiting on one committing gxid means N PROCLOCKs. Plain SELECTs can now fail with "out of shared memory / increase max_locks_per_transaction" — a new failure mode on the read path.
- The loop rescans from scratch and picks the first marked gxid it finds, with no filtering by database, relation, or snapshot relevance. With k concurrent committers it waits k times sequentially, and new commits entering the window extend it. Under sustained write load a reader can be delayed with no bound (maybe long-long time).
2. Global stall
commitInProgress stays set, and the gxid lock stays held, for the entire doNotifyingCommitPrepared retry loop — up to dtx_phase2_retry_second, default 600s, after which it PANICs — plus SyncRepWaitForLSN when synchronous_commit >= remote_apply.
So: one segment hiccups during phase 2, and for ten minutes no backend cluster-wide can obtain a distributed snapshot. Before this patch, only the committing session hung. This converts a rare visibility anomaly into a reproducible cluster-wide outage. That tradeoff is much worse than the bug.
Most probably you faced with that issue while trying to add am_ftsprobe check and add `debug_disable_distributed_snapshot = on` to ~15 existing isolation2 tests
What I want to suggest.
You proposal is to make every reader wait. Let's switch to work with writers only.
The codebase already has machinery to enforce it on conflicting writers only: MyTmGxactLocal->waitGxids, collected in XactLockTableWait on the QE (see lmgr.c) with the comment "need to report the waited transactions to QD to make sure they have the same transaction order on the master," and consumed via GxactLockTableWait in notifyCommittedDtxTransaction.
The gap is that once the predecessor's QE has committed and released the row lock, a successor follows the update chain with no lock wait at all — so no ordering edge is recorded, and the successor can fully retire while the predecessor is still in allTmGxact. The QE has what it needs to detect this: LocalXidGetDistributedXid(xmax) gives the predecessor's gxid, and it can be tested against the distributed snapshot it was handed. Locally committed but in-progress in my distributed snapshot → record it in waitGxids.
That reuses the existing lifecycle (including FORGET and crash recovery), costs O(actual conflicts) instead of O(every snapshot), adds nothing to ProcArrayLock, and can't stall unrelated sessions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org