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

相关推荐

  1. shardingsphere 出现 Cannot support database type ‘MySQL‘

    2024-01-16 19:16:08       55 阅读
  2. ShardingSphere

    2024-01-16 19:16:08       29 阅读
  3. Spring Boot集成ShardingSphere详解

    2024-01-16 19:16:08       23 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-16 19:16:08       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-16 19:16:08       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-16 19:16:08       82 阅读
  4. Python语言-面向对象

    2024-01-16 19:16:08       91 阅读

热门阅读

  1. 构建 aarch64 以及 riscv64 交叉编译工具链(裸机)

    2024-01-16 19:16:08       52 阅读
  2. Python中loguru的配置和使用

    2024-01-16 19:16:08       52 阅读
  3. [HarmonyOS]第一课:运行HelloWorld

    2024-01-16 19:16:08       54 阅读
  4. 《设计模式的艺术》笔记 - 建造者模式

    2024-01-16 19:16:08       38 阅读
  5. GBASE南大通用ExecuteScalar 方法

    2024-01-16 19:16:08       61 阅读
  6. 聊聊PowerJob的QueryConvertUtils

    2024-01-16 19:16:08       47 阅读
  7. liunx常用命令

    2024-01-16 19:16:08       47 阅读
  8. fs 模块

    2024-01-16 19:16:08       49 阅读
  9. 重装系统备份及初始化笔记

    2024-01-16 19:16:08       56 阅读
  10. RSA非对称加密

    2024-01-16 19:16:08       48 阅读
  11. HTML 入门 干货 总结

    2024-01-16 19:16:08       56 阅读