Skip to content

Commit 6bb3f5a

Browse files
committed
Fix merging of active snapshot
1 parent 8ed9197 commit 6bb3f5a

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

contrib/pg_xtm/pg_dtm.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static TransactionId DtmGetNextXid(void);
7373
static TransactionId DtmGetNewTransactionId(bool isSubXact);
7474
static TransactionId DtmGetOldestXmin(Relation rel, bool ignoreVacuum);
7575

76-
static bool TransactionIdIsInDtmSnapshot(TransactionId xid);
76+
static bool TransactionIdIsInSnapshot(TransactionId xid, Snapshot snapshot);
7777
static bool TransactionIdIsInDoubt(TransactionId xid);
7878

7979
static void dtm_shmem_startup(void);
@@ -119,18 +119,18 @@ static void DumpSnapshot(Snapshot s, char *name)
119119
XTM_INFO("%s\n", buf);
120120
}
121121

122-
static bool TransactionIdIsInDtmSnapshot(TransactionId xid)
122+
static bool TransactionIdIsInSnapshot(TransactionId xid, Snapshot snapshot)
123123
{
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;
126126
}
127127

128128

129129
static bool TransactionIdIsInDoubt(TransactionId xid)
130130
{
131131
bool inDoubt;
132132

133-
if (!TransactionIdIsInDtmSnapshot(xid)) {
133+
if (!TransactionIdIsInSnapshot(xid, &DtmSnapshot)) {
134134
LWLockAcquire(dtm->hashLock, LW_SHARED);
135135
inDoubt = hash_search(xid_in_doubt, &xid, HASH_FIND, NULL) != NULL;
136136
LWLockRelease(dtm->hashLock);
@@ -175,8 +175,23 @@ static void DtmMergeSnapshots(Snapshot dst, Snapshot src)
175175

176176
static void DtmMergeWithActiveSnapshot(Snapshot dst)
177177
{
178+
int i, j;
179+
XLogRecPtr lsn;
180+
Snapshot src = &dtm->activeSnapshot;
181+
178182
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+
}
180195
LWLockRelease(dtm->xidLock);
181196
}
182197

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