summaryrefslogtreecommitdiff
path: root/src/backend/replication
diff options
context:
space:
mode:
authorHeikki Linnakangas2024-11-01 11:47:20 +0000
committerHeikki Linnakangas2024-11-01 11:47:20 +0000
commita9c546a5a3783810a1b665f246fc6d0a596d0606 (patch)
tree24dd96745733f9a63f0a68d7c19773e64fa6a81d /src/backend/replication
parente819bbb7c82ac048ffd865ba3f2d2c4933923c77 (diff)
Use ProcNumbers instead of direct Latch pointers to address other procs
This is in preparation for replacing Latches with a new abstraction. That's still work in progress, but this seems a little tidier anyway, so let's get this refactoring out of the way already. Discussion: https://www.postgresql.org/message-id/391abe21-413e-4d91-a650-b663af49500c%40iki.fi
Diffstat (limited to 'src/backend/replication')
-rw-r--r--src/backend/replication/libpqwalreceiver/libpqwalreceiver.c1
-rw-r--r--src/backend/replication/walreceiver.c16
-rw-r--r--src/backend/replication/walreceiverfuncs.c11
3 files changed, 15 insertions, 13 deletions
diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
index 97f957cd87b..c74369953f8 100644
--- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
+++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
@@ -30,6 +30,7 @@
#include "pgstat.h"
#include "pqexpbuffer.h"
#include "replication/walreceiver.h"
+#include "storage/latch.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
#include "utils/pg_lsn.h"
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index a27aee63def..5f641d27905 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -266,8 +266,8 @@ WalReceiverMain(char *startup_data, size_t startup_data_len)
walrcv->lastMsgSendTime =
walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = now;
- /* Report the latch to use to awaken this process */
- walrcv->latch = &MyProc->procLatch;
+ /* Report our proc number so that others can wake us up */
+ walrcv->procno = MyProcNumber;
SpinLockRelease(&walrcv->mutex);
@@ -819,8 +819,8 @@ WalRcvDie(int code, Datum arg)
Assert(walrcv->pid == MyProcPid);
walrcv->walRcvState = WALRCV_STOPPED;
walrcv->pid = 0;
+ walrcv->procno = INVALID_PROC_NUMBER;
walrcv->ready_to_display = false;
- walrcv->latch = NULL;
SpinLockRelease(&walrcv->mutex);
ConditionVariableBroadcast(&walrcv->walRcvStoppedCV);
@@ -1358,15 +1358,15 @@ WalRcvComputeNextWakeup(WalRcvWakeupReason reason, TimestampTz now)
void
WalRcvForceReply(void)
{
- Latch *latch;
+ ProcNumber procno;
WalRcv->force_reply = true;
- /* fetching the latch pointer might not be atomic, so use spinlock */
+ /* fetching the proc number is probably atomic, but don't rely on it */
SpinLockAcquire(&WalRcv->mutex);
- latch = WalRcv->latch;
+ procno = WalRcv->procno;
SpinLockRelease(&WalRcv->mutex);
- if (latch)
- SetLatch(latch);
+ if (procno != INVALID_PROC_NUMBER)
+ SetLatch(&GetPGProcByNumber(procno)->procLatch);
}
/*
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c
index 85a19cdfa5c..8557d10cf9d 100644
--- a/src/backend/replication/walreceiverfuncs.c
+++ b/src/backend/replication/walreceiverfuncs.c
@@ -27,6 +27,7 @@
#include "pgstat.h"
#include "replication/walreceiver.h"
#include "storage/pmsignal.h"
+#include "storage/proc.h"
#include "storage/shmem.h"
#include "utils/timestamp.h"
@@ -66,7 +67,7 @@ WalRcvShmemInit(void)
ConditionVariableInit(&WalRcv->walRcvStoppedCV);
SpinLockInit(&WalRcv->mutex);
pg_atomic_init_u64(&WalRcv->writtenUpto, 0);
- WalRcv->latch = NULL;
+ WalRcv->procno = INVALID_PROC_NUMBER;
}
}
@@ -248,7 +249,7 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo,
WalRcvData *walrcv = WalRcv;
bool launch = false;
pg_time_t now = (pg_time_t) time(NULL);
- Latch *latch;
+ ProcNumber walrcv_proc;
/*
* We always start at the beginning of the segment. That prevents a broken
@@ -309,14 +310,14 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo,
walrcv->receiveStart = recptr;
walrcv->receiveStartTLI = tli;
- latch = walrcv->latch;
+ walrcv_proc = walrcv->procno;
SpinLockRelease(&walrcv->mutex);
if (launch)
SendPostmasterSignal(PMSIGNAL_START_WALRECEIVER);
- else if (latch)
- SetLatch(latch);
+ else if (walrcv_proc != INVALID_PROC_NUMBER)
+ SetLatch(&GetPGProcByNumber(walrcv_proc)->procLatch);
}
/*