从源码到运行:深入解析 Apache Doris 的编译与 Debug 流程

Apache Doris 作为一款高性能、实时的分析型数据库,其底层架构和代码设计令人称道。对于开发者来说,掌握源码编译与调试运行是理解 Doris 内核的关键。然而,Doris 的编译流程涉及多种工具链和依赖配置,Debug 过程中也可能遇到各种复杂问题,初学者常常感到无从下手。

本篇文章将以源码到运行为主线,详细解析 Apache Doris 的编译与 Debug 流程。从环境准备、源码拉取到常见问题排查,我们将结合实际案例,帮助您快速上手 Doris 的开发调试工作。这篇文章适用于初次接触 Doris 的开发者,以及希望优化调试效率的资深用户,提供了实用的技术参考。

导读

:::block-3
你是否好奇一条 SQL 从解析到执行的全过程是如何实现的?在 Apache Doris 中,这一过程涉及多个核心组件和复杂的内部机制。本文将以源码到运行为主线,全面解析 Doris 的编译与调试流程,帮助您深入理解 SQL 的执行原理。
:::

一、环境

1.1 基础环境

  1. 电脑配置:MacBook Pro(芯片:Apple M1,macOS: 15.1)
  2. JDK17
  3. Doris Master分支,适用branch-2.1分支

1.2 安装环境依赖

使用 brew 安装的 jdk 版本为 17,因为在 macOS 上,arm64 版本的 brew 默认没有 8 版本的 jdk, Doris 目前只支持 jdk8 和 jdk17 两个版本

brew install automake autoconf libtool pkg-config texinfo coreutils gnu-getopt \
python@3 cmake ninja ccache bison byacc gettext wget pcre maven llvm@16 openjdk@17 npm

依赖说明:

  1. Java、Maven 等可以单独下载,方便管理
  • Mac 推荐 Zulu JDK17
  • Maven 从 Maven 官网下载即可
  • 自行下载的 Java 与 Maven 需要配置环境变量
  1. 其他依赖的环境变量 (示例为 Apple Silicon 芯片 Mac)
export PATH=/opt/homebrew/opt/llvm/bin:$PATH
export PATH=/opt/homebrew/opt/bison/bin:$PATH
export PATH=/opt/homebrew/opt/texinfo/bin:$PATH
ln -s -f /opt/homebrew/bin/python3 /opt/homebrew/bin/python

您可以在 ~/.bashrc 或 ~/.zshrc 文件中添加上述配置,并运行 source ~/.bashrc 或 source ~/.zshrc 以使其生效。

安装 thrift

:::block-1
注意: 仅在只调试 FE 的情况下需要安装 thrift,同时调试 BE 和 FE 时,BE 的三方库包含 thrift
:::

MacOS: 
    1. 下载:`brew install thrift@0.16.0`
    2. 建立软链接: 
        `mkdir -p ./thirdparty/installed/bin`
        # Apple Silicon 芯片 macOS
        `ln -s /opt/homebrew/Cellar/thrift@0.16.0/0.16.0/bin/thrift ./thirdparty/installed/bin/thrift`
        # Intel 芯片 macOS
        `ln -s /usr/local/Cellar/thrift@0.16.0/0.16.0/bin/thrift ./thirdparty/installed/bin/thrift`

注:macOS 执行 `brew install thrift@0.16.0` 可能会报找不到版本的错误,解决方法如下,在终端执行:
    1. `brew tap homebrew/core --force`
    2. `brew tap-new $USER/local-tap`
    3. `brew extract --version='0.16.0' thrift $USER/local-tap`
    4. `brew install thrift@0.16.0`
参考链接: `https://gist.github.com/tonydeng/02e571f273d6cce4230dc8d5f394493c`

拉取自己的代码

拉取代码

cd ~
mkdir DorisDev
cd DorisDev
git clone https://github.com/GitHubID/doris.git

设置环境变量

export DORIS_HOME=~/DorisDev/doris
export PATH=$DORIS_HOME/bin:$PATH

下载 Doris 编译依赖

  1. Apache Doris Third Party Prebuilt(https://github.com/apache/doris-thirdparty/releases/tag/automation)页面有所有第三方库的源码,可以直接下载doris-thirdparty-source.tgz获得。

  2. 可以在Apache Doris Third Party Prebuilt页面直接下载预编译好的第三方库,省去编译第三方库的过程,参考下面的命令。

cd thirdparty
rm -rf installed

# Intel 芯片
curl -L https://github.com/apache/doris-thirdparty/releases/download/automation/doris-thirdparty-prebuilt-darwin-x86_64.tar.xz \
    -o - | tar -Jxf -

# Apple Silicon 芯片
curl -L https://github.com/apache/doris-thirdparty/releases/download/automation/doris-thirdparty-prebuilt-darwin-arm64.tar.xz \
    -o - | tar -Jxf -

# 保证 protoc 和 thrift 能够正常运行
cd installed/bin

./protoc --version
./thrift --version
  1. 运行protoc和thrift的时候可能会遇到无法打开,因为无法验证开发者的问题,可以到前往安全性与隐私。点按通用面板中的仍要打开按钮,以确认打算打开该二进制。参考https://support.apple.com/zh-cn/HT202491。

修改系统最大文件句柄数,修改后source 对应文件生效。

# bash
echo 'ulimit -n 65536' >>~/.bashrc
    
# zsh
echo 'ulimit -n 65536' >>~/.zshrc

二、编译 Doris

cd $DORIS_HOME

# 编译整个Doris
sh build.sh
# 只编译fe、be
sh build.sh --fe --be

如需加快编译速度且无需 FE 前端页面,可注释掉 build.sh 脚本中编译 FE 前端页面的部分:

# FE UI must be built before building FE
#if [[ "${BUILD_FE}" -eq 1 ]]; then
#    if [[ "${BUILD_UI}" -eq 1 ]]; then
#        build_ui
#    fi
#fi


编译成功后,您将看到类似以下输出:

三、Debug

配置 Debug 环境,本文只Debug Doris FE。

# 将编译好的包cp出来  
cp -r output/ ../doris-run
    
# 配置FE/BE的conf
1、IP、目录
2、BE 额外配置 min_file_descriptor_number = 10000

开始用 IDEA 进行 Debug,这里我们不要直接打开Doris项目根目录,要打开 FE 的目录(**很重要!!**为了不和CLion发生冲突)

生成 FE 代码

打开 IDEA 终端,到代码根目录下执行 sh generated-source.sh

等待显示 Done 就可以了

配置 Debug FE

  • 选择编辑配置

  • 添加 DorisFE 配置

左上角 + 号添加一个应用程序的配置,具体配置参考下图

  • 工作目录选择源码目录下的 fe 目录
  • 参照 Doris 代码根目录下的 fe/bin/start_fe.sh 中 export 的环境变量进行环境变量配置。 其中环境变量的Doris目录值指向准备工作里里自己copy出来的目录。

环境变量参考:

JAVA_OPTS=-Xmx8092m;
LOG_DIR=/Users/abc/DorisDev/doris-run/fe/log;
PID_DIR=/Users/abc/DorisDev/doris-run/fe/log;
DORIS_HOME=/Users/abc/DorisDev/doris-run/fe

启动 FE

点击 Run 或者 Debug 就会开始编译,编译完 fe 就会启动,这里我们选择 Debug。

启动 BE

由于我们已经将编译好的包复制到了doris-run目录下,启动doris-run目录下的 BE。

sh bin/start_be.sh --daemon

Debug FE

通过 mysql client或者dbeaver连接到IDEA 启动的FE

mysql -uroot -h127.0.0.1 -P9030

添加BE节点到集群

alter system add backend "127.0.0.1:9050";

在项目中找到 ConnectProcessor 代码

handleQuery 处打上断点,此时去执行query语句,会自动跳转到断点处,接下来就可以开始愉快的 Debug之旅了,比如在上上期讲的Doris 语法迁移任务,就可以用Debug来不断调试自己的代码啦!

FAQ

Q1 编译过程中可能会遇到锁冲突的报错:Could not acquire lock(s)

A1 解决方法:检查本地仓库中的 .lock 文件并删除
find ~/.m2/repository -name "*.lock" -delete

Q2 编译过程中可能会遇到高版本的 Node.js 导致的错误
opensslErrorStack: [‘error:03000086:digital envelope routines::initialization error’] library: ‘digital envelope routines’ reason: ‘unsupported’ code: ‘ERR_OSSL_EVP_UNSUPPORTED’

A2 以下命令解决问题。参考https://stackoverflow.com/questions/74726224/opensslerrorstack-error03000086digital-envelope-routinesinitialization-e

#指示Node.js使用旧版的OpenSSL提供程序
export NODE_OPTIONS=--openssl-legacy-provider

Q3 IDEA启动FE报错:java: OutOfMemoryError: insufficient memory

A3 Maven的编译器内存不够,添加内存即可,如图

Q4 IDEA启动FE报错:java: 找不到符号
符号: 类 GeneratedMemoPatterns
位置: 程序包 org.apache.doris.nereids.pattern

A4 在doris根目录执行以下命令即可解决:

mv fe/fe-core/target/generated-sources/annotations/org/apache/doris/nereids/pattern/ fe/fe-core/target/generated-sources/org/apache/doris/ 
mv fe/fe-core/target/generated-sources/cup/org/apache/doris/analysis/ fe/fe-core/target/generated-sources/org/apache/doris/

FAQ持续更新中,有需要可通过下图联系我
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数据微光a

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值