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

Commit393b559

Browse files
committed
Use MyBackendType in more places to check what process this is
Remove IsBackgroundWorker, IsAutoVacuumLauncherProcess(),IsAutoVacuumWorkerProcess(), and IsLogicalSlotSyncWorker() in favor ofnew Am*Process() macros that use MyBackendType. For consistency withthe existing Am*Process() macros.Reviewed-by: Andres FreundDiscussion:https://www.postgresql.org/message-id/f3ecd4cb-85ee-4e54-8278-5fabfb3a4ed0@iki.fi
1 parent067701f commit393b559

File tree

20 files changed

+42
-91
lines changed

20 files changed

+42
-91
lines changed

‎src/backend/access/gin/ginfast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ ginInsertCleanup(GinState *ginstate, bool full_clean,
812812
*/
813813
LockPage(index,GIN_METAPAGE_BLKNO,ExclusiveLock);
814814
workMemory=
815-
(IsAutoVacuumWorkerProcess()&&autovacuum_work_mem!=-1) ?
815+
(AmAutoVacuumWorkerProcess()&&autovacuum_work_mem!=-1) ?
816816
autovacuum_work_mem :maintenance_work_mem;
817817
}
818818
else

‎src/backend/access/gin/ginvacuum.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ ginbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
590590
/*
591591
* and cleanup any pending inserts
592592
*/
593-
ginInsertCleanup(&gvs.ginstate, !IsAutoVacuumWorkerProcess(),
593+
ginInsertCleanup(&gvs.ginstate, !AmAutoVacuumWorkerProcess(),
594594
false, true,stats);
595595
}
596596

@@ -701,7 +701,7 @@ ginvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
701701
*/
702702
if (info->analyze_only)
703703
{
704-
if (IsAutoVacuumWorkerProcess())
704+
if (AmAutoVacuumWorkerProcess())
705705
{
706706
initGinState(&ginstate,index);
707707
ginInsertCleanup(&ginstate, false, true, true,stats);
@@ -717,7 +717,7 @@ ginvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
717717
{
718718
stats= (IndexBulkDeleteResult*)palloc0(sizeof(IndexBulkDeleteResult));
719719
initGinState(&ginstate,index);
720-
ginInsertCleanup(&ginstate, !IsAutoVacuumWorkerProcess(),
720+
ginInsertCleanup(&ginstate, !AmAutoVacuumWorkerProcess(),
721721
false, true,stats);
722722
}
723723

‎src/backend/access/heap/vacuumlazy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
307307
char**indnames=NULL;
308308

309309
verbose= (params->options&VACOPT_VERBOSE)!=0;
310-
instrument= (verbose|| (IsAutoVacuumWorkerProcess()&&
310+
instrument= (verbose|| (AmAutoVacuumWorkerProcess()&&
311311
params->log_min_duration >=0));
312312
if (instrument)
313313
{
@@ -3087,7 +3087,7 @@ static int
30873087
dead_items_max_items(LVRelState*vacrel)
30883088
{
30893089
int64max_items;
3090-
intvac_work_mem=IsAutoVacuumWorkerProcess()&&
3090+
intvac_work_mem=AmAutoVacuumWorkerProcess()&&
30913091
autovacuum_work_mem!=-1 ?
30923092
autovacuum_work_mem :maintenance_work_mem;
30933093

‎src/backend/commands/analyze.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
351351
save_nestlevel=NewGUCNestLevel();
352352

353353
/* measure elapsed time iff autovacuum logging requires it */
354-
if (IsAutoVacuumWorkerProcess()&&params->log_min_duration >=0)
354+
if (AmAutoVacuumWorkerProcess()&&params->log_min_duration >=0)
355355
{
356356
if (track_io_timing)
357357
{
@@ -729,7 +729,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
729729
vac_close_indexes(nindexes,Irel,NoLock);
730730

731731
/* Log the action if appropriate */
732-
if (IsAutoVacuumWorkerProcess()&&params->log_min_duration >=0)
732+
if (AmAutoVacuumWorkerProcess()&&params->log_min_duration >=0)
733733
{
734734
TimestampTzendtime=GetCurrentTimestamp();
735735

‎src/backend/commands/vacuum.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy,
564564
else
565565
{
566566
Assert(params->options&VACOPT_ANALYZE);
567-
if (IsAutoVacuumWorkerProcess())
567+
if (AmAutoVacuumWorkerProcess())
568568
use_own_xacts= true;
569569
elseif (in_outer_xact)
570570
use_own_xacts= false;
@@ -809,7 +809,7 @@ vacuum_open_relation(Oid relid, RangeVar *relation, bits32 options,
809809
* statements in the permission checks; otherwise, only log if the caller
810810
* so requested.
811811
*/
812-
if (!IsAutoVacuumWorkerProcess())
812+
if (!AmAutoVacuumWorkerProcess())
813813
elevel=WARNING;
814814
elseif (verbose)
815815
elevel=LOG;
@@ -896,7 +896,7 @@ expand_vacuum_rel(VacuumRelation *vrel, MemoryContext vac_context,
896896
* Since autovacuum workers supply OIDs when calling vacuum(), no
897897
* autovacuum worker should reach this code.
898898
*/
899-
Assert(!IsAutoVacuumWorkerProcess());
899+
Assert(!AmAutoVacuumWorkerProcess());
900900

901901
/*
902902
* We transiently take AccessShareLock to protect the syscache lookup
@@ -2336,7 +2336,7 @@ vacuum_delay_point(void)
23362336
* [autovacuum_]vacuum_cost_delay to take effect while a table is being
23372337
* vacuumed or analyzed.
23382338
*/
2339-
if (ConfigReloadPending&&IsAutoVacuumWorkerProcess())
2339+
if (ConfigReloadPending&&AmAutoVacuumWorkerProcess())
23402340
{
23412341
ConfigReloadPending= false;
23422342
ProcessConfigFile(PGC_SIGHUP);

‎src/backend/postmaster/autovacuum.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ intLog_autovacuum_min_duration = 600000;
136136
#defineMIN_AUTOVAC_SLEEPTIME 100.0/* milliseconds */
137137
#defineMAX_AUTOVAC_SLEEPTIME 300/* seconds */
138138

139-
/* Flags to tell if we are in an autovacuum process */
140-
staticboolam_autovacuum_launcher= false;
141-
staticboolam_autovacuum_worker= false;
142-
143139
/*
144140
* Variables to save the cost-related storage parameters for the current
145141
* relation being vacuumed by this autovacuum worker. Using these, we can
@@ -436,8 +432,6 @@ AutoVacLauncherMain(int argc, char *argv[])
436432
{
437433
sigjmp_buflocal_sigjmp_buf;
438434

439-
am_autovacuum_launcher= true;
440-
441435
MyBackendType=B_AUTOVAC_LAUNCHER;
442436
init_ps_display(NULL);
443437

@@ -1491,8 +1485,6 @@ AutoVacWorkerMain(int argc, char *argv[])
14911485
sigjmp_buflocal_sigjmp_buf;
14921486
Oiddbid;
14931487

1494-
am_autovacuum_worker= true;
1495-
14961488
MyBackendType=B_AUTOVAC_WORKER;
14971489
init_ps_display(NULL);
14981490

@@ -3352,24 +3344,6 @@ autovac_init(void)
33523344
errhint("Enable the \"track_counts\" option.")));
33533345
}
33543346

3355-
/*
3356-
* IsAutoVacuum functions
3357-
*Return whether this is either a launcher autovacuum process or a worker
3358-
*process.
3359-
*/
3360-
bool
3361-
IsAutoVacuumLauncherProcess(void)
3362-
{
3363-
returnam_autovacuum_launcher;
3364-
}
3365-
3366-
bool
3367-
IsAutoVacuumWorkerProcess(void)
3368-
{
3369-
returnam_autovacuum_worker;
3370-
}
3371-
3372-
33733347
/*
33743348
* AutoVacuumShmemSize
33753349
*Compute space needed for autovacuum-related shared memory

‎src/backend/postmaster/bgworker.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,6 @@ BackgroundWorkerMain(void)
731731
if (worker==NULL)
732732
elog(FATAL,"unable to find bgworker entry");
733733

734-
IsBackgroundWorker= true;
735-
736734
MyBackendType=B_BG_WORKER;
737735
init_ps_display(worker->bgw_name);
738736

‎src/backend/postmaster/postmaster.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,9 +5000,6 @@ SubPostmasterMain(int argc, char *argv[])
50005000
}
50015001
if (strcmp(argv[1],"--forkbgworker")==0)
50025002
{
5003-
/* do this as early as possible; in particular, before InitProcess() */
5004-
IsBackgroundWorker= true;
5005-
50065003
/* Restore basic shared memory pointers */
50075004
InitShmemAccess(UsedShmemSegAddr);
50085005

‎src/backend/replication/logical/slotsync.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ static long sleep_ms = MIN_SLOTSYNC_WORKER_NAPTIME_MS;
113113
/* The restart interval for slot sync work used by postmaster */
114114
#defineSLOTSYNC_RESTART_INTERVAL_SEC 10
115115

116-
/* Flag to tell if we are in a slot sync worker process */
117-
staticboolam_slotsync_worker= false;
118-
119116
/*
120117
* Flag to tell if we are syncing replication slots. Unlike the 'syncing' flag
121118
* in SlotSyncCtxStruct, this flag is true only if the current process is
@@ -491,7 +488,7 @@ synchronize_one_slot(RemoteSlot *remote_slot, Oid remote_dbid)
491488
latestFlushPtr=GetStandbyFlushRecPtr(NULL);
492489
if (remote_slot->confirmed_lsn>latestFlushPtr)
493490
{
494-
ereport(am_slotsync_worker ?LOG :ERROR,
491+
ereport(AmLogicalSlotSyncWorkerProcess() ?LOG :ERROR,
495492
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
496493
errmsg("skipping slot synchronization as the received slot sync"
497494
" LSN %X/%X for slot \"%s\" is ahead of the standby position %X/%X",
@@ -1114,8 +1111,6 @@ ReplSlotSyncWorkerMain(int argc, char *argv[])
11141111
sigjmp_buflocal_sigjmp_buf;
11151112
StringInfoDataapp_name;
11161113

1117-
am_slotsync_worker= true;
1118-
11191114
MyBackendType=B_SLOTSYNC_WORKER;
11201115

11211116
init_ps_display(NULL);
@@ -1438,15 +1433,6 @@ IsSyncingReplicationSlots(void)
14381433
returnsyncing_slots;
14391434
}
14401435

1441-
/*
1442-
* Is current process a slot sync worker?
1443-
*/
1444-
bool
1445-
IsLogicalSlotSyncWorker(void)
1446-
{
1447-
returnam_slotsync_worker;
1448-
}
1449-
14501436
/*
14511437
* Amount of shared memory required for slot synchronization.
14521438
*/

‎src/backend/statistics/extended_stats.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ BuildRelationExtStatistics(Relation onerel, bool inh, double totalrows,
173173
natts,vacattrstats);
174174
if (!stats)
175175
{
176-
if (!IsAutoVacuumWorkerProcess())
176+
if (!AmAutoVacuumWorkerProcess())
177177
ereport(WARNING,
178178
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
179179
errmsg("statistics object \"%s.%s\" could not be computed for relation \"%s.%s\"",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ proc_exit(int code)
136136
*/
137137
chargprofDirName[32];
138138

139-
if (IsAutoVacuumWorkerProcess())
139+
if (AmAutoVacuumWorkerProcess())
140140
snprintf(gprofDirName,32,"gprof/avworker");
141141
else
142142
snprintf(gprofDirName,32,"gprof/%d", (int)getpid());

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include"replication/slot.h"
4343
#include"replication/slotsync.h"
4444
#include"replication/syncrep.h"
45-
#include"replication/walsender.h"
4645
#include"storage/condition_variable.h"
4746
#include"storage/ipc.h"
4847
#include"storage/lmgr.h"
@@ -310,11 +309,11 @@ InitProcess(void)
310309
elog(ERROR,"you already exist");
311310

312311
/* Decide which list should supply our PGPROC. */
313-
if (IsAnyAutoVacuumProcess())
312+
if (AmAutoVacuumLauncherProcess()||AmAutoVacuumWorkerProcess())
314313
procgloballist=&ProcGlobal->autovacFreeProcs;
315-
elseif (IsBackgroundWorker)
314+
elseif (AmBackgroundWorkerProcess())
316315
procgloballist=&ProcGlobal->bgworkerFreeProcs;
317-
elseif (am_walsender)
316+
elseif (AmWalSenderProcess())
318317
procgloballist=&ProcGlobal->walsenderFreeProcs;
319318
else
320319
procgloballist=&ProcGlobal->freeProcs;
@@ -344,7 +343,7 @@ InitProcess(void)
344343
* in the autovacuum case?
345344
*/
346345
SpinLockRelease(ProcStructLock);
347-
if (am_walsender)
346+
if (AmWalSenderProcess())
348347
ereport(FATAL,
349348
(errcode(ERRCODE_TOO_MANY_CONNECTIONS),
350349
errmsg("number of requested standby connections exceeds max_wal_senders (currently %d)",
@@ -370,8 +369,8 @@ InitProcess(void)
370369
* Slot sync worker also does not participate in it, see comments atop
371370
* 'struct bkend' in postmaster.c.
372371
*/
373-
if (IsUnderPostmaster&& !IsAutoVacuumLauncherProcess()&&
374-
!IsLogicalSlotSyncWorker())
372+
if (IsUnderPostmaster&& !AmAutoVacuumLauncherProcess()&&
373+
!AmLogicalSlotSyncWorkerProcess())
375374
MarkPostmasterChildActive();
376375

377376
/*
@@ -391,11 +390,11 @@ InitProcess(void)
391390
MyProc->databaseId=InvalidOid;
392391
MyProc->roleId=InvalidOid;
393392
MyProc->tempNamespaceId=InvalidOid;
394-
MyProc->isBackgroundWorker=IsBackgroundWorker;
393+
MyProc->isBackgroundWorker=AmBackgroundWorkerProcess();
395394
MyProc->delayChkptFlags=0;
396395
MyProc->statusFlags=0;
397396
/* NB -- autovac launcher intentionally does not set IS_AUTOVACUUM */
398-
if (IsAutoVacuumWorkerProcess())
397+
if (AmAutoVacuumWorkerProcess())
399398
MyProc->statusFlags |=PROC_IS_AUTOVACUUM;
400399
MyProc->lwWaiting=LW_WS_NOT_WAITING;
401400
MyProc->lwWaitMode=0;
@@ -587,7 +586,7 @@ InitAuxiliaryProcess(void)
587586
MyProc->databaseId=InvalidOid;
588587
MyProc->roleId=InvalidOid;
589588
MyProc->tempNamespaceId=InvalidOid;
590-
MyProc->isBackgroundWorker=IsBackgroundWorker;
589+
MyProc->isBackgroundWorker=AmBackgroundWorkerProcess();
591590
MyProc->delayChkptFlags=0;
592591
MyProc->statusFlags=0;
593592
MyProc->lwWaiting=LW_WS_NOT_WAITING;
@@ -951,8 +950,8 @@ ProcKill(int code, Datum arg)
951950
* Slot sync worker is also not a postmaster child, so skip this shared
952951
* memory related processing here.
953952
*/
954-
if (IsUnderPostmaster&& !IsAutoVacuumLauncherProcess()&&
955-
!IsLogicalSlotSyncWorker())
953+
if (IsUnderPostmaster&& !AmAutoVacuumLauncherProcess()&&
954+
!AmLogicalSlotSyncWorkerProcess())
956955
MarkPostmasterChildInactive();
957956

958957
/* wake autovac launcher if needed -- see comments in FreeWorkerInfo */

‎src/backend/tcop/postgres.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,7 +3259,7 @@ ProcessInterrupts(void)
32593259
ereport(FATAL,
32603260
(errcode(ERRCODE_QUERY_CANCELED),
32613261
errmsg("canceling authentication due to timeout")));
3262-
elseif (IsAutoVacuumWorkerProcess())
3262+
elseif (AmAutoVacuumWorkerProcess())
32633263
ereport(FATAL,
32643264
(errcode(ERRCODE_ADMIN_SHUTDOWN),
32653265
errmsg("terminating autovacuum process due to administrator command")));
@@ -3278,7 +3278,7 @@ ProcessInterrupts(void)
32783278
*/
32793279
proc_exit(1);
32803280
}
3281-
elseif (IsBackgroundWorker)
3281+
elseif (AmBackgroundWorkerProcess())
32823282
ereport(FATAL,
32833283
(errcode(ERRCODE_ADMIN_SHUTDOWN),
32843284
errmsg("terminating background worker \"%s\" due to administrator command",
@@ -3378,7 +3378,7 @@ ProcessInterrupts(void)
33783378
(errcode(ERRCODE_QUERY_CANCELED),
33793379
errmsg("canceling statement due to statement timeout")));
33803380
}
3381-
if (IsAutoVacuumWorkerProcess())
3381+
if (AmAutoVacuumWorkerProcess())
33823382
{
33833383
LockErrorCleanup();
33843384
ereport(ERROR,

‎src/backend/utils/activity/pgstat_relation.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
246246
*/
247247
tabentry->ins_since_vacuum=0;
248248

249-
if (IsAutoVacuumWorkerProcess())
249+
if (AmAutoVacuumWorkerProcess())
250250
{
251251
tabentry->last_autovacuum_time=ts;
252252
tabentry->autovacuum_count++;
@@ -337,7 +337,7 @@ pgstat_report_analyze(Relation rel,
337337
if (resetcounter)
338338
tabentry->mod_since_analyze=0;
339339

340-
if (IsAutoVacuumWorkerProcess())
340+
if (AmAutoVacuumWorkerProcess())
341341
{
342342
tabentry->last_autoanalyze_time=GetCurrentTimestamp();
343343
tabentry->autoanalyze_count++;

‎src/backend/utils/init/globals.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ pid_tPostmasterPid = 0;
115115
boolIsPostmasterEnvironment= false;
116116
boolIsUnderPostmaster= false;
117117
boolIsBinaryUpgrade= false;
118-
boolIsBackgroundWorker= false;
119118

120119
boolExitOnAnyError= false;
121120

‎src/backend/utils/init/miscinit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,8 @@ InitializeSessionUserIdStandalone(void)
841841
* This function should only be called in single-user mode, in autovacuum
842842
* workers, in slot sync worker and in background workers.
843843
*/
844-
Assert(!IsUnderPostmaster||IsAutoVacuumWorkerProcess()||
845-
IsLogicalSlotSyncWorker()||IsBackgroundWorker);
844+
Assert(!IsUnderPostmaster||AmAutoVacuumWorkerProcess()||
845+
AmLogicalSlotSyncWorkerProcess()||AmBackgroundWorkerProcess());
846846

847847
/* call only once */
848848
Assert(!OidIsValid(AuthenticatedUserId));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp