10000 Use MyBackendType in more places to check what process this is · postgrespro/postgres@393b559 · GitHub
[go: up one dir, main page]

Skip to content

Commit 393b559

Browse files
committed
Use MyBackendType in more places to check what process this is
Remove IsBackgroundWorker, IsAutoVacuumLauncherProcess(), IsAutoVacuumWorkerProcess(), and IsLogicalSlotSyncWorker() in favor of new Am*Process() macros that use MyBackendType. For consistency with the existing Am*Process() macros. Reviewed-by: Andres Freund Discussion: https://www.postgresql.org/message-id/f3ecd4cb-85ee-4e54-8278-5fabfb3a4ed0@iki.fi
1 parent 067701f commit 393b559

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
int64 max_items;
3090-
int vac_work_mem = IsAutoVacuumWorkerProcess() &&
3090+
int vac_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
TimestampTz endtime = 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
else if (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
else if (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 @@ int Log_autovacuum_min_duration = 600000;
136136
#define MIN_AUTOVAC_SLEEPTIME 100.0 /* milliseconds */
137137
#define MAX_AUTOVAC_SLEEPTIME 300 /* seconds */
138138

139-
/* Flags to tell if we are in an autovacuum process */
140-
static bool am_autovacuum_launcher = false;
141-
static bool am_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_buf local_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_buf local_sigjmp_buf;
14921486
Oid dbid;
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-
return am_autovacuum_launcher;
3364-
}
3365-
3366-
bool
3367-
IsAutoVacuumWorkerProcess(void)
3368-
{
3369-
return am_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
#define SLOTSYNC_RESTART_INTERVAL_SEC 10
115115

116-
/* Flag to tell if we are in a slot sync worker process */
117-
static bool am_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_buf local_sigjmp_buf;
11151112
StringInfoData app_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
return syncing_slots;
14391434
}
14401435

1441-
/*
1442-
* Is current process a slot sync worker?
1443-
*/
1444-
bool
1445-
IsLogicalSlotSyncWorker(void)
1446-
{
1447-
return am_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\"",

0 commit comments

Comments
 (0)
0