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

Commit28f3915

Browse files
committed
Remove superfluous 'pgprocno' field from PGPROC
It was always just the index of the PGPROC entry from the beginning ofthe proc array. Introduce a macro to compute it from the pointerinstead.Reviewed-by: Andres FreundDiscussion:https://www.postgresql.org/message-id/8171f1aa-496f-46a6-afc3-c46fe7a9b407@iki.fi
1 parent4989ce7 commit28f3915

File tree

14 files changed

+46
-43
lines changed

14 files changed

+46
-43
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
425425
{
426426
volatilePROC_HDR*procglobal=ProcGlobal;
427427
PGPROC*proc=MyProc;
428+
intpgprocno=MyProcNumber;
428429
uint32nextidx;
429430
uint32wakeidx;
430431

@@ -458,7 +459,7 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
458459
* less efficiently.
459460
*/
460461
if (nextidx!=INVALID_PGPROCNO&&
461-
ProcGlobal->allProcs[nextidx].clogGroupMemberPage!=proc->clogGroupMemberPage)
462+
GetPGProcByNumber(nextidx)->clogGroupMemberPage!=proc->clogGroupMemberPage)
462463
{
463464
/*
464465
* Ensure that this proc is not a member of any clog group that
@@ -473,7 +474,7 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
473474

474475
if (pg_atomic_compare_exchange_u32(&procglobal->clogGroupFirst,
475476
&nextidx,
476-
(uint32)proc->pgprocno))
477+
(uint32)pgprocno))
477478
break;
478479
}
479480

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ TwoPhaseShmemInit(void)
284284
TwoPhaseState->freeGXacts=&gxacts[i];
285285

286286
/* associate it with a PGPROC assigned by InitProcGlobal */
287-
gxacts[i].pgprocno=PreparedXactProcs[i].pgprocno;
287+
gxacts[i].pgprocno=GetNumberFromPGProc(&PreparedXactProcs[i]);
288288

289289
/*
290290
* Assign a unique ID for each dummy proc, so that the range of
@@ -461,7 +461,6 @@ MarkAsPreparingGuts(GlobalTransaction gxact, TransactionId xid, const char *gid,
461461

462462
/* Initialize the PGPROC entry */
463463
MemSet(proc,0,sizeof(PGPROC));
464-
proc->pgprocno=gxact->pgprocno;
465464
dlist_node_init(&proc->links);
466465
proc->waitStatus=PROC_WAIT_STATUS_OK;
467466
if (LocalTransactionIdIsValid(MyProc->lxid))
@@ -780,7 +779,7 @@ pg_prepared_xact(PG_FUNCTION_ARGS)
780779
while (status->array!=NULL&&status->currIdx<status->ngxacts)
781780
{
782781
GlobalTransactiongxact=&status->array[status->currIdx++];
783-
PGPROC*proc=&ProcGlobal->allProcs[gxact->pgprocno];
782+
PGPROC*proc=GetPGProcByNumber(gxact->pgprocno);
784783
Datumvalues[5]= {0};
785784
boolnulls[5]= {0};
786785
HeapTupletuple;
@@ -935,7 +934,7 @@ TwoPhaseGetDummyProc(TransactionId xid, bool lock_held)
935934
{
936935
GlobalTransactiongxact=TwoPhaseGetGXact(xid,lock_held);
937936

938-
return&ProcGlobal->allProcs[gxact->pgprocno];
937+
returnGetPGProcByNumber(gxact->pgprocno);
939938
}
940939

941940
/************************************************************************/
@@ -1080,7 +1079,7 @@ save_state_data(const void *data, uint32 len)
10801079
void
10811080
StartPrepare(GlobalTransactiongxact)
10821081
{
1083-
PGPROC*proc=&ProcGlobal->allProcs[gxact->pgprocno];
1082+
PGPROC*proc=GetPGProcByNumber(gxact->pgprocno);
10841083
TransactionIdxid=gxact->xid;
10851084
TwoPhaseFileHeaderhdr;
10861085
TransactionId*children;
@@ -1539,7 +1538,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
15391538
* try to commit the same GID at once.
15401539
*/
15411540
gxact=LockGXact(gid,GetUserId());
1542-
proc=&ProcGlobal->allProcs[gxact->pgprocno];
1541+
proc=GetPGProcByNumber(gxact->pgprocno);
15431542
xid=gxact->xid;
15441543

15451544
/*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ WALInsertLockAcquire(void)
13791379
staticintlockToTry=-1;
13801380

13811381
if (lockToTry==-1)
1382-
lockToTry=MyProc->pgprocno %NUM_XLOGINSERT_LOCKS;
1382+
lockToTry=MyProcNumber %NUM_XLOGINSERT_LOCKS;
13831383
MyLockNo=lockToTry;
13841384

13851385
/*

‎src/backend/postmaster/bgwriter.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ BackgroundWriterMain(void)
326326
if (rc==WL_TIMEOUT&&can_hibernate&&prev_hibernate)
327327
{
328328
/* Ask for notification at next buffer allocation */
329-
StrategyNotifyBgWriter(MyProc->pgprocno);
329+
StrategyNotifyBgWriter(MyProcNumber);
330330
/* Sleep ... */
331331
(void)WaitLatch(MyLatch,
332332
WL_LATCH_SET |WL_TIMEOUT |WL_EXIT_ON_PM_DEATH,

‎src/backend/postmaster/pgarch.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ PgArchiverMain(void)
242242
* Advertise our pgprocno so that backends can use our latch to wake us up
243243
* while we're sleeping.
244244
*/
245-
PgArch->pgprocno=MyProc->pgprocno;
245+
PgArch->pgprocno=MyProcNumber;
246246

247247
/* Create workspace for pgarch_readyXlog() */
248248
arch_files=palloc(sizeof(structarch_files_state));

‎src/backend/postmaster/walsummarizer.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ WalSummarizerMain(void)
248248
/* Advertise ourselves. */
249249
on_shmem_exit(WalSummarizerShutdown, (Datum)0);
250250
LWLockAcquire(WALSummarizerLock,LW_EXCLUSIVE);
251-
WalSummarizerCtl->summarizer_pgprocno=MyProc->pgprocno;
251+
WalSummarizerCtl->summarizer_pgprocno=MyProcNumber;
252252
LWLockRelease(WALSummarizerLock);
253253

254254
/* Create and switch to a memory context that we can reset on error. */

‎src/backend/storage/buffer/bufmgr.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4780,7 +4780,7 @@ UnlockBuffers(void)
47804780
* got a cancel/die interrupt before getting the signal.
47814781
*/
47824782
if ((buf_state&BM_PIN_COUNT_WAITER)!=0&&
4783-
buf->wait_backend_pgprocno==MyProc->pgprocno)
4783+
buf->wait_backend_pgprocno==MyProcNumber)
47844784
buf_state &= ~BM_PIN_COUNT_WAITER;
47854785

47864786
UnlockBufHdr(buf,buf_state);
@@ -4930,7 +4930,7 @@ LockBufferForCleanup(Buffer buffer)
49304930
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
49314931
elog(ERROR,"multiple backends attempting to wait for pincount 1");
49324932
}
4933-
bufHdr->wait_backend_pgprocno=MyProc->pgprocno;
4933+
bufHdr->wait_backend_pgprocno=MyProcNumber;
49344934
PinCountWaitBuf=bufHdr;
49354935
buf_state |=BM_PIN_COUNT_WAITER;
49364936
UnlockBufHdr(bufHdr,buf_state);
@@ -4994,7 +4994,7 @@ LockBufferForCleanup(Buffer buffer)
49944994
*/
49954995
buf_state=LockBufHdr(bufHdr);
49964996
if ((buf_state&BM_PIN_COUNT_WAITER)!=0&&
4997-
bufHdr->wait_backend_pgprocno==MyProc->pgprocno)
4997+
bufHdr->wait_backend_pgprocno==MyProcNumber)
49984998
buf_state &= ~BM_PIN_COUNT_WAITER;
49994999
UnlockBufHdr(bufHdr,buf_state);
50005000

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ CreateSharedProcArray(void)
468468
void
469469
ProcArrayAdd(PGPROC*proc)
470470
{
471+
intpgprocno=GetNumberFromPGProc(proc);
471472
ProcArrayStruct*arrayP=procArray;
472473
intindex;
473474
intmovecount;
@@ -499,13 +500,13 @@ ProcArrayAdd(PGPROC *proc)
499500
*/
500501
for (index=0;index<arrayP->numProcs;index++)
501502
{
502-
intprocnoPG_USED_FOR_ASSERTS_ONLY=arrayP->pgprocnos[index];
503+
intthis_procno=arrayP->pgprocnos[index];
503504

504-
Assert(procno >=0&&procno< (arrayP->maxProcs+NUM_AUXILIARY_PROCS));
505-
Assert(allProcs[procno].pgxactoff==index);
505+
Assert(this_procno >=0&&this_procno< (arrayP->maxProcs+NUM_AUXILIARY_PROCS));
506+
Assert(allProcs[this_procno].pgxactoff==index);
506507

507508
/* If we have found our right position in the array, break */
508-
if (arrayP->pgprocnos[index]>proc->pgprocno)
509+
if (this_procno>pgprocno)
509510
break;
510511
}
511512

@@ -523,7 +524,7 @@ ProcArrayAdd(PGPROC *proc)
523524
&ProcGlobal->statusFlags[index],
524525
movecount*sizeof(*ProcGlobal->statusFlags));
525526

526-
arrayP->pgprocnos[index]=proc->pgprocno;
527+
arrayP->pgprocnos[index]=GetNumberFromPGProc(proc);
527528
proc->pgxactoff=index;
528529
ProcGlobal->xids[index]=proc->xid;
529530
ProcGlobal->subxidStates[index]=proc->subxidStatus;
@@ -791,6 +792,7 @@ ProcArrayEndTransactionInternal(PGPROC *proc, TransactionId latestXid)
791792
staticvoid
792793
ProcArrayGroupClearXid(PGPROC*proc,TransactionIdlatestXid)
793794
{
795+
intpgprocno=GetNumberFromPGProc(proc);
794796
PROC_HDR*procglobal=ProcGlobal;
795797
uint32nextidx;
796798
uint32wakeidx;
@@ -808,7 +810,7 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
808810

809811
if (pg_atomic_compare_exchange_u32(&procglobal->procArrayGroupFirst,
810812
&nextidx,
811-
(uint32)proc->pgprocno))
813+
(uint32)pgprocno))
812814
break;
813815
}
814816

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ConditionVariableInit(ConditionVariable *cv)
5757
void
5858
ConditionVariablePrepareToSleep(ConditionVariable*cv)
5959
{
60-
intpgprocno=MyProc->pgprocno;
60+
intpgprocno=MyProcNumber;
6161

6262
/*
6363
* If some other sleep is already prepared, cancel it; this is necessary
@@ -181,10 +181,10 @@ ConditionVariableTimedSleep(ConditionVariable *cv, long timeout,
181181
* guarantee not to return spuriously, we'll avoid this obvious case.
182182
*/
183183
SpinLockAcquire(&cv->mutex);
184-
if (!proclist_contains(&cv->wakeup,MyProc->pgprocno,cvWaitLink))
184+
if (!proclist_contains(&cv->wakeup,MyProcNumber,cvWaitLink))
185185
{
186186
done= true;
187-
proclist_push_tail(&cv->wakeup,MyProc->pgprocno,cvWaitLink);
187+
proclist_push_tail(&cv->wakeup,MyProcNumber,cvWaitLink);
188188
}
189189
SpinLockRelease(&cv->mutex);
190190

@@ -236,8 +236,8 @@ ConditionVariableCancelSleep(void)
236236
return false;
237237

238238
SpinLockAcquire(&cv->mutex);
239-
if (proclist_contains(&cv->wakeup,MyProc->pgprocno,cvWaitLink))
240-
proclist_delete(&cv->wakeup,MyProc->pgprocno,cvWaitLink);
239+
if (proclist_contains(&cv->wakeup,MyProcNumber,cvWaitLink))
240+
proclist_delete(&cv->wakeup,MyProcNumber,cvWaitLink);
241241
else
242242
signaled= true;
243243
SpinLockRelease(&cv->mutex);
@@ -281,7 +281,7 @@ ConditionVariableSignal(ConditionVariable *cv)
281281
void
282282
ConditionVariableBroadcast(ConditionVariable*cv)
283283
{
284-
intpgprocno=MyProc->pgprocno;
284+
intpgprocno=MyProcNumber;
285285
PGPROC*proc=NULL;
286286
boolhave_sentinel= false;
287287

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,9 +1056,9 @@ LWLockQueueSelf(LWLock *lock, LWLockMode mode)
10561056

10571057
/* LW_WAIT_UNTIL_FREE waiters are always at the front of the queue */
10581058
if (mode==LW_WAIT_UNTIL_FREE)
1059-
proclist_push_head(&lock->waiters,MyProc->pgprocno,lwWaitLink);
1059+
proclist_push_head(&lock->waiters,MyProcNumber,lwWaitLink);
10601060
else
1061-
proclist_push_tail(&lock->waiters,MyProc->pgprocno,lwWaitLink);
1061+
proclist_push_tail(&lock->waiters,MyProcNumber,lwWaitLink);
10621062

10631063
/* Can release the mutex now */
10641064
LWLockWaitListUnlock(lock);
@@ -1097,7 +1097,7 @@ LWLockDequeueSelf(LWLock *lock)
10971097
*/
10981098
on_waitlist=MyProc->lwWaiting==LW_WS_WAITING;
10991099
if (on_waitlist)
1100-
proclist_delete(&lock->waiters,MyProc->pgprocno,lwWaitLink);
1100+
proclist_delete(&lock->waiters,MyProcNumber,lwWaitLink);
11011101

11021102
if (proclist_is_empty(&lock->waiters)&&
11031103
(pg_atomic_read_u32(&lock->state)&LW_FLAG_HAS_WAITERS)!=0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp