使用docker启动的 shardingSphere-proxy,提示找不到ext-lib下的分片算法

我使用docker镜像启动了shardingSphere-proxy容器,挂载了我的分片算法至ext-lib目录下,提示“ No implementation class load from SPI `org.apache.shardingsphere.sharding.spi.ShardingAlgorithm”。

使用环境:

shardingSphere-proxy5.0.0

场景、问题:

spi


docker容器报错截图

挂载的jar

已进行操作:

现状:

1 个赞

我尝试使用 HINT_INLINE 方式 ,发现sql执行的是全库路由。是否方便帮我看看我的配置问题出在哪儿。
下面是我的配置
schemaName: planet
dataSources:
ds-5979377586143233:
url: jdbc:mysql://10.5.8.77:3306/bmw?serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds-5979377586143232:
url: jdbc:mysql://10.5.8.77:3306/planet_local?serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1

rules:

  • !SHARDING
    tables:
    dishes_table:
    actualDataNodes: ds-5979377586143232.dishes_table, ds-5979377586143233.dishes_table

    defaultDatabaseStrategy:
    hint:
    shardingAlgorithmName: multi-tenancy-hint
    defaultTableStrategy:
    none:

    shardingAlgorithms:
    multi-tenancy-hint:
    type: HINT_INLINE
    props:
    algorithm-expression: ds-$->{Integer.valueOf(value)}
    sql执行日志:

hint 已开启
proxy-hint-enabled: true

1 个赞

使用自定义算法,除了部署 jar 包外,分片算法配置也要指定使用的类,可以参考 CLASS_BASED 配置:

1 个赞

hint 的使用可以参考下之前的帖子:

使用HINT_INLINE的方式是对应InlineShardingAlgorithm这个内置分片算法吗。

1 个赞

我已经看过这个帖子,还是没有找到问题出在哪里。
下面是我 server.yaml和config-sharding.yaml的配置
server.yaml
rules:

  • !AUTHORITY
    users:
    • root@%:root
    • sharding@:sharding
      provider:
      type: ALL_PRIVILEGES_PERMITTED

props:
proxy-hint-enabled: true
sql-show: true

config-sharding.yaml
schemaName: planet
dataSources:
ds-5979377586143233:
url: jdbc:mysql://10.5.8.77:3306/bmw?serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds-5979377586143232:
url: jdbc:mysql://10.5.8.77:3306/planet_local?serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1

rules:

  • !SHARDING
    tables:
    dishes_table:
    actualDataNodes: ds-5979377586143232.dishes_table, ds-5979377586143233.dishes_table

    defaultDatabaseStrategy:
    hint:
    shardingAlgorithmName: multi-tenancy-hint
    defaultTableStrategy:
    none:

    shardingAlgorithms:
    multi-tenancy-hint:
    type: HINT_INLINE
    props:
    algorithm-expression: ds-$->{Integer.valueOf(value)}

我使用HintManager指定了sharding value,


看sql执行日志还是全库路由,

我没找到问题出在哪里

HintInlineShardingAlgorithm

我没找到问题出在哪里

需要复现调查下

好的,是否需要我提供其它相关信息

@方保彦
你好,我发现两个问题:
1、你的分片 value 值很大,不应该用 Integer.valueOf,应使用 Long 型;
2、Proxy 中设置 hint 值需要通过 SQL 命令(如之前提供的帖子),你在代码中调用 HintManager 是无法操作 Proxy 中的变量的。

感谢您的及时回复,针对问题2,我是否可以理解为:Proxy 中设置 hint值不可以使用HintManager ,HintManager 只适用shardingsphere-jdbc的方式。

Proxy 中设置 hint值不可以使用HintManager ,HintManager 只适用shardingsphere-jdbc的方式。

@方保彦 完全正确

:ok_hand:

连接的地址已经不存在了
The ‘apache/shardingsphere’ repository doesn’t contain the ‘examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/src/main/resources/META-INF/sharding-databases.yaml’ path in ‘master’.

时间很长了,ShardingSphere 已经迭代到了 5.3.x 版本。 最新的 example 可以查看仓库:

Gitee 也有镜像地址:

1 个赞

[INFO] shardingsphere-src-distribution … SKIPPED
[INFO] shardingsphere-agent-distribution … SKIPPED
[INFO] shardingsphere-jdbc-distribution … SKIPPED
[INFO] shardingsphere-proxy-distribution … SKIPPED
[INFO] shardingsphere-proxy-native-distribution … SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15:27 min
[INFO] Finished at: 2023-03-16T14:54:00+08:00
[INFO] Final Memory: 155M/842M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project shardingsphere-distsql-parser: Compilation failure: Compilation failure:
[ERROR] /root/exapmle/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/utility/UtilityDistSQLStatementVisitor.java:[20,56] 程序包org.apache.shardingsphere.distsql.parser.autogen不存在
[ERROR] /root/exapmle/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/utility/UtilityDistSQLStatementVisitor.java:[21,86] 程序包org.apache.shardingsphere.distsql.parser.autogen.UtilityDistSQLStatementParser不存在
[ERROR] /root/exapmle/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/utility/UtilityDistSQLStatementVisitor.java:[22,86] 程序包org.apache.shardingsphere.distsql.parser.autogen.UtilityDistSQLStatementParser不存在
[ERROR] /root/exapmle/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/utility/UtilityDistSQLStatementVisitor.java:[23,86] 程序包org.apache.shardingsphere.distsql.parser.autogen.UtilityDistSQLStatementParser不存在
[ERROR] /root/exapmle/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/utility/UtilityDistSQLStatementVisitor.java:[33,59] 找不到符号
[ERROR] 符号: 类 UtilityDistSQLStatementBaseVisitor
[ERROR] /root/exapmle/distsql/parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/utility/UtilityDistSQLStatementVisitor.java:[36,42] 找不到符号
[ERROR] 符号: 类 PreviewSQLContext


[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :shardingsphere-distsql-parser

ANTLR 编译需要 JDK 11 以上版本,请检查一下是不是版本不符合要求。
https://shardingsphere.apache.org/community/cn/involved/contribute/dev-env/

1 个赞

是的,谢谢。
把原来java-1.8.0改为了jdk-17.0.5就好了。

京ICP备2021015875号