方便更快捷的说明问题,可以按需填写(可删除)
使用环境:
运行环境为 Docker 20.10.12
, Image为 apache/shardingsphere-proxy:5.0.0
场景、问题:
我看到 ShardingSphere Doc 提到很多功能实现类的加载方式是通过 SPI(Service Provider Interface) 注入的方式完成的。我同样在Source的org.apache.shardingsphere.example.extension.sharding.algortihm.spibased.spi.SpiBasedShardingAlgorithm
看到了其具体用法.
但我疑惑在 Proxy 启动 :: ShardingSphere (apache.org) 一节中, 针对于 ShardingSphere Proxy 并没有提及建立类似/resources/META-INF/services
的文件夹, 然后在内部建文件的方式来指定 SPI 的实现. 是 Proxy 尚不支持, 还是 ShardingSphere Proxy 这种类似的场景只能使用 CLASS_BASE ? 亦或是在包含 SPI 实现类的 JAR 包中引入 /resources/META-INF/services
的文件夹来处理?
我有一种想法, 就是有时候注意到 ShardingSphere 的 Master 分支有些内置算法的对应类更新, 此时当然能通过 CLASS_BASE 自定义分片算法将其改动简单复刻到低版本的 ShardingSphere 上, 但 CLASS_BASE 无法传入 YAML 文件中的参数. 此时能否通过 SPI 机制, 让一个类 copy 其 Master 分支的类新的改动代码到此类, 并在SPI 中(即org.apache.shardingsphere.sharding.spi.ShardingAlgorithm
)注册, 这样这个类如何做才能识别到之前类的YAML参数?
一个典型场景是在 ShardSphere 5.0.0 中的org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithm
, 它的getDateTimePattern()
和getDateTimeLower()
函数, Preconditions.checkArgument()
使用了%
而不是%s
, 而在ShardingSphere 的 Master 分支这个问题已解决. 那我能否定义一个类com.xxx.IntervalShardingAlgorithm
, 来通过private Properties props = new Properties();
读取YAML内定义的值? 在标准的 SpringBoot Project 中当然有方法让类读取到 Yaml 中的值,但如果是ShardingSphere Proxy呢? (在 In terms of date ranges, there are some problems with actual-data-nodes · Issue #13240 · apache/shardingsphere (github.com) 中我也有类似的疑惑)