Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9b44cc6

Browse files
committed
Remove CopySmapshot from XTM API
1 parent8a9c01b commit9b44cc6

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-
staticSnapshotDtmGetSnapshot(void);
54+
staticSnapshotDtmGetSnapshot(Snapshotsnapshot);
5555
staticvoidDtmMergeSnapshots(Snapshotdst,Snapshotsrc);
56-
staticSnapshotDtmCopySnapshot(Snapshotsnapshot);
5756
staticXidStatusDtmGetTransactionStatus(TransactionIdxid,XLogRecPtr*lsn);
5857
staticvoidDtmSetTransactionStatus(TransactionIdxid,intnsubxids,TransactionId*subxids,XidStatusstatus,XLogRecPtrlsn);
5958
staticvoidDtmUpdateRecentXmin(void);
@@ -73,11 +72,10 @@ static Snapshot CurrentTransactionSnapshot;
7372

7473
staticTransactionIdDtmNextXid;
7574
staticSnapshotDataDtmSnapshot= {HeapTupleSatisfiesMVCC };
76-
staticSnapshotDataDtmLocalSnapshot= {HeapTupleSatisfiesMVCC };
7775
staticboolDtmHasGlobalSnapshot;
7876
staticboolDtmIsGlobalTransaction;
7977
staticintDtmLocalXidReserve;
80-
staticTransactionManagerDtmTM= {DtmGetTransactionStatus,DtmSetTransactionStatus,DtmGetSnapshot,DtmCopySnapshot,DtmGetNextXid };
78+
staticTransactionManagerDtmTM= {DtmGetTransactionStatus,DtmSetTransactionStatus,DtmGetSnapshot,DtmGetNextXid };
8179

8280

8381
#defineXTM_TRACE(fmt, ...)
@@ -136,43 +134,42 @@ static void DtmMergeSnapshots(Snapshot dst, Snapshot src)
136134
{
137135
inti,j,n;
138136
TransactionIdxid;
139-
Snapshotlocal;
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
gotoGetLocalSnapshot;
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
gotoGetLocalSnapshot;
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-
staticSnapshotDtmCopySnapshot(Snapshotsnapshot)
206-
{
207-
Snapshotnewsnap;
208-
Sizesize=sizeof(SnapshotData)+GetMaxSnapshotXidCount()*sizeof(TransactionId);
209-
Sizesubxipoff=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-
returnnewsnap;
236-
}
237-
238202
staticTransactionIdDtmGetNextXid()
239203
{
240204
TransactionIdxid;
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
returnxid;
259225
}
260226

261-
staticSnapshotDtmGetSnapshot()
227+
staticSnapshotDtmGetSnapshot(Snapshotsnapshot)
262228
{
263-
Snapshotsnapshot=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
returnsnapshot;
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-
TransactionManagerDefaultTM= {CLOGTransactionIdGetStatus,CLOGTransactionIdSetTreeStatus,GetLocalTransactionSnapshot,CopyLocalSnapshot,GetNextTransactionId };
47+
TransactionManagerDefaultTM= {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
returnTOTAL_MAX_CACHED_SUBXIDS;
14741474
}
14751475

1476+
Snapshot
1477+
GetSnapshotData(Snapshotsnapshot)
1478+
{
1479+
returnTM->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(Snapshotsnapshot)
1518+
GetLocalSnapshotData(Snapshotsnapshot)
15131519
{
15141520
ProcArrayStruct*arrayP=procArray;
15151521
TransactionIdxmin;

‎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
returnCurrentSnapshot;
252252
}
253253

254-
Snapshot
255-
GetTransactionSnapshot()
256-
{
257-
returnTM->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(Snapshotsnapshot)
471-
{
472-
returnTM->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(Snapshotsnapshot)
469+
staticSnapshot
470+
CopySnapshot(Snapshotsnapshot)
485471
{
486472
Snapshotnewsnap;
487473
Sizesubxipoff;

‎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)(TransactionIdxid,XLogRecPtr*lsn);
2020
void (*SetTransactionStatus)(TransactionIdxid,intnsubxids,TransactionId*subxids,XidStatusstatus,XLogRecPtrlsn);
21-
Snapshot (*GetSnapshot)();
22-
Snapshot (*CopySnapshot)(Snapshotsnapshot);
21+
Snapshot (*GetSnapshot)(Snapshotsnapshot);
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 intGetMaxSnapshotXidCount(void);
4444
externintGetMaxSnapshotSubxidCount(void);
4545

4646
externSnapshotGetSnapshotData(Snapshotsnapshot);
47+
externSnapshotGetLocalSnapshotData(Snapshotsnapshot);
4748

4849
externboolProcArrayInstallImportedXmin(TransactionIdxmin,
4950
TransactionIdsourcexid);

‎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
externTransactionIdRecentGlobalDataXmin;
2727

2828
externSnapshotGetTransactionSnapshot(void);
29-
externSnapshotGetLocalTransactionSnapshot(void);
3029
externSnapshotGetLatestSnapshot(void);
3130
externvoidSnapshotSetCommandId(CommandIdcurcid);
3231

@@ -41,7 +40,6 @@ extern void PopActiveSnapshot(void);
4140
externSnapshotGetActiveSnapshot(void);
4241
externboolActiveSnapshotSet(void);
4342

44-
externSnapshotCopyLocalSnapshot(Snapshotsnapshot);
4543
externSnapshotRegisterSnapshot(Snapshotsnapshot);
4644
externvoidUnregisterSnapshot(Snapshotsnapshot);
4745
externSnapshotRegisterSnapshotOnOwner(Snapshotsnapshot,ResourceOwnerowner);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp