Skip to content

Commit 78dd16d

Browse files
committed
Support read committed isolation level
1 parent e83a073 commit 78dd16d

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

contrib/pg_xtm/pg_dtm.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ static TransactionId DtmMinXid;
8686
static bool DtmHasGlobalSnapshot;
8787
static bool DtmIsGlobalTransaction;
8888
static int DtmLocalXidReserve;
89+
static int DtmCurcid;
90+
static Snapshot DtmLastSnapshot;
8991
static TransactionManager DtmTM = { DtmGetTransactionStatus, DtmSetTransactionStatus, DtmGetSnapshot, DtmGetNewTransactionId, DtmGetOldestXmin };
9092

9193

9294
#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, ...)
9597

9698
static void DumpSnapshot(Snapshot s, char *name)
9799
{
@@ -100,8 +102,8 @@ static void DumpSnapshot(Snapshot s, char *name)
100102
char *cursor = buf;
101103
cursor += sprintf(
102104
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
105107
);
106108
for (i = 0; i < s->xcnt; i++) {
107109
if (i == 0) {
@@ -480,10 +482,12 @@ DtmGetNewTransactionId(bool isSubXact)
480482

481483
static Snapshot DtmGetSnapshot(Snapshot snapshot)
482484
{
483-
if (TransactionIdIsValid(DtmNextXid)) {
484-
if (!DtmHasGlobalSnapshot) {
485+
if (TransactionIdIsValid(DtmNextXid) && IsMVCCSnapshot(snapshot) && snapshot != &CatalogSnapshotData) {
486+
if (!DtmHasGlobalSnapshot && (snapshot != DtmLastSnapshot || DtmCurcid != snapshot->curcid)) {
485487
DtmGlobalGetSnapshot(DtmNextXid, &DtmSnapshot, &DtmMinXid);
486488
}
489+
DtmCurcid = snapshot->curcid;
490+
DtmLastSnapshot = snapshot;
487491
DtmMergeSnapshots(snapshot, &DtmSnapshot);
488492
if (!IsolationUsesXactSnapshot()) {
489493
DtmHasGlobalSnapshot = false;
@@ -595,6 +599,7 @@ DtmXactCallback(XactEvent event, void *arg)
595599
LWLockRelease(dtm->hashLock);
596600
}
597601
DtmNextXid = InvalidTransactionId;
602+
DtmLastSnapshot = NULL;
598603
}
599604
}
600605
}
@@ -701,6 +706,7 @@ dtm_begin_transaction(PG_FUNCTION_ARGS)
701706

702707
DtmHasGlobalSnapshot = true;
703708
DtmIsGlobalTransaction = true;
709+
DtmLastSnapshot = NULL;
704710

705711
PG_RETURN_INT32(DtmNextXid);
706712
}
@@ -716,6 +722,7 @@ Datum dtm_join_transaction(PG_FUNCTION_ARGS)
716722

717723
DtmHasGlobalSnapshot = true;
718724
DtmIsGlobalTransaction = true;
725+
DtmLastSnapshot = NULL;
719726

720727
PG_RETURN_VOID();
721728
}

src/backend/utils/time/tqual.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ HeapTupleSatisfiesDirty(HeapTuple htup, Snapshot snapshot,
970970
* and more contention on the PGXACT array.
971971
*/
972972
bool
973-
HeapTupleSatisfiesMVCC(HeapTuple htup, Snapshot snapshot,
973+
_HeapTupleSatisfiesMVCC(HeapTuple htup, Snapshot snapshot,
974974
Buffer buffer)
975975
{
976976
HeapTupleHeader tuple = htup->t_data;
@@ -1156,7 +1156,7 @@ HeapTupleSatisfiesMVCC(HeapTuple htup, Snapshot snapshot,
11561156

11571157
return false;
11581158
}
1159-
#if 0
1159+
#if 1
11601160
bool
11611161
HeapTupleSatisfiesMVCC(HeapTuple htup, Snapshot snapshot,
11621162
Buffer buffer)

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