mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
aio: Infrastructure for io_method=worker
This commit contains the basic, system-wide, infrastructure for
io_method=worker. It does not yet actually execute IO, this commit just
provides the infrastructure for running IO workers, kept separate for easier
review.
The number of IO workers can be adjusted with a PGC_SIGHUP GUC. Eventually
we'd like to make the number of workers dynamically scale up/down based on the
current "IO load".
To allow the number of IO workers to be increased without a restart, we need
to reserve PGPROC entries for the workers unconditionally. This has been
judged to be worth the cost. If it turns out to be problematic, we can
introduce a PGC_POSTMASTER GUC to control the maximum number.
As io workers might be needed during shutdown, e.g. for AIO during the
shutdown checkpoint, a new PMState phase is added. IO workers are shut down
after the shutdown checkpoint has been performed and walsender/archiver have
shut down, but before the checkpointer itself shuts down. See also
87a6690cc6.
Updates PGSTAT_FILE_FORMAT_ID due to the addition of a new BackendType.
Reviewed-by: Noah Misch <noah@leadboat.com>
Co-authored-by: Thomas Munro <thomas.munro@gmail.com>
Co-authored-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/uvrtrknj4kdytuboidbhwclo4gxhswwcpgadptsjvjqcluzmah%40brqs62irg4dt
Discussion: https://postgr.es/m/20210223100344.llw5an2aklengrmn@alap3.anarazel.de
Discussion: https://postgr.es/m/stj36ea6yyhoxtqkhpieia2z4krnam7qyetc57rfezgk4zgapf@gcnactj4z56m
This commit is contained in:
@@ -15,6 +15,7 @@ OBJS = \
|
||||
aio_io.o \
|
||||
aio_target.o \
|
||||
method_sync.o \
|
||||
method_worker.o \
|
||||
read_stream.o
|
||||
|
||||
include $(top_srcdir)/src/backend/common.mk
|
||||
|
||||
@@ -7,5 +7,6 @@ backend_sources += files(
|
||||
'aio_io.c',
|
||||
'aio_target.c',
|
||||
'method_sync.c',
|
||||
'method_worker.c',
|
||||
'read_stream.c',
|
||||
)
|
||||
|
||||
88
src/backend/storage/aio/method_worker.c
Normal file
88
src/backend/storage/aio/method_worker.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* method_worker.c
|
||||
* AIO - perform AIO using worker processes
|
||||
*
|
||||
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* src/backend/storage/aio/method_worker.c
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "libpq/pqsignal.h"
|
||||
#include "miscadmin.h"
|
||||
#include "postmaster/auxprocess.h"
|
||||
#include "postmaster/interrupt.h"
|
||||
#include "storage/aio_subsys.h"
|
||||
#include "storage/io_worker.h"
|
||||
#include "storage/ipc.h"
|
||||
#include "storage/latch.h"
|
||||
#include "storage/proc.h"
|
||||
#include "tcop/tcopprot.h"
|
||||
#include "utils/wait_event.h"
|
||||
|
||||
|
||||
/* GUCs */
|
||||
int io_workers = 3;
|
||||
|
||||
|
||||
void
|
||||
IoWorkerMain(const void *startup_data, size_t startup_data_len)
|
||||
{
|
||||
sigjmp_buf local_sigjmp_buf;
|
||||
|
||||
MyBackendType = B_IO_WORKER;
|
||||
AuxiliaryProcessMainCommon();
|
||||
|
||||
pqsignal(SIGHUP, SignalHandlerForConfigReload);
|
||||
pqsignal(SIGINT, die); /* to allow manually triggering worker restart */
|
||||
|
||||
/*
|
||||
* Ignore SIGTERM, will get explicit shutdown via SIGUSR2 later in the
|
||||
* shutdown sequence, similar to checkpointer.
|
||||
*/
|
||||
pqsignal(SIGTERM, SIG_IGN);
|
||||
/* SIGQUIT handler was already set up by InitPostmasterChild */
|
||||
pqsignal(SIGALRM, SIG_IGN);
|
||||
pqsignal(SIGPIPE, SIG_IGN);
|
||||
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
|
||||
pqsignal(SIGUSR2, SignalHandlerForShutdownRequest);
|
||||
|
||||
/* see PostgresMain() */
|
||||
if (sigsetjmp(local_sigjmp_buf, 1) != 0)
|
||||
{
|
||||
error_context_stack = NULL;
|
||||
HOLD_INTERRUPTS();
|
||||
|
||||
EmitErrorReport();
|
||||
|
||||
proc_exit(1);
|
||||
}
|
||||
|
||||
/* We can now handle ereport(ERROR) */
|
||||
PG_exception_stack = &local_sigjmp_buf;
|
||||
|
||||
sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
|
||||
|
||||
while (!ShutdownRequestPending)
|
||||
{
|
||||
WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, -1,
|
||||
WAIT_EVENT_IO_WORKER_MAIN);
|
||||
ResetLatch(MyLatch);
|
||||
CHECK_FOR_INTERRUPTS();
|
||||
}
|
||||
|
||||
proc_exit(0);
|
||||
}
|
||||
|
||||
bool
|
||||
pgaio_workers_enabled(void)
|
||||
{
|
||||
/* placeholder for future commit */
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user