shardingsphere 出现 Cannot support database type ‘MySQL‘

场景

近日一个项目使用了shardingsphere后出现 java.lang.UnsupportedOperationException: Cannot support database type 'MySQL' ,

重点是在dev-pre环境中无法出现这个问题,而是在prod环境中会发生,且prod也不是100%发生,

当流量过大时会发生这个问题,这个项目之前没有引入查询DB的操作,近日因为需求引入了DB查询,前同事写代码随便乱入各种多线程,虽然最终问题得以解决,还是因为怀疑乱用多线程导致。

解决方法

Spring Boot项目在 main 方法启动时,增加一个 NewInstanceServiceLoader.register(SQLParserConfiguration.class);

复制代码
@SpringBootApplication
@EnableAsync
@EnableScheduling
@MapperScan(basePackages = {"XXXXXXX"})
@EnableAutoConfiguration(exclude = {ElasticsearchAutoConfiguration.class, RestClientAutoConfiguration.class})
public class StartEngine {
public static void main(String[] args) {
	NewInstanceServiceLoader.register(SQLParserConfiguration.class);
	SpringApplication.run(StartEngine.class, args);
}
}

非spring boot项目使用

复制代码
@component
@slf4j
public class ApplicationStartedListener implements ApplicationListener {
@OverRide
public void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) {
onApplicationStarted(applicationStartedEvent);
}

@SneakyThrows
private void onApplicationStarted(ApplicationStartedEvent event) {
	String applicationName = event.getApplicationContext().getApplicationName();
	log.info("应用【{}】已启动....", applicationName);
	NewInstanceServiceLoader.register(SQLParserConfiguration.class);
	log.info("已加载{}", "SQLParserConfiguration");
}
}

总之,加上 NewInstanceServiceLoader.register(SQLParserConfiguration.class); 这个就对了。

主要参考这两个issues:

  1. https://github.com/apache/shardingsphere/issues/7701
  2. https://github.com/apache/shardingsphere/issues/7947

这里还提到了使用多线程API parallelStream 也会导致这个问题等等。

相关推荐
知识分享小能手17 小时前
Redis入门学习教程,从入门到精通,Redis 概述:知识点详解(1)
数据库·redis·学习
**蓝桉**19 小时前
mysql二进制部署
mysql
xixihaha132419 小时前
将Python Web应用部署到服务器(Docker + Nginx)
jvm·数据库·python
夕除19 小时前
Mysql--07
数据库·mysql
数据最前线19 小时前
5个瞬间,盘点国产数据库的2025年
数据库
jiankeljx19 小时前
Redis-配置文件
数据库·redis·oracle
xixihaha132419 小时前
Python游戏中的碰撞检测实现
jvm·数据库·python
Schengshuo19 小时前
SQL 中 COUNT 的用法详解
数据库·sql
顶点多余19 小时前
Mysql--后端与前端关系
数据库·mysql
mygljx19 小时前
【MySQL 的 ONLY_FULL_GROUP_BY 模式】
android·数据库·mysql