<p>If that is the case you should add that index to the code too.</p>
<p>That doesn&#39;t excuse all the actual threading issues that are still present :)</p>
<div class="gmail_quote">On Jul 27, 2013 5:26 AM, &quot;Steven Ayre&quot; &lt;<a href="mailto:steveayre@gmail.com">steveayre@gmail.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Also given that this is 2 different hosts connecting to a shared database this is not a threading issue.<div><br></div><div>Rather it is queries locking too many rows blocking other concurrent connections.</div><div><br></div>


<div><br></div><div><br></div><div><div><br><br><div class="gmail_quote">On 27 July 2013 11:18, Steven Ayre <span dir="ltr">&lt;<a href="mailto:steveayre@gmail.com" target="_blank">steveayre@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"><div><span style="color:rgb(31,73,125);font-family:Calibri,sans-serif;font-size:15px">delete from registrations where expires &gt; 0 and expires &lt;= 1374852304 and hostname=&#39;freeswitch_ha0&#39;;</span></div>



<div><span style="color:rgb(31,73,125);font-family:Calibri,sans-serif;font-size:15px">delete from registrations where expires &gt; 0 and expires &lt;= 1374852306 and hostname=&#39;freeswitch_ha1&#39;;</span></div>
<div><br></div><div>So it is 2 different servers both removing expired registrations at the same time.</div><div><br></div><div>I think there&#39;s a small flaw in the indexes on the table freeswitch-autocreates.</div><div>




<br></div><div>In sip_registrations there is an index on (expires), but it would be better for the above to have a compound index on (hostname,expires). That way the innodb row locking will lock only the entries in that range for the host during the delete instead of locking every entry in that range for all hosts and then scan the range for the hostname.</div>




<div><br></div><div><div>In registrations there are no indexes to help this query at all. The compound index would help there too.</div></div><div><br></div><div>It&#39;ll also help find the relevant entries faster, especially if you have a lot of servers sharing the db.</div>




<div><br></div><div>Try manually making these modifications to the database:</div><div>ALTER TABLE registrations ADD KEY r_host_expires (hostname,expires);</div><div>ALTER TABLE sip_registrations ADD KEY host_expires (hostname,expires);</div>




<div><br></div><div>-Steve</div><div><div><div><br></div><br><br><div class="gmail_quote">On 26 July 2013 16:30, Ira Tessler <span dir="ltr">&lt;<a href="mailto:ira@connectmevoice.com" target="_blank">ira@connectmevoice.com</a>&gt;</span> wrote:<br>




<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">I am getting the same problem on my development system today. I just put up a new version of mysql. Went from 5.1.67 to 5.6.12. Here is the deadlock section:</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">------------------------</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">LATEST DETECTED DEADLOCK</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">------------------------</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">2013-07-26 11:23:22 7fd473f1e700</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">*** (1) TRANSACTION:</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">TRANSACTION 251674, ACTIVE 2 sec fetching rows</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">mysql tables in use 1, locked 1</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">LOCK WAIT 3 lock struct(s), heap size 376, 3 row lock(s)</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 38, OS thread handle 0x7fd473fa0700, query id 156782 192.168.1.27 root updating</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">delete from registrations where expires &gt; 0 and expires &lt;= 1374852304 and hostname=&#39;freeswitch_ha0&#39;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">*** (1) WAITING FOR THIS LOCK TO BE GRANTED:</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">RECORD LOCKS space id 10 page no 3 n bits 96 index `GEN_CLUST_INDEX` of table `freeswitch`.`registrations` trx id 251674 lock_mode X waiting</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Record lock, heap no 22 PHYSICAL RECORD: n_fields 13; compact format; info bits 32</span></p><p class="MsoNormal">





<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 0: len 6; hex 000000001769; asc      i;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 1: len 6; hex 00000003d709; asc       ;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 2: len 7; hex 070000015b0352; asc     [ R;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 3: len 3; hex 373033; asc 703;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 4: len 28; hex 32323535352e7463702e6861312e746573747362636461782e636f6d; asc <a href="http://22555.tcp.ha1.testsbcdax.com" target="_blank">22555.tcp.ha1.testsbcdax.com</a>;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 5: len 30; hex 313030303130342d302d313730333030304034372e32332e3130362e3233; asc <a href="mailto:1000104-0-1703000@47.23.106.23" target="_blank">1000104-0-1703000@47.23.106.23</a>; (total 31 bytes);</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 6: len 30; hex 736f6669612f6861315f696e7465726e616c5f7463702f7369703a373033; asc sofia/ha1_internal_tcp/sip:703; (total 152 bytes);</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 7: len 4; hex d1f2962a; asc    *;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 8: len 12; hex 31302e31302e31302e313032; asc 10.10.10.102;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 9: len 5; hex 3230303031; asc 20001;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 10: len 3; hex 746370; asc tcp;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 11: len 14; hex 667265657377697463685f686131; asc freeswitch_ha1;;</span></p><p class="MsoNormal">




<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 12: SQL NULL;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">*** (2) TRANSACTION:</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">TRANSACTION 251657, ACTIVE 2 sec starting index read</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">mysql tables in use 1, locked 1</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">5 lock struct(s), heap size 1248, 5 row lock(s), undo log entries 2</span></p><p class="MsoNormal">




<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 28, OS thread handle 0x7fd473f1e700, query id 156786 192.168.1.45 root updating</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">delete from registrations where expires &gt; 0 and expires &lt;= 1374852306 and hostname=&#39;freeswitch_ha1&#39;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">*** (2) HOLDS THE LOCK(S):</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">RECORD LOCKS space id 10 page no 3 n bits 96 index `GEN_CLUST_INDEX` of table `freeswitch`.`registrations` trx id 251657 lock_mode X locks rec but not gap</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Record lock, heap no 22 PHYSICAL RECORD: n_fields 13; compact format; info bits 32</span></p><p class="MsoNormal">





<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 0: len 6; hex 000000001769; asc      i;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 1: len 6; hex 00000003d709; asc       ;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 2: len 7; hex 070000015b0352; asc     [ R;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 3: len 3; hex 373033; asc 703;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 4: len 28; hex 32323535352e7463702e6861312e746573747362636461782e636f6d; asc <a href="http://22555.tcp.ha1.testsbcdax.com" target="_blank">22555.tcp.ha1.testsbcdax.com</a>;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 5: len 30; hex 313030303130342d302d313730333030304034372e32332e3130362e3233; asc <a href="mailto:1000104-0-1703000@47.23.106.23" target="_blank">1000104-0-1703000@47.23.106.23</a>; (total 31 bytes);</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 6: len 30; hex 736f6669612f6861315f696e7465726e616c5f7463702f7369703a373033; asc sofia/ha1_internal_tcp/sip:703; (total 152 bytes);</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 7: len 4; hex d1f2962a; asc    *;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 8: len 12; hex 31302e31302e31302e313032; asc 10.10.10.102;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 9: len 5; hex 3230303031; asc 20001;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 10: len 3; hex 746370; asc tcp;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 11: len 14; hex 667265657377697463685f686131; asc freeswitch_ha1;;</span></p><p class="MsoNormal">




<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 12: SQL NULL;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">*** (2) WAITING FOR THIS LOCK TO BE GRANTED:</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">RECORD LOCKS space id 10 page no 3 n bits 96 index `GEN_CLUST_INDEX` of table `freeswitch`.`registrations` trx id 251657 lock_mode X waiting</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Record lock, heap no 3 PHYSICAL RECORD: n_fields 13; compact format; info bits 0</span></p><p class="MsoNormal">





<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 0: len 6; hex 0000000016d1; asc       ;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 1: len 6; hex 000000033bc4; asc     ; ;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 2: len 7; hex d20000022f0110; asc     /  ;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 3: len 3; hex 383033; asc 803;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 4: len 21; hex 32323535382e636d767465737474656c652e636f6d; asc <a href="http://22558.cmvtesttele.com" target="_blank">22558.cmvtesttele.com</a>;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 5: len 30; hex 62326365383430342d6438313665303162403139322e3136382e3230302e; asc <a href="mailto:b2ce8404-d816e01b@192.168.200." target="_blank">b2ce8404-d816e01b@192.168.200.</a>; (total 33 bytes);</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 6: len 30; hex 736f6669612f6861305f696e7465726e616c2f7369703a38303340313038; asc sofia/ha0_internal/sip:803@108; (total 46 bytes);</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 7: len 4; hex d1f29d68; asc    h;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 8: len 14; hex 3130382e35382e3130302e313432; asc 108.58.100.142;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 9: len 4; hex 35303630; asc 5060;;</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 10: len 3; hex 756470; asc udp;;</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 11: len 14; hex 667265657377697463685f686130; asc freeswitch_ha0;;</span></p><p class="MsoNormal">




<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> 12: SQL NULL;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">*** WE ROLL BACK TRANSACTION (1)</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">------------</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">TRANSACTIONS</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">------------</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Trx id counter 252611</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Purge done for trx&#39;s n:o &lt; 252607 undo n:o &lt; 0 state: running but idle</span></p><p class="MsoNormal">





<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">History list length 2731</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">LIST OF TRANSACTIONS FOR EACH SESSION:</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252530, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 127, OS thread handle 0x7fd49c0e4700, query id 157673 192.168.1.45 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252039, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 126, OS thread handle 0x7fd473e1a700, query id 157059 192.168.1.45 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252344, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 125, OS thread handle 0x7fd46f12a700, query id 157516 192.168.1.27 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 0, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 117, OS thread handle 0x7fd473e5b700, query id 157835 localhost root init</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">show engine innodb status</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252610, not started</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 42, OS thread handle 0x7fd46f332700, query id 157834 192.168.1.27 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252382, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 39, OS thread handle 0x7fd473f5f700, query id 157566 192.168.1.27 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252605, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 38, OS thread handle 0x7fd473fa0700, query id 157830 192.168.1.27 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252378, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 37, OS thread handle 0x7fd473edd700, query id 157553 192.168.1.27 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252609, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 33, OS thread handle 0x7fd46f22e700, query id 157832 192.168.1.45 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252387, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 30, OS thread handle 0x7fd46f26f700, query id 157592 192.168.1.45 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252396, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 29, OS thread handle 0x7fd473fe1700, query id 157609 192.168.1.45 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252319, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 28, OS thread handle 0x7fd473f1e700, query id 157496 192.168.1.45 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">---TRANSACTION 252386, not started</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">MySQL thread id 27, OS thread handle 0x7fd46f2b0700, query id 157579 192.168.1.45 root cleaning up</span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> </span></p><p class="MsoNormal"><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#222222;background:white">Ira Tessler</span><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#222222"><br>





<span style="background:white">Lead Software Engineer</span><br><span style="background:white">ConnectMe</span><br><span style="background:white"><a href="tel:%28732%29%20490-9007%20x2" value="+17324909007" target="_blank">(732) 490-9007 x2</a></span><br>




</span><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><a href="mailto:ira@connectmevoice.com" target="_blank"><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">ira@connectmevoice.com</span></a></span></p>





<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> </span></p><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a> [mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a>] <b>On Behalf Of </b>Steven Ayre<br>





<b>Sent:</b> Wednesday, July 17, 2013 3:55 PM<br><b>To:</b> FreeSWITCH Users Help<br><b>Subject:</b> Re: [Freeswitch-users] Lock wait timeout exceeded; try restarting transaction</span></p><div><div><p class="MsoNormal">




 </p><p class="MsoNormal">
Run &#39;SHOW ENGINE INNODB STATUS\G&#39;</p><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal">What does it show in the latest deadlock section?</p></div><div><p class="MsoNormal"> </p><div><p class="MsoNormal" style="margin-bottom:12.0pt">





 </p><div><p class="MsoNormal">On 17 July 2013 14:16, Lloyd Aloysius &lt;<a href="mailto:lloyd.aloysius@gmail.com" target="_blank">lloyd.aloysius@gmail.com</a>&gt; wrote:</p><p class="MsoNormal"><span style="font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">This is newly installed switch. Only one call and two registrations. I do not do any queries against the DB. I do not see the problem again in last 24 hours. But want to know how to solve this issue.</span></p>





<div><p class="MsoNormal"> </p></div><div><p class="MsoNormal"><span style="font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">Switch - 2 Quad Core / 24 GB Memory / 15RPM SCSI , DB - 2 Quad Core / 24 GB Memory / 15RPM SCSI . Switch and DB connected through a cross over cable directly. I do not think this related to a environment issue.</span></p>





</div><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal"><span style="font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">Thanks</span></p></div><div><p class="MsoNormal"><span><span style="font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#888888">Lloyd</span></span></p>





<div><div><div><p class="MsoNormal"> </p><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal"> </p><div><p class="MsoNormal">On Tue, Jul 16, 2013 at 7:01 AM, Steven Ayre &lt;<a href="mailto:steveayre@gmail.com" target="_blank">steveayre@gmail.com</a>&gt; wrote:</p>





<p class="MsoNormal">+1</p><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal">The error is the actual MySQL error, so yes it&#39;s definitely a lock timeout.</p></div><div><p class="MsoNormal"> </p></div><div>





<p class="MsoNormal">This means two different queries were trying to access the same data at the same time. Normally one&#39;ll wait until the other is finished, but if it waits too long you get the lock timeout error.</p>





</div><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal">It can be caused by a query taking too long, or a transaction modifying the data but then taking too long before commit. To avoid that make sure MySQL is tuned correctly. Good indexes on the tables and good sizes for the cache buffers.</p>





</div><div><div><p class="MsoNormal"> </p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in"><p class="MsoNormal">Make sure you&#39;re using a proper index for the delete operation, I&#39;d also avoid ORs if possible.</p>





</blockquote><div><p class="MsoNormal"> </p></div></div><div><p class="MsoNormal">The query is part of mod_sofia, so isn&#39;t modifiable. Having a KEY(hostname,expires) on sip_dialogs may help though if it doesn&#39;t already exist (check with SHOW CREATE TABLE sip_dialogs).</p>





</div><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal">Avoid accessing sip_dialogs from any of your own code to minimise the number of things that might block each other.</p></div><div><p class="MsoNormal">




 </p>
</div><div><p class="MsoNormal">-Steve</p></div><div><div><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal" style="margin-bottom:12.0pt"> </p><div><p class="MsoNormal">On 16 July 2013 06:48, Rafal Gwizdala &lt;<a href="mailto:rafal.gwizdala@gmail.com" target="_blank">rafal.gwizdala@gmail.com</a>&gt; wrote:</p>





<div><p class="MsoNormal">I&#39;d bet this is a lock timeout, caused by database operation taking too long.</p><div><p class="MsoNormal">Make sure you&#39;re using a proper index for the delete operation, I&#39;d also avoid ORs if possible.</p>





</div><div><p class="MsoNormal">R</p></div></div><div><p class="MsoNormal" style="margin-bottom:12.0pt"> </p><div><div><div><p class="MsoNormal">On Tue, Jul 16, 2013 at 4:21 AM, Lloyd Aloysius &lt;<a href="mailto:lloyd.aloysius@gmail.com" target="_blank">lloyd.aloysius@gmail.com</a>&gt; wrote:</p>





</div></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in"><div><div><p class="MsoNormal"><span style="font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">Hi,</span></p>





<div><p class="MsoNormal"> </p></div><div><p class="MsoNormal"><span style="font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">I got the following error</span></p></div><div><p class="MsoNormal"> </p></div><div><div>





<p class="MsoNormal"><span style="font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">2013-07-15 21:47:<a href="tel:41.061450" target="_blank">41.061450</a> [ERR] switch_odbc.c:514 ERR: [delete from sip_dialogs where (expires = -1 or (expires &gt; 0 and expires &lt;= 1373939087)) and hostname=&#39;<a href="http://mydomain.com" target="_blank">mydomain.com</a>&#39;]</span></p>





</div><div><p class="MsoNormal"><span style="font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;">[STATE: HY000 CODE 1205 ERROR: [unixODBC][MySQL][ODBC 5.1 Driver][mysqld-5.5.32]Lock wait timeout exceeded; try restarting transaction]</span></p>





</div><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal">and the odbcinst.ini</p></div><div><p class="MsoNormal"> </p></div><div><div><p class="MsoNormal">[MySQL]</p></div><div><p class="MsoNormal">Description     = ODBC for MySQL</p>





</div><div><p class="MsoNormal">Driver          = /usr/lib/libmyodbc5.so</p></div><div><p class="MsoNormal">Setup           = /usr/lib/libodbcmyS.so</p></div><div><p class="MsoNormal">Driver64        = /usr/lib64/libmyodbc5.so</p>





</div><div><p class="MsoNormal">Setup64         = /usr/lib64/libodbcmyS.so</p></div><div><p class="MsoNormal">FileUsage       = 1</p></div><div><p class="MsoNormal">Threading       = 0</p></div><div><p class="MsoNormal">




UsageCount      = 1</p>
</div></div><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal">This is a mysql memory leak? How can fix this error?</p></div><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal">DB Server running with 24 GB memory and 2 Quad Core Xeon</p>





</div><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal"> </p></div><div><p class="MsoNormal">Thanks</p></div><div><p class="MsoNormal"><span style="color:#888888">Lloyd</span></p></div></div><p class="MsoNormal">





 </p></div></div><p class="MsoNormal" style="margin-bottom:12.0pt">_________________________________________________________________________<br>Professional FreeSWITCH Consulting Services:<br><a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>





<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br><br>FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br><a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>





<br>Official FreeSWITCH Sites<br><a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br><a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br><a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>





<br>FreeSWITCH-users mailing list<br><a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br><a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>





UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br><a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a></p>





</blockquote></div><p class="MsoNormal"> </p></div><p class="MsoNormal" style="margin-bottom:12.0pt"><br>_________________________________________________________________________<br>Professional FreeSWITCH Consulting Services:<br>





<a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br><a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br><br>FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>





<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br><br>Official FreeSWITCH Sites<br><a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br><a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>





<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br><br>FreeSWITCH-users mailing list<br><a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>





<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>





<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a></p></div><p class="MsoNormal"> </p></div></div></div><p class="MsoNormal" style="margin-bottom:12.0pt"><br>_________________________________________________________________________<br>





Professional FreeSWITCH Consulting Services:<br><a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br><a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>





<br>FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br><a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br><br>Official FreeSWITCH Sites<br><a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>





<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br><a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br><br>FreeSWITCH-users mailing list<br><a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>





<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>





<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a></p></div><p class="MsoNormal"> </p></div></div></div></div></div><p class="MsoNormal" style="margin-bottom:12.0pt"><br>_________________________________________________________________________<br>





Professional FreeSWITCH Consulting Services:<br><a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br><a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>





<br>FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br><a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br><br>Official FreeSWITCH Sites<br><a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>





<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br><a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br><br>FreeSWITCH-users mailing list<br><a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>





<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>





<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a></p></div><p class="MsoNormal"> </p></div></div></div></div></div></div>
<br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br>
</div></div></blockquote></div><br></div></div>
<br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div>