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

相关推荐
MAGICIAN...1 天前
【Redis】--持久化机制
数据库·redis·缓存
我真的是大笨蛋1 天前
JVM调优总结
java·jvm·数据库·redis·缓存·性能优化·系统架构
步步为营DotNet1 天前
5-2EFCore性能优化
数据库·性能优化·.net
2501_920047031 天前
Redis-集群
数据库·redis·bootstrap
半夏陌离1 天前
SQL 拓展指南:不同数据库差异对比(MySQL/Oracle/SQL Server 基础区别)
大数据·数据库·sql·mysql·oracle·数据库架构
旋转的油纸伞1 天前
SQL表一共有几种写入方式
数据库·sql
半夏陌离1 天前
SQL 入门指南:排序与分页查询(ORDER BY 多字段排序、LIMIT 分页实战)
java·前端·数据库
isyoungboy1 天前
SQL高效处理海量GPS轨迹数据:人员gps轨迹数据抽稀实战指南
数据库·sql
敬业小码哥1 天前
记一次:mysql的json及json数组使用组合使用
数据库·mysql·json
练小杰1 天前
【Mysql-installer-community-8.0.26.0】Mysql 社区版(8.0.26.0) 在Window 系统的默认安装配置
数据库·sql·mysql·adb·配置文件·mysql安装·关系型数据库