PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup.h"
#include "access/htup_details.h"
#include "access/tableam.h"
#include "access/xact.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_subscription_rel.h"
#include "funcapi.h"
#include "lib/dshash.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "postmaster/bgworker.h"
#include "postmaster/interrupt.h"
#include "replication/logicallauncher.h"
#include "replication/slot.h"
#include "replication/walreceiver.h"
#include "replication/worker_internal.h"
#include "storage/ipc.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
#include "utils/pg_lsn.h"
#include "utils/snapmgr.h"
Go to the source code of this file.
Data Structures | |
struct | LogicalRepCtxStruct |
struct | LauncherLastStartTimesEntry |
Macros | |
#define | DEFAULT_NAPTIME_PER_CYCLE 180000L |
#define | PG_STAT_GET_SUBSCRIPTION_COLS 10 |
Typedefs | |
typedef struct LogicalRepCtxStruct | LogicalRepCtxStruct |
typedef struct LauncherLastStartTimesEntry | LauncherLastStartTimesEntry |
Variables | |
int | max_logical_replication_workers = 4 |
int | max_sync_workers_per_subscription = 2 |
int | max_parallel_apply_workers_per_subscription = 2 |
LogicalRepWorker * | MyLogicalRepWorker = NULL |
static LogicalRepCtxStruct * | LogicalRepCtx |
static const dshash_parameters | dsh_params |
static dsa_area * | last_start_times_dsa = NULL |
static dshash_table * | last_start_times = NULL |
static bool | on_commit_launcher_wakeup = false |
#define DEFAULT_NAPTIME_PER_CYCLE 180000L |
Definition at line 47 of file launcher.c.
#define PG_STAT_GET_SUBSCRIPTION_COLS 10 |
typedef struct LauncherLastStartTimesEntry LauncherLastStartTimesEntry |
typedef struct LogicalRepCtxStruct LogicalRepCtxStruct |
void ApplyLauncherForgetWorkerStartTime | ( | Oid | subid | ) |
Definition at line 1081 of file launcher.c.
References dshash_delete_key(), last_start_times, and logicalrep_launcher_attach_dshmem().
Referenced by apply_worker_exit(), DisableSubscriptionAndExit(), DropSubscription(), InitializeLogRepWorker(), maybe_reread_subscription(), and process_syncing_tables_for_apply().
|
static |
Definition at line 1055 of file launcher.c.
References dshash_find(), dshash_release_lock(), LauncherLastStartTimesEntry::last_start_time, last_start_times, and logicalrep_launcher_attach_dshmem().
Referenced by ApplyLauncherMain().
void ApplyLauncherMain | ( | Datum | main_arg | ) |
Definition at line 1128 of file launcher.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, ApplyLauncherGetWorkerStartTime(), ApplyLauncherSetWorkerStartTime(), Assert, BackgroundWorkerInitializeConnection(), BackgroundWorkerUnblockSignals(), before_shmem_exit(), CHECK_FOR_INTERRUPTS, ConfigReloadPending, Subscription::dbid, DEBUG1, DEFAULT_NAPTIME_PER_CYCLE, die, DSM_HANDLE_INVALID, Subscription::enabled, ereport, errmsg_internal(), get_subscription_list(), GetCurrentTimestamp(), InvalidOid, LogicalRepCtxStruct::launcher_pid, lfirst, logicalrep_launcher_onexit(), logicalrep_worker_find(), logicalrep_worker_launch(), LogicalRepCtx, LW_SHARED, LWLockAcquire(), LWLockRelease(), MemoryContextDelete(), MemoryContextSwitchTo(), Min, MyLatch, MyProcPid, Subscription::name, now(), Subscription::oid, Subscription::owner, PGC_SIGHUP, pqsignal(), ProcessConfigFile(), ResetLatch(), SIGHUP, SignalHandlerForConfigReload(), TimestampDifferenceMilliseconds(), TopMemoryContext, WaitLatch(), wal_retrieve_retry_interval, WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_TIMEOUT, and WORKERTYPE_APPLY.
void ApplyLauncherRegister | ( | void | ) |
Definition at line 924 of file launcher.c.
References BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_main_arg, BGW_MAXLEN, BackgroundWorker::bgw_name, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_restart_time, BackgroundWorker::bgw_start_time, BackgroundWorker::bgw_type, BGWORKER_BACKEND_DATABASE_CONNECTION, BGWORKER_SHMEM_ACCESS, BgWorkerStart_RecoveryFinished, IsBinaryUpgrade, max_logical_replication_workers, MAXPGPATH, RegisterBackgroundWorker(), and snprintf.
Referenced by PostmasterMain().
|
static |
Definition at line 1039 of file launcher.c.
References dshash_find_or_insert(), dshash_release_lock(), LauncherLastStartTimesEntry::last_start_time, last_start_times, logicalrep_launcher_attach_dshmem(), and start_time.
Referenced by ApplyLauncherMain().
void ApplyLauncherShmemInit | ( | void | ) |
Definition at line 960 of file launcher.c.
References ApplyLauncherShmemSize(), DSA_HANDLE_INVALID, DSHASH_HANDLE_INVALID, LogicalRepCtxStruct::last_start_dsa, LogicalRepCtxStruct::last_start_dsh, LogicalRepCtx, max_logical_replication_workers, LogicalRepWorker::relmutex, ShmemInitStruct(), SpinLockInit, and LogicalRepCtxStruct::workers.
Referenced by CreateOrAttachShmemStructs().
Size ApplyLauncherShmemSize | ( | void | ) |
Definition at line 905 of file launcher.c.
References add_size(), max_logical_replication_workers, MAXALIGN, mul_size(), and size.
Referenced by ApplyLauncherShmemInit(), and CalculateShmemSize().
|
static |
Definition at line 1118 of file launcher.c.
References kill, LogicalRepCtxStruct::launcher_pid, LogicalRepCtx, and SIGUSR1.
Referenced by AtEOXact_ApplyLauncher(), and logicalrep_worker_onexit().
void ApplyLauncherWakeupAtCommit | ( | void | ) |
Definition at line 1111 of file launcher.c.
References on_commit_launcher_wakeup.
Referenced by AlterSubscription(), AlterSubscriptionOwner_internal(), and CreateSubscription().
void AtEOXact_ApplyLauncher | ( | bool | isCommit | ) |
Definition at line 1092 of file launcher.c.
References ApplyLauncherWakeup(), and on_commit_launcher_wakeup.
Referenced by AbortTransaction(), CommitTransaction(), and PrepareTransaction().
|
static |
Definition at line 112 of file launcher.c.
References AccessShareLock, CommitTransactionCommand(), CurrentMemoryContext, Subscription::dbid, Subscription::enabled, ForwardScanDirection, GETSTRUCT, GetTransactionSnapshot(), heap_getnext(), HeapTupleIsValid, lappend(), MemoryContextSwitchTo(), Subscription::name, NameStr, NIL, Subscription::oid, Subscription::owner, palloc0(), pstrdup(), res, StartTransactionCommand(), table_beginscan_catalog(), table_close(), table_endscan(), and table_open().
Referenced by ApplyLauncherMain().
pid_t GetLeaderApplyWorkerPid | ( | pid_t | pid | ) |
Definition at line 1259 of file launcher.c.
References i, InvalidPid, isParallelApplyWorker, LogicalRepWorker::leader_pid, LogicalRepCtx, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_logical_replication_workers, PGPROC::pid, LogicalRepWorker::proc, and LogicalRepCtxStruct::workers.
Referenced by pg_stat_get_activity().
bool IsLogicalLauncher | ( | void | ) |
Definition at line 1249 of file launcher.c.
References LogicalRepCtxStruct::launcher_pid, LogicalRepCtx, and MyProcPid.
Referenced by ProcessInterrupts().
|
static |
Definition at line 995 of file launcher.c.
References dsa_attach(), dsa_create, dsa_get_handle(), dsa_pin(), dsa_pin_mapping(), dsh_params, dshash_attach(), dshash_create(), dshash_get_hash_table_handle(), DSHASH_HANDLE_INVALID, LogicalRepCtxStruct::last_start_dsa, LogicalRepCtxStruct::last_start_dsh, last_start_times, last_start_times_dsa, LogicalRepCtx, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), LWTRANCHE_LAUNCHER_DSA, MemoryContextSwitchTo(), and TopMemoryContext.
Referenced by ApplyLauncherForgetWorkerStartTime(), ApplyLauncherGetWorkerStartTime(), and ApplyLauncherSetWorkerStartTime().
|
static |
Definition at line 813 of file launcher.c.
References LogicalRepCtxStruct::launcher_pid, and LogicalRepCtx.
Referenced by ApplyLauncherMain().
|
static |
Definition at line 878 of file launcher.c.
References Assert, i, isParallelApplyWorker, LogicalRepCtx, LWLockHeldByMe(), max_logical_replication_workers, res, LogicalRepWorker::subid, and LogicalRepCtxStruct::workers.
Referenced by logicalrep_worker_launch().
void logicalrep_pa_worker_stop | ( | ParallelApplyWorkerInfo * | winfo | ) |
Definition at line 639 of file launcher.c.
References Assert, ParallelApplyWorkerInfo::error_mq_handle, LogicalRepWorker::generation, isParallelApplyWorker, ParallelApplyWorkerShared::logicalrep_worker_generation, ParallelApplyWorkerShared::logicalrep_worker_slot_no, logicalrep_worker_stop_internal(), LogicalRepCtx, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_logical_replication_workers, ParallelApplyWorkerShared::mutex, LogicalRepWorker::proc, ParallelApplyWorkerInfo::shared, shm_mq_detach(), SpinLockAcquire, SpinLockRelease, and LogicalRepCtxStruct::workers.
Referenced by pa_free_worker().
int logicalrep_sync_worker_count | ( | Oid | subid | ) |
Definition at line 854 of file launcher.c.
References Assert, i, isTablesyncWorker, LogicalRepCtx, LWLockHeldByMe(), max_logical_replication_workers, res, LogicalRepWorker::subid, and LogicalRepCtxStruct::workers.
Referenced by logicalrep_worker_launch(), and process_syncing_tables_for_apply().
void logicalrep_worker_attach | ( | int | slot | ) |
Definition at line 713 of file launcher.c.
References Assert, before_shmem_exit(), ereport, errcode(), errmsg(), ERROR, LogicalRepWorker::in_use, logicalrep_worker_onexit(), LogicalRepCtx, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_logical_replication_workers, MyLogicalRepWorker, MyProc, LogicalRepWorker::proc, and LogicalRepCtxStruct::workers.
Referenced by ParallelApplyWorkerMain(), and SetupApplyOrSyncWorker().
|
static |
Definition at line 792 of file launcher.c.
References Assert, LogicalRepWorker::dbid, LogicalRepWorker::in_use, InvalidOid, InvalidPid, LogicalRepWorker::leader_pid, LW_EXCLUSIVE, LWLockHeldByMeInMode(), LogicalRepWorker::parallel_apply, LogicalRepWorker::proc, LogicalRepWorker::relid, LogicalRepWorker::subid, LogicalRepWorker::type, LogicalRepWorker::userid, and WORKERTYPE_UNKNOWN.
Referenced by logicalrep_worker_detach(), logicalrep_worker_launch(), and WaitForReplicationWorkerAttach().
|
static |
Definition at line 750 of file launcher.c.
References am_leader_apply_worker(), isParallelApplyWorker, lfirst, logicalrep_worker_cleanup(), logicalrep_worker_stop_internal(), logicalrep_workers_find(), LW_EXCLUSIVE, LW_SHARED, LWLockAcquire(), LWLockRelease(), MyLogicalRepWorker, pa_detach_all_error_mq(), and LogicalRepWorker::subid.
Referenced by logicalrep_worker_onexit().
LogicalRepWorker* logicalrep_worker_find | ( | Oid | subid, |
Oid | relid, | ||
bool | only_running | ||
) |
Definition at line 243 of file launcher.c.
References Assert, i, LogicalRepWorker::in_use, isParallelApplyWorker, LogicalRepCtx, LWLockHeldByMe(), max_logical_replication_workers, LogicalRepWorker::proc, LogicalRepWorker::relid, res, LogicalRepWorker::subid, and LogicalRepCtxStruct::workers.
Referenced by ApplyLauncherMain(), logicalrep_worker_stop(), logicalrep_worker_wakeup(), process_syncing_tables_for_apply(), wait_for_relation_state_change(), and wait_for_worker_state_change().
bool logicalrep_worker_launch | ( | LogicalRepWorkerType | wtype, |
Oid | dbid, | ||
Oid | subid, | ||
const char * | subname, | ||
Oid | userid, | ||
Oid | relid, | ||
dsm_handle | subworker_dsm | ||
) |
Definition at line 306 of file launcher.c.
References Assert, BackgroundWorker::bgw_extra, BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_main_arg, BGW_MAXLEN, 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_RecoveryFinished, LogicalRepWorker::dbid, DEBUG1, DSM_HANDLE_INVALID, elog, ereport, errcode(), errhint(), errmsg(), errmsg_internal(), ERROR, LogicalRepWorker::generation, GetCurrentTimestamp(), i, LogicalRepWorker::in_use, Int32GetDatum(), InvalidPid, InvalidXLogRecPtr, LogicalRepWorker::last_lsn, LogicalRepWorker::last_recv_time, LogicalRepWorker::last_send_time, LogicalRepWorker::launch_time, LogicalRepWorker::leader_pid, logicalrep_pa_worker_count(), logicalrep_sync_worker_count(), logicalrep_worker_cleanup(), LogicalRepCtx, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_logical_replication_workers, max_parallel_apply_workers_per_subscription, max_replication_slots, max_sync_workers_per_subscription, MAXPGPATH, MyProcPid, now(), OidIsValid, LogicalRepWorker::parallel_apply, LogicalRepWorker::proc, RegisterDynamicBackgroundWorker(), LogicalRepWorker::relid, LogicalRepWorker::relstate, LogicalRepWorker::relstate_lsn, LogicalRepWorker::reply_lsn, LogicalRepWorker::reply_time, snprintf, LogicalRepWorker::stream_fileset, LogicalRepWorker::subid, subname, TIMESTAMP_NOBEGIN, TimestampDifferenceExceeds(), LogicalRepWorker::type, LogicalRepWorker::userid, WaitForReplicationWorkerAttach(), wal_receiver_timeout, WARNING, LogicalRepCtxStruct::workers, WORKERTYPE_APPLY, WORKERTYPE_PARALLEL_APPLY, WORKERTYPE_TABLESYNC, and WORKERTYPE_UNKNOWN.
Referenced by ApplyLauncherMain(), pa_launch_parallel_worker(), and process_syncing_tables_for_apply().
|
static |
Definition at line 824 of file launcher.c.
References ApplyLauncherWakeup(), DEFAULT_LOCKMETHOD, FileSetDeleteAll(), InitializingApplyWorker, LockReleaseAll(), logicalrep_worker_detach(), LogRepWorkerWalRcvConn, MyLogicalRepWorker, LogicalRepWorker::stream_fileset, and walrcv_disconnect.
Referenced by logicalrep_worker_attach().
Definition at line 615 of file launcher.c.
References Assert, isParallelApplyWorker, logicalrep_worker_find(), logicalrep_worker_stop_internal(), LW_SHARED, LWLockAcquire(), and LWLockRelease().
Referenced by AlterSubscription_refresh(), and DropSubscription().
|
static |
Definition at line 533 of file launcher.c.
References Assert, CHECK_FOR_INTERRUPTS, LogicalRepWorker::generation, LogicalRepWorker::in_use, kill, LW_SHARED, LWLockAcquire(), LWLockHeldByMeInMode(), LWLockRelease(), MyLatch, PGPROC::pid, LogicalRepWorker::proc, ResetLatch(), WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, and WL_TIMEOUT.
Referenced by logicalrep_pa_worker_stop(), logicalrep_worker_detach(), and logicalrep_worker_stop().
Definition at line 682 of file launcher.c.
References logicalrep_worker_find(), logicalrep_worker_wakeup_ptr(), LW_SHARED, LWLockAcquire(), and LWLockRelease().
Referenced by apply_handle_stream_start(), and pg_attribute_noreturn().
void logicalrep_worker_wakeup_ptr | ( | LogicalRepWorker * | worker | ) |
Definition at line 702 of file launcher.c.
References Assert, LWLockHeldByMe(), LogicalRepWorker::proc, PGPROC::procLatch, and SetLatch().
Referenced by AtEOXact_LogicalRepWorkers(), logicalrep_worker_wakeup(), process_syncing_tables_for_apply(), and wait_for_worker_state_change().
Definition at line 275 of file launcher.c.
References Assert, i, LogicalRepWorker::in_use, lappend(), LogicalRepCtx, LW_SHARED, LWLockAcquire(), LWLockHeldByMe(), LWLockRelease(), max_logical_replication_workers, NIL, LogicalRepWorker::proc, res, LogicalRepWorker::subid, and LogicalRepCtxStruct::workers.
Referenced by AlterSubscription(), AtEOXact_LogicalRepWorkers(), DropSubscription(), and logicalrep_worker_detach().
Datum pg_stat_get_subscription | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1286 of file launcher.c.
References CStringGetTextDatum, elog, ERROR, i, InitMaterializedSRF(), Int32GetDatum(), InvalidOid, IsBackendPid(), isParallelApplyWorker, isTablesyncWorker, LogicalRepWorker::last_lsn, LogicalRepWorker::last_recv_time, LogicalRepWorker::last_send_time, LogicalRepWorker::leader_pid, LogicalRepCtx, LSNGetDatum(), LW_SHARED, LWLockAcquire(), LWLockRelease(), max_logical_replication_workers, ObjectIdGetDatum(), OidIsValid, PG_ARGISNULL, PG_GETARG_OID, PG_STAT_GET_SUBSCRIPTION_COLS, PGPROC::pid, LogicalRepWorker::proc, LogicalRepWorker::relid, LogicalRepWorker::reply_lsn, LogicalRepWorker::reply_time, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, LogicalRepWorker::subid, TimestampTzGetDatum(), tuplestore_putvalues(), LogicalRepWorker::type, values, LogicalRepCtxStruct::workers, WORKERTYPE_APPLY, WORKERTYPE_PARALLEL_APPLY, WORKERTYPE_TABLESYNC, WORKERTYPE_UNKNOWN, and XLogRecPtrIsInvalid.
|
static |
Definition at line 183 of file launcher.c.
References BGWH_STOPPED, CHECK_FOR_INTERRUPTS, LogicalRepWorker::generation, GetBackgroundWorkerPid(), LogicalRepWorker::in_use, logicalrep_worker_cleanup(), LW_EXCLUSIVE, LW_SHARED, LWLockAcquire(), LWLockRelease(), MyLatch, LogicalRepWorker::proc, ResetLatch(), WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, and WL_TIMEOUT.
Referenced by logicalrep_worker_launch().
|
static |
Definition at line 79 of file launcher.c.
Referenced by logicalrep_launcher_attach_dshmem().
|
static |
Definition at line 89 of file launcher.c.
Referenced by ApplyLauncherForgetWorkerStartTime(), ApplyLauncherGetWorkerStartTime(), ApplyLauncherSetWorkerStartTime(), logicalrep_launcher_attach_dshmem(), and process_syncing_tables_for_apply().
|
static |
Definition at line 88 of file launcher.c.
Referenced by logicalrep_launcher_attach_dshmem().
|
static |
Definition at line 69 of file launcher.c.
Referenced by ApplyLauncherMain(), ApplyLauncherShmemInit(), ApplyLauncherWakeup(), GetLeaderApplyWorkerPid(), IsLogicalLauncher(), logicalrep_launcher_attach_dshmem(), logicalrep_launcher_onexit(), logicalrep_pa_worker_count(), logicalrep_pa_worker_stop(), logicalrep_sync_worker_count(), logicalrep_worker_attach(), logicalrep_worker_find(), logicalrep_worker_launch(), logicalrep_workers_find(), and pg_stat_get_subscription().
int max_logical_replication_workers = 4 |
Definition at line 50 of file launcher.c.
Referenced by ApplyLauncherRegister(), ApplyLauncherShmemInit(), ApplyLauncherShmemSize(), GetLeaderApplyWorkerPid(), logicalrep_pa_worker_count(), logicalrep_pa_worker_stop(), logicalrep_sync_worker_count(), logicalrep_worker_attach(), logicalrep_worker_find(), logicalrep_worker_launch(), logicalrep_workers_find(), and pg_stat_get_subscription().
int max_parallel_apply_workers_per_subscription = 2 |
Definition at line 52 of file launcher.c.
Referenced by logicalrep_worker_launch(), and pa_free_worker().
int max_sync_workers_per_subscription = 2 |
Definition at line 51 of file launcher.c.
Referenced by logicalrep_worker_launch(), and process_syncing_tables_for_apply().
LogicalRepWorker* MyLogicalRepWorker = NULL |
Definition at line 54 of file launcher.c.
Referenced by am_leader_apply_worker(), am_parallel_apply_worker(), am_tablesync_worker(), apply_handle_stream_abort(), apply_handle_stream_commit(), apply_handle_stream_prepare(), apply_handle_stream_start(), apply_spooled_messages(), apply_worker_exit(), DisableSubscriptionAndExit(), ensure_last_message(), InitializeLogRepWorker(), IsLogicalWorker(), logicalrep_worker_attach(), logicalrep_worker_detach(), logicalrep_worker_onexit(), LogicalRepSyncTableStart(), maybe_reread_subscription(), pa_can_start(), pa_free_worker_info(), pa_launch_parallel_worker(), pa_lock_stream(), pa_lock_transaction(), pa_set_fileset_state(), pa_shutdown(), pa_unlock_stream(), pa_unlock_transaction(), ParallelApplyWorkerMain(), pg_attribute_noreturn(), process_syncing_tables(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), run_tablesync_worker(), set_stream_options(), SetupApplyOrSyncWorker(), should_apply_changes_for_rel(), stream_abort_internal(), stream_cleanup_files(), stream_open_file(), stream_start_internal(), stream_stop_internal(), subxact_info_read(), subxact_info_write(), UpdateWorkerStats(), wait_for_relation_state_change(), and wait_for_worker_state_change().
Definition at line 91 of file launcher.c.
Referenced by ApplyLauncherWakeupAtCommit(), and AtEOXact_ApplyLauncher().