PostgreSQL Source Code git master
|
#include "postgres.h"
#include <unistd.h>
#include "access/relation.h"
#include "access/xact.h"
#include "pgstat.h"
#include "postmaster/bgworker.h"
#include "postmaster/interrupt.h"
#include "storage/buf_internals.h"
#include "storage/dsm.h"
#include "storage/dsm_registry.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/lwlock.h"
#include "storage/procsignal.h"
#include "storage/read_stream.h"
#include "storage/smgr.h"
#include "tcop/tcopprot.h"
#include "utils/guc.h"
#include "utils/rel.h"
#include "utils/relfilenumbermap.h"
#include "utils/timestamp.h"
Go to the source code of this file.
Data Structures | |
struct | BlockInfoRecord |
struct | AutoPrewarmSharedState |
struct | AutoPrewarmReadStreamData |
Macros | |
#define | AUTOPREWARM_FILE "autoprewarm.blocks" |
#define | cmp_member_elem(fld) |
Typedefs | |
typedef struct BlockInfoRecord | BlockInfoRecord |
typedef struct AutoPrewarmSharedState | AutoPrewarmSharedState |
typedef struct AutoPrewarmReadStreamData | AutoPrewarmReadStreamData |
Functions | |
PGDLLEXPORT void | autoprewarm_main (Datum main_arg) |
PGDLLEXPORT void | autoprewarm_database_main (Datum main_arg) |
PG_FUNCTION_INFO_V1 (autoprewarm_start_worker) | |
PG_FUNCTION_INFO_V1 (autoprewarm_dump_now) | |
static void | apw_load_buffers (void) |
static int | apw_dump_now (bool is_bgworker, bool dump_unlogged) |
static void | apw_start_leader_worker (void) |
static void | apw_start_database_worker (void) |
static bool | apw_init_shmem (void) |
static void | apw_detach_shmem (int code, Datum arg) |
static int | apw_compare_blockinfo (const void *p, const void *q) |
void | _PG_init (void) |
static BlockNumber | apw_read_stream_next_block (ReadStream *stream, void *callback_private_data, void *per_buffer_data) |
Datum | autoprewarm_start_worker (PG_FUNCTION_ARGS) |
Datum | autoprewarm_dump_now (PG_FUNCTION_ARGS) |
static void | apw_init_state (void *ptr) |
Variables | |
static AutoPrewarmSharedState * | apw_state = NULL |
static bool | autoprewarm = true |
static int | autoprewarm_interval = 300 |
#define AUTOPREWARM_FILE "autoprewarm.blocks" |
Definition at line 52 of file autoprewarm.c.
#define cmp_member_elem | ( | fld | ) |
typedef struct AutoPrewarmReadStreamData AutoPrewarmReadStreamData |
typedef struct AutoPrewarmSharedState AutoPrewarmSharedState |
typedef struct BlockInfoRecord BlockInfoRecord |
void _PG_init | ( | void | ) |
Definition at line 126 of file autoprewarm.c.
References apw_start_leader_worker(), autoprewarm, autoprewarm_interval, DefineCustomBoolVariable(), DefineCustomIntVariable(), GUC_UNIT_S, MarkGUCPrefixReserved(), PGC_POSTMASTER, PGC_SIGHUP, and process_shared_preload_libraries_in_progress.
|
static |
Definition at line 991 of file autoprewarm.c.
References a, b, cmp_member_elem, and tablespace.
Referenced by apw_load_buffers().
|
static |
Definition at line 887 of file autoprewarm.c.
References apw_state, AutoPrewarmSharedState::bgworker_pid, InvalidPid, AutoPrewarmSharedState::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyProcPid, and AutoPrewarmSharedState::pid_using_dumpfile.
Referenced by autoprewarm_dump_now(), and autoprewarm_main().
|
static |
Definition at line 665 of file autoprewarm.c.
References AllocateFile(), apw_state, AUTOPREWARM_FILE, BlockInfoRecord::blocknum, buftag::blockNum, BM_PERMANENT, BM_TAG_VALID, BufTagGetForkNum(), BufTagGetRelNumber(), CHECK_FOR_INTERRUPTS, BlockInfoRecord::database, buftag::dbOid, DEBUG1, durable_rename(), ereport, errcode_for_file_access(), errmsg(), errmsg_internal(), ERROR, BlockInfoRecord::filenumber, BlockInfoRecord::forknum, fprintf, FreeFile(), GetBufferDescriptor(), i, InvalidPid, AutoPrewarmSharedState::lock, LockBufHdr(), LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MAXPGPATH, MyProcPid, NBuffers, palloc(), pfree(), AutoPrewarmSharedState::pid_using_dumpfile, snprintf, buftag::spcOid, BlockInfoRecord::tablespace, tablespace, BufferDesc::tag, and UnlockBufHdr().
Referenced by autoprewarm_dump_now(), and autoprewarm_main().
|
static |
Definition at line 870 of file autoprewarm.c.
References apw_init_state(), apw_state, GetNamedDSMSegment(), AutoPrewarmSharedState::lock, LWLockRegisterTranche(), and LWLock::tranche.
Referenced by autoprewarm_database_main(), autoprewarm_dump_now(), autoprewarm_main(), and autoprewarm_start_worker().
|
static |
Definition at line 855 of file autoprewarm.c.
References InvalidPid, LWLockInitialize(), and LWLockNewTrancheId().
Referenced by apw_init_shmem().
|
static |
Definition at line 292 of file autoprewarm.c.
References AllocateFile(), apw_compare_blockinfo(), apw_start_database_worker(), apw_state, Assert(), AUTOPREWARM_FILE, AutoPrewarmSharedState::block_info_handle, BlockInfoRecord::database, AutoPrewarmSharedState::database, dsm_create(), dsm_detach(), DSM_HANDLE_INVALID, dsm_segment_address(), dsm_segment_handle(), ereport, errcode_for_file_access(), errmsg(), ERROR, BlockInfoRecord::forknum, FreeFile(), have_free_buffer(), i, InvalidOid, InvalidPid, j, AutoPrewarmSharedState::lock, LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyProcPid, AutoPrewarmSharedState::pid_using_dumpfile, AutoPrewarmSharedState::prewarm_start_idx, AutoPrewarmSharedState::prewarm_stop_idx, AutoPrewarmSharedState::prewarmed_blocks, qsort, ShutdownRequestPending, and tablespace.
Referenced by autoprewarm_main().
|
static |
Definition at line 453 of file autoprewarm.c.
References apw_state, AutoPrewarmReadStreamData::block_info, BlockInfoRecord::blocknum, CHECK_FOR_INTERRUPTS, BlockInfoRecord::filenumber, AutoPrewarmReadStreamData::filenumber, BlockInfoRecord::forknum, AutoPrewarmReadStreamData::forknum, have_free_buffer(), InvalidBlockNumber, AutoPrewarmReadStreamData::nblocks, AutoPrewarmReadStreamData::pos, AutoPrewarmSharedState::prewarm_stop_idx, BlockInfoRecord::tablespace, and AutoPrewarmReadStreamData::tablespace.
Referenced by autoprewarm_database_main().
|
static |
Definition at line 942 of file autoprewarm.c.
References BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_name, BGW_NEVER_RESTART, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_restart_time, BackgroundWorker::bgw_start_time, BackgroundWorker::bgw_type, BGWORKER_BACKEND_DATABASE_CONNECTION, BGWORKER_SHMEM_ACCESS, BgWorkerStart_ConsistentState, ereport, errcode(), errhint(), errmsg(), ERROR, MyProcPid, RegisterDynamicBackgroundWorker(), and WaitForBackgroundWorkerShutdown().
Referenced by apw_load_buffers().
|
static |
Definition at line 901 of file autoprewarm.c.
References BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_name, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_start_time, BackgroundWorker::bgw_type, BGWH_STARTED, BGWORKER_SHMEM_ACCESS, BgWorkerStart_ConsistentState, ereport, errcode(), errhint(), errmsg(), ERROR, MyProcPid, process_shared_preload_libraries_in_progress, RegisterBackgroundWorker(), RegisterDynamicBackgroundWorker(), and WaitForBackgroundWorkerStartup().
Referenced by _PG_init(), and autoprewarm_start_worker().
void autoprewarm_database_main | ( | Datum | main_arg | ) |
Definition at line 501 of file autoprewarm.c.
References AccessShareLock, apw_init_shmem(), apw_read_stream_next_block(), apw_state, Assert(), BackgroundWorkerInitializeConnectionByOid(), BackgroundWorkerUnblockSignals(), AutoPrewarmReadStreamData::block_info, AutoPrewarmSharedState::block_info_handle, buf, CommitTransactionCommand(), BlockInfoRecord::database, AutoPrewarmSharedState::database, die, dsm_attach(), dsm_detach(), dsm_segment_address(), ereport, errcode(), errmsg(), ERROR, BlockInfoRecord::filenumber, AutoPrewarmReadStreamData::filenumber, BlockInfoRecord::forknum, AutoPrewarmReadStreamData::forknum, have_free_buffer(), i, InvalidBuffer, InvalidForkNumber, InvalidOid, MAX_FORKNUM, AutoPrewarmReadStreamData::nblocks, OidIsValid, AutoPrewarmReadStreamData::pos, pqsignal, AutoPrewarmSharedState::prewarm_start_idx, AutoPrewarmSharedState::prewarm_stop_idx, AutoPrewarmSharedState::prewarmed_blocks, read_stream_begin_relation(), READ_STREAM_DEFAULT, read_stream_end(), read_stream_next_buffer(), READ_STREAM_USE_BATCHING, relation_close(), RelationGetNumberOfBlocksInFork(), RelationGetSmgr(), ReleaseBuffer(), RelidByRelfilenumber(), smgrexists(), StartTransactionCommand(), BlockInfoRecord::tablespace, AutoPrewarmReadStreamData::tablespace, tablespace, and try_relation_open().
Datum autoprewarm_dump_now | ( | PG_FUNCTION_ARGS | ) |
Definition at line 839 of file autoprewarm.c.
References apw_detach_shmem(), apw_dump_now(), apw_init_shmem(), PG_END_ENSURE_ERROR_CLEANUP, PG_ENSURE_ERROR_CLEANUP, and PG_RETURN_INT64.
void autoprewarm_main | ( | Datum | main_arg | ) |
Definition at line 167 of file autoprewarm.c.
References apw_detach_shmem(), apw_dump_now(), apw_init_shmem(), apw_load_buffers(), apw_state, autoprewarm_interval, BackgroundWorkerUnblockSignals(), before_shmem_exit(), AutoPrewarmSharedState::bgworker_pid, ConfigReloadPending, ereport, errmsg(), GetCurrentTimestamp(), InvalidPid, AutoPrewarmSharedState::lock, LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyLatch, MyProcPid, PG_WAIT_EXTENSION, PGC_SIGHUP, pqsignal, ProcessConfigFile(), procsignal_sigusr1_handler(), ResetLatch(), ShutdownRequestPending, SIGHUP, SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), SIGUSR1, TimestampDifferenceMilliseconds(), TimestampTzPlusMilliseconds, WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, and WL_TIMEOUT.
Datum autoprewarm_start_worker | ( | PG_FUNCTION_ARGS | ) |
Definition at line 807 of file autoprewarm.c.
References apw_init_shmem(), apw_start_leader_worker(), apw_state, autoprewarm, AutoPrewarmSharedState::bgworker_pid, ereport, errcode(), errmsg(), ERROR, InvalidPid, AutoPrewarmSharedState::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), and PG_RETURN_VOID.
PG_FUNCTION_INFO_V1 | ( | autoprewarm_dump_now | ) |
PG_FUNCTION_INFO_V1 | ( | autoprewarm_start_worker | ) |
|
static |
Definition at line 116 of file autoprewarm.c.
Referenced by apw_detach_shmem(), apw_dump_now(), apw_init_shmem(), apw_load_buffers(), apw_read_stream_next_block(), autoprewarm_database_main(), autoprewarm_main(), and autoprewarm_start_worker().
|
static |
Definition at line 119 of file autoprewarm.c.
Referenced by _PG_init(), and autoprewarm_start_worker().
|
static |
Definition at line 120 of file autoprewarm.c.
Referenced by _PG_init(), and autoprewarm_main().