当前位置:网站首页>PostgreSQL database replication - background first-class citizen process walreceiver ready_ to_ display
PostgreSQL database replication - background first-class citizen process walreceiver ready_ to_ display
2022-06-09 07:18:00 【Tertium ferrugosum】

After processing walRcvState After the state , That is to do the normal process of the state machine (WALRCV_STARTING–>WALRCV_STREAMING), Will be set WalRcvData Of pid and walRcvState. Set up ready_to_display by false, Because we haven't learned from WalRcvData Remove connection information ( When the standby machine starts, it will call RequestXLogStreaming function , This function will GUC In the parameter primary_conninfo The information is kept in WalRcvData in (WalRcvData By WalRcvShmemInit Function initialized in shared memory ), It will also be saved WAL Log replication start LSN And timeline information ). The following is the code for extracting information :
strlcpy(conninfo, (char *) walrcv->conninfo, MAXCONNINFO); // take WalRcvData Copy the connection string of to the local conninfo in
strlcpy(slotname, (char *) walrcv->slotname, NAMEDATALEN); // take WalRcvData Copy the slot name string of to the local slotname in
is_temp_slot = walrcv->is_temp_slot; // Whether to use temporary copy slots
startpoint = walrcv->receiveStart; // Standby Want to ask for XLOG Logical address location
startpointTLI = walrcv->receiveStartTLI; // Standby Want to request a timeline
receiveStart and receiveStartTLI Indicates the position and timeline of the first byte to be received . When the startup process starts walreceiver when , It sets these to the point where it wants the streaming to start .
/* Shared memory area for management of walreceiver process */
typedef struct {
/* receiveStart and receiveStartTLI indicate the first byte position and timeline that will be received. When startup process starts the walreceiver, it sets these to the point where it wants the streaming to begin. */
XLogRecPtr receiveStart;
TimeLineID receiveStartTLI;
...
} WalRcvData;
lastMsgSendTime and lastMsgReceiptTime Represents the timestamp of message receiving and sending ,latestWalEndTime Recently received WAL Time for .
writtenUpto And flushedUpto similar , But advanced operations are performed after writing and before refreshing , No need to acquire a spin lock . up to now , Other processes can read data , It should not be used for data integrity purposes .writtenUpto yes Standby WalReceiver On wal Write the position ,flushedUpto yes Standby WalReceiver On wal The position of the brush plate .flushedUpto-1 Is the last byte position that has been received ,receivedTLI It's the timeline it comes from . In the first boot walreceiver when , These settings are receiveStart and receiveStartTLI. after , Whenever you will receive WAL Refresh to disk ,walreceiver Will update these contents .
/* Initialise to a sanish value */
walrcv->lastMsgSendTime = walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = now;
walrcv->latch = &MyProc->procLatch; /* Report the latch to use to awaken this process */
SpinLockRelease(&walrcv->mutex);
pg_atomic_write_u64(&WalRcv->writtenUpto, 0);
typedef struct {
/* Time of send and receive of any message received. */
TimestampTz lastMsgSendTime;
TimestampTz lastMsgReceiptTime;
/* Time Latest reported end of WAL on the sender */
TimestampTz latestWalEndTime;
/* Like flushedUpto, but advanced after writing and before flushing, without the need to acquire the spin lock. Data can be read by another process up to this point, but shouldn't be used for data integrity purposes. */
pg_atomic_uint64 writtenUpto;
} WalRcvData;
The signal processing logic and the shared memory exit callback function register and obtain libpqwalreceiver Some functions defined .
/* Arrange to clean up at walreceiver exit */
on_shmem_exit(WalRcvDie, 0);
/* Properly accept or ignore signals the postmaster might send us */
pqsignal(SIGHUP, SignalHandlerForConfigReload); /* set flag to read config file */
pqsignal(SIGINT, SIG_IGN);
pqsignal(SIGTERM, SignalHandlerForShutdownRequest); /* request shutdown */
/* SIGQUIT handler was already set up by InitPostmasterChild */
pqsignal(SIGALRM, SIG_IGN);
pqsignal(SIGPIPE, SIG_IGN);
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
pqsignal(SIGUSR2, SIG_IGN);
/* Reset some signals that are accepted by postmaster but not here */
pqsignal(SIGCHLD, SIG_DFL);
/* Load the libpq-specific functions */
load_file("libpqwalreceiver", false);
if (WalReceiverFunctions == NULL) elog(ERROR, "libpqwalreceiver didn't initialize correctly");
/* Unblock signals (they were blocked when the postmaster forked us) */
PG_SETMASK(&UnBlockSig);
PostgreSQL Database replication —— Backstage first-class citizen process WalReceiver Learn about connections
Save the connection string visible to the user . For safety's sake , This will destroy the original conninfo. Also save this walreceiver The host and port of the sending server connected to . Set the obtained connection string to walrcv->conninfo in ; take sender_host and sender_port Also set to walrcv in .
tmp_conninfo = walrcv_get_conninfo(wrconn); // Save connection string
walrcv_get_senderinfo(wrconn, &sender_host, &sender_port); // Get the host name and port of the sender
memset(walrcv->conninfo, 0, MAXCONNINFO);
if (tmp_conninfo) strlcpy((char *) walrcv->conninfo, tmp_conninfo, MAXCONNINFO);
memset(walrcv->sender_host, 0, NI_MAXHOST);
if (sender_host) strlcpy((char *) walrcv->sender_host, sender_host, NI_MAXHOST);
walrcv->sender_port = sender_port;
walrcv->ready_to_display = true;
边栏推荐
- PostgreSQL数据库复制——后台一等公民进程WalReceiver ready_to_display
- 「冲刺大厂基础2」
- Pycharm and MySQL as a student information management system
- 【工作向】conda常用命令汇总
- Use postman to simulate a request to carry a token
- Database operation statement
- 工控安全行为规范
- Related methods of thread class
- Distributed message middleware -- Introduction to message queue
- How to solve security problems in low code platforms?
猜你喜欢
![[STL] Introduction to the use of set and map](/img/04/cf9deb990af72eece3d081a563c7fc.jpg)
[STL] Introduction to the use of set and map

Pycharm and MySQL as a student information management system

【系统分析师之路】第十五章 复盘数据库系统(关系数据库应用)

推送相关的总结

defineProperty

InfoWorld article - applying data orchestration technology to AI model training

UML series (24) advanced behavior - time and space

2022年全国最新消防设施操作员(中级消防设施操作员)考试模拟题库及答案

Apache 网页与安全优化

2022 national latest Fire Facility operator (Intermediate Fire Facility operator) test Simulated question base and Answers
随机推荐
In the afternoon of July 2, 2022, Jinan IT technology gathering, interested friends scanned the code to sign up for group exchange
5. Multimedia Foundation
UML总结
Champignon Street publie les résultats de l'exercice 2022: les pertes du deuxième semestre ont diminué de 50% d'une année sur l'autre
大厂面试算法系列-动态规划求解最长公共子串问题
数据库期末考试大纲
Naive Bayes classifier
C语言文件——字符读出与写入
287. 寻找重复数
如何解决低代码平台中的安全问题?
Basic knowledge summary of database
pycharm 和mysql做学生信息管理系统问题求解
如何防范最大的云安全威胁
UML series (24) advanced behavior - time and space
Android importing sqllite database
Distributed message middleware -- Introduction to message queue
[C language] summary of document knowledge points
WPF data binding (II)
Fourier transform signal processing
209. minimum length subarray