@@ -86,12 +86,14 @@ static TransactionId DtmMinXid;
86
86
static bool DtmHasGlobalSnapshot ;
87
87
static bool DtmIsGlobalTransaction ;
88
88
static int DtmLocalXidReserve ;
89
+ static int DtmCurcid ;
90
+ static Snapshot DtmLastSnapshot ;
89
91
static TransactionManager DtmTM = { DtmGetTransactionStatus , DtmSetTransactionStatus , DtmGetSnapshot , DtmGetNewTransactionId , DtmGetOldestXmin };
90
92
91
93
92
94
#define XTM_TRACE (fmt , ...)
93
- // #define XTM_INFO(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
94
- #define XTM_INFO (fmt , ...)
95
+ #define XTM_INFO (fmt , ...) fprintf(stderr, fmt, ## __VA_ARGS__)
96
+ // #define XTM_INFO(fmt, ...)
95
97
96
98
static void DumpSnapshot (Snapshot s , char * name )
97
99
{
@@ -100,8 +102,8 @@ static void DumpSnapshot(Snapshot s, char *name)
100
102
char * cursor = buf ;
101
103
cursor += sprintf (
102
104
cursor ,
103
- "snapshot %s for transaction %d: xmin=%d, xmax=%d, active=[" ,
104
- name , GetCurrentTransactionId (), s -> xmin , s -> xmax
105
+ "snapshot %s(%p) for transaction %d: xmin=%d, xmax=%d, active=[" ,
106
+ name , s , GetCurrentTransactionId (), s -> xmin , s -> xmax
105
107
);
106
108
for (i = 0 ; i < s -> xcnt ; i ++ ) {
107
109
if (i == 0 ) {
@@ -480,10 +482,12 @@ DtmGetNewTransactionId(bool isSubXact)
480
482
481
483
static Snapshot DtmGetSnapshot (Snapshot snapshot )
482
484
{
483
- if (TransactionIdIsValid (DtmNextXid )) {
484
- if (!DtmHasGlobalSnapshot ) {
485
+ if (TransactionIdIsValid (DtmNextXid ) && IsMVCCSnapshot ( snapshot ) && snapshot != & CatalogSnapshotData ) {
486
+ if (!DtmHasGlobalSnapshot && ( snapshot != DtmLastSnapshot || DtmCurcid != snapshot -> curcid ) ) {
485
487
DtmGlobalGetSnapshot (DtmNextXid , & DtmSnapshot , & DtmMinXid );
486
488
}
489
+ DtmCurcid = snapshot -> curcid ;
490
+ DtmLastSnapshot = snapshot ;
487
491
DtmMergeSnapshots (snapshot , & DtmSnapshot );
488
492
if (!IsolationUsesXactSnapshot ()) {
489
493
DtmHasGlobalSnapshot = false;
@@ -595,6 +599,7 @@ DtmXactCallback(XactEvent event, void *arg)
595
599
LWLockRelease (dtm -> hashLock );
596
600
}
597
601
DtmNextXid = InvalidTransactionId ;
602
+ DtmLastSnapshot = NULL ;
598
603
}
599
604
}
600
605
}
@@ -701,6 +706,7 @@ dtm_begin_transaction(PG_FUNCTION_ARGS)
701
706
702
707
DtmHasGlobalSnapshot = true;
703
708
DtmIsGlobalTransaction = true;
709
+ DtmLastSnapshot = NULL ;
704
710
705
711
PG_RETURN_INT32 (DtmNextXid );
706
712
}
@@ -716,6 +722,7 @@ Datum dtm_join_transaction(PG_FUNCTION_ARGS)
716
722
717
723
DtmHasGlobalSnapshot = true;
718
724
DtmIsGlobalTransaction = true;
725
+ DtmLastSnapshot = NULL ;
719
726
720
727
PG_RETURN_VOID ();
721
728
}
0 commit comments