doc-exports/docs/ddm/umn/ddm_04_0008.html
Hasko, Vladimir a5cc543164 reverting ddm umn to state before last commit in #613
Reviewed-by: Wagner, Fabian <fabian.wagner@t-systems.com>
Co-authored-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-committed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
2024-01-17 13:06:49 +00:00

45 lines
5.9 KiB
HTML

<a name="ddm_04_0008"></a><a name="ddm_04_0008"></a>
<h1 class="topictitle1">What Do I Do If I Fail to Connect to a DDM Instance Using the JDBC Driver?</h1>
<div id="body1530616921863"><p id="ddm_04_0008__p319332111140">When you access a DDM instance using the <span class="keyword" id="ddm_04_0008__keyword83971139859">MySQL driver</span> (JDBC) in <span class="keyword" id="ddm_04_0008__keyword018016321954">load balancing</span> mode, an infinite loop may occur during connection switchover, resulting in stack overflow.</p>
<div class="section" id="ddm_04_0008__section32751322962"><h4 class="sectiontitle">Fault Locating</h4><ol id="ddm_04_0008__ol928110375614"><li id="ddm_04_0008__li1360861763112">Query the application logs and locate the fault cause.<div class="p" id="ddm_04_0008__p1428173720619"><a name="ddm_04_0008__li1360861763112"></a><a name="li1360861763112"></a>For example, the following logs show that the fault is caused by stack overflow.<pre class="screen" id="ddm_04_0008__screen1850371373111">Caused by: java.lang.StackOverflowError
at java.nio.HeapByteBuffer.&lt;init&gt;(HeapByteBuffer.java:57)
at java.nio.ByteBuffer.allocate(ByteBuffer.java:335)
at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:795)
at java.nio.charset.Charset.encode(Charset.java:843)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:2362)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:2344)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:568)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:626)
at com.mysql.jdbc.Buffer.writeStringNoNull(Buffer.java:670)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2636)</pre>
</div>
</li><li id="ddm_04_0008__li15723181703319">Analyze the overflow source.<div class="p" id="ddm_04_0008__p1928417378617"><a name="ddm_04_0008__li15723181703319"></a><a name="li15723181703319"></a>For example, the following logs show that the overflow results from an infinite loop inside the driver.<pre class="screen" id="ddm_04_0008__screen56709589325">at com.mysql.jdbc.LoadBalancedConnectionProxy.<em id="ddm_04_0008__i4822124481317">pickNewConnection</em>(LoadBalancedConnectionProxy.java:344)
at com.mysql.jdbc.LoadBalancedAutoCommitInterceptor.<em id="ddm_04_0008__i2119156161314">postProcess</em>(LoadBalancedAutoCommitInterceptor.java:104)
at com.mysql.jdbc.MysqlIO.invokeStatementInterceptorsPost(MysqlIO.java:2885)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2808)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483)
at com.mysql.jdbc.ConnectionImpl.setReadOnlyInternal(ConnectionImpl.java:4961)
at com.mysql.jdbc.ConnectionImpl.setReadOnly(ConnectionImpl.java:4954)
at com.mysql.jdbc.MultiHostConnectionProxy.syncSessionState(MultiHostConnectionProxy.java:381)
at com.mysql.jdbc.MultiHostConnectionProxy.syncSessionState(MultiHostConnectionProxy.java:366)
at com.mysql.jdbc.LoadBalancedConnectionProxy.<em id="ddm_04_0008__i1059117181412">pickNewConnection</em>(LoadBalancedConnectionProxy.java:344)</pre>
</div>
</li><li id="ddm_04_0008__li62874371364">Query the MySQL version, which is 5.1.44.<p id="ddm_04_0008__p62871376612"><a name="ddm_04_0008__li62874371364"></a><a name="li62874371364"></a>According to the source code of the version, when a connection is obtained, <strong id="ddm_04_0008__b1675311431694">LoadBalance</strong> updates the connection based on the load balancing policy and copies the configurations of the old connection to the new connection. If <strong id="ddm_04_0008__b3411153251211">AutoCommit</strong> is <strong id="ddm_04_0008__b1301144691213">true</strong> for the new connection, parameters of the new connection are inconsistent with those of the old connection, and <strong id="ddm_04_0008__b1188417813519">loadBalanceAutoCommitStatementThreshold</strong> is not configured, an infinite loop occurs. The connection update function calls the parameter synchronization function, and the parameter synchronization function calls the connection update function at the same time, resulting in stack overflow.</p>
</li></ol>
</div>
<div class="section" id="ddm_04_0008__section132331111272"><h4 class="sectiontitle">Solution</h4><p id="ddm_04_0008__p148922362712">Add the <strong id="ddm_04_0008__b566435118276">loadBalanceAutoCommitStatementThreshold=5&amp;retriesAllDown=10</strong> parameter to the URL for connecting to the DDM instance.</p>
<pre class="screen" id="ddm_04_0008__screen16919114617619">//Connection example when load balancing is used
//jdbc:mysql:loadbalance://<em id="ddm_04_0008__i16795521172714">ip</em><em id="ddm_04_0008__i12796142110274">1:port1,ip2:port2..ipN</em><em id="ddm_04_0008__i353819512597">:port</em>N/<em id="ddm_04_0008__i55021025143017">{db_name}</em>
String url = "jdbc:mysql:loadbalance://192.168.0.200:5066,192.168.0.201:5066/db_5133?<em id="ddm_04_0008__i29553104141">loadBalanceAutoCommitStatementThreshold=5&amp;retriesAllDown=10</em>";</pre>
<ul id="ddm_04_0008__ul108175820352"><li id="ddm_04_0008__li112837693618"><strong id="ddm_04_0008__b155263921719">loadBalanceAutoCommitStatementThreshold</strong> indicates the number of statements executed before a reconnection.<p id="ddm_04_0008__p881267183614">If <strong id="ddm_04_0008__b81171414121811">loadBalanceAutoCommitStatementThreshold</strong> is set to <strong id="ddm_04_0008__b151171614111816">5</strong>, a reconnection is initiated after five SQL statements (queries or updates) are executed. A value of <strong id="ddm_04_0008__b45391516161819">0</strong> indicates a sticky connection, and no reconnection is required. When automatic submission is disabled (<strong id="ddm_04_0008__b162426194185">autocommit</strong> is set to <strong id="ddm_04_0008__b162571319111811">false</strong>), the system waits for the transaction to complete and then determines whether to initiate a reconnection.</p>
</li></ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="ddm_04_0004.html">DDM Usage</a></div>
</div>
</div>