Apache Doris,一個高性能、即時分析的資料庫,擁有令人印象深刻的底層架構和程式碼設計。對於開發者來說,掌握源碼編譯和調試是理解Doris核心的關鍵。然而,構建過程涉及多個工具鏈和依賴配置,在調試過程中,您可能會遇到各種複雜問題,讓初學者感到不知所措。
本文將引導您從源碼到運行時的過程,提供Apache Doris的編譯和調試程序的詳細分析。從環境設置和程式碼檢出到排除常見問題,我們結合實用範例,幫助您快速入門Doris的開發和調試。
概覽
您是否曾經想過SQL查詢是如何從開始到結束被解析和執行的?在Apache Doris中,這個過程涉及多個核心組件和複雜的內部機制。本文將指導您從源碼到運行時的旅程,提供Doris的構建和調試過程的全面分析,幫助您深入理解SQL執行原則。
1. 環境
基本環境
- 計算機配置。MacBook Pro(晶片:Apple M1,macOS:15.1)
- JDK。版本17
- Doris分支。使用Doris Master分支(具體為branch-2.1)
安裝環境依賴
在使用Homebrew時,安裝的JDK版本為17,因為在 macOS 上,arm64 版本的 Homebrew 預設不包含 JDK 8。目前,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 等。這些可分別下載以便更輕鬆管理。
- 在 macOS 上,建議使用Zulu JDK17。
- Maven 可從官方 Maven 網站下載。
- 手動下載的 Java 和 Maven 必須配置在您的環境變數中。
2. 其他依賴的環境變數(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
注意:僅在您僅調試 FE(前端)時需要安裝 Thrift。當調試 BE(後端)和 FE 時,BE 第三方庫已包含 Thrift。
MacOS:
1. Download: `brew install [email protected]`
2. Create a symbolic link:
`mkdir -p ./thirdparty/installed/bin`
# Apple Silicon 芯片 macOS
`ln -s /opt/homebrew/Cellar/[email protected]/0.16.0/bin/thrift ./thirdparty/installed/bin/thrift`
# Intel 芯片 macOS
`ln -s /usr/local/Cellar/[email protected]/0.16.0/bin/thrift ./thirdparty/installed/bin/thrift`
Note: Running `brew install [email protected]` on macOS may report that the version cannot be found. To resolve this, execute the following commands in the terminal:
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 [email protected]`
Reference: `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 第三方預構建 頁面(鏈接)以找到所有第三方庫的源代碼。您可以直接下載 doris-thirdparty-source.tgz
。
2. 或者,您可以從同一頁面下載預編譯的第三方庫,這樣可以避免自行編譯這些庫。參考以下命令。
cd thirdparty
rm -rf installed
# For Intel Macs: curl -L <https://github.com/apache/doris-thirdparty/releases/download/automation/doris-thirdparty-prebuilt-darwin-x86_64.tar.xz> \\
-o - | tar -Jxf -
# For Apple Silicon Macs: curl -L <https://github.com/apache/doris-thirdparty/releases/download/automation/doris-thirdparty-prebuilt-darwin-arm64.tar.xz> \\
-o - | tar -Jxf -
# Verify that protoc and thrift run correctly:
cd installed/bin
./protoc --version
./thrift --versio
運行 protoc
和 thrift
時,您可能會遇到由於開發者驗證問題而無法打開它們的問題。在這種情況下,請前往 安全性與隱私,並在一般選項卡中點擊 仍要打開 按鈕以確認您要打開該二進位文件。有關更多詳情,請參閱 蘋果支持。
增加系統最大文件描述符限制
修改後,運行對應文件上的 source
以應用更改。
# For bash: echo 'ulimit -n 65536' >>~/.bashrc
# For zsh: echo 'ulimit -n 65536' >>~/.zshrc
2. 編譯 Doris
進入您的 Doris 主目錄並運行構建腳本:
cd $DORIS_HOME
# Compile the entire Doris project:
sh build.sh
# Or compile only FE and BE:
sh build.sh --fe --be
如果要加快構建過程並且不需要 FE 前端頁面,可以在 build.sh 腳本中註釋掉 FE UI 構建部分:
# FE UI must be built before building FE
#if [[ "${BUILD_FE}" -eq 1 ]]; then
# if [[ "${BUILD_UI}" -eq 1 ]]; then
# build_ui
# fi
#fi
成功編譯後,您應該看到類似以下的輸出:
3. 调试
配置调试环境
此指南涵盖了调试 Doris 前端的过程。
# Copy the compiled package to a separate directory:
cp -r output/ ../doris-run
# Configure FE/BE settings:
1. Set the IP and directories.
2. For BE, add the extra configuration: min_file_descriptor_number = 10000.
使用 IntelliJ IDEA 开始调试。
重要提示:不要打开 Doris 项目的根目录,而是打开 FE 目录,以避免与 CLion 发生冲突。
生成 FE 代码
打开 IDEA 终端,导航至代码的根目录,并执行:
sh generated-source.sh
等待看到“完成”消息。
配置 FE 的调试
1. 编辑配置。
2. 添加 DorisFE 配置。点击左上角的 + 图标添加一个应用配置。具体设置请参考下方的图像。
3. 工作目录。设置为源代码中的 fe
目录。
4. 环境变量。配置环境变量,类似于在 Doris 根目录中的 fe/bin/start_fe.sh
中导出的那些。DORIS_HOME
变量应指向您在设置过程中先前复制的目录。
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
点击 运行 或 调试。这将触发 FE 的构建过程;完成后,FE 将启动。在本指南中,我们选择了 调试。
启动 BE
由于您已经将编译包复制到 doris-run
目录中,从该目录内启动 BE:
sh bin/start_be.sh --daemon
調試 FE
1. 連接到 FE. 使用 MySQL 客戶端或 DBeaver 連接到由 IDEA 啟動的 FE。
mysql -uroot -h127.0.0.1 -P9030
2. 將 BE 節點添加到集群.
alter system add backend "127.0.0.1:9050";
3. 在代碼中設置斷點。在項目中定位 ConnectProcessor 代碼:
在 handleQuery 方法上設置斷點。當您執行查詢時,調試器將命中斷點,您可以開始愉快的調試之旅。例如,如果您正在進行之前會議中提到的 Doris 語法遷移任務,您可以使用調試來迭代改進您的代碼。
常見問題
問題 1
在編譯過程中,您可能會遇到鎖定衝突錯誤:
Could not acquire lock(s)
答案
通過運行以下命令刪除本地 Maven 倉庫中的任何 .lock
文件:
find ~/.m2/repository -name "*.lock" -delete
問題 2
在編譯過程中,可能會出現由於 Node.js 新版本引起的錯誤:
opensslErrorStack: ['error:03000086:digital envelope routines::initialization error'] library: 'digital envelope routines' reason: 'unsupported' code: 'ERR_OSSL_EVP_UNSUPPORTED'
答案
通過執行以下命令將 Node.js 設置為使用舊版 OpenSSL 提供程序:
# Instruct Node.js to use the legacy OpenSSL provider export NODE_OPTIONS=--openssl-legacy-provider
問題 3
IntelliJ IDEA 啟動 FE 失敗,出現錯誤:
java: OutOfMemoryError: insufficient memory
答案
Maven 的編譯器可能沒有足夠的內存。請按如下所示增加內存分配:
問題5
IntelliJ IDEA無法啟動FE,出現錯誤:
java: cannot find symbol Symbol: class GeneratedMemoPatterns Location: package org.apache.doris.nereids.pattern
答案
通過在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/
問題5
在某些版本中,編譯可能會出現錯誤:
error: reference to ‘detail’ is ambiguous
答案
根據這個PR修改代碼或執行以下命令:
wget https://github.com/apache/doris/pull/43868.patch
git apply 43868.patch
問題6
在某些版本中,進行調試時,端口9030上的FE無法啟動,並且fe.log
報告:
Can not find help zip file: help-resource.zip
答案
進入doris/docs
目錄,執行以下命令,然後重新啟動FE:
cd doris/docs sh build_help_zip.sh
cp -r build/help-resource.zip ../fe/fe-core/target/classes
通過遵循這個指南,您應該能夠更輕鬆地設置環境,編譯和調試Apache Doris。祝您調試愉快!
Source:
https://dzone.com/articles/guide-to-building-and-debugging-apache-doris