StarRocks源码编译

标签: 无 分类: 未分类 创建时间:2022-03-11 09:11:31 更新时间:2023-10-20 11:23:26

这个需求挺奇葩的,老板想要把SQL命令:SHOW VARIABLES,显示的内容,比如 version_comment、version 等修改掉,目的就是对外提供数据的时候,不让别人看到数据库信息(对外提供数据的时候,不是通过接口方式,而是直接提供数据库连接,我也是醉了)。为了这个,不惜修改源码也要实现,这不是难为我了吗。

1
2
---- 尝试修改环境变量,失败了,ERROR 1064 (HY000): Variable 'version_comment' is a read only variable
set GLOBAL version_comment = test;
参考文章:
1.MySQL 系统变量(system variables)
2.系统变量 version_comment 用于显示 StarRocks 的版本。不可更改。
3.StarRocks 源码导读一 StarRocks CBO 优化器、StarRocks 向量化执行器,感觉已经超出我的认知范围了

1.Docker中编译安装

经过我长时间的尝试和修改(大约两三天),我最终还是没有实现成功的自己搭建编译环境,我觉得要是自己搭建编译环境还是有一定的难度的,会遇到各种各样的问题,比如 protobuf、zlib问题,还有其他问题,比如我下面列举的,我一一解决,最后还是有解决不完的问题,总是缺少这个,缺少那个,我真是烦透了,所以我最后还是放弃了自己搭建编译环境。

官方提供了Docker编译环境,应该是把需要的依赖什么的都安装好了,只需要上传源码就可以了,真的太丝滑了,我都开始怀疑我花了两天时间搞本地编译,到底价值何在呢?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## 1.下载docker(已有可以忽略)
yum install -y docker
## 2.启动docker
systemctl start docker
## 3.pull 镜像
docker pull starrocks/dev-env:main
## 4.启动镜像
docker run -it --name starrocks --privileged=true -d starrocks/dev-env:main
## 启动时挂载本地镜像,本地的 ~/.m2 指向 容器内的 /root/.m2,本地的 /cloud,指向容器内的 /cloud,我的源码就放在了 /cloud 目录下
docker run -it -v ~/.m2:/root/.m2 -v /cloud:/cloud --name starrocks -d starrocks/dev-env:main

## 5.进入镜像
docker exec -it starrocks /bin/bash
## 6.下载代码
git clone https://github.com/StarRocks/starrocks.git

## 7.编译
cd starrocks
## 为了解决项目下载pom的问题
cd fe
## 先进行fe模块打包
mvn clean package -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
## 进入jdbcbridge 目录
cd ../jdbc_bridge
## 同样执行
mvn clean package -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
## 回到主目录
cd ..
## 执行编译
sh build.sh
## 8.编译不需要AVX2支持的starrocks
vi build.sh
## 将USE_AVX2=ON 修改为USE_AVX2=OFF 保存退出后,执行 sh build.sh

注意
使用官方的docker进行编译的时候,内存占用特别的厉害,我16G的电脑,都扛不住。

参考文章:
1.第1.1章:StarRocks部署–源码编译 这里除了源码编译,还有一些解释说明
2.dev-env image 使用说明 官方的文档
3.Doris系列2-Doris编译和安装 使用Docker 镜像编译安装Doris
4.StarRocks FE开发环境搭建 这个主要就是上面的命令,我觉得这样写,还是简单方便的
5.Apache Doris技术实践 这篇文章介绍的Doris的安装,部署还有在美团的应用,可以好好的看一看。

问题

使用官方的Docker镜像编译,看来也不是一帆风顺,遇到的第一个问题和第二个问题可以合并解决。

(1) Could not transfer artifact org.apache.maven.plugins:maven-checkstyle-plugin:pom:3.1.1 from/to spring-plugins (https://repo.spring.io/plugins-release/)
这个问题,意思就是无法下载依赖包。我尝试设置了maven的中央仓库指向 阿里云,重新执行编译工作,还是报错。

1
Plugin org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-checkstyle-plugin:jar:3.1.1: Could not transfer artifact org.apache.maven.plugins:maven-checkstyle-plugin:pom:3.1.1 from/to spring-plugins (https://repo.spring.io/plugins-release/): Transfer failed for https://repo.spring.io/plugins-release/org/apache/maven/plugins/maven-checkstyle-plugin/3.1.1/maven-checkstyle-plugin-3.1.1.pom: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty -> [Help 1]

这里显示,这个插件必须要用户名密码才能下载,我打开了上面的链接,确实是需要用户密码的。但是奇怪的是,我在本机的代码中,单独编译fe这个模块,竟然不会报这个错误,虽然也无法编译通过,但是没有报需要认证这个错误。我尝试降低版本,也是不行的,总是报错。

【无效尝试】
我尝试了很多的方法,似好都不起作用

  • 1.重新下载版本
  • 2.重新挂载.m2目录
  • 3.设置代理

我甚至修改了源码中的关于 maven-checkstyle-plugin 的引用,直接删掉了部分内容,虽然暂时的解决了无法编译 maven-checkstyle-plugin,不过又出现了新的问题。

(2) Could not transfer artifact org.codehaus.plexus:plexus-utils:pom
和上一个问题是一模一样的问题,这个问题也是认证的问题,这个到底是什么问题呢?虽然上个问题我通过注释掉 maven-checkstyle-plugin 这个插件解决了,但是不能全部无法下载的依赖都进行删除吧。

1
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project fe-common: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile failed: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-compiler-plugin:jar:3.1 -> org.apache.maven:maven-artifact:jar:2.0.9 -> org.codehaus.plexus:plexus-utils:jar:1.5.1: Failed to read artifact descriptor for org.codehaus.plexus:plexus-utils:jar:1.5.1: Could not transfer artifact org.codehaus.plexus:plexus-utils:pom:1.5.1 from/to spring-plugins (https://repo.spring.io/plugins-release/): Transfer failed for https://repo.spring.io/plugins-release/org/codehaus/plexus/plexus-utils/1.5.1/plexus-utils-1.5.1.pom: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty -> [Help 1]

[解决]
主要就是因为缺少安全证书导致的,在打包的时候可以跳过ssl认证。

1
2
3
4
5
6
## 进入fe目录
cd fe
## 执行打包
mvn clean package -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
## 回到主目录,执行编译
./build.sh

(3) image does not exist: /cloud/soft/starrocks/output/fe/meta/image/image.0
源码编译之后,部署 fe 的时候,启动日志中出现了这个问题。

【解决】
其实我觉得可能不需要解决,如果非要做了什么的话,就是 修改了 fe/conf/fe.conf 中的 meta_dir 注释打开了。

2.编译完成

编译完成后,产出文件在output/目录中

3.windows开发问题

在windows上打开idea编译fe模块的时候,无法编译成功,显示 thrift did not exit cleanly.

(1) 下载
下载 thrift.exe 程序,记得重命名,放到 自定义目录中,我这里放到了 D:\soft\thrift 目录

(2) 设置环境变量
在系统的环境变量中,添加 D:\soft\thrift 目录。

参考文章:
1.解决thrift:compile编译报错问题thrift failed error: /bin/sh 1. 系统环境变量配置的有问题(调整thrift的环境变量目录配置,在PATH后加入thrift编译后的可执行文件) 2. 系统环境变量没有问题,但是IDE运行时读取的环境变量有问题
2. Thrift did not exit cleanly
3.Thrift开发 之 windows上安装 下载,重命名,并添加环境变量

4.编译Broke

作为备份和恢复的Broke需要单独的编译,进入到目录之后,执行build.sh编译就可以了。编译后,产出文件在fs_brokers/apache_hdfs_broker/output目录中

1
cd fs_brokers/apache_hdfs_broker/ && sh build.sh

4.手动安装编译环境

我刚开始使用的是手动编译环境,就是在一个CentOS8的环境中,安装一些依赖然后进行编译,简直要痛苦死了,最后没有编译成功,放弃了。

1.编译环境搭建

我的虚拟机是CentOS8,需要的环境:

  • python 2.7+
  • java 1.8+
  • gcc
  • cmake
  • gcc-c++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## 安装python
yum install python2
## 查看python安装
cd /usr/bin
## 设置软链接
ln -s /usr/bin/python3.6 /usr/bin/python

## 安装gcc
yum -y install gcc gcc-c++

## 安装cmake
yum install cmake libarchive patch byacc flex libtoolize zlib-devel libstdc++* *atomic*

## 或者 安装一系列的软件开发包 Install 168 Packages Upgrade 12 Packages Total download size: 143 M
dnf group install "Development Tools"

2.下载第三方依赖包

由于编译的时候,需要一些外部依赖包,但是因为墙的存在,所以可能会出现 429 错误,下载 OpenSSL_1_1_1m.tar.gz 文件,放置到 源码目录 thirdparty/src 文件夹下。如果其他的下载也出现了问题,可以重新执行 ./build.sh 命令,或者是下载相应的资源包到该文件夹下。

参考文章:
1.ERROR 429: Too Many Requests. 下载 OpenSSL_1_1_1m.tar.gz 的时候,会出现这个问题,主要就是墙的问题。

(1) patch: command not found

1
yum -y install patch

(2) byacc: command not found

1
yum install byacc

(3) flex: command not found

1
yum -y install flex 

(4) libtoolize: command not found

1
yum -y install libtool 

(5) Failed to build B2 build engine
依赖安装之后,出现了这个问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
A C++11 capable compiler is required for building the B2 engine.
Toolset 'cxx' does not appear to support C++11.

** Note, the C++11 capable compiler is _only_ required for building the B2
** engine. The B2 build system allows for using any C++ level and any other
** supported language and resource in your projects.


You can specify the toolset as the argument, i.e.:
./build.sh gcc

Toolsets supported by this script are:
acc, clang, como, gcc, intel-darwin, intel-linux, kcc, kylix, mipspro,
pathscale, pgi, qcc, sun, sunpro, tru64cxx, vacpp

For any toolset you can override the path to the compiler with the CXX
environment variable. You can also use additional flags for the compiler
with the CXXFLAGS environment variable.

A special toolset; cxx, is available which is used as a fallback when a more
specific toolset is not found and the cxx command is detected. The 'cxx'
toolset will use the CXX, CXXFLAGS, and LIBS environment variables, if present.

Similarly, the cross-cxx toolset is available for cross-compiling by using the
BUILD_CXX, BUILD_CXXFLAGS, and BUILD_LDFLAGS environment variables to compile
binaries that will be executed on the build system. This allows CXX etc. to be
set for cross-compilers to be propagated to subprocesses.


Failed to build B2 build engine

这个意思是要兼容c++11的编译器。
【尝试】
我重新安装了开发工具包

1
2
3
4
## 安装gcc-c++
yum install gcc-c++
## 开发工具包
dnf group install "Development Tools"

(6) but no working zlib library was found
这里显示,没有可用的zlib,不是没有zlib命令,所以即便是使用了yum安装了zlib-devel也可能出现这个问题。

1
2
3
4
checking for library containing zlibVersion... no
configure: error: in `/cloud/soft/starrocks-main/thirdparty/src/protobuf-3.14.0':
configure: error: --with-zlib was given, but no working zlib library was found
See `config.log' for more details

【解决】
我暂时修改了编译源码,把 thirdparty/build-thirdparty.sh 中的 build_protobuf 代码部分的 –with-zlib –with-zlib-include=${TP_INSTALL_DIR}/include 配置去掉了。

(7) unrecognized option: `-j13’
这个问题我不知道怎么产生的,我以为是java版本的问题,因为我使用的jdk就是openjdk13,我重新安装了jdk1.8,好像还是不行。

1
2
3
configure: WARNING: you should use --build, --host, --target
configure: error: unrecognized option: `-j13'
Try `./configure --help' for more information

这个问题是我修复上个问题产生的,我删除zlib的时候,把make位置放错了。

(8) cannot find /usr/lib64/libatomic.so.1.2.0

1
2
3
4
5
6
7
/usr/bin/ld: cannot find /usr/lib64/libatomic.so.1.2.0
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:3890: protoc] Error 1
make[2]: Leaving directory '/cloud/soft/starrocks-main/thirdparty/src/protobuf-3.14.0/src'
make[1]: *** [Makefile:1871: all-recursive] Error 1
make[1]: Leaving directory '/cloud/soft/

[解决]

1
2
## 安装依赖
yum -y install *atomic*

[错误方法]

1
2
3
4
5
6
7
## 使用下面的方法可能还是报错
## 查获libatomic.so库
find / -name libatomic.so
## 创建软连接
ln -s /usr/lib/gcc/x86_64-redhat-linux/8/libatomic.so /usr/lib64/libatomic.so.1.2.0
## 删除软连接
rm -rf /usr/lib64/libatomic.so.1.2.0

(9) /usr/bin/ld: cannot find -lstdc++

1
2
3
4
5
6
7
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:3890: protoc] Error 1
make[2]: Leaving directory '/cloud/soft/starrocks-main/thirdparty/src/protobuf-3.14.0/src'
make[1]: *** [Makefile:1871: all-recursive] Error 1
make[1]: Leaving directory '/cloud/soft/starrocks-main/thirdparty/src/protobuf-3.14.0'
make: *** [Makefile:1778: all] Error 2

[解决]

1
yum install -y libstdc++*
小额赞助
本人提供免费与付费咨询服务,感谢您的支持!赞助请发邮件通知,方便公布您的善意!
**光 3.01 元
Sun 3.00 元
bibichuan 3.00 元
微信公众号
广告位
诚心邀请广大金主爸爸洽谈合作
每日一省
isNaN 和 Number.isNaN 函数的区别?

1.函数 isNaN 接收参数后,会尝试将这个参数转换为数值,任何不能被转换为数值的的值都会返回 true,因此非数字值传入也会返回 true ,会影响 NaN 的判断。

2.函数 Number.isNaN 会首先判断传入参数是否为数字,如果是数字再继续判断是否为 NaN ,不会进行数据类型的转换,这种方法对于 NaN 的判断更为准确。

每日二省
为什么0.1+0.2 ! == 0.3,如何让其相等?

一个直接的解决方法就是设置一个误差范围,通常称为“机器精度”。对JavaScript来说,这个值通常为2-52,在ES6中,提供了Number.EPSILON属性,而它的值就是2-52,只要判断0.1+0.2-0.3是否小于Number.EPSILON,如果小于,就可以判断为0.1+0.2 ===0.3。

每日三省
== 操作符的强制类型转换规则?

1.首先会判断两者类型是否**相同,**相同的话就比较两者的大小。

2.类型不相同的话,就会进行类型转换。

3.会先判断是否在对比 null 和 undefined,是的话就会返回 true。

4.判断两者类型是否为 string 和 number,是的话就会将字符串转换为 number。

5.判断其中一方是否为 boolean,是的话就会把 boolean 转为 number 再进行判断。

6.判断其中一方是否为 object 且另一方为 string、number 或者 symbol,是的话就会把 object 转为原始类型再进行判断。

每日英语
Happiness is time precipitation, smile is the lonely sad.
幸福是年华的沉淀,微笑是寂寞的悲伤。