Skip to content

Commit 26195ab

Browse files
committed
Aff lock graph serializatgion
1 parent 1bc810d commit 26195ab

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

contrib/mmts/multimaster.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,3 +1516,73 @@ MtmGetState(void)
15161516
{
15171517
return dtm;
15181518
}
1519+
1520+
static void
1521+
MtmGetGtid(TransactionId xid, GlobalTransactionId* gtid)
1522+
{
1523+
MtmTransState* ts;
1524+
1525+
MtmLock(LW_SHARED);
1526+
ts = (MtmTransState*)hash_search(xid2state, &xid, HASH_FIND, NULL);
1527+
Assert(ts != NULL);
1528+
*gtid = ts->gtid;
1529+
MtmUnlock();
1530+
}
1531+
1532+
1533+
static void
1534+
MtmSerializeLock(PROCLOCK* proclock, void* arg)
1535+
{
1536+
ByteBuffer* buf = (ByteBuffer*)arg;
1537+
LOCK* lock = proclock->tag.myLock;
1538+
PGPROC* proc = proclock->tag.myProc;
1539+
GlobalTransactionId gtid;
1540+
if (lock != NULL) {
1541+
PGXACT* srcPgXact = &ProcGlobal->allPgXact[proc->pgprocno];
1542+
1543+
if (TransactionIdIsValid(srcPgXact->xid) && proc->waitLock == lock) {
1544+
LockMethod lockMethodTable = GetLocksMethodTable(lock);
1545+
int numLockModes = lockMethodTable->numLockModes;
1546+
int conflictMask = lockMethodTable->conflictTab[proc->waitLockMode];
1547+
SHM_QUEUE *procLocks = &(lock->procLocks);
1548+
int lm;
1549+
1550+
MtmGetGtid(srcPgXact->xid, &gtid); /* waiting transaction */
1551+
1552+
ByteBufferAppendInt32(buf, gtid.node);
1553+
ByteBufferAppendInt32(buf, gtid.xid);
1554+
1555+
proclock = (PROCLOCK *) SHMQueueNext(procLocks, procLocks,
1556+
offsetof(PROCLOCK, lockLink));
1557+
while (proclock)
1558+
{
1559+
if (proc != proclock->tag.myProc) {
1560+
PGXACT* dstPgXact = &ProcGlobal->allPgXact[proclock->tag.myProc->pgprocno];
1561+
if (TransactionIdIsValid(dstPgXact->xid)) {
1562+
Assert(srcPgXact->xid != dstPgXact->xid);
1563+
for (lm = 1; lm <= numLockModes; lm++)
1564+
{
1565+
if ((proclock->holdMask & LOCKBIT_ON(lm)) && (conflictMask & LOCKBIT_ON(lm)))
1566+
{
1567+
MTM_TRACE("%d: %u(%u) waits for %u(%u)\n", getpid(), srcPgXact->xid, proc->pid, dstPgXact->xid, proclock->tag.myProc->pid);
1568+
MtmGetGtid(srcPgXact->xid, &gtid); /* transaction holding lock */
1569+
ByteBufferAppendInt32(buf, gtid.node);
1570+
ByteBufferAppendInt32(buf, gtid.xid);
1571+
break;
1572+
}
1573+
}
1574+
}
1575+
}
1576+
proclock = (PROCLOCK *) SHMQueueNext(procLocks, &proclock->lockLink,
1577+
offsetof(PROCLOCK, lockLink));
1578+
}
1579+
ByteBufferAppendInt32(buf, 0); /* end of lock owners list */
1580+
ByteBufferAppendInt32(buf, 0); /* end of lock owners list */
1581+
}
1582+
}
1583+
}
1584+
1585+
void MtmSerializeLockGraph(ByteBuffer* buf)
1586+
{
1587+
EnumerateLocks(MtmSerializeLock, buf);
1588+
}

contrib/mmts/multimaster.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,6 @@ extern MtmState* MtmGetState(void);
145145
extern timestamp_t MtmGetCurrentTime(void);
146146
extern void MtmSleep(timestamp_t interval);
147147
extern bool MtmIsRecoveredNode(int nodeId);
148+
extern void MtmSerializeLockGraph(ByteBuffer* buf);
149+
148150
#endif

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