当前位置:网站首页>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
边栏推荐
- STM32串口寄存器库函数配置方法
- go mod module declares its path as: gtihub. com/xxx-xx but was required as:xx-xx
- Troublesome problem of image resizing when using typora to edit markdown to upload CSDN
- [istio introduction, architecture, components]
- GoLand set goproxy
- 【ChaosBlade:节点 CPU 负载、节点网络延迟、节点网络丢包、节点域名访问异常】
- Simulation volume leetcode [general] 1609 Parity tree
- 【ChaosBlade:节点磁盘填充、杀节点上指定进程、挂起节点上指定进程】
- Simple use of Xray
- Gson converts the entity class to JSON times declare multiple JSON fields named
猜你喜欢
LeetCode 715. Range 模块
Pointer advanced, string function
Greenplum 6.x build_ Environment configuration
Markdown editor Use of MD plug-in
Mountaineering team (DFS)
STM32 serial port register library function configuration method
数字三角形模型 AcWing 275. 传纸条
硬核分享:硬件工程师常用工具包
Simple use of Xray
Platformization, a fulcrum of strong chain complementing chain
随机推荐
Common operating commands of Linux
MySQL partition explanation and operation statement
Led analog and digital dimming
Greenplum 6.x monitoring software setup
channel. Detailed explanation of queuedeclare parameters
Original collection of hardware bear (updated on June 2022)
Category of IP address
Required String parameter ‘XXX‘ is not present
Image segmentation in opencv
Platformization, a fulcrum of strong chain complementing chain
Reading notes of pyramid principle
C语言指针(特别篇)
阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳
OpenGL三维图形绘制
Simulation volume leetcode [general] 1706 Where does the ball meet
NCS Chengdu New Electric interview Experience
模拟卷Leetcode【普通】1557. 可以到达所有点的最少点数目
C语言指针(下篇)
Troublesome problem of image resizing when using typora to edit markdown to upload CSDN
Gson converts the entity class to JSON times declare multiple JSON fields named