<div dir="ltr">Great thanks!  Now we just need to figure out why the heck that would happen...<div><br></div><div>Perhaps the ORM gods are angry.  An offering will be required.</div><div><br></div><div>Note: I wonder what would happen if we put a unique constraint on pd_templates (combination of id and lang columns).  That could be a workaround until we found the root cause.</div><div><br></div><div>-Eric</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 6, 2017 at 2:37 AM, Andy Yar <span dir="ltr">&lt;<a href="mailto:andyyar66@gmail.com" target="_blank">andyyar66@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I&#39;ve enabled logging of org.hibernate.SQL. Now I can see inserts to<br>
the &quot;pd_templates&quot; in my server.log:<br>
<a href="https://hastebin.com/zovefusoyo.sql" rel="noreferrer" target="_blank">https://hastebin.com/<wbr>zovefusoyo.sql</a>. These are triggered when browsing<br>
an OAuth policy.<br>
<br>
The &quot;policydefs&quot; table seems to be OK - only a single record for the<br>
Keycloak OAuth.<br>
<div class="HOEnZb"><div class="h5"><br>
On Fri, Jun 2, 2017 at 2:50 PM, Eric Wittmann &lt;<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>&gt; wrote:<br>
&gt; This is a very strange problem.  I&#39;ll add some technical info to this<br>
&gt; discussion in case it helps.<br>
&gt;<br>
&gt; The &quot;pd_templates&quot; table stores potentially multiple html templates for<br>
&gt; displaying the *summary* of a configured instance of a policy.  It can store<br>
&gt; multiple templates by language - this is basically an  i18n feature.  In<br>
&gt; practice, we only really have English language versions, so there should<br>
&gt; only be one row in that table for each row in the &quot;policydefs&quot; table.  The<br>
&gt; &quot;policydefs&quot; table should have one row per policy definition (basically one<br>
&gt; row for each item in the Policy Type drop-down when adding a new policy to<br>
&gt; an API).<br>
&gt;<br>
&gt; The ORM class for the pd_templates table is here:<br>
&gt;<br>
&gt; <a href="https://github.com/apiman/apiman/blob/master/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyDefinitionTemplateBean.java" rel="noreferrer" target="_blank">https://github.com/apiman/<wbr>apiman/blob/master/manager/<wbr>api/beans/src/main/java/io/<wbr>apiman/manager/api/beans/<wbr>policies/<wbr>PolicyDefinitionTemplateBean.<wbr>java</a><br>
&gt;<br>
&gt; And the policy definition ORM bean is here:<br>
&gt;<br>
&gt; <a href="https://github.com/apiman/apiman/blob/master/manager/api/beans/src/main/java/io/apiman/manager/api/beans/policies/PolicyDefinitionBean.java" rel="noreferrer" target="_blank">https://github.com/apiman/<wbr>apiman/blob/master/manager/<wbr>api/beans/src/main/java/io/<wbr>apiman/manager/api/beans/<wbr>policies/PolicyDefinitionBean.<wbr>java</a><br>
&gt;<br>
&gt; This sounds like hibernate making a mess of things (or more likely my<br>
&gt; mis-understanding of something hibernate is doing).  It&#39;s one of the reasons<br>
&gt; I&#39;m on the fence about ORM technologies in general.  They can be so helpful,<br>
&gt; but if you wrote your own SQL statements you&#39;d never have a weird issue like<br>
&gt; this.<br>
&gt;<br>
&gt; In any case, at this point I have no theory about how this could be<br>
&gt; happening.<br>
&gt;<br>
&gt; I assume your &quot;policydefs&quot; table is sensible.  So the question is why<br>
&gt; hibernate would be duplicating the data in &quot;pd_templates&quot;, especially when<br>
&gt; doing a simple GET of the information (shouldn&#39;t be mutating anything!).<br>
&gt;<br>
&gt; Could try enabling SQL logging in hibernate to see what&#39;s going on.<br>
&gt;<br>
&gt; But of course trying to replicate the problem locally is always the best<br>
&gt; approach. :)<br>
&gt;<br>
&gt; -Eric<br>
&gt;<br>
&gt;<br>
&gt; On Fri, Jun 2, 2017 at 7:49 AM, Marc Savy &lt;<a href="mailto:marc.savy@redhat.com">marc.savy@redhat.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi Andy,<br>
&gt;&gt;<br>
&gt;&gt; Can you describe how your API, ClientApp &amp; Plan is set up?<br>
&gt;&gt;<br>
&gt;&gt; e.g.<br>
&gt;&gt;<br>
&gt;&gt; API = [Keycloak OAuth2 Policy]<br>
&gt;&gt; Plan = [&lt;nothing&gt;]<br>
&gt;&gt; ClientApp = [Header Policy]<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Regards,<br>
&gt;&gt; Marc<br>
&gt;&gt;<br>
&gt;&gt; On 2 June 2017 at 12:20, Andy Yar &lt;<a href="mailto:andyyar66@gmail.com">andyyar66@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt; Oh, sorry I missed version info.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; psql (PostgreSQL) 9.4.12<br>
&gt;&gt; &gt; JDBC connector - PostgreSQL 9.4.1212<br>
&gt;&gt; &gt; Apiman 1.2.9.Final<br>
&gt;&gt; &gt; CentOS7<br>
&gt;&gt; &gt; Oracle Java 1.8.0_111<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; No export/import was done prior this issue.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I can say I&#39;ve been observed slower and slower responses during<br>
&gt;&gt; &gt; operation with the Manager OAuth related pages.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; The trigger action seems to be a GET on a URL pattern like this:<br>
&gt;&gt; &gt; apimanui/api-manager/orgs/<wbr>MyOrg/plans/<wbr>MyOrgKeycloakOAuth/1/policies/<wbr>1155<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Resulting screen loads a policy config scheme from Keycloak OAuth<br>
&gt;&gt; &gt; Plugin and displays it. It also generates N^2 new rows in<br>
&gt;&gt; &gt; pd_templates. I&#39;ve observed 16, 32, 64, 128 and then 256 added new<br>
&gt;&gt; &gt; rows...<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Fri, Jun 2, 2017 at 12:26 PM, Marc Savy &lt;<a href="mailto:marc.savy@redhat.com">marc.savy@redhat.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt; Hi Andy,<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; I spent time yesterday evening trying to replicate this after our chat<br>
&gt;&gt; &gt;&gt; on IRC, but I haven&#39;t been able to trigger it. Perhaps with more<br>
&gt;&gt; &gt;&gt; information we can narrow this down.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Which version of Postgres are you using? Which driver version?<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; I&#39;ve been using: Postgres 9.6.2, Driver 42.1.1, apiman 1.3.0.Final<br>
&gt;&gt; &gt;&gt; (should be same as 1.2.9.Final for this).<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Have you done any export-import?<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Have you observed the precise action that corresponds with the<br>
&gt;&gt; &gt;&gt; extraneous pd_templates entries being inserted?<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Regards,<br>
&gt;&gt; &gt;&gt; Marc<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; On 2 June 2017 at 08:05, Andy Yar &lt;<a href="mailto:andyyar66@gmail.com">andyyar66@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; Hello,<br>
&gt;&gt; &gt;&gt;&gt; Keycloak OAuth plugin&#39;s presence generates a certain amount of records<br>
&gt;&gt; &gt;&gt;&gt; to pd_templates table on each action of Apiman Manager related to a<br>
&gt;&gt; &gt;&gt;&gt; Keycloak OAuth policy (even read-only ones like listing a plan&#39;s<br>
&gt;&gt; &gt;&gt;&gt; policies, etc.).<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; Over time the number of records in pd_templates table can grow to<br>
&gt;&gt; &gt;&gt;&gt; milions resulting in Apiman Manager OoM exceptions. Given these<br>
&gt;&gt; &gt;&gt;&gt; records are basically just text hints it is really funny.<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; A workaround is to periodically dedup the records.<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; I guess this issue should be an easy fix.<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; Affected version is: Apiman 1.2.9.Final + corresponding Keycloak OAuth<br>
&gt;&gt; &gt;&gt;&gt; plugin.<br>
&gt;&gt; &gt;&gt;&gt; ______________________________<wbr>_________________<br>
&gt;&gt; &gt;&gt;&gt; Apiman-user mailing list<br>
&gt;&gt; &gt;&gt;&gt; <a href="mailto:Apiman-user@lists.jboss.org">Apiman-user@lists.jboss.org</a><br>
&gt;&gt; &gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/apiman-user" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/apiman-user</a><br>
&gt;&gt; ______________________________<wbr>_________________<br>
&gt;&gt; Apiman-user mailing list<br>
&gt;&gt; <a href="mailto:Apiman-user@lists.jboss.org">Apiman-user@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/apiman-user" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/apiman-user</a><br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br></div>