Fix spurious global xmin > xmin error on rollback - #1890
Open
gfphoenix78 wants to merge 1 commit into
Open
Conversation
GetSnapshotData() on a QE computes xmin under ProcArrayLock but reads/advances DistributedLogShared->oldestXmin afterwards, in a different lock domain. In that window a concurrent backend can advance the shared oldestXmin past this snapshot's xmin: when the transaction whose local xid equals xmin aborts, its distributed-log entry keeps distribXid == 0, so DistributedLog_AdvanceOldestXmin()'s forward scan skips over it instead of stopping, bumping oldestXmin beyond xmin. The resulting globalxmin > xmin then tripped a hard elog(ERROR) and failed the query (seen intermittently in the partition_prune regression test). The aborted xid is invisible to this snapshot anyway, and the visibility horizon only needs to be a valid lower bound, so a horizon at our own xmin loses nothing. Clamp globalxmin to xmin instead of erroring -- always safe, and consistent with the clamp already done in DistributedLog_GetOldestXmin().
Contributor
Author
|
The problem is: repro: -- prepare
drop table if exists t1;
create table t1(a int);
-- T1
1: begin;
1: insert into t1 select i from generate_series(1,10)i;
-- to see the local xid on segments
1: select gp_segment_id, xmin, * from t1;
-- T2, will trigger the error
2: set optimizer=off; -- invoke the QE backend on segments
-- gdb attach to one of the QEs and break after release the ProcArrayLock
-- gdb -p xxxx
-- > b procarray.c:3303
-- > c
-- the following sql will be break when running GetSnapshotData
2: create temp table ttmp(a int);
-- rollback T1
1: rollback;
-- running SQL that advance DistributedLogShared.oldestXmin
1: insert into t1 select i from generate_series(1,10)i;
-- gdb: the QE of T2 should be still hanged in GetSnapshotData
-- quit the gdb now
-- > quit
-- now, the above SQL to create temp table will failgdb break the function GetSnapshotData at: /*
* GP: In computing Globals, also take distributed snapshots into
* account.
*/
if (TransactionIdPrecedes(xmin, globalxmin))
globalxmin = xmin;
if (!IS_QUERY_DISPATCHER()) |
yjhjstz
approved these changes
Aug 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GetSnapshotData() on a QE computes xmin under ProcArrayLock but reads/advances DistributedLogShared->oldestXmin afterwards, in a different lock domain. In that window a concurrent backend can advance the shared oldestXmin past this snapshot's xmin: when the transaction whose local xid equals xmin aborts, its distributed-log entry keeps distribXid == 0, so DistributedLog_AdvanceOldestXmin()'s forward scan skips over it instead of stopping, bumping oldestXmin beyond xmin. The resulting globalxmin > xmin then tripped a hard elog(ERROR) and failed the query (seen intermittently in the partition_prune regression test).
The aborted xid is invisible to this snapshot anyway, and the visibility horizon only needs to be a valid lower bound, so a horizon at our own xmin loses nothing. Clamp globalxmin to xmin instead of erroring -- always safe, and consistent with the clamp already done in DistributedLog_GetOldestXmin().
Fixes #ISSUE_Number
What does this PR do?
Type of Change
Breaking Changes
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance:
User-facing changes:
Dependencies:
Checklist
Additional Context
CI Skip Instructions