Skip to content

Commit 9b44cc6

Browse files
committed
Remove CopySmapshot from XTM API
1 parent 8a9c01b commit 9b44cc6

File tree

8 files changed

+43
-86
lines changed

8 files changed

+43
-86
lines changed

contrib/pg_xtm/dtmd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CC=gcc
2-
CFLAGS=-g -Wall -Iinclude -D_LARGEFILE64_SOURCE -DDEBUG
2+
CFLAGS=-g -Wall -Iinclude -D_LARGEFILE64_SOURCE
33
LIBUV_PREFIX=$(HOME)/libuv-build
44
LIBUV_CFLAGS=-I"$(LIBUV_PREFIX)/include" -L"$(LIBUV_PREFIX)/lib"
55
LIBUV_LDFLAGS=-luv -pthread

contrib/pg_xtm/pg_dtm.c

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ typedef struct
5151
void _PG_init(void);
5252
void _PG_fini(void);
5353

54-
static Snapshot DtmGetSnapshot(void);
54+
static Snapshot DtmGetSnapshot(Snapshot snapshot);
5555
static void DtmMergeSnapshots(Snapshot dst, Snapshot src);
56-
static Snapshot DtmCopySnapshot(Snapshot snapshot);
5756
static XidStatus DtmGetTransactionStatus(TransactionId xid, XLogRecPtr *lsn);
5857
static void DtmSetTransactionStatus(TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn);
5958
static void DtmUpdateRecentXmin(void);
@@ -73,11 +72,10 @@ static Snapshot CurrentTransactionSnapshot;
7372

7473
static TransactionId DtmNextXid;
7574
static SnapshotData DtmSnapshot = { HeapTupleSatisfiesMVCC };
76-
static SnapshotData DtmLocalSnapshot = { HeapTupleSatisfiesMVCC };
7775
static bool DtmHasGlobalSnapshot;
7876
static bool DtmIsGlobalTransaction;
7977
static int DtmLocalXidReserve;
80-
static TransactionManager DtmTM = { DtmGetTransactionStatus, DtmSetTransactionStatus, DtmGetSnapshot, DtmCopySnapshot, DtmGetNextXid };
78+
static TransactionManager DtmTM = { DtmGetTransactionStatus, DtmSetTransactionStatus, DtmGetSnapshot, DtmGetNextXid };
8179

8280

8381
#define XTM_TRACE(fmt, ...)
@@ -136,43 +134,42 @@ static void DtmMergeSnapshots(Snapshot dst, Snapshot src)
136134
{
137135
int i, j, n;
138136
TransactionId xid;
139-
Snapshot local;
140137

141138
Assert(TransactionIdIsValid(src->xmin) && TransactionIdIsValid(src->xmax));
142139

143140
GetLocalSnapshot:
144-
local = GetSnapshotData(&DtmLocalSnapshot);
145-
for (i = 0; i < local->xcnt; i++) {
146-
if (TransactionIdIsInDoubt(local->xip[i])) {
141+
dst = GetLocalSnapshotData(dst);
142+
for (i = 0; i < dst->xcnt; i++) {
143+
if (TransactionIdIsInDoubt(dst->xip[i])) {
147144
goto GetLocalSnapshot;
148145
}
149146
}
150-
for (xid = local->xmax; xid < src->xmax; xid++) {
147+
for (xid = dst->xmax; xid < src->xmax; xid++) {
151148
if (TransactionIdIsInDoubt(xid)) {
152149
goto GetLocalSnapshot;
153150
}
154151
}
155-
DumpSnapshot(local, "local");
152+
DumpSnapshot(dst, "local");
156153
DumpSnapshot(src, "DTM");
157154

158155
/* Merge two snapshots: produce most restrictive snapshots whihc includes running transactions from both of them */
159-
dst->xmin = local->xmin < src->xmin ? local->xmin : src->xmin;
160-
dst->xmax = local->xmax < src->xmax ? local->xmax : src->xmax;
156+
if (src->xmin < dst->xmin) dst->xmin = src->xmin;
157+
if (src->xmax < dst->xmax) dst->xmax = src->xmax;
161158

162-
n = local->xcnt;
163-
for (xid = local->xmax; xid <= src->xmin; xid++) {
164-
local->xip[n++] = xid;
159+
n = dst->xcnt;
160+
for (xid = dst->xmax; xid <= src->xmin; xid++) {
161+
dst->xip[n++] = xid;
165162
}
166-
memcpy(local->xip + n, src->xip, src->xcnt*sizeof(TransactionId));
163+
memcpy(dst->xip + n, src->xip, src->xcnt*sizeof(TransactionId));
167164
n += src->xcnt;
168165
Assert(n <= GetMaxSnapshotXidCount());
169166

170-
qsort(local->xip, n, sizeof(TransactionId), xidComparator);
167+
qsort(dst->xip, n, sizeof(TransactionId), xidComparator);
171168
xid = InvalidTransactionId;
172169

173-
for (i = 0, j = 0; i < n && local->xip[i] < dst->xmax; i++) {
174-
if (local->xip[i] != xid) {
175-
dst->xip[j++] = xid = local->xip[i];
170+
for (i = 0, j = 0; i < n && dst->xip[i] < dst->xmax; i++) {
171+
if (dst->xip[i] != xid) {
172+
dst->xip[j++] = xid = dst->xip[i];
176173
}
177174
}
178175
dst->xcnt = j;
@@ -202,54 +199,23 @@ static void DtmUpdateRecentXmin(void)
202199
}
203200
}
204201

205-
static Snapshot DtmCopySnapshot(Snapshot snapshot)
206-
{
207-
Snapshot newsnap;
208-
Size size = sizeof(SnapshotData) + GetMaxSnapshotXidCount() * sizeof(TransactionId);
209-
Size subxipoff = size;
210-
if (snapshot->subxcnt > 0) {
211-
size += snapshot->subxcnt * sizeof(TransactionId);
212-
}
213-
newsnap = (Snapshot) MemoryContextAlloc(TopTransactionContext, size);
214-
memcpy(newsnap, snapshot, sizeof(SnapshotData));
215-
216-
newsnap->regd_count = 0;
217-
newsnap->active_count = 0;
218-
newsnap->copied = true;
219-
220-
newsnap->xip = (TransactionId *) (newsnap + 1);
221-
if (snapshot->xcnt > 0)
222-
{
223-
memcpy(newsnap->xip, snapshot->xip, snapshot->xcnt * sizeof(TransactionId));
224-
}
225-
if (snapshot->subxcnt > 0 &&
226-
(!snapshot->suboverflowed || snapshot->takenDuringRecovery))
227-
{
228-
newsnap->subxip = (TransactionId *) ((char *) newsnap + subxipoff);
229-
memcpy(newsnap->subxip, snapshot->subxip,
230-
snapshot->subxcnt * sizeof(TransactionId));
231-
}
232-
else
233-
newsnap->subxip = NULL;
234-
235-
return newsnap;
236-
}
237-
238202
static TransactionId DtmGetNextXid()
239203
{
240204
TransactionId xid;
241205
if (TransactionIdIsValid(DtmNextXid)) {
242206
XTM_INFO("Use global XID %d\n", DtmNextXid);
243207
xid = DtmNextXid;
208+
dtm->nReservedXids = 0;
209+
ShmemVariableCache->nextXid = xid;
244210
} else {
245211
LWLockAcquire(dtm->xidLock, LW_EXCLUSIVE);
246212
if (dtm->nReservedXids == 0) {
247213
dtm->nReservedXids = DtmGlobalReserve(ShmemVariableCache->nextXid, DtmLocalXidReserve, &xid);
248-
ShmemVariableCache->nextXid = xid;
249-
dtm->nextXid = xid;
250-
}
251-
Assert(dtm->nextXid == ShmemVariableCache->nextXid);
252-
xid = ShmemVariableCache->nextXid;
214+
ShmemVariableCache->nextXid = dtm->nextXid = xid;
215+
} else {
216+
Assert(dtm->nextXid == ShmemVariableCache->nextXid);
217+
xid = ShmemVariableCache->nextXid;
218+
}
253219
XTM_INFO("Obtain new local XID %d\n", xid);
254220
dtm->nextXid += 1;
255221
dtm->nReservedXids -= 1;
@@ -258,9 +224,9 @@ static TransactionId DtmGetNextXid()
258224
return xid;
259225
}
260226

261-
static Snapshot DtmGetSnapshot()
227+
static Snapshot DtmGetSnapshot(Snapshot snapshot)
262228
{
263-
Snapshot snapshot = GetLocalTransactionSnapshot();
229+
264230
if (TransactionIdIsValid(DtmNextXid)) {
265231
if (!DtmHasGlobalSnapshot) {
266232
DtmGlobalGetSnapshot(DtmNextXid, &DtmSnapshot);
@@ -270,7 +236,9 @@ static Snapshot DtmGetSnapshot()
270236
if (!IsolationUsesXactSnapshot()) {
271237
DtmHasGlobalSnapshot = false;
272238
}
273-
}
239+
} else {
240+
snapshot = GetLocalSnapshotData(snapshot);
241+
}
274242
CurrentTransactionSnapshot = snapshot;
275243
return snapshot;
276244
}
@@ -354,7 +322,6 @@ static void DtmInitialize()
354322
);
355323

356324
RegisterXactCallback(DtmXactCallback, NULL);
357-
DtmInitSnapshot(&DtmLocalSnapshot);
358325

359326
TM = &DtmTM;
360327
}

src/backend/access/transam/clog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include "miscadmin.h"
4545
#include "pg_trace.h"
4646

47-
TransactionManager DefaultTM = { CLOGTransactionIdGetStatus, CLOGTransactionIdSetTreeStatus, GetLocalTransactionSnapshot, CopyLocalSnapshot, GetNextTransactionId };
47+
TransactionManager DefaultTM = { CLOGTransactionIdGetStatus, CLOGTransactionIdSetTreeStatus, GetLocalSnapshotData, GetNextTransactionId };
4848
TransactionManager* TM = &DefaultTM;
4949

5050
/*

src/backend/storage/ipc/procarray.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,12 @@ GetMaxSnapshotSubxidCount(void)
14731473
return TOTAL_MAX_CACHED_SUBXIDS;
14741474
}
14751475

1476+
Snapshot
1477+
GetSnapshotData(Snapshot snapshot)
1478+
{
1479+
return TM->GetSnapshot(snapshot);
1480+
}
1481+
14761482
/*
14771483
* GetSnapshotData -- returns information about running transactions.
14781484
*
@@ -1509,7 +1515,7 @@ GetMaxSnapshotSubxidCount(void)
15091515
* not statically allocated (see xip allocation below).
15101516
*/
15111517
Snapshot
1512-
GetSnapshotData(Snapshot snapshot)
1518+
GetLocalSnapshotData(Snapshot snapshot)
15131519
{
15141520
ProcArrayStruct *arrayP = procArray;
15151521
TransactionId xmin;

src/backend/utils/time/snapmgr.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ typedef struct SerializedSnapshotData
185185
* used very long.
186186
*/
187187
Snapshot
188-
GetLocalTransactionSnapshot(void)
188+
GetTransactionSnapshot(void)
189189
{
190190
/*
191191
* Return historic snapshot if doing logical decoding. We'll never need a
@@ -251,13 +251,6 @@ GetLocalTransactionSnapshot(void)
251251
return CurrentSnapshot;
252252
}
253253

254-
Snapshot
255-
GetTransactionSnapshot()
256-
{
257-
return TM->GetSnapshot();
258-
}
259-
260-
261254
/*
262255
* GetLatestSnapshot
263256
* Get a snapshot that is up-to-date as of the current instant,
@@ -466,22 +459,15 @@ SetTransactionSnapshot(Snapshot sourcesnap, TransactionId sourcexid,
466459
FirstSnapshotSet = true;
467460
}
468461

469-
Snapshot
470-
CopySnapshot(Snapshot snapshot)
471-
{
472-
return TM->CopySnapshot(snapshot);
473-
}
474-
475-
476462
/*
477463
* CopySnapshot
478464
* Copy the given snapshot.
479465
*
480466
* The copy is palloc'd in TopTransactionContext and has initial refcounts set
481467
* to 0. The returned snapshot has the copied flag set.
482468
*/
483-
Snapshot
484-
CopyLocalSnapshot(Snapshot snapshot)
469+
static Snapshot
470+
CopySnapshot(Snapshot snapshot)
485471
{
486472
Snapshot newsnap;
487473
Size subxipoff;

src/include/access/xtm.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ typedef struct
1818
{
1919
XidStatus (*GetTransactionStatus)(TransactionId xid, XLogRecPtr *lsn);
2020
void (*SetTransactionStatus)(TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn);
21-
Snapshot (*GetSnapshot)();
22-
Snapshot (*CopySnapshot)(Snapshot snapshot);
21+
Snapshot (*GetSnapshot)(Snapshot snapshot);
2322
TransactionId (*GetNextXid)();
2423
} TransactionManager;
2524

src/include/storage/procarray.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern int GetMaxSnapshotXidCount(void);
4444
extern int GetMaxSnapshotSubxidCount(void);
4545

4646
extern Snapshot GetSnapshotData(Snapshot snapshot);
47+
extern Snapshot GetLocalSnapshotData(Snapshot snapshot);
4748

4849
extern bool ProcArrayInstallImportedXmin(TransactionId xmin,
4950
TransactionId sourcexid);

src/include/utils/snapmgr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ extern TransactionId RecentGlobalXmin;
2626
extern TransactionId RecentGlobalDataXmin;
2727

2828
extern Snapshot GetTransactionSnapshot(void);
29-
extern Snapshot GetLocalTransactionSnapshot(void);
3029
extern Snapshot GetLatestSnapshot(void);
3130
extern void SnapshotSetCommandId(CommandId curcid);
3231

@@ -41,7 +40,6 @@ extern void PopActiveSnapshot(void);
4140
extern Snapshot GetActiveSnapshot(void);
4241
extern bool ActiveSnapshotSet(void);
4342

44-
extern Snapshot CopyLocalSnapshot(Snapshot snapshot);
4543
extern Snapshot RegisterSnapshot(Snapshot snapshot);
4644
extern void UnregisterSnapshot(Snapshot snapshot);
4745
extern Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner);

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