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

Commitb4da6f1

Browse files
committed
port xtm to 11-current
1 parent3f80895 commitb4da6f1

File tree

15 files changed

+336
-26
lines changed

15 files changed

+336
-26
lines changed

‎src/backend/access/transam/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include $(top_builddir)/src/Makefile.global
1515
OBJS = clog.o commit_ts.o generic_xlog.o multixact.o parallel.o rmgr.o slru.o\
1616
subtrans.o timeline.o transam.o twophase.o twophase_rmgr.o varsup.o\
1717
xact.o xlog.o xlogarchive.o xlogfuncs.o\
18-
xloginsert.o xlogreader.o xlogutils.o
18+
xloginsert.o xlogreader.o xlogutils.o xtm.o
1919

2020
include$(top_srcdir)/src/backend/common.mk
2121

‎src/backend/access/transam/clog.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include"access/xlog.h"
3939
#include"access/xloginsert.h"
4040
#include"access/xlogutils.h"
41+
#include"access/xtm.h"
4142
#include"miscadmin.h"
4243
#include"pg_trace.h"
4344

@@ -79,6 +80,12 @@ static SlruCtlData ClogCtlData;
7980

8081
#defineClogCtl (&ClogCtlData)
8182

83+
void
84+
TransactionIdSetTreeStatus(TransactionIdxid,intnsubxids,
85+
TransactionId*subxids,XidStatusstatus,XLogRecPtrlsn)
86+
{
87+
returnTM->SetTransactionStatus(xid,nsubxids,subxids,status,lsn);
88+
}
8289

8390
staticintZeroCLOGPage(intpageno,boolwriteXlog);
8491
staticboolCLOGPagePrecedes(intpage1,intpage2);
@@ -146,7 +153,7 @@ static void set_status_by_pages(int nsubxids, TransactionId *subxids,
146153
* cache yet.
147154
*/
148155
void
149-
TransactionIdSetTreeStatus(TransactionIdxid,intnsubxids,
156+
PgTransactionIdSetTreeStatus(TransactionIdxid,intnsubxids,
150157
TransactionId*subxids,XidStatusstatus,XLogRecPtrlsn)
151158
{
152159
intpageno=TransactionIdToPage(xid);/* get page of parent */
@@ -352,10 +359,10 @@ TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, i
352359
* Current state change should be from 0 or subcommitted to target state
353360
* or we should already be there when replaying changes during recovery.
354361
*/
355-
Assert(curval==0||
356-
(curval==TRANSACTION_STATUS_SUB_COMMITTED&&
357-
status!=TRANSACTION_STATUS_IN_PROGRESS)||
358-
curval==status);
362+
/*Assert(curval == 0 || */
363+
/* (curval == TRANSACTION_STATUS_SUB_COMMITTED && */
364+
/*status != TRANSACTION_STATUS_IN_PROGRESS) || */
365+
/* curval == status); */
359366

360367
/* note this assumes exclusive access to the clog page */
361368
byteval=*byteptr;
@@ -397,6 +404,12 @@ TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, i
397404
*/
398405
XidStatus
399406
TransactionIdGetStatus(TransactionIdxid,XLogRecPtr*lsn)
407+
{
408+
returnTM->GetTransactionStatus(xid,lsn);
409+
}
410+
411+
XidStatus
412+
PgTransactionIdGetStatus(TransactionIdxid,XLogRecPtr*lsn)
400413
{
401414
intpageno=TransactionIdToPage(xid);
402415
intbyteno=TransactionIdToByte(xid);

‎src/backend/access/transam/subtrans.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ SubTransGetParent(TransactionId xid)
115115
TransactionIdparent;
116116

117117
/* Can't ask about stuff that might not be around anymore */
118-
Assert(TransactionIdFollowsOrEquals(xid,TransactionXmin));
118+
//Assert(TransactionIdFollowsOrEquals(xid, TransactionXmin));
119119

120120
/* Bootstrap and frozen XIDs have no parent */
121121
if (!TransactionIdIsNormal(xid))
@@ -153,7 +153,10 @@ SubTransGetTopmostTransaction(TransactionId xid)
153153
previousXid=xid;
154154

155155
/* Can't ask about stuff that might not be around anymore */
156-
Assert(TransactionIdFollowsOrEquals(xid,TransactionXmin));
156+
if (!TransactionIdFollowsOrEquals(xid,TransactionXmin))
157+
{
158+
returnxid;
159+
}
157160

158161
while (TransactionIdIsValid(parentXid))
159162
{

‎src/backend/access/transam/varsup.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include"access/transam.h"
2020
#include"access/xact.h"
2121
#include"access/xlog.h"
22+
#include"access/xtm.h"
2223
#include"commands/dbcommands.h"
2324
#include"miscadmin.h"
2425
#include"postmaster/autovacuum.h"
@@ -33,6 +34,11 @@
3334
/* pointer to "variable cache" in shared memory (set up by shmem.c) */
3435
VariableCacheShmemVariableCache=NULL;
3536

37+
TransactionId
38+
GetNewTransactionId(boolisSubXact)
39+
{
40+
returnTM->GetNewTransactionId(isSubXact);
41+
}
3642

3743
/*
3844
* Allocate the next XID for a new transaction or subtransaction.
@@ -45,7 +51,7 @@ VariableCache ShmemVariableCache = NULL;
4551
* issue a warning about XID wrap.
4652
*/
4753
TransactionId
48-
GetNewTransactionId(boolisSubXact)
54+
PgGetNewTransactionId(boolisSubXact)
4955
{
5056
TransactionIdxid;
5157

‎src/backend/access/transam/xact.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include"access/transam.h"
2828
#include"access/twophase.h"
2929
#include"access/xact.h"
30+
#include"access/xtm.h"
3031
#include"access/xlog.h"
3132
#include"access/xloginsert.h"
3233
#include"access/xlogutils.h"
@@ -4897,6 +4898,7 @@ SerializeTransactionState(Size maxsize, char *start_address)
48974898
Assert(maxsize >= (nParallelCurrentXids+c)*sizeof(TransactionId));
48984899
memcpy(&result[c],ParallelCurrentXids,
48994900
nParallelCurrentXids*sizeof(TransactionId));
4901+
TM->SerializeTransactionState(&result[c+nParallelCurrentXids]);
49004902
return;
49014903
}
49024904

@@ -4930,6 +4932,7 @@ SerializeTransactionState(Size maxsize, char *start_address)
49304932
/* Copy data into output area. */
49314933
result[c++]= (TransactionId)nxids;
49324934
memcpy(&result[c],workspace,nxids*sizeof(TransactionId));
4935+
TM->SerializeTransactionState(&result[c+nxids]);
49334936
}
49344937

49354938
/*
@@ -4952,6 +4955,7 @@ StartParallelWorkerTransaction(char *tstatespace)
49524955
currentCommandId=tstate[4];
49534956
nParallelCurrentXids= (int)tstate[5];
49544957
ParallelCurrentXids=&tstate[6];
4958+
TM->DeserializeTransactionState(&tstate[nParallelCurrentXids+6]);
49554959

49564960
CurrentTransactionState->blockState=TBLOCK_PARALLEL_INPROGRESS;
49574961
}

‎src/backend/access/transam/xtm.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* xtm.c
4+
*PostgreSQL implementation of transaction manager protocol
5+
*
6+
* This module defines default iplementaiton of PostgreSQL transaction manager protocol
7+
*
8+
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
9+
* Portions Copyright (c) 1994, Regents of the University of California
10+
*
11+
* src/backend/access/transam/xtm.c
12+
*
13+
*-------------------------------------------------------------------------
14+
*/
15+
16+
#include"postgres.h"
17+
18+
#include"access/transam.h"
19+
#include"access/xtm.h"
20+
21+
TransactionId
22+
PgGetGlobalTransactionId(void)
23+
{
24+
returnInvalidTransactionId;
25+
}
26+
27+
bool
28+
PgDetectGlobalDeadLock(PGPROC*proc)
29+
{
30+
return false;
31+
}
32+
33+
charconst*
34+
PgGetTransactionManagerName(void)
35+
{
36+
return"postgres";
37+
}
38+
39+
size_t
40+
PgGetTransactionStateSize(void)
41+
{
42+
return0;
43+
}
44+
45+
void
46+
PgSerializeTransactionState(void*ctx)
47+
{
48+
}
49+
50+
void
51+
PgDeserializeTransactionState(void*ctx)
52+
{
53+
}
54+
55+
voidPgInitializeSequence(int64*init,int64*step)
56+
{
57+
*init=1;
58+
*step=1;
59+
}
60+
61+
62+
TransactionManagerPgTM= {
63+
PgTransactionIdGetStatus,
64+
PgTransactionIdSetTreeStatus,
65+
PgGetSnapshotData,
66+
PgGetNewTransactionId,
67+
PgGetOldestXmin,
68+
PgTransactionIdIsInProgress,
69+
PgGetGlobalTransactionId,
70+
PgXidInMVCCSnapshot,
71+
PgDetectGlobalDeadLock,
72+
PgGetTransactionManagerName,
73+
PgGetTransactionStateSize,
74+
PgSerializeTransactionState,
75+
PgDeserializeTransactionState,
76+
PgInitializeSequence
77+
};
78+
79+
TransactionManager*TM=&PgTM;
80+
81+
TransactionManager*
82+
GetTransactionManager(void)
83+
{
84+
returnTM;
85+
}

‎src/backend/storage/ipc/procarray.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include"access/twophase.h"
5252
#include"access/xact.h"
5353
#include"access/xlog.h"
54+
#include"access/xtm.h"
5455
#include"catalog/catalog.h"
5556
#include"miscadmin.h"
5657
#include"pgstat.h"
@@ -969,6 +970,12 @@ ProcArrayApplyXidAssignment(TransactionId topxid,
969970
LWLockRelease(ProcArrayLock);
970971
}
971972

973+
bool
974+
TransactionIdIsInProgress(TransactionIdxid)
975+
{
976+
returnTM->IsInProgress(xid);
977+
}
978+
972979
/*
973980
* TransactionIdIsInProgress -- is given transaction running in some backend
974981
*
@@ -996,7 +1003,7 @@ ProcArrayApplyXidAssignment(TransactionId topxid,
9961003
* PGXACT again anyway; see GetNewTransactionId).
9971004
*/
9981005
bool
999-
TransactionIdIsInProgress(TransactionIdxid)
1006+
PgTransactionIdIsInProgress(TransactionIdxid)
10001007
{
10011008
staticTransactionId*xids=NULL;
10021009
intnxids=0;
@@ -1256,6 +1263,11 @@ TransactionIdIsActive(TransactionId xid)
12561263
returnresult;
12571264
}
12581265

1266+
TransactionId
1267+
GetOldestXmin(Relationrel,intflags)
1268+
{
1269+
returnTM->GetOldestXmin(rel,flags);
1270+
}
12591271

12601272
/*
12611273
* GetOldestXmin -- returns oldest transaction that was running
@@ -1312,7 +1324,7 @@ TransactionIdIsActive(TransactionId xid)
13121324
* GetOldestXmin() move backwards, with no consequences for data integrity.
13131325
*/
13141326
TransactionId
1315-
GetOldestXmin(Relationrel,intflags)
1327+
PgGetOldestXmin(Relationrel,intflags)
13161328
{
13171329
ProcArrayStruct*arrayP=procArray;
13181330
TransactionIdresult;
@@ -1469,6 +1481,12 @@ GetMaxSnapshotSubxidCount(void)
14691481
returnTOTAL_MAX_CACHED_SUBXIDS;
14701482
}
14711483

1484+
Snapshot
1485+
GetSnapshotData(Snapshotsnapshot)
1486+
{
1487+
returnTM->GetSnapshot(snapshot);
1488+
}
1489+
14721490
/*
14731491
* GetSnapshotData -- returns information about running transactions.
14741492
*
@@ -1506,7 +1524,7 @@ GetMaxSnapshotSubxidCount(void)
15061524
* not statically allocated (see xip allocation below).
15071525
*/
15081526
Snapshot
1509-
GetSnapshotData(Snapshotsnapshot)
1527+
PgGetSnapshotData(Snapshotsnapshot)
15101528
{
15111529
ProcArrayStruct*arrayP=procArray;
15121530
TransactionIdxmin;

‎src/backend/storage/lmgr/deadlock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include"pgstat.h"
3131
#include"storage/lmgr.h"
3232
#include"storage/proc.h"
33+
#include"access/xtm.h"
3334
#include"utils/memutils.h"
3435

3536

@@ -281,7 +282,7 @@ DeadLockCheck(PGPROC *proc)
281282
elseif (blocking_autovacuum_proc!=NULL)
282283
returnDS_BLOCKED_BY_AUTOVACUUM;
283284
else
284-
returnDS_NO_DEADLOCK;
285+
returnTM->DetectGlobalDeadLock(proc) ?DS_DISTRIBUTED_DEADLOCK :DS_NO_DEADLOCK;
285286
}
286287

287288
/*

‎src/backend/storage/lmgr/lock.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,6 +3849,20 @@ GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode)
38493849
returnLockMethods[lockmethodid]->lockModeNames[mode];
38503850
}
38513851

3852+
void
3853+
EnumerateLocks(LockIteratoriterator,void*arg)
3854+
{
3855+
PROCLOCK*proclock;
3856+
HASH_SEQ_STATUSstatus;
3857+
3858+
hash_seq_init(&status,LockMethodProcLockHash);
3859+
3860+
while ((proclock= (PROCLOCK*)hash_seq_search(&status))!=NULL)
3861+
{
3862+
iterator(proclock,arg);
3863+
}
3864+
}
3865+
38523866
#ifdefLOCK_DEBUG
38533867
/*
38543868
* Dump all locks in the given proc's myProcLocks lists.

‎src/backend/storage/lmgr/predicate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4011,7 +4011,7 @@ CheckForSerializableConflictOut(bool visible, Relation relation,
40114011
xid=InvalidTransactionId;
40124012
}
40134013
Assert(TransactionIdIsValid(xid));
4014-
Assert(TransactionIdFollowsOrEquals(xid,TransactionXmin));
4014+
//Assert(TransactionIdFollowsOrEquals(xid, TransactionXmin));
40154015

40164016
/*
40174017
* Find top level xid. Bail out if xid is too early to be a conflict, or

‎src/backend/storage/lmgr/proc.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,22 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
14491449
"Processes holding the lock: %s. Wait queue: %s.",
14501450
lockHoldersNum,lock_holders_sbuf.data,lock_waiters_sbuf.data))));
14511451
}
1452+
elseif (deadlock_state==DS_DISTRIBUTED_DEADLOCK)
1453+
{
1454+
/*
1455+
* This message is a bit redundant with the error that will be
1456+
* reported subsequently, but in some cases the error report
1457+
* might not make it to the log (eg, if it's caught by an
1458+
* exception handler), and we want to ensure all long-wait
1459+
* events get logged.
1460+
*/
1461+
ereport(LOG,
1462+
(errmsg("process %d detected distributed deadlock while waiting for %s on %s after %ld.%03d ms",
1463+
MyProcPid,modename,buf.data,msecs,usecs),
1464+
(errdetail_log_plural("Process holding the lock: %s. Wait queue: %s.",
1465+
"Processes holding the lock: %s. Wait queue: %s.",
1466+
lockHoldersNum,lock_holders_sbuf.data,lock_waiters_sbuf.data))));
1467+
}
14521468

14531469
if (myWaitStatus==STATUS_WAITING)
14541470
ereport(LOG,
@@ -1473,7 +1489,7 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
14731489
* future-proofing, print a message if it looks like someone
14741490
* else kicked us off the lock.
14751491
*/
1476-
if (deadlock_state!=DS_HARD_DEADLOCK)
1492+
if (deadlock_state!=DS_HARD_DEADLOCK&&deadlock_state!=DS_DISTRIBUTED_DEADLOCK)
14771493
ereport(LOG,
14781494
(errmsg("process %d failed to acquire %s on %s after %ld.%03d ms",
14791495
MyProcPid,modename,buf.data,msecs,usecs),
@@ -1693,7 +1709,7 @@ CheckDeadLock(void)
16931709
/* Run the deadlock check, and set deadlock_state for use by ProcSleep */
16941710
deadlock_state=DeadLockCheck(MyProc);
16951711

1696-
if (deadlock_state==DS_HARD_DEADLOCK)
1712+
if (deadlock_state==DS_HARD_DEADLOCK||deadlock_state==DS_DISTRIBUTED_DEADLOCK)
16971713
{
16981714
/*
16991715
* Oops. We have a deadlock.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp