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

Commita513f1d

Browse files
committed
Remove STATUS_WAITING
Add a separate enum for use in the locking APIs, which were the onlyuser.Discussion:https://www.postgresql.org/message-id/flat/a6f91ead-0ce4-2a34-062b-7ab9813ea308%402ndquadrant.com
1 parent42aa1f0 commita513f1d

File tree

5 files changed

+38
-32
lines changed

5 files changed

+38
-32
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ MarkAsPreparingGuts(GlobalTransaction gxact, TransactionId xid, const char *gid,
460460
MemSet(proc,0,sizeof(PGPROC));
461461
proc->pgprocno=gxact->pgprocno;
462462
SHMQueueElemInit(&(proc->links));
463-
proc->waitStatus=STATUS_OK;
463+
proc->waitStatus=PROC_WAIT_STATUS_OK;
464464
/* We set up the gxact's VXID as InvalidBackendId/XID */
465465
proc->lxid= (LocalTransactionId)xid;
466466
pgxact->xid=xid;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@ WaitOnLock(LOCALLOCK *locallock, ResourceOwner owner)
18561856
*/
18571857
PG_TRY();
18581858
{
1859-
if (ProcSleep(locallock,lockMethodTable)!=STATUS_OK)
1859+
if (ProcSleep(locallock,lockMethodTable)!=PROC_WAIT_STATUS_OK)
18601860
{
18611861
/*
18621862
* We failed as a result of a deadlock, see CheckDeadLock(). Quit
@@ -1907,7 +1907,7 @@ WaitOnLock(LOCALLOCK *locallock, ResourceOwner owner)
19071907
/*
19081908
* Remove a proc from the wait-queue it is on (caller must know it is on one).
19091909
* This is only used when the proc has failed to get the lock, so we set its
1910-
* waitStatus toSTATUS_ERROR.
1910+
* waitStatus toPROC_WAIT_STATUS_ERROR.
19111911
*
19121912
* Appropriate partition lock must be held by caller. Also, caller is
19131913
* responsible for signaling the proc if needed.
@@ -1923,7 +1923,7 @@ RemoveFromWaitQueue(PGPROC *proc, uint32 hashcode)
19231923
LOCKMETHODIDlockmethodid=LOCK_LOCKMETHOD(*waitLock);
19241924

19251925
/* Make sure proc is waiting */
1926-
Assert(proc->waitStatus==STATUS_WAITING);
1926+
Assert(proc->waitStatus==PROC_WAIT_STATUS_WAITING);
19271927
Assert(proc->links.next!=NULL);
19281928
Assert(waitLock);
19291929
Assert(waitLock->waitProcs.size>0);
@@ -1946,7 +1946,7 @@ RemoveFromWaitQueue(PGPROC *proc, uint32 hashcode)
19461946
/* Clean up the proc's own state, and pass it the ok/fail signal */
19471947
proc->waitLock=NULL;
19481948
proc->waitProcLock=NULL;
1949-
proc->waitStatus=STATUS_ERROR;
1949+
proc->waitStatus=PROC_WAIT_STATUS_ERROR;
19501950

19511951
/*
19521952
* Delete the proclock immediately if it represents no already-held locks.

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ InitProcess(void)
383383
* initialized by InitProcGlobal.
384384
*/
385385
SHMQueueElemInit(&(MyProc->links));
386-
MyProc->waitStatus=STATUS_OK;
386+
MyProc->waitStatus=PROC_WAIT_STATUS_OK;
387387
MyProc->lxid=InvalidLocalTransactionId;
388388
MyProc->fpVXIDLock= false;
389389
MyProc->fpLocalTransactionId=InvalidLocalTransactionId;
@@ -567,7 +567,7 @@ InitAuxiliaryProcess(void)
567567
* initialized by InitProcGlobal.
568568
*/
569569
SHMQueueElemInit(&(MyProc->links));
570-
MyProc->waitStatus=STATUS_OK;
570+
MyProc->waitStatus=PROC_WAIT_STATUS_OK;
571571
MyProc->lxid=InvalidLocalTransactionId;
572572
MyProc->fpVXIDLock= false;
573573
MyProc->fpLocalTransactionId=InvalidLocalTransactionId;
@@ -755,7 +755,7 @@ LockErrorCleanup(void)
755755
* did grant us the lock, we'd better remember it in our local lock
756756
* table.
757757
*/
758-
if (MyProc->waitStatus==STATUS_OK)
758+
if (MyProc->waitStatus==PROC_WAIT_STATUS_OK)
759759
GrantAwaitedLock();
760760
}
761761

@@ -1051,14 +1051,14 @@ ProcQueueInit(PROC_QUEUE *queue)
10511051
* The lock table's partition lock must be held at entry, and will be held
10521052
* at exit.
10531053
*
1054-
* Result:STATUS_OK if we acquired the lock,STATUS_ERROR if not (deadlock).
1054+
* Result:PROC_WAIT_STATUS_OK if we acquired the lock,PROC_WAIT_STATUS_ERROR if not (deadlock).
10551055
*
10561056
* ASSUME: that no one will fiddle with the queue until after
10571057
*we release the partition lock.
10581058
*
10591059
* NOTES: The process queue is now a priority queue for locking.
10601060
*/
1061-
int
1061+
ProcWaitStatus
10621062
ProcSleep(LOCALLOCK*locallock,LockMethodlockMethodTable)
10631063
{
10641064
LOCKMODElockmode=locallock->tag.mode;
@@ -1070,7 +1070,7 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
10701070
LOCKMASKmyHeldLocks=MyProc->heldLocks;
10711071
boolearly_deadlock= false;
10721072
boolallow_autovacuum_cancel= true;
1073-
intmyWaitStatus;
1073+
ProcWaitStatusmyWaitStatus;
10741074
PGPROC*proc;
10751075
PGPROC*leader=MyProc->lockGroupLeader;
10761076
inti;
@@ -1161,7 +1161,7 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
11611161
/* Skip the wait and just grant myself the lock. */
11621162
GrantLock(lock,proclock,lockmode);
11631163
GrantAwaitedLock();
1164-
returnSTATUS_OK;
1164+
returnPROC_WAIT_STATUS_OK;
11651165
}
11661166
/* Break out of loop to put myself before him */
11671167
break;
@@ -1195,7 +1195,7 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
11951195
MyProc->waitProcLock=proclock;
11961196
MyProc->waitLockMode=lockmode;
11971197

1198-
MyProc->waitStatus=STATUS_WAITING;
1198+
MyProc->waitStatus=PROC_WAIT_STATUS_WAITING;
11991199

12001200
/*
12011201
* If we detected deadlock, give up without waiting. This must agree with
@@ -1204,7 +1204,7 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
12041204
if (early_deadlock)
12051205
{
12061206
RemoveFromWaitQueue(MyProc,hashcode);
1207-
returnSTATUS_ERROR;
1207+
returnPROC_WAIT_STATUS_ERROR;
12081208
}
12091209

12101210
/* mark that we are waiting for a lock */
@@ -1236,7 +1236,7 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
12361236
/*
12371237
* Set timer so we can wake up after awhile and check for a deadlock. If a
12381238
* deadlock is detected, the handler sets MyProc->waitStatus =
1239-
*STATUS_ERROR, allowing us to know that we must report failure rather
1239+
*PROC_WAIT_STATUS_ERROR, allowing us to know that we must report failure rather
12401240
* than success.
12411241
*
12421242
* By delaying the check until we've waited for a bit, we can avoid
@@ -1302,11 +1302,11 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
13021302
}
13031303

13041304
/*
1305-
* waitStatus could change fromSTATUS_WAITING to something else
1305+
* waitStatus could change fromPROC_WAIT_STATUS_WAITING to something else
13061306
* asynchronously. Read it just once per loop to prevent surprising
13071307
* behavior (such as missing log messages).
13081308
*/
1309-
myWaitStatus=*((volatileint*)&MyProc->waitStatus);
1309+
myWaitStatus=*((volatileProcWaitStatus*)&MyProc->waitStatus);
13101310

13111311
/*
13121312
* If we are not deadlocked, but are waiting on an autovacuum-induced
@@ -1487,24 +1487,24 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
14871487
lockHoldersNum,lock_holders_sbuf.data,lock_waiters_sbuf.data))));
14881488
}
14891489

1490-
if (myWaitStatus==STATUS_WAITING)
1490+
if (myWaitStatus==PROC_WAIT_STATUS_WAITING)
14911491
ereport(LOG,
14921492
(errmsg("process %d still waiting for %s on %s after %ld.%03d ms",
14931493
MyProcPid,modename,buf.data,msecs,usecs),
14941494
(errdetail_log_plural("Process holding the lock: %s. Wait queue: %s.",
14951495
"Processes holding the lock: %s. Wait queue: %s.",
14961496
lockHoldersNum,lock_holders_sbuf.data,lock_waiters_sbuf.data))));
1497-
elseif (myWaitStatus==STATUS_OK)
1497+
elseif (myWaitStatus==PROC_WAIT_STATUS_OK)
14981498
ereport(LOG,
14991499
(errmsg("process %d acquired %s on %s after %ld.%03d ms",
15001500
MyProcPid,modename,buf.data,msecs,usecs)));
15011501
else
15021502
{
1503-
Assert(myWaitStatus==STATUS_ERROR);
1503+
Assert(myWaitStatus==PROC_WAIT_STATUS_ERROR);
15041504

15051505
/*
15061506
* Currently, the deadlock checker always kicks its own
1507-
* process, which means that we'll only seeSTATUS_ERROR when
1507+
* process, which means that we'll only seePROC_WAIT_STATUS_ERROR when
15081508
* deadlock_state == DS_HARD_DEADLOCK, and there's no need to
15091509
* print redundant messages. But for completeness and
15101510
* future-proofing, print a message if it looks like someone
@@ -1529,7 +1529,7 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
15291529
pfree(lock_holders_sbuf.data);
15301530
pfree(lock_waiters_sbuf.data);
15311531
}
1532-
}while (myWaitStatus==STATUS_WAITING);
1532+
}while (myWaitStatus==PROC_WAIT_STATUS_WAITING);
15331533

15341534
/*
15351535
* Disable the timers, if they are still running. As in LockErrorCleanup,
@@ -1568,7 +1568,7 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
15681568
/*
15691569
* If we got the lock, be sure to remember it in the locallock table.
15701570
*/
1571-
if (MyProc->waitStatus==STATUS_OK)
1571+
if (MyProc->waitStatus==PROC_WAIT_STATUS_OK)
15721572
GrantAwaitedLock();
15731573

15741574
/*
@@ -1590,18 +1590,18 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
15901590
* XXX: presently, this code is only used for the "success" case, and only
15911591
* works correctly for that case. To clean up in failure case, would need
15921592
* to twiddle the lock's request counts too --- see RemoveFromWaitQueue.
1593-
* Hence, in practice the waitStatus parameter must beSTATUS_OK.
1593+
* Hence, in practice the waitStatus parameter must bePROC_WAIT_STATUS_OK.
15941594
*/
15951595
PGPROC*
1596-
ProcWakeup(PGPROC*proc,intwaitStatus)
1596+
ProcWakeup(PGPROC*proc,ProcWaitStatuswaitStatus)
15971597
{
15981598
PGPROC*retProc;
15991599

16001600
/* Proc should be sleeping ... */
16011601
if (proc->links.prev==NULL||
16021602
proc->links.next==NULL)
16031603
returnNULL;
1604-
Assert(proc->waitStatus==STATUS_WAITING);
1604+
Assert(proc->waitStatus==PROC_WAIT_STATUS_WAITING);
16051605

16061606
/* Save next process before we zap the list link */
16071607
retProc= (PGPROC*)proc->links.next;
@@ -1657,7 +1657,7 @@ ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock)
16571657
{
16581658
/* OK to waken */
16591659
GrantLock(lock,proc->waitProcLock,lockmode);
1660-
proc=ProcWakeup(proc,STATUS_OK);
1660+
proc=ProcWakeup(proc,PROC_WAIT_STATUS_OK);
16611661

16621662
/*
16631663
* ProcWakeup removes proc from the lock's waiting process queue
@@ -1737,7 +1737,7 @@ CheckDeadLock(void)
17371737
* preserve the flexibility to kill some other transaction than the
17381738
* one detecting the deadlock.)
17391739
*
1740-
* RemoveFromWaitQueue sets MyProc->waitStatus toSTATUS_ERROR, so
1740+
* RemoveFromWaitQueue sets MyProc->waitStatus toPROC_WAIT_STATUS_ERROR, so
17411741
* ProcSleep will report an error after we return from the signal
17421742
* handler.
17431743
*/

‎src/include/c.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,6 @@ typedef union PGAlignedXLogBlock
11331133
#defineSTATUS_OK(0)
11341134
#defineSTATUS_ERROR(-1)
11351135
#defineSTATUS_EOF(-2)
1136-
#defineSTATUS_WAITING(2)
11371136

11381137
/*
11391138
* gettext support

‎src/include/storage/proc.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ struct XidCache
7676
*/
7777
#defineINVALID_PGPROCNOPG_INT32_MAX
7878

79+
typedefenum
80+
{
81+
PROC_WAIT_STATUS_OK,
82+
PROC_WAIT_STATUS_WAITING,
83+
PROC_WAIT_STATUS_ERROR,
84+
}ProcWaitStatus;
85+
7986
/*
8087
* Each backend has a PGPROC struct in shared memory. There is also a list of
8188
* currently-unused PGPROC structs that will be reallocated to new backends.
@@ -99,7 +106,7 @@ struct PGPROC
99106
PGPROC**procgloballist;/* procglobal list that owns this PGPROC */
100107

101108
PGSemaphoresem;/* ONE semaphore to sleep on */
102-
intwaitStatus;/* STATUS_WAITING, STATUS_OK or STATUS_ERROR */
109+
ProcWaitStatuswaitStatus;
103110

104111
LatchprocLatch;/* generic latch for process */
105112

@@ -315,8 +322,8 @@ extern bool HaveNFreeProcs(int n);
315322
externvoidProcReleaseLocks(boolisCommit);
316323

317324
externvoidProcQueueInit(PROC_QUEUE*queue);
318-
externintProcSleep(LOCALLOCK*locallock,LockMethodlockMethodTable);
319-
externPGPROC*ProcWakeup(PGPROC*proc,intwaitStatus);
325+
externProcWaitStatusProcSleep(LOCALLOCK*locallock,LockMethodlockMethodTable);
326+
externPGPROC*ProcWakeup(PGPROC*proc,ProcWaitStatuswaitStatus);
320327
externvoidProcLockWakeup(LockMethodlockMethodTable,LOCK*lock);
321328
externvoidCheckDeadLockAlert(void);
322329
externboolIsWaitingForLock(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp