当前位置:网站首页>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 
边栏推荐
- LeetCode 736. Lisp 语法解析
- Golang etcdv3 reports an error. The attribute in grpc does not exist
- MySQL partition explanation and operation statement
- ncs成都新电面试经验
- Un salaire annuel de 50 W Ali P8 vous montrera comment passer du test
- 【ChaosBlade:根据标签删除POD、Pod 域名访问异常场景、Pod 文件系统 I/O 故障场景】
- Mountaineering team (DFS)
- Expérience de port série - simple réception et réception de données
- Analysis of Hessian serialization principle
- How to add a mask of a target in a picture
猜你喜欢

Greenplum 6.x build_ Environment configuration

串口實驗——簡單數據收發

寄存器地址名映射

A bug using module project in idea

NCS Chengdu New Electric interview Experience

Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up

【istio简介、架构、组件】

Goldbach conjecture C language

2022-07-06 unity core 9 - 3D animation

Oracle makes it clear at one time that a field with multiple separators will be split into multiple rows, and then multiple rows and columns. Multiple separators will be split into multiple rows, and
随机推荐
MySQL主从延迟的解决方案
Simulation volume leetcode [general] 1706 Where does the ball meet
Several common database connection methods
NCS Chengdu New Electric interview Experience
UnityShader入门精要个人总结--基础篇(一)
数字三角形模型 AcWing 275. 传纸条
端口复用和重映像
Markdown编辑器Editor.md插件的使用
Database storage - table partition
Uniapp wechat applet monitoring network
[istio introduction, architecture, components]
Vagrant failed to mount directory mount: unknown filesystem type 'vboxsf'
How to add a mask of a target in a picture
C语言指针(习题篇)
External interrupt to realize key experiment
Systick滴答定时器
Category of IP address
【ChaosBlade:节点磁盘填充、杀节点上指定进程、挂起节点上指定进程】
Image segmentation in opencv
Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop