shardingsphere源码编译
# 一、下载编译
# 1.1、下载
我们可以去Shardingsphere的GitHub (opens new window)或者Gitee (opens new window)下载源码,Shardingsphere较大,建议去Gitee下载,速度较快
# 1.2、选择版本
我这里选择编译的是5.3.2版本
git checkout 5.3.2
# 1.3、处理编译报错问题
项目编译完成后,会发现项目引入org.apache.shardingsphere.sql.parser.autogen
相关类报错,这是由于org.apache.shardingsphere.sql.parser.autogen
包下的代码由 ANTLR 生成,,可以执行以下命令快速生成:
./mvnw -Dcheckstyle.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true -Djacoco.skip=true -DskipITs -DskipTests install -T1C
注意版本差异,在5.4.1中使用上面脚本会报错,5.4.1脚本如下
./mvnw -DskipITs -DskipTests install -T1C
1
# 1.4、处理文件未索引问题
生成的代码例如 org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser
等 Java 文件由于较大,默认配置的 IDEA 可能不会索引该文件。 可以调整 IDEA 的属性,Help-->Edit Custom Properties
,在文件中增加如下行:
idea.max.intellisense.filesize=10000
# 1.5、启动proxy项目
在shardingsphere-->proxy-->bootstrap
的 server.yaml
中增加如下配置
#部署模式,这里表示Standalone
mode:
type: Standalone
repository:
type: JDBC
#rules 认证相关,可以通过mycli或者DBeaver或者Navicat工具连接,默认端口3307
rules:
- !AUTHORITY
users:
- root@%:root
- sharding@:sharding
provider:
type: ALL_PERMITTED
- !TRANSACTION
defaultType: XA
providerType: Atomikos
- !SQL_PARSER
sqlCommentParseEnabled: true
sqlStatementCache:
initialCapacity: 2000
maximumSize: 65535
parseTreeCache:
initialCapacity: 128
maximumSize: 1024
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
随后启动Bootstrap
即可,启动日志如下
Connected to the target VM, address: '127.0.0.1:51104', transport: 'socket'
[INFO ] 2023-07-03 17:56:56.075 [main] o.a.s.p.frontend.ShardingSphereProxy - ShardingSphere-Proxy Standalone mode started successfully
2
# 二、常见问题
# 2.1、 Windows环境下,通过Git克隆 ShardingSphere 源码时为什么提示文件名过长,如何解决
git clone git@xxxx.git
......
error:unable to create file xxxx : Filename too long
fatal:unable to checkout working tree
warning:Clone succeeded,butcheckout failed
You can inspect what was checked out with ‘git status’ and retry the checkout with ‘git checkout -f HEAD’
......
2
3
4
5
6
7
8
问题原因:
为保证源码的可读性,ShardingSphere 编码规范要求类、方法和变量的命名要做到顾名思义,避免使用缩写,因此可能导致部分源码文件命名较长。由于 Windows 版本的 Git 是使用 msys 编译的,它使用了旧版本的 Windows Api,限制文件名不能超过 260 个字符
解决方法:
打开 cmd.exe(你需要将 git添加到环境变量中)并执行下面的命令,可以让 git 支持长文件名
git config --global core.longpaths true
# 2.2、文件未索引问题
问题原因:
生成的代码例如 org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser
等 Java 文件由于较大,默认配置的 IDEA 可能不会索引该文件。
解决方法:
调整 IDEA 的属性,路径Idea-->Help-->Edit Custom Properties-->idea.properties,添加如下属性
idea.max.intellisense.filesize=10000