Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8b6595d

Browse files
committed
Replace locking_backendid with locking_pid in twophase
1 parent 076234f commit 8b6595d

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/backend/access/transam/twophase.c

+14-16
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ typedef struct GlobalTransactionData
150150
XLogRecPtr prepare_end_lsn; /* XLOG offset of prepare record end */
151151

152152
Oid owner; /* ID of user that executed the xact */
153-
BackendId locking_backend; /* backend currently working on the xact */
153+
int locking_pid; /* backend currently working on the xact */
154154
bool valid; /* TRUE if PGPROC entry is in proc array */
155155
bool ondisk; /* TRUE if prepare state file is on disk */
156156
int prep_index; /* Index of prepXacts array */
@@ -358,6 +358,7 @@ TwoPhaseShmemInit(void)
358358
*/
359359
gxacts[i].dummyBackendId = MaxBackends + 1 + i;
360360
SpinLockInit(&gxacts[i].spinlock);
361+
gxacts[i].locking_pid = -1;
361362
}
362363
}
363364
else
@@ -382,7 +383,7 @@ AtAbort_Twophase(void)
382383
{
383384
if (MyLockedGxact == NULL)
384385
return;
385-
386+
Assert(MyLockedGxact->locking_pid >= 0);
386387
/*
387388
* What to do with the locked global transaction entry? If we were in the
388389
* process of preparing the transaction, but haven't written the WAL
@@ -409,7 +410,7 @@ AtAbort_Twophase(void)
409410
}
410411
else
411412
{
412-
MyLockedGxact->locking_backend = InvalidBackendId;
413+
MyLockedGxact->locking_pid = -1;
413414
SpinLockRelease(&MyLockedGxact->spinlock);
414415
}
415416
MyLockedGxact = NULL;
@@ -422,8 +423,8 @@ AtAbort_Twophase(void)
422423
void
423424
PostPrepare_Twophase(void)
424425
{
425-
Assert(MyLockedGxact->locking_backend != InvalidBackendId);
426-
MyLockedGxact->locking_backend = InvalidBackendId;
426+
Assert(MyLockedGxact->locking_pid >= 0);
427+
MyLockedGxact->locking_pid = -1;
427428
SpinLockRelease(&MyLockedGxact->spinlock);
428429
MyLockedGxact = NULL;
429430
}
@@ -496,6 +497,8 @@ MarkAsPreparing(TransactionId xid, const char *gid,
496497
SpinLockAcquire(&gxact->spinlock);
497498
LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
498499

500+
Assert(gxact->locking_pid < 0);
501+
499502
/* Include in collision chain */
500503
gxact->next = TwoPhaseState->hashTable[i];
501504
TwoPhaseState->hashTable[i] = gxact;
@@ -537,9 +540,9 @@ MarkAsPreparing(TransactionId xid, const char *gid,
537540
gxact->prepare_start_lsn = InvalidXLogRecPtr;
538541
gxact->prepare_end_lsn = InvalidXLogRecPtr;
539542
gxact->owner = owner;
540-
gxact->locking_backend = MyBackendId;
543+
gxact->locking_pid = MyProcPid;
541544
gxact->valid = false;
542-
gxact->ondisk = false;
545+
gxact->ondisk = false;
543546
gxact->prep_index = TwoPhaseState->numPrepXacts;
544547
strcpy(gxact->gid, gid);
545548
*gxact->state_3pc = '\0';
@@ -646,14 +649,6 @@ LockGXact(const char *gid, Oid user)
646649
errmsg("prepared transaction with identifier \"%s\" is not valid",
647650
gid)));
648651
}
649-
/* Found it, but has someone else got it locked? */
650-
if (gxact->locking_backend != InvalidBackendId) {
651-
SpinLockRelease(&gxact->spinlock);
652-
ereport(ERROR,
653-
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
654-
errmsg("prepared transaction with identifier \"%s\" is busy",
655-
gid)));
656-
}
657652

658653
if (user != gxact->owner && !superuser_arg(user)) {
659654
SpinLockRelease(&gxact->spinlock);
@@ -679,7 +674,8 @@ LockGXact(const char *gid, Oid user)
679674

680675

681676
/* OK for me to lock it */
682-
gxact->locking_backend = MyBackendId;
677+
Assert(gxact->locking_pid < 0);
678+
gxact->locking_pid = MyProcPid;
683679
MyLockedGxact = gxact;
684680

685681
return gxact;
@@ -729,6 +725,8 @@ RemoveGXact(GlobalTransaction gxact)
729725
gxact->next = TwoPhaseState->freeGXacts;
730726
TwoPhaseState->freeGXacts = gxact;
731727

728+
gxact->locking_pid = -1;
729+
732730
LWLockRelease(TwoPhaseStateLock);
733731
SpinLockRelease(&gxact->spinlock);
734732

0 commit comments

Comments
 (0)