<div dir="ltr">Hi Ishii-San<div><br></div><div>Thanks for reviewing the patch. <br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 17, 2015 at 7:31 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Usama,<br>
<br>
I have taken a look at your patch.<br>
<br>
1) Below diff seems to be unnecessary because even without the &quot;+ if<br>
(cache_connection)&quot;, the result would be same.<br></blockquote><div><br></div><div>Yes this is correct the result will be same after this new if statement. The reason I made this change was to bypass if statement with four strcmp()s when we already knew the cache_connection will remain false. Although might not make much difference but done this to improve performance of this condition statement.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
-       /*<br>
-        * For those special databases, and when frontend client exits abnormally,<br>
-        * we don&#39;t cache connection to backend.<br>
-        */<br>
-    if ((sp &amp;&amp;<br>
-               (!strcmp(sp-&gt;database, &quot;template0&quot;) ||<br>
-                !strcmp(sp-&gt;database, &quot;template1&quot;) ||<br>
-                !strcmp(sp-&gt;database, &quot;postgres&quot;) ||<br>
-                !strcmp(sp-&gt;database, &quot;regression&quot;))) ||<br>
-                (*frontend != NULL &amp;&amp;<br>
-                 ((*frontend)-&gt;socket_state == POOL_SOCKET_EOF ||<br>
-                 (*frontend)-&gt;socket_state == POOL_SOCKET_ERROR)))<br>
-        cache_connection = false;<br>
-<br>
+       if (cache_connection)<br>
+       {<br>
+               /*<br>
+                * For those special databases, and when frontend client exits abnormally,<br>
+                * we don&#39;t cache connection to backend.<br>
+                */<br>
+               if ((sp &amp;&amp;<br>
+                       (!strcmp(sp-&gt;database, &quot;template0&quot;) ||<br>
+                        !strcmp(sp-&gt;database, &quot;template1&quot;) ||<br>
+                        !strcmp(sp-&gt;database, &quot;postgres&quot;) ||<br>
+                        !strcmp(sp-&gt;database, &quot;regression&quot;))) ||<br>
+                        (*frontend != NULL &amp;&amp;<br>
+                         ((*frontend)-&gt;socket_state == POOL_SOCKET_EOF ||<br>
+                         (*frontend)-&gt;socket_state == POOL_SOCKET_ERROR)))<br>
+                       cache_connection = false;<br>
+       }<br>
<br>
2) Shouldn&#39;t frontend_invalid variable be bool because it takes only 0<br>
   or 1. If so, geterrposition()&#39;s return type should be declared as<br>
   bool.<br></blockquote><div><br></div><div>Yes, you are right. frontend_invalid should&#39;ve been bool. I have updated this in attached version of the patch.</div><div><br></div><div><br></div><div>Thanks</div><div>Best regards</div><div>Muhammad Usama  </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5"><br>
Best regards,<br>
--<br>
Tatsuo Ishii<br>
SRA OSS, Inc. Japan<br>
English: <a href="http://www.sraoss.co.jp/index_en.php" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.jp</a><br>
<br>
&gt; Hi Ishii San<br>
&gt;<br>
&gt; Can you please have a look at the attached patch for 3.4 branch.<br>
&gt; Basically it introduces a new error level FRONTEND_ERROR for ereport(), to<br>
&gt; inform the error handler not to cache the current backend connection. Other<br>
&gt; than that, this FRONTEND_ERROR error level behaves and works similar to the<br>
&gt; ereport(ERROR..)<br>
&gt;<br>
&gt; Thanks<br>
&gt; Best regards<br>
&gt; Muhammad Usama<br>
&gt;<br>
&gt;<br>
&gt; On Thu, Oct 15, 2015 at 4:45 PM, Muhammad Usama &lt;<a href="mailto:m.usama@gmail.com">m.usama@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Thu, Oct 15, 2015 at 2:23 AM, Tatsuo Ishii &lt;<a href="mailto:ishii@postgresql.org">ishii@postgresql.org</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt; Usama,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Can you please propose a patch to implement similar thing with 3.4?  I<br>
&gt;&gt;&gt; think it will make 3.4 more robust. I have no idea how to implement<br>
&gt;&gt;&gt; it with 3.4&#39;s exception mechanism.<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; sure I will work on this<br>
&gt;&gt;<br>
&gt;&gt; Thanks<br>
&gt;&gt; best regards<br>
&gt;&gt; Muhammad Usama<br>
&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Best regards,<br>
&gt;&gt;&gt; --<br>
&gt;&gt;&gt; Tatsuo Ishii<br>
&gt;&gt;&gt; SRA OSS, Inc. Japan<br>
&gt;&gt;&gt; English: <a href="http://www.sraoss.co.jp/index_en.php" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
&gt;&gt;&gt; Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.jp</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &gt; Hi Ishii San<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; I think this difference of behavior between 3.3. And 3.4 is caused by<br>
&gt;&gt;&gt; the<br>
&gt;&gt;&gt; &gt; commit &quot;cb735f22441001b6afdbb5bac72808db66094ca9&quot; that was not ported to<br>
&gt;&gt;&gt; &gt; the 3.4 branch.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; <a href="http://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=cb735f22441001b6afdbb5bac72808db66094ca9" rel="noreferrer" target="_blank">http://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=cb735f22441001b6afdbb5bac72808db66094ca9</a><br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; Thanks<br>
&gt;&gt;&gt; &gt; Best regards<br>
&gt;&gt;&gt; &gt; Muhammad Usama<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; On Tue, Oct 13, 2015 at 2:45 PM, Tatsuo Ishii &lt;<a href="mailto:ishii@postgresql.org">ishii@postgresql.org</a>&gt;<br>
&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; Usama,<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; While I have been working on:<br>
&gt;&gt;&gt; &gt;&gt; &gt; <a href="http://www.pgpool.net/mantisbt/view.php?id=147" rel="noreferrer" target="_blank">http://www.pgpool.net/mantisbt/view.php?id=147</a><br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; Oops. This is wrong. Here is the correct one.<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; <a href="http://www.pgpool.net/mantisbt/view.php?id=145" rel="noreferrer" target="_blank">http://www.pgpool.net/mantisbt/view.php?id=145</a><br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; I found there was an interesting behavior change between pgpool-II<br>
&gt;&gt;&gt; 3.3<br>
&gt;&gt;&gt; &gt;&gt; &gt; and 3.4.<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; It turns out that the bug was related to the action when<br>
&gt;&gt;&gt; &gt;&gt; &gt; client_idle_limit is reached. In 3.3, when client_idle_limit is<br>
&gt;&gt;&gt; &gt;&gt; &gt; reached, following statement is executed (pool_process_query.c):<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; if (idle_count &gt; pool_config-&gt;client_idle_limit)<br>
&gt;&gt;&gt; &gt;&gt; &gt; {<br>
&gt;&gt;&gt; &gt;&gt; &gt;       pool_log(&quot;pool_process_query: child connection forced to<br>
&gt;&gt;&gt; terminate<br>
&gt;&gt;&gt; &gt;&gt; due to client_idle_limit (%d) reached,<br>
&gt;&gt;&gt; &gt;&gt; &gt;                pool_config-&gt;client_idle_limit);<br>
&gt;&gt;&gt; &gt;&gt; &gt;               pool_send_error_message(frontend, MAJOR(backend),<br>
&gt;&gt;&gt; &gt;&gt; &gt;               &quot;57000&quot;, &quot;connection terminated due to client idle<br>
&gt;&gt;&gt; limit<br>
&gt;&gt;&gt; &gt;&gt; reached&quot;,<br>
&gt;&gt;&gt; &gt;&gt; &gt;                                       &quot;&quot;,&quot;&quot;,  __FILE__, __LINE__);<br>
&gt;&gt;&gt; &gt;&gt; &gt;       return POOL_END_WITH_FRONTEND_ERROR;<br>
&gt;&gt;&gt; &gt;&gt; &gt; }<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; then goes to this (child.c)<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; if (status == POOL_END_WITH_FRONTEND_ERROR ||<br>
&gt;&gt;&gt; &gt;&gt; &gt;    pool_config-&gt;connection_cache == 0 ||<br>
&gt;&gt;&gt; &gt;&gt; &gt;    !strcmp(sp-&gt;database, &quot;template0&quot;) ||<br>
&gt;&gt;&gt; &gt;&gt; &gt;    !strcmp(sp-&gt;database, &quot;template1&quot;) ||<br>
&gt;&gt;&gt; &gt;&gt; &gt;    !strcmp(sp-&gt;database, &quot;postgres&quot;) ||<br>
&gt;&gt;&gt; &gt;&gt; &gt;    !strcmp(sp-&gt;database, &quot;regression&quot;))<br>
&gt;&gt;&gt; &gt;&gt; &gt; {<br>
&gt;&gt;&gt; &gt;&gt; &gt;       reset_connection();<br>
&gt;&gt;&gt; &gt;&gt; &gt;       pool_close(frontend);<br>
&gt;&gt;&gt; &gt;&gt; &gt;       pool_send_frontend_exits(backend);<br>
&gt;&gt;&gt; &gt;&gt; &gt;       pool_discard_cp(sp-&gt;user, sp-&gt;database, sp-&gt;major);<br>
&gt;&gt;&gt; &gt;&gt; &gt; }<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; This results in closing connection to backend.<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; In 3.4,<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; if (idle_count &gt; pool_config-&gt;client_idle_limit)<br>
&gt;&gt;&gt; &gt;&gt; &gt; {<br>
&gt;&gt;&gt; &gt;&gt; &gt;       ereport(ERROR,<br>
&gt;&gt;&gt; &gt;&gt; &gt;            (pool_error_code(&quot;57000&quot;),<br>
&gt;&gt;&gt; &gt;&gt; &gt;                errmsg(&quot;unable to read data&quot;),<br>
&gt;&gt;&gt; &gt;&gt; &gt;                  errdetail(&quot;child connection forced to terminate due<br>
&gt;&gt;&gt; to<br>
&gt;&gt;&gt; &gt;&gt; client_idle_limit:%d is reached&quot;,<br>
&gt;&gt;&gt; &gt;&gt; &gt;                   pool_config-&gt;client_idle_limit)));<br>
&gt;&gt;&gt; &gt;&gt; &gt; }<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; Then jump to backend_cleanup() and call pool_process_query() to<br>
&gt;&gt;&gt; &gt;&gt; &gt; execute queries defined in reset_query_list. This results in sending<br>
&gt;&gt;&gt; &gt;&gt; &gt; typically &quot;DISCARD ALL&quot; to backend. The problem reported in the bug<br>
&gt;&gt;&gt; id<br>
&gt;&gt;&gt; &gt;&gt; &gt; 147 happens in this route (actually the reporter claims that<br>
&gt;&gt;&gt; pgpool-II<br>
&gt;&gt;&gt; &gt;&gt; &gt; hangs in sending &quot;DISCARD&quot;).<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; In summary, when client idle limit reaches, pgpool-II 3.3 disconnects<br>
&gt;&gt;&gt; &gt;&gt; &gt; connections to backend, while 3.4 does not close the connections to<br>
&gt;&gt;&gt; &gt;&gt; &gt; backend and sends DISCARD to backend.<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; We have a few reports that pgpool-II 3.4 hangs while sending DISCARD<br>
&gt;&gt;&gt; &gt;&gt; &gt; and I wonder those problems somewhat related to the behavior change<br>
&gt;&gt;&gt; &gt;&gt; &gt; described above because the code path in 3.4 is executed even if<br>
&gt;&gt;&gt; &gt;&gt; &gt; client_idle_limit is not reached (elog(ERROR...)).<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; Usama,<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; Was this behavior change intentional?<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; Best regards,<br>
&gt;&gt;&gt; &gt;&gt; &gt; --<br>
&gt;&gt;&gt; &gt;&gt; &gt; Tatsuo Ishii<br>
&gt;&gt;&gt; &gt;&gt; &gt; SRA OSS, Inc. Japan<br>
&gt;&gt;&gt; &gt;&gt; &gt; English: <a href="http://www.sraoss.co.jp/index_en.php" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
&gt;&gt;&gt; &gt;&gt; &gt; Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.jp</a><br>
&gt;&gt;&gt; &gt;&gt; &gt; _______________________________________________<br>
&gt;&gt;&gt; &gt;&gt; &gt; pgpool-hackers mailing list<br>
&gt;&gt;&gt; &gt;&gt; &gt; <a href="mailto:pgpool-hackers@pgpool.net">pgpool-hackers@pgpool.net</a><br>
&gt;&gt;&gt; &gt;&gt; &gt; <a href="http://www.pgpool.net/mailman/listinfo/pgpool-hackers" rel="noreferrer" target="_blank">http://www.pgpool.net/mailman/listinfo/pgpool-hackers</a><br>
&gt;&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; &gt;&gt; pgpool-hackers mailing list<br>
&gt;&gt;&gt; &gt;&gt; <a href="mailto:pgpool-hackers@pgpool.net">pgpool-hackers@pgpool.net</a><br>
&gt;&gt;&gt; &gt;&gt; <a href="http://www.pgpool.net/mailman/listinfo/pgpool-hackers" rel="noreferrer" target="_blank">http://www.pgpool.net/mailman/listinfo/pgpool-hackers</a><br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
</div></div></blockquote></div><br></div></div></div>