<div dir="ltr">Thanks Tatsuo for your review.<div><br></div><div>Usama is currently working on the last piece of this effort by integrating the memory/exception manager in the query parsing module. We are hoping to complete the coding by the end of next week. The goal is to get this functionality committed to the master branch before the end of Jan.</div>
<div><br></div><div>I don&#39;t think we need to write any new test cases to test the functionality. We need to ensure that the current test suite runs fine with the changes. </div><div><br></div><div>-- Ahsan  <br><div><br>
</div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 7, 2014 at 5:26 AM, Tatsuo Ishii <span dir="ltr">&lt;<a href="mailto:ishii@postgresql.org" target="_blank">ishii@postgresql.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have verified v3 patch and it complies fine on my Linux box. Thanks!  I<br>
have committed and pushed to master. In addition to your v3 patch, I<br>
have changed copyright year of pool.h.<br>
<div class="HOEnZb"><div class="h5">--<br>
Tatsuo Ishii<br>
SRA OSS, Inc. Japan<br>
English: <a href="http://www.sraoss.co.jp/index_en.php" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
Japanese: <a href="http://www.sraoss.co.jp" target="_blank">http://www.sraoss.co.jp</a><br>
<br>
&gt; Hi Tatsuo, Thanks for the review<br>
&gt;<br>
&gt; your version of patch is causing the compilation problem on the OS/X, The<br>
&gt; reason is the configure script is<br>
&gt; defining HAVE_STRLCPY in config.h file while the pool.h is adding the<br>
&gt; condition on HAVE_DECL_STRLCPY.<br>
&gt; I have updated the patch to fix this issue can you please verify if the<br>
&gt; attached version works on your linux box.<br>
&gt;<br>
&gt;<br>
&gt; Regards<br>
&gt; Usama<br>
&gt;<br>
&gt; On Sat, Jan 4, 2014 at 4:44 PM, Tatsuo Ishii &lt;<a href="mailto:ishii@postgresql.org">ishii@postgresql.org</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; Sorry for delay. I have checked your patch.<br>
&gt;&gt;<br>
&gt;&gt; &gt; Hi Tatsuo<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks a bundle for looking into the patch.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Sat, Dec 14, 2013 at 2:35 PM, Tatsuo Ishii &lt;<a href="mailto:ishii@postgresql.org">ishii@postgresql.org</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; Usama,<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Thanks for the great work.<br>
&gt;&gt; &gt;&gt; I have take a look at your patches.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Compiling the source code:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; I see some &quot;//&quot; comments. I believe they are temporary ones. We follow<br>
&gt;&gt; &gt;&gt; the PostgreSQL coding standard and it does not allow to use &quot;//&quot;<br>
&gt;&gt; &gt;&gt; comments. I also see some compiler warnings because of function<br>
&gt;&gt; &gt;&gt; prototypes are not declared.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Yes I intend to follow the PostgreSQL coding style and standards, the<br>
&gt;&gt; &quot;//&quot;<br>
&gt;&gt; &gt; style comments were left<br>
&gt;&gt; &gt; in the code unintentionally, and I had this thing in the mind and last<br>
&gt;&gt; TODO<br>
&gt;&gt; &gt; of this effort is to clean up<br>
&gt;&gt; &gt; the code for these kind of mistakes.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; I noticed you commented out following line which causes lots of<br>
&gt;&gt; &gt;&gt; compiler warnings. Is that intended?<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; extern size_t strlcpy(char *dst, const char *src, size_t siz);<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Actually I use Mac OS/X for development and since OS/X is BSD based<br>
&gt;&gt;  which<br>
&gt;&gt; &gt; already<br>
&gt;&gt; &gt; contains the native strlcpy function defined in string.h, So I was<br>
&gt;&gt; getting<br>
&gt;&gt; &gt; the compilation error.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Please find the attached patch (strlcpy_fix.patch) to properly fix this<br>
&gt;&gt; &gt; problem, The patch adds the check<br>
&gt;&gt; &gt; in configure to test if strlcpy is provided by OS and in that case does<br>
&gt;&gt; not<br>
&gt;&gt; &gt; externs the function in pool.h.<br>
&gt;&gt; &gt; Since this issue also exists in the master branch so If you feel the<br>
&gt;&gt; &gt; comfortable with the patch and the fix<br>
&gt;&gt; &gt; ,can you please also apply this on master branch.<br>
&gt;&gt; &gt; Note: You will require to run the autoconf after this patch.<br>
&gt;&gt;<br>
&gt;&gt; Unfortunately your patch did not work on my Linux box.<br>
&gt;&gt;<br>
&gt;&gt; AC_CHECK_DECLS([strlcat, strlcpy]) produces config.h like this if<br>
&gt;&gt; there&#39;s no strlcpy in system library.<br>
&gt;&gt;<br>
&gt;&gt; /* Define to 1 if you have the declaration of `strlcpy&#39;, and to 0 if you<br>
&gt;&gt;    don&#39;t. */<br>
&gt;&gt; #define HAVE_DECL_STRLCPY 0<br>
&gt;&gt;<br>
&gt;&gt; which makes following declaration in pool.h void, which I think you<br>
&gt;&gt; are not willing to do so.<br>
&gt;&gt;<br>
&gt;&gt; #ifndef HAVE_DECL_STRLCPY<br>
&gt;&gt; extern size_t strlcpy(char *dst, const char *src, size_t siz);<br>
&gt;&gt; #endif<br>
&gt;&gt;<br>
&gt;&gt; So I have changed AC_CHECK_DECLS([strlcat, strlcpy]) to<br>
&gt;&gt; AC_CHECK_FUNCS([strlcat, strlcpy]). Please verify attached patch works<br>
&gt;&gt; for Mac OS X.<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><br>
&gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt; pgpool_main.c PgpoolMain()<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; The patch changes the flow of how health check failures are processed,<br>
&gt;&gt; &gt;&gt; &gt; health_check() function which<br>
&gt;&gt; &gt;&gt; &gt; previously used to return health check failing node number or success<br>
&gt;&gt; is<br>
&gt;&gt; &gt;&gt; &gt; changed to do_health_check(),<br>
&gt;&gt; &gt;&gt; &gt; which reports an error through ereport in case of failed health check<br>
&gt;&gt; on<br>
&gt;&gt; &gt;&gt; &gt; backend node and than the failure is<br>
&gt;&gt; &gt;&gt; &gt; processed by &quot;process_backend_health_check_failure()&quot; function.<br>
&gt;&gt; &gt;&gt; &gt; This portion of the code requires the most review and suggestions,<br>
&gt;&gt; Since<br>
&gt;&gt; &gt;&gt; &gt; there are many different<br>
&gt;&gt; &gt;&gt; &gt; ways to implement this health checking.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; I saw followings:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; LOG:  starting health check<br>
&gt;&gt; &gt;&gt; LOCATION:  pgpool_main.c:369<br>
&gt;&gt; &gt;&gt; LOG:  after retry 0, All backends are returned to healthy state<br>
&gt;&gt; &gt;&gt; LOCATION:  pgpool_main.c:411<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Before &quot;starting health check&quot; message was debug message and should<br>
&gt;&gt; &gt;&gt; remain debug IMO. Otherwise they flood the log file.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; I also see problem with &quot;after retry 0, All backends are returned to<br>
&gt;&gt; &gt;&gt; healthy state&quot; message since the message appears even there&#39;s no retry<br>
&gt;&gt; &gt;&gt; (again before we do not spit the message if we are not doing retry).<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks for pointing these. The 2nd attached patch &quot;exmgr_fix.patch&quot; tries<br>
&gt;&gt; &gt; to fix these, which can be applied<br>
&gt;&gt; &gt; on EXCEPTION_MGR development branch.<br>
&gt;&gt;<br>
&gt;&gt; Looks good.<br>
&gt;&gt;<br>
&gt;&gt; &gt;&gt; Most importantly, the message style is pretty different from current<br>
&gt;&gt; &gt;&gt; one. no timestamp, no pid.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Yes this one is known thing, I some how missed to point it out<br>
&gt;&gt; &gt; specifically. This is the part of the TODO item mentioned<br>
&gt;&gt; &gt; upthread &quot;changes and cleanup of elog.c and elog.h&quot;. I have intentionally<br>
&gt;&gt; &gt; left it as a last item because it deals mostly with<br>
&gt;&gt; &gt; cosmetic issues. Apart from that this TODO item also have couple of more<br>
&gt;&gt; &gt; things which are needed to be done<br>
&gt;&gt; &gt; by elog api. e.g. adding the configuration parameters similar to<br>
&gt;&gt; &gt; PostgreSQL&#39;s<br>
&gt;&gt; &gt; log_min_error_statement, log_min_messages, client_min_messages to control<br>
&gt;&gt; &gt; the level of message generated and reported by pgpool.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks<br>
&gt;&gt; &gt; Muhammad Usama<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; Another way could be to use PG_TRY and PG_CATCH inside health_check<br>
&gt;&gt; &gt;&gt; &gt; function and if<br>
&gt;&gt; &gt;&gt; &gt; &quot;make_persistent_db_connection()&quot; throws an error, the PG_CATCH block<br>
&gt;&gt; &gt;&gt; &gt; catches the error<br>
&gt;&gt; &gt;&gt; &gt; and return the failing node number<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; something like<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; health_check()<br>
&gt;&gt; &gt;&gt; &gt; {<br>
&gt;&gt; &gt;&gt; &gt; ....<br>
&gt;&gt; &gt;&gt; &gt; for(i =0; i&lt; MAX_BACKEND; i++)<br>
&gt;&gt; &gt;&gt; &gt; PG_TRY()<br>
&gt;&gt; &gt;&gt; &gt; {<br>
&gt;&gt; &gt;&gt; &gt;     make_persistent_db_connection();<br>
&gt;&gt; &gt;&gt; &gt; ...<br>
&gt;&gt; &gt;&gt; &gt; }<br>
&gt;&gt; &gt;&gt; &gt; PG_CATCH();<br>
&gt;&gt; &gt;&gt; &gt; {<br>
&gt;&gt; &gt;&gt; &gt; ....<br>
&gt;&gt; &gt;&gt; &gt;  return i;<br>
&gt;&gt; &gt;&gt; &gt; }<br>
&gt;&gt; &gt;&gt; &gt; PG_END_TRY();<br>
&gt;&gt; &gt;&gt; &gt; return 0;<br>
&gt;&gt; &gt;&gt; &gt; }<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; And than the main loop process the failure, the similar way it it<br>
&gt;&gt; &gt;&gt; &gt; processing it now (with out the patch).<br>
&gt;&gt; &gt;&gt; &gt; But the current approach followed by the patch seems to come more<br>
&gt;&gt; natural<br>
&gt;&gt; &gt;&gt; &gt; with the exception manager<br>
&gt;&gt; &gt;&gt; &gt; and yet on the negative side the current approach requires to add a<br>
&gt;&gt; state<br>
&gt;&gt; &gt;&gt; &gt; machine to the main loop.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Agreed.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt; So suggestions and comments on this portion of code and implementation<br>
&gt;&gt; &gt;&gt; &gt; approach would be very helpful.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; pgpool child process loop<br>
&gt;&gt; &gt;&gt; &gt; ==================<br>
&gt;&gt; &gt;&gt; &gt; src/protocol/child.c  do_child()<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; do_child() function is the work horse of pg_pool child process, and<br>
&gt;&gt; &gt;&gt; &gt; basically contains two loops those<br>
&gt;&gt; &gt;&gt; &gt; spans the life cycle of child process. First step is to wait for the<br>
&gt;&gt; &gt;&gt; client<br>
&gt;&gt; &gt;&gt; &gt; connection, and once this part<br>
&gt;&gt; &gt;&gt; &gt; is successful, the child is connected with the front end, the process<br>
&gt;&gt; &gt;&gt; goes<br>
&gt;&gt; &gt;&gt; &gt; into the query process mode.<br>
&gt;&gt; &gt;&gt; &gt; So I have used two memory contexts instead of one per loop memory<br>
&gt;&gt; context<br>
&gt;&gt; &gt;&gt; &gt; for this process.<br>
&gt;&gt; &gt;&gt; &gt; QueryProcessMemoryContext and ChildLoopMemoryContext, where later is<br>
&gt;&gt; used<br>
&gt;&gt; &gt;&gt; &gt; for the pahse<br>
&gt;&gt; &gt;&gt; &gt; where child is waiting for the front end connections and the former is<br>
&gt;&gt; &gt;&gt; for<br>
&gt;&gt; &gt;&gt; &gt; the query process phase.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Secondly for the query processing function all my current code<br>
&gt;&gt; browsing<br>
&gt;&gt; &gt;&gt; &gt; leads me to the believe that<br>
&gt;&gt; &gt;&gt; &gt; although &quot;pool_process_query()&quot; caller has handled five possible<br>
&gt;&gt; return<br>
&gt;&gt; &gt;&gt; &gt; values from the function<br>
&gt;&gt; &gt;&gt; &gt; i.e POOL_END, POOL_ERROR, POOL_FATAL, POOL_IDLE and POOL_CONTINUE.<br>
&gt;&gt; &gt;&gt; &gt; But in actual the function returns only POOL_END, POOL_ERROR and the<br>
&gt;&gt; &gt;&gt; &gt; success which is<br>
&gt;&gt; &gt;&gt; &gt; POOL_CONTINUE. and to squeeze in the managers in query processing<br>
&gt;&gt; &gt;&gt; function<br>
&gt;&gt; &gt;&gt; &gt; I have moved forward<br>
&gt;&gt; &gt;&gt; &gt; with the above mentioned assumptions. Also my current code<br>
&gt;&gt; understanding<br>
&gt;&gt; &gt;&gt; on<br>
&gt;&gt; &gt;&gt; &gt; child process flow is when<br>
&gt;&gt; &gt;&gt; &gt; ever some error occurs in query process phase of child process that<br>
&gt;&gt; error<br>
&gt;&gt; &gt;&gt; &gt; actually terminates that particular client<br>
&gt;&gt; &gt;&gt; &gt; So I have added the below code in elog.c file to treat the ERROR in<br>
&gt;&gt; child<br>
&gt;&gt; &gt;&gt; &gt; process as FATAL in case the<br>
&gt;&gt; &gt;&gt; &gt; front end clint is connected with the child process.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; if(elevel  == ERROR)<br>
&gt;&gt; &gt;&gt; &gt; {<br>
&gt;&gt; &gt;&gt; &gt;    if(processType == PT_CHILD)<br>
&gt;&gt; &gt;&gt; &gt;    {<br>
&gt;&gt; &gt;&gt; &gt;      /*<br>
&gt;&gt; &gt;&gt; &gt;       * If the frontend connection exists, treat this error as FATAL<br>
&gt;&gt; &gt;&gt; &gt;       */<br>
&gt;&gt; &gt;&gt; &gt;      if(is_session_connected())<br>
&gt;&gt; &gt;&gt; &gt;         elevel = FATAL;<br>
&gt;&gt; &gt;&gt; &gt;     }<br>
&gt;&gt; &gt;&gt; &gt; }<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Reviews comments and suggestions are most welcome<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Thanks<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Muhammad Usama<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt;<br>
</div></div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
pgpool-hackers mailing list<br>
<a href="mailto:pgpool-hackers@pgpool.net">pgpool-hackers@pgpool.net</a><br>
<a href="http://www.pgpool.net/mailman/listinfo/pgpool-hackers" target="_blank">http://www.pgpool.net/mailman/listinfo/pgpool-hackers</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Ahsan Hadi<br>Snr Director Product Development<br>EnterpriseDB Corporation<br>The Enterprise Postgres Company<br><br>Phone: +92-51-8358874    <br>Mobile: +92-333-5162114<br>
<br>Website: <a href="http://www.enterprisedb.com">www.enterprisedb.com</a><br>EnterpriseDB Blog: <a href="http://blogs.enterprisedb.com/">http://blogs.enterprisedb.com/</a><br>Follow us on Twitter: <a href="http://www.twitter.com/enterprisedb">http://www.twitter.com/enterprisedb</a><br>
<br>This e-mail message (and any attachment) is intended for the use of the individual or entity to whom it is addressed. This message contains information from EnterpriseDB Corporation that may be privileged, confidential, or exempt from disclosure under applicable law. If you are not the intended recipient or authorized to receive this for the intended recipient, any use, dissemination, distribution, retention, archiving, or copying of this communication is strictly prohibited. If you have received this e-mail in error, please notify the sender immediately by reply e-mail and delete this message.
</div>