Open MrYang-Jia opened 1 year ago
Thanks @MrYang-Jia for your reporting!
So at first, is this configuration working on the plain shardingsphere or other runtime, such as spring-boot
?
If that is the case, does it work with JVM mode on quarkus?
谢谢您的反馈,但是我使用的不是springBoot,不知道在quarkus上,我想这么实现自定义策略,我需要怎么做?有对应的实现案例吗?
Thank you for your feedback, but I am not using SpringBoot and I am not sure if I want to implement a custom policy on Quarkus. What do I need to do? Is there a corresponding implementation case?
Thanks @MrYang-Jia for your reporting!
So at first, is this configuration working on the plain shardingsphere or other runtime, such as
spring-boot
? If that is the case, does it work with JVM mode on quarkus?
As I far as Know, there was no such case before. So can you share with a project? Maybe I can take a look next week.
@zhfeng 您好,我已经找到了解决方案,几个问题一起反馈下吧! 第一个: 自建 StandardShardingAlgorithm 规则类后,需要通过 config 配置文件里使用 type: CLASSBASED 的方式来加载对象类 然后如果使用这种模式的话,现有的 ClassBasedShardingAlgorithmFactory 对象类无法正常加载class 需要改写方法逻辑,主要部分为: First: After creating the StandardShardingAlgorithm rule class, you need to use type: class in the config configuration file BASED method to load object classes Then, if this mode is used, the existing ClassBasedShardingAlgorithmFactory object class cannot load the class properly The method logic needs to be rewritten, mainly including:
public static <T extends ShardingAlgorithm> T newInstance(String shardingAlgorithmClassName, Class<T> superShardingAlgorithmClass, Properties props) {
try {
Class<?> algorithmClass =
// 这部分代码必须改写成如下方式,否则quarkus里加载不到对应的 class
// This part of the code must be rewritten as follows, otherwise the corresponding class cannot be loaded in Quarkus
Class.forName(shardingAlgorithmClassName,false,Thread.currentThread().getContextClassLoader());
if (!superShardingAlgorithmClass.isAssignableFrom(algorithmClass)) {
throw new ShardingAlgorithmClassImplementationException(shardingAlgorithmClassName, superShardingAlgorithmClass);
} else {
T result = (T) algorithmClass.getDeclaredConstructor().newInstance();
result.init(convertToStringTypedProperties(props));
return result;
}
} catch (ReflectiveOperationException var5) {
throw new RuntimeException(var5);
}
}
第二个问题:
所以方便的话,最好还是您这里将这两个问题给修复下,因为quarkus是可以在 runtime 目录底下将对应有问题的类覆写,还有修正一些可能性的第三方jar包bug,感谢您抽空阅读完我编写的信息,谢谢 So, if it's convenient, it's best for you to fix these two issues here, because quarkus can overwrite the corresponding problematic classes in the runtime directory, and also fix some possible third-party jar package bugs. Thank you for taking the time to read the information I wrote. Thank you
@MrYang-Jia Sorry for the late reply and thanks for your investigation!
Is it possible to share your project with sharding algorithm?
目前我是在配置文件 org.apache.shardingsphere.sharding.spi.ShardingAlgorithm 里添加新的分片规则,结果发现配置表里引用的话会引用不到,请问如何实现
pom 配置如下
config.yaml
application.properties 配置内容如下,不引入自定义分片规则的情况下可正常运行
报错信息如下: