On 2021/03/02 10:10, Thomas Munro wrote:
On Tue, Mar 2, 2021 at 12:00 AM Thomas Munro <thomas.mu...@gmail.com> wrote:
On Mon, Nov 16, 2020 at 8:56 PM Michael Paquier <mich...@paquier.xyz> wrote:
No objections with the two changes from pg_usleep() to WaitLatch() so
they could be applied separately first.

I thought about committing that first part, and got as far as
splitting the patch into two (see attached), but then I re-read
Fujii-san's message about the speed of promotion and realised that we
really should have something like a condition variable for walRcvState
changes.  I'll look into that.

Here's an experimental attempt at that, though I'm not sure if it's
the right approach.  Of course it's not necessary to use condition
variables here: we could use recoveryWakeupLatch, because we're not in
any doubt about who needs to be woken up.  But then you could get
constant wakeups while recovery is paused, unless you also suppressed
that somehow.  You could use the startup process's procLatch,
advertised in shmem, but that's almost a condition variable.  With a
condition variable, you get to name it something like
walRcvStateChanged, and then the programming rule is very clear: if
you change walRcvState, you need to broadcast that fact (and you don't
have to worry about who might be interested).  One question I haven't
got to the bottom of: is it a problem for the startup process that CVs
use CHECK_FOR_INTERRUPTS()?

I found 0001 patch was committed in de829ddf23, and which added new
wait event WalrcvExit. This name seems not consistent with other wait
events. I'm thinking it's better to rename it to WalReceiverExit. Thought?
Patch attached.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 19540206f9..43c07da20e 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -1763,8 +1763,8 @@ postgres   27093  0.0  0.0  30096  2752 ?        Ss   
11:34   0:00 postgres: ser
        replication.</entry>
      </row>
      <row>
-      <entry><literal>WalrcvExit</literal></entry>
-      <entry>Waiting for the walreceiver to exit.</entry>
+      <entry><literal>WalReceiverExit</literal></entry>
+      <entry>Waiting for the WAL receiver to exit.</entry>
      </row>
      <row>
       <entry><literal>WalReceiverWaitStart</literal></entry>
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index b7af7c2707..60f45ccc4e 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -4121,8 +4121,8 @@ pgstat_get_wait_ipc(WaitEventIPC w)
                case WAIT_EVENT_SYNC_REP:
                        event_name = "SyncRep";
                        break;
-               case WAIT_EVENT_WALRCV_EXIT:
-                       event_name = "WalrcvExit";
+               case WAIT_EVENT_WAL_RECEIVER_EXIT:
+                       event_name = "WalReceiverExit";
                        break;
                case WAIT_EVENT_WAL_RECEIVER_WAIT_START:
                        event_name = "WalReceiverWaitStart";
diff --git a/src/backend/replication/walreceiverfuncs.c 
b/src/backend/replication/walreceiverfuncs.c
index fff6c54c45..6f0acbfdef 100644
--- a/src/backend/replication/walreceiverfuncs.c
+++ b/src/backend/replication/walreceiverfuncs.c
@@ -224,7 +224,7 @@ ShutdownWalRcv(void)
        ConditionVariablePrepareToSleep(&walrcv->walRcvStoppedCV);
        while (WalRcvRunning())
                ConditionVariableSleep(&walrcv->walRcvStoppedCV,
-                                                          
WAIT_EVENT_WALRCV_EXIT);
+                                                          
WAIT_EVENT_WAL_RECEIVER_EXIT);
        ConditionVariableCancelSleep();
 }
 
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 2c82313550..87672e6f30 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -1008,7 +1008,7 @@ typedef enum
        WAIT_EVENT_REPLICATION_SLOT_DROP,
        WAIT_EVENT_SAFE_SNAPSHOT,
        WAIT_EVENT_SYNC_REP,
-       WAIT_EVENT_WALRCV_EXIT,
+       WAIT_EVENT_WAL_RECEIVER_EXIT,
        WAIT_EVENT_WAL_RECEIVER_WAIT_START,
        WAIT_EVENT_XACT_GROUP_UPDATE
 } WaitEventIPC;

Reply via email to