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 也会导致这个问题等等。

相关推荐
m0_6239556629 分钟前
Oracle使用SQL一次性向表中插入多行数据
数据库·sql·oracle
阿蒙Amon1 小时前
C#读写文件:多种方式详解
开发语言·数据库·c#
东窗西篱梦1 小时前
Redis集群部署指南:高可用与分布式实践
数据库·redis·分布式
就是有点傻2 小时前
C#如何实现中英文快速切换
数据库·c#
1024小神3 小时前
hono框架绑定cloudflare的d1数据库操作步骤
数据库
KellenKellenHao4 小时前
MySQL数据库主从复制
数据库·mysql
@ chen5 小时前
Redis事务机制
数据库·redis
KaiwuDB5 小时前
使用Docker实现KWDB数据库的快速部署与配置
数据库·docker
一只fish5 小时前
MySQL 8.0 OCP 1Z0-908 题目解析(16)
数据库·mysql
泊浮目6 小时前
未来数据库硬件-网络篇
数据库·架构·云计算