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

相关推荐
富贵儿99810 分钟前
NL2SQL 实践手记 05:表结构之外,还有业务知识——给查询流程接上 RAG
数据库·sql·ai·自然语言处理·langchain
csdn_aspnet1 小时前
如何使用 Docker 设置 PostgreSQL
运维·数据库·docker·postgresql·容器
皮皮林5512 小时前
CTO说MySQL单表行数不要超过2000w,为啥?
mysql
倔强的石头_4 小时前
KES Studio 与 DMS 辅助开发管理实践:让接入过程可视化
数据库
富贵儿9985 小时前
NL2SQL 实践手记 06:四个角色怎样合作——拆解一个 Multi-Agent 查询系统
数据库·sql·ai·自然语言处理·langchain
codeejun6 小时前
每日一Go·MySQL-24、死锁排查与解决方案
开发语言·mysql·golang
Decay__7 小时前
PostgreSQL 监控体系构建 —— postgres_exporter + Prometheus + Grafana 全栈实战
运维·数据库·sql·postgresql
码农张38 小时前
MySQL 8.4.13 LTS 压缩版安装步骤 + 规范配置文件
mysql
Decay__9 小时前
PostgreSQL 告警与自动化运维 —— 告警分级收敛、Webhook、定时巡检、脚本库
运维·数据库·sql·postgresql
老纪的技术唠嗑局10 小时前
OceanBase × 知跃空间智能:从感知,到记忆,再到行为,打造具身智能数据底座
数据库