@@ -3475,6 +3475,34 @@ signal_child(PMChild *pmchild, int signal)
34753475#endif
34763476}
34773477
3478+ static void
3479+ adjust_bkendtype_if_needed (PMChild * bp , BackendTypeMask targetMask )
3480+ {
3481+ /*
3482+ * If we need to distinguish between B_BACKEND and B_WAL_SENDER, check
3483+ * if any B_BACKEND backends have recently announced that they are
3484+ * actually WAL senders.
3485+ */
3486+ if (btmask_contains (targetMask , B_WAL_SENDER ) != btmask_contains (targetMask , B_BACKEND ) &&
3487+ bp -> bkend_type == B_BACKEND )
3488+ {
3489+ if (IsPostmasterChildWalSender (bp -> child_slot ))
3490+ bp -> bkend_type = B_WAL_SENDER ;
3491+ }
3492+
3493+ /*
3494+ * If we need to distinguish between B_BG_WORKER and B_WAL_SENDER,
3495+ * check if any B_BG_WORKER backends have recently announced that
3496+ * they are actually WAL senders.
3497+ */
3498+ if (btmask_contains (targetMask , B_WAL_SENDER ) != btmask_contains (targetMask , B_BG_WORKER ) &&
3499+ bp -> bkend_type == B_BG_WORKER )
3500+ {
3501+ if (IsPostmasterChildWalSender (bp -> child_slot ))
3502+ bp -> bkend_type = B_WAL_SENDER ;
3503+ }
3504+ }
3505+
34783506/*
34793507 * Send a signal to the targeted children.
34803508 */
@@ -3488,29 +3516,7 @@ SignalChildren(int signal, BackendTypeMask targetMask)
34883516 {
34893517 PMChild * bp = dlist_container (PMChild , elem , iter .cur );
34903518
3491- /*
3492- * If we need to distinguish between B_BACKEND and B_WAL_SENDER, check
3493- * if any B_BACKEND backends have recently announced that they are
3494- * actually WAL senders.
3495- */
3496- if (btmask_contains (targetMask , B_WAL_SENDER ) != btmask_contains (targetMask , B_BACKEND ) &&
3497- bp -> bkend_type == B_BACKEND )
3498- {
3499- if (IsPostmasterChildWalSender (bp -> child_slot ))
3500- bp -> bkend_type = B_WAL_SENDER ;
3501- }
3502-
3503- /*
3504- * If we need to distinguish between B_BG_WORKER and B_WAL_SENDER,
3505- * check if any B_BG_WORKER backends have recently announced that
3506- * they are actually WAL senders.
3507- */
3508- if (btmask_contains (targetMask , B_WAL_SENDER ) != btmask_contains (targetMask , B_BG_WORKER ) &&
3509- bp -> bkend_type == B_BG_WORKER )
3510- {
3511- if (IsPostmasterChildWalSender (bp -> child_slot ))
3512- bp -> bkend_type = B_WAL_SENDER ;
3513- }
3519+ adjust_bkendtype_if_needed (bp , targetMask );
35143520
35153521 if (!btmask_contains (targetMask , bp -> bkend_type ))
35163522 continue ;
@@ -3934,29 +3940,7 @@ CountChildren(BackendTypeMask targetMask)
39343940 {
39353941 PMChild * bp = dlist_container (PMChild , elem , iter .cur );
39363942
3937- /*
3938- * If we need to distinguish between B_BACKEND and B_WAL_SENDER, check
3939- * if any B_BACKEND backends have recently announced that they are
3940- * actually WAL senders.
3941- */
3942- if (btmask_contains (targetMask , B_WAL_SENDER ) != btmask_contains (targetMask , B_BACKEND ) &&
3943- bp -> bkend_type == B_BACKEND )
3944- {
3945- if (IsPostmasterChildWalSender (bp -> child_slot ))
3946- bp -> bkend_type = B_WAL_SENDER ;
3947- }
3948-
3949- /*
3950- * If we need to distinguish between B_BG_WORKER and B_WAL_SENDER,
3951- * check if any B_BG_WORKER backends have recently announced that
3952- * they are actually WAL senders.
3953- */
3954- if (btmask_contains (targetMask , B_WAL_SENDER ) != btmask_contains (targetMask , B_BG_WORKER ) &&
3955- bp -> bkend_type == B_BG_WORKER )
3956- {
3957- if (IsPostmasterChildWalSender (bp -> child_slot ))
3958- bp -> bkend_type = B_WAL_SENDER ;
3959- }
3943+ adjust_bkendtype_if_needed (bp , targetMask );
39603944
39613945 if (!btmask_contains (targetMask , bp -> bkend_type ))
39623946 continue ;
0 commit comments