@@ -97,15 +97,11 @@ static bool
97
97
TransactionIdInRecentPast (FullTransactionId fxid , TransactionId * extracted_xid )
98
98
{
99
99
TransactionId xid = XidFromFullTransactionId (fxid );
100
- uint32 now_epoch ;
101
- TransactionId now_epoch_next_xid ;
102
100
FullTransactionId now_fullxid ;
103
- TransactionId oldest_xid ;
104
- FullTransactionId oldest_fxid ;
101
+ TransactionId oldest_clog_xid ;
102
+ FullTransactionId oldest_clog_fxid ;
105
103
106
104
now_fullxid = ReadNextFullTransactionId ();
107
- now_epoch_next_xid = XidFromFullTransactionId (now_fullxid );
108
- now_epoch = EpochFromFullTransactionId (now_fullxid );
109
105
110
106
if (extracted_xid != NULL )
111
107
* extracted_xid = xid ;
@@ -135,52 +131,19 @@ TransactionIdInRecentPast(FullTransactionId fxid, TransactionId *extracted_xid)
135
131
136
132
/*
137
133
* If fxid is not older than TransamVariables->oldestClogXid, the relevant
138
- * CLOG entry is guaranteed to still exist. Convert
139
- * TransamVariables->oldestClogXid into a FullTransactionId to compare it
140
- * with fxid. Determine the right epoch knowing that oldest_fxid
141
- * shouldn't be more than 2^31 older than now_fullxid.
142
- */
143
- oldest_xid = TransamVariables -> oldestClogXid ;
144
- Assert (TransactionIdPrecedesOrEquals (oldest_xid , now_epoch_next_xid ));
145
- if (oldest_xid <= now_epoch_next_xid )
146
- {
147
- oldest_fxid = FullTransactionIdFromEpochAndXid (now_epoch , oldest_xid );
148
- }
149
- else
150
- {
151
- Assert (now_epoch > 0 );
152
- oldest_fxid = FullTransactionIdFromEpochAndXid (now_epoch - 1 , oldest_xid );
153
- }
154
- return !FullTransactionIdPrecedes (fxid , oldest_fxid );
155
- }
156
-
157
- /*
158
- * Convert a TransactionId obtained from a snapshot held by the caller to a
159
- * FullTransactionId. Use next_fxid as a reference FullTransactionId, so that
160
- * we can compute the high order bits. It must have been obtained by the
161
- * caller with ReadNextFullTransactionId() after the snapshot was created.
162
- */
163
- static FullTransactionId
164
- widen_snapshot_xid (TransactionId xid , FullTransactionId next_fxid )
165
- {
166
- TransactionId next_xid = XidFromFullTransactionId (next_fxid );
167
- uint32 epoch = EpochFromFullTransactionId (next_fxid );
168
-
169
- /* Special transaction ID. */
170
- if (!TransactionIdIsNormal (xid ))
171
- return FullTransactionIdFromEpochAndXid (0 , xid );
172
-
173
- /*
174
- * The 64 bit result must be <= next_fxid, since next_fxid hadn't been
175
- * issued yet when the snapshot was created. Every TransactionId in the
176
- * snapshot must therefore be from the same epoch as next_fxid, or the
177
- * epoch before. We know this because next_fxid is never allow to get
178
- * more than one epoch ahead of the TransactionIds in any snapshot.
134
+ * CLOG entry is guaranteed to still exist.
135
+ *
136
+ * TransamVariables->oldestXid governs allowable XIDs. Usually,
137
+ * oldestClogXid==oldestXid. It's also possible for oldestClogXid to
138
+ * follow oldestXid, in which case oldestXid might advance after our
139
+ * ReadNextFullTransactionId() call. If oldestXid has advanced, that
140
+ * advancement reinstated the usual oldestClogXid==oldestXid. Whether or
141
+ * not that happened, oldestClogXid is allowable relative to now_fullxid.
179
142
*/
180
- if ( xid > next_xid )
181
- epoch -- ;
182
-
183
- return FullTransactionIdFromEpochAndXid ( epoch , xid );
143
+ oldest_clog_xid = TransamVariables -> oldestClogXid ;
144
+ oldest_clog_fxid =
145
+ FullTransactionIdFromAllowableAt ( now_fullxid , oldest_clog_xid );
146
+ return ! FullTransactionIdPrecedes ( fxid , oldest_clog_fxid );
184
147
}
185
148
186
149
/*
@@ -420,12 +383,18 @@ pg_current_snapshot(PG_FUNCTION_ARGS)
420
383
nxip = cur -> xcnt ;
421
384
snap = palloc (PG_SNAPSHOT_SIZE (nxip ));
422
385
423
- /* fill */
424
- snap -> xmin = widen_snapshot_xid (cur -> xmin , next_fxid );
425
- snap -> xmax = widen_snapshot_xid (cur -> xmax , next_fxid );
386
+ /*
387
+ * Fill. This is the current backend's active snapshot, so MyProc->xmin
388
+ * is <= all these XIDs. As long as that remains so, oldestXid can't
389
+ * advance past any of these XIDs. Hence, these XIDs remain allowable
390
+ * relative to next_fxid.
391
+ */
392
+ snap -> xmin = FullTransactionIdFromAllowableAt (next_fxid , cur -> xmin );
393
+ snap -> xmax = FullTransactionIdFromAllowableAt (next_fxid , cur -> xmax );
426
394
snap -> nxip = nxip ;
427
395
for (i = 0 ; i < nxip ; i ++ )
428
- snap -> xip [i ] = widen_snapshot_xid (cur -> xip [i ], next_fxid );
396
+ snap -> xip [i ] =
397
+ FullTransactionIdFromAllowableAt (next_fxid , cur -> xip [i ]);
429
398
430
399
/*
431
400
* We want them guaranteed to be in ascending order. This also removes
0 commit comments