PostgreSQL Source Code: src/backend/replication/logical/logicalctl.c File Reference
PostgreSQL Source Code git master Loading... Searching... No Matches Data Structures | Typedefs | Functions | Variables logicalctl.c File Reference #include " postgres.h " #include " access/xloginsert.h " #include " catalog/pg_control.h " #include " miscadmin.h " #include " replication/slot.h " #include " storage/ipc.h " #include " storage/lmgr.h " #include " storage/proc.h " #include " storage/procarray.h " #include " storage/procsignal.h " #include " storage/subsystems.h " #include " utils/injection_point.h " Include dependency graph for logicalctl.c: Go to the source code of this file.
Data Structures struct LogicalDecodingCtlData Typedefs typedef struct LogicalDecodingCtlData LogicalDecodingCtlData Functions static void LogicalDecodingCtlShmemRequest ( void * arg ) static void update_xlog_logical_info ( void ) static void abort_logical_decoding_activation ( int code, Datum arg ) static void write_logical_decoding_status_update_record ( bool status) void StartupLogicalDecodingStatus ( bool last_status ) void InitializeProcessXLogLogicalInfo ( void ) bool ProcessBarrierUpdateXLogLogicalInfo ( void ) bool IsLogicalDecodingEnabled ( void ) bool IsXLogLogicalInfoEnabled ( void ) void AtEOXact_LogicalCtl ( void ) void EnsureLogicalDecodingEnabled ( void ) void EnableLogicalDecoding ( void ) void RequestDisableLogicalDecoding ( void ) void DisableLogicalDecodingIfNecessary ( void ) void DisableLogicalDecoding ( void ) void UpdateLogicalDecodingStatusEndOfRecovery ( void ) Variables static LogicalDecodingCtlData * LogicalDecodingCtl = NULL const ShmemCallbacks LogicalDecodingCtlShmemCallbacks bool XLogLogicalInfo = false static bool XLogLogicalInfoUpdatePending = false Typedef Documentation ◆ LogicalDecodingCtlData typedef struct LogicalDecodingCtlData LogicalDecodingCtlData Function Documentation ◆ abort_logical_decoding_activation() static void abort_logical_decoding_activation ( int code , Datum arg ) static Definition at line 268 of file logicalctl.c .
269 { 270 elog ( DEBUG1 , "aborting logical decoding activation process" ); 271 RequestDisableLogicalDecoding (); 272 } DEBUG1 #define DEBUG1 Definition elog.h:31 elog #define elog(elevel,...) Definition elog.h:228 RequestDisableLogicalDecoding void RequestDisableLogicalDecoding(void) Definition logicalctl.c:423 References DEBUG1 , elog , and RequestDisableLogicalDecoding() . Referenced by EnsureLogicalDecodingEnabled() . ◆ AtEOXact_LogicalCtl() void AtEOXact_LogicalCtl ( void ) Definition at line 233 of file logicalctl.c .
234 { 235 /* Update the local cache if there is a pending update */ 236 if ( XLogLogicalInfoUpdatePending ) 237 { 238 update_xlog_logical_info (); 239 XLogLogicalInfoUpdatePending = false ; 240 } 241 } XLogLogicalInfoUpdatePending static bool XLogLogicalInfoUpdatePending Definition logicalctl.c:124 update_xlog_logical_info static void update_xlog_logical_info(void) Definition logicalctl.c:164 References update_xlog_logical_info() , and XLogLogicalInfoUpdatePending .
Referenced by AbortTransaction() , CommitTransaction() , and PrepareTransaction() . ◆ DisableLogicalDecoding() void DisableLogicalDecoding ( void ) Definition at line 481 of file logicalctl.c . 482 { 483 bool in_recovery = RecoveryInProgress (); 484 bool was_enabled ; 485 486 LWLockAcquire ( LogicalDecodingControlLock , LW_EXCLUSIVE ); 487 488 /* 489 * Check if we can disable logical decoding. 490 * 491 * Nothing to do if both flags are already off, or if valid slots exist 492 * (skip the slot check during recovery because the existing slots will be 493 * invalidated after disabling logical decoding.) 494 */ 495 if ((!
LogicalDecodingCtl -> logical_decoding_enabled && 496 ! LogicalDecodingCtl -> xlog_logical_info ) || 497 (! in_recovery && CheckLogicalSlotExists ())) 498 { 499 LogicalDecodingCtl -> pending_disable = false ; 500 LWLockRelease ( LogicalDecodingControlLock ); 501 return ; 502 } 503 504 /* 505 * Remember if logical decoding was enabled. An interrupted activation can 506 * leave xlog_logical_info=true while logical_decoding_enabled remains 507 * false.
508 */ 509 was_enabled = LogicalDecodingCtl -> logical_decoding_enabled ; 510 511 START_CRIT_SECTION (); 512 513 /* 514 * We need to disable logical decoding first and then disable logical 515 * information WAL logging in order to ensure that no logical decoding 516 * processes WAL records with insufficient information. 517 */ 518 LogicalDecodingCtl -> logical_decoding_enabled = false ; 519 520 /* Write the WAL to disable logical decoding on standbys too */ 521 if (! in_recovery && was_enabled ) 522 write_logical_decoding_status_update_record ( false ); 523 524 /* Now disable logical information WAL logging */ 525 LogicalDecodingCtl -> xlog_logical_info = false ; 526 LogicalDecodingCtl -> pending_disable = false ; 527 528 END_CRIT_SECTION (); 529 530 /* 531 * Logging under the lock guarantees our "is disabled" message appears in 532 * the server log before its eventual "is enabled", making server log 533 * diagnostics easy.
534 */ 535 if (! in_recovery && was_enabled ) 536 ereport ( LOG , 537 errmsg ( "logical decoding is disabled because there are no valid logical replication slots" )); 538 539 LWLockRelease ( LogicalDecodingControlLock ); 540 541 /* 542 * Tell all running processes to reflect the xlog_logical_info update. 543 * Unlike when enabling logical decoding, we don't need to wait for all 544 * processes to complete it in this case.
We already disabled logical 545 * decoding and it's always safe to write logical information to WAL 546 * records, even when not strictly required. Therefore, we don't need to 547 * wait for all running transactions to finish either. 548 */ 549 EmitProcSignalBarrier ( PROCSIGNAL_BARRIER_UPDATE_XLOG_LOGICAL_INFO ); 550 } LOG #define LOG Definition elog.h:32 ereport #define ereport(elevel,...) Definition elog.h:152 LogicalDecodingCtl static LogicalDecodingCtlData * LogicalDecodingCtl Definition logicalctl.c:100 write_logical_decoding_status_update_record static void write_logical_decoding_status_update_record(bool status) Definition logicalctl.c:248 LWLockAcquire bool LWLockAcquire(LWLock *lock, LWLockMode mode) Definition lwlock.c:1150 LWLockRelease void LWLockRelease(LWLock *lock) Definition lwlock.c:1767 LW_EXCLUSIVE @ LW_EXCLUSIVE Definition lwlock.h:104 START_CRIT_SECTION #define START_CRIT_SECTION() Definition miscadmin.h:152 END_CRIT_SECTION #define END_CRIT_SECTION() Definition miscadmin.h:154 errmsg static char * errmsg Definition oauth_hook_client.c:61 fb static int fb(int x) Definition preproc-init.c:92 EmitProcSignalBarrier uint64 EmitProcSignalBarrier(ProcSignalBarrierType type) Definition procsignal.c:368 PROCSIGNAL_BARRIER_UPDATE_XLOG_LOGICAL_INFO @ PROCSIGNAL_BARRIER_UPDATE_XLOG_LOGICAL_INFO Definition procsignal.h:51 CheckLogicalSlotExists bool CheckLogicalSlotExists(void) Definition slot.c:1619 LogicalDecodingCtlData::pending_disable bool pending_disable Definition logicalctl.c:97 LogicalDecodingCtlData::xlog_logical_info bool xlog_logical_info Definition logicalctl.c:91 LogicalDecodingCtlData::logical_decoding_enabled bool logical_decoding_enabled Definition logicalctl.c:94 RecoveryInProgress bool RecoveryInProgress(void) Definition xlog.c:6835 References CheckLogicalSlotExists() , EmitProcSignalBarrier() , END_CRIT_SECTION , ereport , errmsg , fb() , LOG , LogicalDecodingCtlData::logical_decoding_enabled , LogicalDecodingCtl , LW_EXCLUSIVE , LWLockAcquire() , LWLockRelease() , LogicalDecodingCtlData::pending_disable , PROCSIGNAL_BARRIER_UPDATE_XLOG_LOGICAL_INFO , RecoveryInProgress() , START_CRIT_SECTION , write_logical_decoding_status_update_record() , and LogicalDecodingCtlData::xlog_logical_info .
Referenced by DisableLogicalDecodingIfNecessary() , and xlog_redo() . ◆ DisableLogicalDecodingIfNecessary() void DisableLogicalDecodingIfNecessary ( void ) Definition at line 450 of file logicalctl.c . 451 { 452 bool pending_disable; 453 454 if ( wal_level != WAL_LEVEL_REPLICA ) 455 return ; 456 45
The rest of this page is on the live site.