<div dir="ltr"><div>Hi,</div><div><br></div><div>While working on the pcp_stop_pgpool command to implement cluster mode,</div><div>I realized that we have a lot of clutter in few source files. Especially pool.h include</div><div>file. So I also did some code reorganization and added a bunch of new include</div><div>files in the hope to reduce the size of pool.h and also get rid of too many</div><div>global functions.</div><div><br></div><div>Along with that, I think there are few other files that need a little shredding,</div><div>src/main/pgpool_main.c and src/protocol/child.c are at the top of this</div><div>wanted to be trimmed list. </div><div>So as part of this patch, I have taken a few things related to internal commands</div><div>(interface between the child processes can and Pgpool-II main process)  from</div><div>pgpool_main.c file and moved them into new <font color="#2fb41d" face="Meslo LG L DZ for Powerline"><span style="font-size:14px;font-variant-ligatures:no-common-ligatures">&quot;</span></font>src/main/pgpool_internal_commands.c&quot;</div>





<div><br></div><div>Similarly, src/protocol/child.c had and still has so many functions that do not fit</div><div>with the personality of child.c file. So I have moved some of the stuff related to</div><div>DB functions info src/protocol/pool_pg_utils.c file.</div><div><br></div><div>But I think this is still not enough and we may require another round ( if someone</div><div>is willing to work on it) of a source file shredding. </div>





<div><br></div>Also, I would like to suggest that we just try to refrain from putting everything in pool.h<div>and only do that if it is absolutely necessary. </div><div>As pool.h is like a global include for Pgpool-II source and in my opinion other than few</div><div>struct definitions, Macros, preprocessor Defines, global variable externs like pool_config</div><div>there are very few things (especially functions) that really needed to be globally</div><div>scoped in Pgpool-II.</div><div>So I would like to suggest that we should at least think twice before adding anything to</div><div>pool.h file and consider adding a new include file or even new source file if we</div><div>can&#39;t find an appropriate existing file for putting in the function we just worked up.</div><div><br></div><div>Other than lots and lots of core reorganization changes the patch implements</div><div>&quot;--scope=cluster/local&quot; option in the pcp_stop_pgpool command and adds a proper</div><div>infrastructure in watchdog for broadcasting the custom commands over the watchdog</div><div>cluster to make it easier to implement the --scope=cluster for other PCP utilities.</div><div><br></div><div>Note on implementing the new command to execute over the watchdog network.</div><div><br></div><div>Step 1: Define the command name string</div><div>============</div><div>Define a new string to identify the command name in <span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0);font-family:&quot;Meslo LG L DZ for Powerline&quot;;font-size:14px">src/include/watchdog/wd_ipc_defines.h</span></div>





<div><br></div><div>For example </div><div><br></div><font face="monospace" size="4">+#define WD_COMMAND_RESTART_CLUSTE       &quot;RESTART_CLUSTER&quot;<br>+#define WD_COMMAND_REELECT_MASTER       &quot;REELECT_MASTER&quot;<br>+#define WD_COMMAND_SHUTDOWN_CLUSTER     &quot;SHUTDOWN_CLUSTER&quot;</font><div><br></div><div>Step 2: send the command to watchdog </div><div>=========</div>Construct the argument list using WDExecCommandArg struct<div>and just fire   wd_execute_cluster_command() function with your new command name</div><div>and argument list.</div><div>See implementation of process_shutown_request() for details</div><div><br></div><div>....</div><div>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><font face="monospace" style="" size="4" color="#000000"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">WDExecCommandArg wdExecCommandArg;</span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><font face="monospace" size="4" color="#000000"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">strncpy(wdExecCommandArg.arg_name, &quot;mode&quot;, sizeof(wdExecCommandArg.arg_name) - 1);</span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><font face="monospace" size="4" color="#000000"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">snprintf(wdExecCommandArg.arg_value, sizeof(wdExecCommandArg.arg_name) - 1, &quot;%c&quot;,mode);</span></font></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><font face="monospace" size="4" color="#000000"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">if (wd_execute_cluster_command(WD_COMMAND_SHUTDOWN_CLUSTER,1, &amp;wdExecCommandArg) != COMMAND_OK)</span></font></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><font face="monospace" size="4" color="#000000"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"> <span class="gmail-Apple-converted-space">  </span></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">ereport(ERROR,</span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><font face="monospace" size="4" color="#000000"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> <span class="gmail-Apple-converted-space">      </span></span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">(errmsg(&quot;PCP: error while processing shutdown cluster request&quot;),</span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><font face="monospace" size="4" color="#000000"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">        </span></span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">errdetail(&quot;failed to propogate shutdown command through watchdog&quot;)));</span></font></p></div><div>...</div><div><br></div><div><br></div><div><div>Step 3: Implement the executor</div><div>===========</div><div><font face="monospace"><b>wd_execute_cluster_command_processor</b></font>(..) in watchdog.c is a place where a remote</div><div>Pgpool-II would receive a command. So Just verify if its the command you are implementing</div><div>by comparing the clusterCommand string as it is done for the shutdown command<br><font face="monospace" size="4"><br>if (strcasecmp(WD_COMMAND_SHUTDOWN_CLUSTER, clusterCommand) == 0)<br>{<br>...<br>}</font></div><div><br></div><div><br></div><div><a class="gmail_plusreply" id="plusReplyChip-1" href="mailto:ishii@sraoss.co.jp" tabindex="-1">@Tatsuo Ishii</a> what are your thoughts on using the &quot;--scope=[local | cluster ]&quot; argument<br></div><div>and also on the code reorganization. </div><div><br></div><div><br></div><div>Thanks</div><div>Best regards</div><div>...</div><div><div style="color:rgb(0,0,0)"><div id="gmail-Zm-_Id_-Sgn"><div><span class="gmail-colour" style="color:rgb(68,68,68)">Muhammad Usama<br></span></div><div><span class="gmail-highlight"><span class="gmail-font" style="font-family:Lato"><span class="gmail-size" style="font-size:14px"><span class="gmail-colour" style="color:rgb(68,68,68)">Highgo Software (Canada/China/Pakistan)</span><span class="gmail-Apple-converted-space"><span class="gmail-colour" style="color:rgb(68,68,68)"> </span></span></span></span></span><span class="gmail-colour" style="color:rgb(68,68,68)"><br></span></div><div><span class="gmail-highlight"><span class="gmail-font" style="font-family:Lato"><span class="gmail-size" style="font-size:14px"><span class="gmail-colour" style="color:rgb(68,68,68)">URL :</span><span class="gmail-Apple-converted-space"><span class="gmail-colour" style="color:rgb(68,68,68)"> </span></span></span></span></span><a target="_blank" href="http://www.highgo.ca/" style="color:rgb(89,143,222);font-family:Lato;font-size:14px"><span class="gmail-colour" style="color:rgb(68,68,68)">http://www.highgo.ca</span></a><span class="gmail-highlight"><span class="gmail-font" style="font-family:Lato"><span class="gmail-size" style="font-size:14px"><span class="gmail-Apple-converted-space"><span class="gmail-colour" style="color:rgb(68,68,68)"> </span></span></span></span></span><span class="gmail-colour" style="color:rgb(68,68,68)"><br></span></div><div><span class="gmail-highlight"><span class="gmail-font" style="font-family:Lato"><span class="gmail-size" style="font-size:14px"><span class="gmail-colour" style="color:rgb(68,68,68)">ADDR: 10318 WHALLEY BLVD, Surrey, BC</span><span class="gmail-Apple-converted-space"><span class="gmail-colour" style="color:rgb(68,68,68)"> </span></span></span></span></span><br></div></div></div></div><div><br></div><div><br></div><div><br><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 28, 2020 at 5:30 PM Muhammad Usama &lt;<a href="mailto:m.usama@gmail.com">m.usama@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><br>On Thu, Apr 23, 2020 at 2:06 PM Muhammad Usama &lt;<a href="mailto:m.usama@gmail.com" target="_blank">m.usama@gmail.com</a>&gt; wrote:<br>&gt;<br>&gt; On Tue, Apr 21, 2020 at 12:33 PM Tatsuo Ishii &lt;<a href="mailto:ishii@sraoss.co.jp" target="_blank">ishii@sraoss.co.jp</a>&gt; wrote:<br>&gt; &gt;<br>&gt; &gt; Usama,<br>&gt; &gt;<br>&gt; &gt; Thank you for the propsal.<br>&gt; &gt;<br>&gt; &gt; &gt; Hi Hackers,<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; When PCP was first added to Pgpool-II it was meant to manage/control<br>&gt; &gt; &gt; the single Pgpool-II instance.<br>&gt; &gt; &gt; And after the addition of watchdog more often than not multiple<br>&gt; &gt; &gt; Pgpool-II nodes are installed the system<br>&gt; &gt; &gt; and there is not much work/thoughts have gone into the enhancements of<br>&gt; &gt; &gt; the PCP utilities to make<br>&gt; &gt; &gt; them work on the Pgpool-II cluster.  So lately I was thinking to<br>&gt; &gt; &gt; enhance/add the PCP utilities to make them<br>&gt; &gt; &gt; more cluster-mode friendly.<br>&gt; &gt; &gt; And for that purpose, I think we would require to add/enhance the<br>&gt; &gt; &gt; following PCP commands.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; 1- pcp_reload_config<br>&gt; &gt; &gt; ==================<br>&gt; &gt; &gt; The utility to make the whole Pgpool-II cluster to reload the<br>&gt; &gt; &gt; configuration files at once.<br>&gt; &gt; &gt; I think this is required because currently if some installation has<br>&gt; &gt; &gt; let say 3 node Pgpool-II cluster<br>&gt; &gt; &gt; and we want to change one specific configuration parameter ( for<br>&gt; &gt; &gt; example: adding a new backend node)<br>&gt; &gt; &gt; we would require to go on and edit Pgpool configuration files on each<br>&gt; &gt; &gt; node separately and then<br>&gt; &gt; &gt; issue pgpool reload on each node one by one.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; In my opinion, we need multiple enhancement in this area.<br>&gt; &gt; &gt; We need some mechanisms to let pgpool-II cluster use the centralized<br>&gt; &gt; &gt; configuration<br>&gt; &gt; &gt; ( except watchdog config) or at least a mechanism to push the<br>&gt; &gt; &gt; configuration settings using some<br>&gt; &gt; &gt; new utility like &quot;pcp_load_config&quot; that could take a pgpool.conf file<br>&gt; &gt; &gt; and propagate it to all nodes<br>&gt; &gt; &gt; using watchdog.<br>&gt; &gt;<br>&gt; &gt; Yeah, we definitely need it.<br>&gt; &gt;<br>&gt; &gt; &gt; The centralized configuration part of the problem is a big task and I<br>&gt; &gt; &gt; believe we could take it on after the<br>&gt; &gt; &gt; &quot;simplifying watchdog config&quot; feature that Peng is working on.<br>&gt; &gt; &gt; Meanwhile, I think we can work on pcp_reload_config utility in<br>&gt; &gt; &gt; parallel to make reloading part easier.<br>&gt; &gt;<br>&gt; &gt; +1.<br>&gt; &gt;<br>&gt; &gt; &gt; 2- pcp_restart_pgpool [cluster]<br>&gt; &gt; &gt; ==========================<br>&gt; &gt; &gt; Sometimes, a simple restart solves more problems than any other remedy<br>&gt; &gt; &gt; or debugging.<br>&gt; &gt; &gt; So I think we should have a PCP utility to restart a Pgpool-II node or<br>&gt; &gt; &gt; all node on Pgpool-II cluster.<br>&gt; &gt; &gt; something similar in functionality like &quot;pg_ctl restart&quot; in postgres<br>&gt; &gt;<br>&gt; &gt; +1.<br>&gt; &gt;<br>&gt; &gt; &gt; 3- pcp_watchdog_re-elect<br>&gt; &gt; &gt; ======================<br>&gt; &gt; &gt; What if we want to change the master/coordinator node of the watchdog cluster.<br>&gt; &gt; &gt; There exists no good way for that currently. So I purpose we should<br>&gt; &gt; &gt; have a command to make<br>&gt; &gt; &gt; watchdog re-do the elections. I already had a discussion on this one<br>&gt; &gt; &gt; with Ishii-San sometimes<br>&gt; &gt; &gt; back so I will send a separate proposal for that as well<br>&gt; &gt;<br>&gt; &gt; Looking forward to seeing it.<br>&gt; &gt;<br>&gt; &gt; &gt; 4- pcp_stop_pgpool enhancements<br>&gt; &gt; &gt; ===================<br>&gt; &gt; &gt; pcp_stop_pgpool should be able to stop all the Pgpool-II nodes in<br>&gt; &gt; &gt; Pgpool-II cluster.<br>&gt; &gt; &gt; And for that, I have also cooked up a POC patch which allows the<br>&gt; &gt; &gt; [--all (-a)] option to<br>&gt; &gt; &gt; pcp_stop_pgpool utility and when this --all is specified then the<br>&gt; &gt; &gt; utility stops all the Pgpool-II<br>&gt; &gt; &gt; nodes part of the watchdog cluster.<br>&gt; &gt; &gt; So can you please try the patch and also suggest about the command<br>&gt; &gt; &gt; line option we should<br>&gt; &gt; &gt; use for making the PCP commands interact with cluster rather than the<br>&gt; &gt; &gt; single node.<br>&gt; &gt; &gt; Because I think --all would not be the best choice since it is used by<br>&gt; &gt; &gt; other utilities for a different purpose,<br>&gt; &gt; &gt; and we should come up with new standard command-line switch for all<br>&gt; &gt; &gt; utilities if they want to operate on<br>&gt; &gt; &gt; the cluster rather than on a single node.<br>&gt; &gt;<br>&gt; &gt; +1.<br>&gt; &gt;<br>&gt; &gt; What about:<br>&gt; &gt;<br>&gt; &gt; --cluster, -c   /* affect to whole watchdog cluster */<br>&gt; &gt; --local, -l     /* affect only to local watchdog cluster */<br>&gt;<br>&gt; Yes seems like a good option since both -c and -l are currently not<br>&gt; used by any PCP utility.<br>&gt;<br>&gt;<br>&gt; &gt;<br>&gt; &gt; We actually need --cluster only but for completeness I feel like we&#39;d<br>&gt; &gt; want to have --local as well (it exactly behaves as PCP commands do<br>&gt; &gt; today).<br>&gt; &gt;<br>&gt; &gt; &gt; Or another way would be to leave the pcp_stop_pgpool utility untouched<br>&gt; &gt; &gt; and add a new utility pcp_stop_cluster ?<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; So what are your suggestions and thoughts on this and do you have<br>&gt; &gt; &gt; other functions especially related to<br>&gt; &gt; &gt; cluster mode of pgpool-II that needed controlling/management using PCP system?<br>&gt; &gt;<br>&gt; &gt; I have tested your patch and it worked as expected. Great!<br>&gt;<br>&gt; Thanks, I will make the argument changes (-c and -l) and push it.<br><br><br>I have been thinking about this further, Instead of introducing -c and -l<br>how about adding new argument scope which can be assigned either local or cluster<div><br></div><div>i.e.</div><div><br><div><font size="4">--scope=[local | cluster]<br>and the short form would be -s=[l|c]<br><br></font>Regards</div><div>Muhammad Usama</div><div> <br>&gt;<br>&gt;<br>&gt; Best regards<br>&gt; Muhammad Usama<br>&gt;<br>&gt; &gt;<br>&gt; &gt; Best regards,<br>&gt; &gt; --<br>&gt; &gt; Tatsuo Ishii<br>&gt; &gt; SRA OSS, Inc. Japan<br>&gt; &gt; English: <a href="http://www.sraoss.co.jp/index_en.php" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>&gt; &gt; Japanese:<a href="http://www.sraoss.co.jp" target="_blank">http://www.sraoss.co.jp</a></div></div></div>
</blockquote></div></div></div></div></div>