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

相关推荐
IvorySQL41 分钟前
PostgreSQL 分区表的 ALTER TABLE 语句执行机制解析
数据库·postgresql·开源
·云扬·1 小时前
MySQL 8.0 Redo Log 归档与禁用实战指南
android·数据库·mysql
IT邦德1 小时前
Oracle 26ai DataGuard 搭建(RAC到单机)
数据库·oracle
惊讶的猫1 小时前
redis分片集群
数据库·redis·缓存·分片集群·海量数据存储·高并发写
不爱缺氧i1 小时前
完全卸载MariaDB
数据库·mariadb
纤纡.2 小时前
Linux中SQL 从基础到进阶:五大分类详解与表结构操作(ALTER/DROP)全攻略
linux·数据库·sql
jiunian_cn2 小时前
【Redis】渐进式遍历
数据库·redis·缓存
橙露2 小时前
Spring Boot 核心原理:自动配置机制与自定义 Starter 开发
java·数据库·spring boot
冰暮流星2 小时前
sql语言之分组语句group by
java·数据库·sql
符哥20082 小时前
Ubuntu 常用指令集大全(附实操实例)
数据库·ubuntu·postgresql