Skip to content

Commit b9e89b5

Browse files
committed
init global_snapshot_xmin on start of new global tx
1 parent 9645d73 commit b9e89b5

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/backend/access/transam/global_snapshot.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ DtmCurrentTrans dtm_tx; // XXXX: make static
9595

9696
static bool DtmXidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
9797
static void DtmAdjustOldestXid(void);
98+
static void DtmInitGlobalXmin(TransactionId xid);
9899
static bool DtmDetectGlobalDeadLock(PGPROC *proc);
99100
static void DtmAddSubtransactions(DtmTransStatus * ts, TransactionId *subxids, int nSubxids);
100101
static char const *DtmGetName(void);
@@ -365,6 +366,17 @@ DtmAdjustOldestXid()
365366
// elog(LOG, "DtmAdjustOldestXid total=%d, deleted=%d, xid=%d, prev=%p, ts=%p", total, deleted, oldest_xid, prev, ts);
366367
}
367368

369+
static void
370+
DtmInitGlobalXmin(TransactionId xid)
371+
{
372+
TransactionId current_xmin;
373+
374+
/* Better change to CAS */
375+
current_xmin = ProcArrayGetGlobalSnapshotXmin();
376+
if (!TransactionIdIsValid(current_xmin))
377+
ProcArraySetGlobalSnapshotXmin(xid);
378+
}
379+
368380

369381
/*
370382
* Check tuple bisibility based on CSN of current transaction.
@@ -503,6 +515,7 @@ DtmLocalExtend(GlobalTransactionId gtid)
503515
SpinLockRelease(&local->lock);
504516
}
505517
x->is_global = true;
518+
DtmInitGlobalXmin(x->xid);
506519
return x->snapshot;
507520
}
508521

@@ -524,6 +537,7 @@ DtmLocalAccess(DtmCurrentTrans * x, GlobalTransactionId gtid, cid_t global_cid)
524537
id->xid = GetCurrentTransactionId();
525538
id->nSubxids = 0;
526539
id->subxids = 0;
540+
x->xid = id->xid;
527541
}
528542
local_cid = dtm_sync(global_cid);
529543
x->snapshot = global_cid;
@@ -535,6 +549,7 @@ DtmLocalAccess(DtmCurrentTrans * x, GlobalTransactionId gtid, cid_t global_cid)
535549
{
536550
elog(ERROR, "Too old snapshot: requested %ld, current %ld", global_cid, local_cid);
537551
}
552+
DtmInitGlobalXmin(x->xid);
538553
return global_cid;
539554
}
540555

src/backend/storage/ipc/procarray.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,6 +3042,19 @@ ProcArraySetGlobalSnapshotXmin(TransactionId xmin)
30423042
LWLockRelease(ProcArrayLock);
30433043
}
30443044

3045+
/*
3046+
* ProcArrayGetGlobalSnapshotXmin
3047+
*/
3048+
TransactionId
3049+
ProcArrayGetGlobalSnapshotXmin(void)
3050+
{
3051+
TransactionId xmin;
3052+
LWLockAcquire(ProcArrayLock, LW_SHARED);
3053+
xmin = procArray->global_snapshot_xmin;
3054+
LWLockRelease(ProcArrayLock);
3055+
return xmin;
3056+
}
3057+
30453058
#define XidCacheRemove(i) \
30463059
do { \
30473060
MyProc->subxids.xids[i] = MyProc->subxids.xids[MyPgXact->nxids - 1]; \

src/include/storage/procarray.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,6 @@ extern void ProcArrayGetReplicationSlotXmin(TransactionId *xmin,
125125
TransactionId *catalog_xmin);
126126

127127
extern void ProcArraySetGlobalSnapshotXmin(TransactionId xmin);
128+
extern TransactionId ProcArrayGetGlobalSnapshotXmin(void);
128129

129130
#endif /* PROCARRAY_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy