@@ -73,7 +73,7 @@ static TransactionId DtmGetNextXid(void);
73
73
static TransactionId DtmGetNewTransactionId (bool isSubXact );
74
74
static TransactionId DtmGetOldestXmin (Relation rel , bool ignoreVacuum );
75
75
76
- static bool TransactionIdIsInDtmSnapshot (TransactionId xid );
76
+ static bool TransactionIdIsInSnapshot (TransactionId xid , Snapshot snapshot );
77
77
static bool TransactionIdIsInDoubt (TransactionId xid );
78
78
79
79
static void dtm_shmem_startup (void );
@@ -119,18 +119,18 @@ static void DumpSnapshot(Snapshot s, char *name)
119
119
XTM_INFO ("%s\n" , buf );
120
120
}
121
121
122
- static bool TransactionIdIsInDtmSnapshot (TransactionId xid )
122
+ static bool TransactionIdIsInSnapshot (TransactionId xid , Snapshot snapshot )
123
123
{
124
- return xid >= DtmSnapshot . xmax
125
- || bsearch (& xid , DtmSnapshot . xip , DtmSnapshot . xcnt , sizeof (TransactionId ), xidComparator ) != NULL ;
124
+ return xid >= snapshot -> xmax
125
+ || bsearch (& xid , snapshot -> xip , snapshot -> xcnt , sizeof (TransactionId ), xidComparator ) != NULL ;
126
126
}
127
127
128
128
129
129
static bool TransactionIdIsInDoubt (TransactionId xid )
130
130
{
131
131
bool inDoubt ;
132
132
133
- if (!TransactionIdIsInDtmSnapshot (xid )) {
133
+ if (!TransactionIdIsInSnapshot (xid , & DtmSnapshot )) {
134
134
LWLockAcquire (dtm -> hashLock , LW_SHARED );
135
135
inDoubt = hash_search (xid_in_doubt , & xid , HASH_FIND , NULL ) != NULL ;
136
136
LWLockRelease (dtm -> hashLock );
@@ -175,8 +175,23 @@ static void DtmMergeSnapshots(Snapshot dst, Snapshot src)
175
175
176
176
static void DtmMergeWithActiveSnapshot (Snapshot dst )
177
177
{
178
+ int i , j ;
179
+ XLogRecPtr lsn ;
180
+ Snapshot src = & dtm -> activeSnapshot ;
181
+
178
182
LWLockAcquire (dtm -> xidLock , LW_EXCLUSIVE );
179
- DtmMergeSnapshots (dst , & dtm -> activeSnapshot );
183
+ for (i = 0 , j = 0 ; i < src -> xcnt ; i ++ ) {
184
+ if (!TransactionIdIsInSnapshot (src -> xip [i ], dst )
185
+ && DtmGetTransactionStatus (src -> xip [i ], & lsn ) == TRANSACTION_STATUS_IN_PROGRESS )
186
+ {
187
+ src -> xip [j ++ ] = src -> xip [i ];
188
+ }
189
+ }
190
+ src -> xcnt = j ;
191
+ if (j != 0 ) {
192
+ src -> xmin = src -> xip [0 ];
193
+ DtmMergeSnapshots (dst , src );
194
+ }
180
195
LWLockRelease (dtm -> xidLock );
181
196
}
182
197
0 commit comments