This repository was archived by the owner on May 24, 2024. It is now read-only.
Commit 87fbf06
authored
Fix several DistributedTransaction related issues (#13810)
* Avoid enlarging inProgressXidArray when CreateDistributedSnapshot().
* latestCompletedXid should be uint64.
* DistributedLog_AdvanceOldestXmin() returns more accurate oldestXmin.
* Remove unnecessary check in DistributedSnapshotWithLocalMapping_CommittedTest().
* Remove unnecessary check in HeapTupleSatisfiesMVCC().
There are several issues/enhancements related to DistributedTransactionId or DistributedSnapshot.
Since they are closely related, we put them all together here.
1, latestCompletedGxid is uint32
gxid is unit64 now, latestCompletedGxid should also be unit64.
2, Avoid enlarging inProgressXidArray during CreateDistributedSnapshot()
DistributedSnapshot's xmax is set to latestCompletedGxid + 1 after ProcArrayLock is held.
if (gxid > xmax)
{
xmax = gxid;
}
There is no need to update xmax because latestCompletedGxid can't be increased during
CreateDistributedSnapshot() and any gxid bigger than latestCompletedGxid should be seen
as a future gxid.
And we should avoid enlarging inProgressXidArray for efficiency.
3, DistributedLog_AdvanceOldestXmin() should return more accurate oldestXmin
while (1)
{
if (pg_atomic_compare_exchange_u32((pg_atomic_uint32 *)&DistributedLogShared->oldestXmin,
&expected, (uint32)oldestXmin))
break;
if (TransactionIdPrecedesOrEquals(oldestXmin, expected))
break;
}
When failed to update oldestXmin in a CAS operation and the expected value
is bigger than the value we want to set.
Some other processes must have updated oldestXmi to a bigger value.
And we should return that more accurate value.
4, Enhancements in DistributedSnapshotWithLocalMapping_CommittedTest()
redundant codes:
/*
* We found it in the distributed log.
*/
Assert(distribXid != InvalidDistributedTransactionId);
/*
* We have a distributed committed xid that corresponds to the
* local xid.
*/
Assert(distribXid != InvalidDistributedTransactionId);
unnecessary check:
if (LocalDistribXactCache_CommittedFind(localXid,&distribXid))
{
/*
* We cache local-only committed transactions for better performance,
* too.
*/
if (distribXid == InvalidDistributedTransactionId)
return DISTRIBUTEDSNAPSHOT_COMMITTED_IGNORE;
/*
* Fall below and evaluate the committed distributed transaction
* against the distributed snapshot.
*/
}
It can't happen that distribXid == InvalidDistributedTransactionId.
If we found it in LocalDistribXactCache_CommittedFind(), the distribXid must be valid.
We add it to cache in LocalDistribXactCache_AddCommitted() and there is nowhere to update
distribXid to InvalidDistributedTransactionId.
distribXid in cache must be valid or we don't find it in cache(never added or removed by cache LRU).
5, Redundant checks in HeapTupleSatisfiesMVCC()
if (snapshotCheckResult == XID_NOT_IN_SNAPSHOT)
{
if (snapshotCheckResult == XID_SURELY_COMMITTED || TransactionIdDidCommit(xvac))
{
SetHintBits(tuple, buffer, relation, HEAP_XMIN_INVALID,
InvalidTransactionId);
return false;
}
SetHintBits(tuple, buffer, relation, HEAP_XMIN_COMMITTED,
InvalidTransactionId);
}
snapshotCheckResult == XID_SURELY_COMMITTED check is unnecessary.1 parent 183b69f commit 87fbf06
6 files changed
Lines changed: 36 additions & 36 deletions
File tree
- src
- backend
- access
- heap
- transam
- cdb
- storage/ipc
- test
- include/access
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1069 | 1069 | | |
1070 | 1070 | | |
1071 | 1071 | | |
1072 | | - | |
| 1072 | + | |
1073 | 1073 | | |
1074 | 1074 | | |
1075 | 1075 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
276 | 282 | | |
| 283 | + | |
277 | 284 | | |
278 | 285 | | |
279 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
89 | 95 | | |
90 | | - | |
| 96 | + | |
91 | 97 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | 98 | | |
107 | 99 | | |
108 | 100 | | |
| |||
114 | 106 | | |
115 | 107 | | |
116 | 108 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | 109 | | |
124 | 110 | | |
125 | 111 | | |
| |||
137 | 123 | | |
138 | 124 | | |
139 | 125 | | |
| 126 | + | |
140 | 127 | | |
141 | 128 | | |
142 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2000 | 2000 | | |
2001 | 2001 | | |
2002 | 2002 | | |
2003 | | - | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
2004 | 2009 | | |
2005 | | - | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
2006 | 2017 | | |
2007 | 2018 | | |
2008 | 2019 | | |
| |||
2013 | 2024 | | |
2014 | 2025 | | |
2015 | 2026 | | |
2016 | | - | |
2017 | | - | |
2018 | | - | |
2019 | | - | |
2020 | 2027 | | |
2021 | 2028 | | |
2022 | 2029 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
99 | 100 | | |
100 | | - | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
127 | | - | |
| 126 | + | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
133 | 132 | | |
134 | 133 | | |
135 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
156 | | - | |
| 155 | + | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| |||
0 commit comments