当前位置:网站首页>Upgrade Alibaba cloud RDS (relational database service) instance to com mysql. jdbc. exceptions. Troubleshooting of jdbc4.communicationsexception
Upgrade Alibaba cloud RDS (relational database service) instance to com mysql. jdbc. exceptions. Troubleshooting of jdbc4.communicationsexception
2022-07-07 08:59:00 【bboyzqh】
List of articles
The phenomenon
Currently, alicloud is used in the marketing database MYSQL database , Need support in the near future DBA To Alibaba cloud RDS upgrade , The upgrade announcement is as follows :
In the morning 5 spot 10 Start to report errors in the log after upgrading , The error message is as follows :
Problem analysis and conclusion
In general duridCommunicationsException The reason is that the connection pool obtains the invalid connection . from mysql Come up and say :
Mysql Server default “wait_timeout” yes 8 Hours ( That is to say, the default value is 28800 second ), That is, a connection More leisure than 8 Hours ,Mysql Will automatically disconnect the connection, Generally speaking, it is a connection between 8 There was no activity for hours , Will automatically disconnect the connection . And the connection pool thinks that the connection is still valid ( Because the validity of the connection is not verified ), When the app requests to use the connection , Will lead to the above error .
from druid There are several properties on configuration properties and connection failures :
- minEvictableIdleTimeMillis: The connection idle time is greater than this value and the free connection in the pool is greater than minIdle Then close the connection . Default values used in configuration 30 minute .
- maxEvictableIdleTimeMillis: Connection idle time is greater than this value , No matter minIdle Close the connection . Default values used in configuration 7 Hours .
- maxidle: at present druid It's abandoned maxidle attribute , Use maxActive and minIdel Instead of , Reference resources https: //github.com/alibaba/druid/wiki/FAQ, from druid In terms of configuration ,minIdle yes 50,maxActive yes 400( Unreasonable code setting , Adjustable ).
In theory druid By default, the maximum number of connection failures 7 An hour is less than the database 8 Hours , There will be no failed connections at the configuration level . And from the announcement , Have a show :“ In the process of migration, there will be 30 Seconds of connection ”, explain rds After the flash, the original database connection It's not working , and smc In the system druid The connection pool is still valid , So it leads to com.mysql.jdbc.exceptions.jdbc4. CommunicationsException happen .
Solution
Direct thinking in druid The thread gets the connection and checks it ok 了 , Related attributes are test- WhileIdle、testOnBorrow, The meaning is as follows :
- testWhileIdle: If true( Default true), When an application applies to the connection pool for a connection , also testOnBorrow by false when , The connection pool will determine if the connection is idle , If it is , Verify that the connection is available ( Efficient , Recommended ).
- testOnBorrow:( Default false) Check the connection validity when applying for connection ( Inefficient , Affect performance ), And testWhileIdle It's almost the same , It is to test the validity of the connection when obtaining the connection , If both are true, be testOnBorrow first High class , You will not use testWhileIdle.
- validationQuery: The query used to verify the connection before the connection pool returns the connection to the caller SQL, A query statement is required ( Turn on testWhileIdle You have to set validationQuery).
druid Add... To the configuration :
spring.datasource.druid.test-on-borrow=false
spring.datasource.druid.test-while-idle=true
spring.datasource.druid.validation-query=SELECT 1
There's another question , Without configuring the above properties ,testWhileIdlel The default is true,testOnBorrow Default by false,validationQuery The default is empty. , Why is it not mandatory validationQuery Well ? At this time, we should divide 2 There are three stages to explain the problem :
- durid Initialization phase : Played only error, The initialization process is not interrupted
- Get the connection process : Check the minEvictableIdleTimeMillis and maxEvictableIdleTimeMillis, Find out validation- Query by null Straight back , So the above configuration only needs to add validationQuery The configuration of can also solve the problem .
Welcome to WeChat official account. : Fang Chen's blog
边栏推荐
猜你喜欢
[MySQL] detailed explanation of trigger content of database advanced
Output a spiral matrix C language
Synchronized underlying principle, volatile keyword analysis
LeetCode 736. Lisp 语法解析
Druid monitoring - Introduction to JMX usage and principle
How to realize sliding operation component in fast application
Platformization, a fulcrum of strong chain complementing chain
Category of IP address
数字三角形模型 AcWing 275. 传纸条
面试题:高速PCB一般布局、布线原则
随机推荐
Simulation volume leetcode [general] 1567 Length of the longest subarray whose product is a positive number
LeetCode 736. LISP syntax parsing
模拟卷Leetcode【普通】1557. 可以到达所有点的最少点数目
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
Calf problem
Tronapi wave field interface - source code without encryption - can be opened twice - interface document attached - package based on thinkphp5 - detailed guidance of the author - July 6, 2022 - Novice
C语言指针(上篇)
Simulation volume leetcode [general] 1557 The minimum number of points that can reach all points
ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
Image segmentation in opencv
Several methods of calculating the average value of two numbers
个人力扣题目分类记录
Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
2022-06-30 Unity核心8——模型导入
Simple use of Xray
Implement custom memory allocator
Gson converts the entity class to JSON times declare multiple JSON fields named