A Comprehensive Guide to Building and Debugging Apache Doris

Apache Doris, a high-performance, real-time analytical database, boasts an impressive underlying architecture and code design. For developers, mastering source code compilation and debugging is key to understanding Doris’s core. However, the build process involves multiple toolchains and dependency configurations, and during debugging, you may encounter various complex issues that can leave beginners feeling overwhelmed.

This article walks you through the process from source code to runtime, providing a detailed analysis of Apache Doris’s compilation and debugging procedures. From environment setup and code checkout to troubleshooting common issues, we combine practical examples to help you quickly get started with Doris development and debugging. 

Overview

Have you ever wondered how a SQL query is parsed and executed from start to finish? In Apache Doris, this process involves multiple core components and complex internal mechanisms. This article will guide you through the journey from source code to runtime, offering a comprehensive analysis of Doris’s build and debugging process, and helping you gain a deep understanding of SQL execution principles.

1. Environment

Basic Environment

  1. Computer configuration. MacBook Pro (Chip: Apple M1, macOS: 15.1)
  2. JDK. Version 17
  3. Doris branch. Use the Doris Master branch (specifically, the branch-2.1)

Installing Environment Dependencies

When using Homebrew, the installed JDK version is 17 because on macOS the arm64 version of Homebrew does not include JDK 8 by default. Currently, Doris supports only JDK8 and JDK17.

PowerShell

 

Dependency Explanation

1. Java, Maven, etc. These can be downloaded separately for easier management.

  • On macOS, Zulu JDK17 is recommended.
  • Maven can be downloaded from the official Maven website.
  • Manually downloaded Java and Maven must be configured in your environment variables.

2. Other dependencies’ environment variables (example for Apple Silicon Macs):

PowerShell

 

Add the above configurations to your ~/.bashrc or ~/.zshrc file and run source ~/.bashrc or source ~/.zshrc to apply the changes.

Installing Thrift

Note: Thrift needs to be installed only when you are debugging just the FE (Frontend). When debugging both BE (Backend) and FE, the BE third-party libraries already include Thrift.

Plain Text

 

Fetching Your Code

Clone your code by executing the following commands:

PowerShell

 

Setting Environment Variables

PowerShell

 

Downloading Doris Build Dependencies

1. Visit the Apache Doris Third Party Prebuilt page (link) to find the source code for all third-party libraries. You can directly download doris-thirdparty-source.tgz.

2. Alternatively, you can download the precompiled third-party libraries from the same page, which saves you from compiling these libraries yourself. Refer to the commands below.

Apache Doris Third Party Prebuilt

PowerShell

 

When running protoc and thrift, you might encounter issues opening them due to developer verification problems. In that case, navigate to Security & Privacy and click the Open Anyway button in the General tab to confirm that you want to open the binary. For more details, refer to Apple Support.

Increase the System Maximum File Descriptor Limit

After modifying, run source on the corresponding file to apply the changes.

PowerShell

 

2. Compiling Doris

Navigate to your Doris home directory and run the build script:

PowerShell

 

If you want to speed up the build process and you do not require the FE frontend page, you can comment out the FE UI build section in the build.sh script:

Shell

 

After a successful compilation, you should see output similar to the following:

The output

3. Debugging

Configuring the Debug Environment

This guide covers debugging the Doris FE only.

Plain Text

 

Start debugging using IntelliJ IDEA. 

Important: Do not open the root directory of the Doris project; instead, open the FE directory to avoid conflicts with CLion.

Generating FE Code

Open the IDEA terminal, navigate to the root directory of the code, and execute:

PowerShell

 

Wait until you see the message “Done”.

Configuring Debug for FE

1. Edit configurations.

Edit configurations

2. Add a DorisFE configuration. Click the + icon in the upper left to add an Application configuration. Refer to the image below for the specific settings.

Specific settings

3. Working directory. Set it to the fe directory within the source code.

4. Environment variables. Configure the environment variables similarly to those exported in fe/bin/start_fe.sh in the Doris root directory. The DORIS_HOME variable should point to the directory you copied earlier during setup.

Plain Text

 

Environment variables

Starting FE

Click Run or Debug. This will trigger the build process for FE; once completed, the FE will start. In this guide, we choose Debug.

Choose Debug

Starting BE

Since you have already copied the compiled package to the doris-run directory, start the BE from within that directory:

PowerShell

 

Debugging FE

1. Connect to the FE. Use a MySQL client or DBeaver to connect to the FE launched by IDEA.

MySQL

 

2. Add the BE node to the cluster.

MySQL

 

3. Set breakpoints in code. Locate the ConnectProcessor code in the project:

Locate the ConnectProcessor code

Set a breakpoint at the handleQuery method. When you execute a query, the debugger will hit the breakpoint, and you can start an enjoyable debugging journey. For instance, if you are working on the Doris syntax migration task mentioned in previous sessions, you can use debugging to iteratively refine your code.

mysql> create database demo;Set a breakpoint at the handleQuery method

FAQs

Question 1

During compilation, you might encounter a lock conflict error:

Plain Text

 

Answer

Delete any .lock files in your local Maven repository by running:

Plain Text

 

Question 2

During compilation, an error caused by a newer version of Node.js may occur:

Plain Text

 

Answer

Set Node.js to use the legacy OpenSSL provider by executing:

Plain Text

 

Reference: StackOverflow Discussion

Question 3

IntelliJ IDEA fails to start FE with the error:

Plain Text

 

Answer

Maven’s compiler may not have enough memory. Increase the memory allocation as shown below:

Question 5

IntelliJ IDEA fails to start FE with the error:

Plain Text

 

Answer

Resolve this issue by executing the following commands in the Doris root directory:

Plain Text

 

Question 5

In some versions, compilation may fail with the error:

Plain Text

 

Answer

Modify the code according to this PR or execute the following commands:

Plain Text

 

Question 6

In some versions during debugging, the FE on port 9030 fails to start, and fe.log reports:

Plain Text

 

Answer

Navigate to the doris/docs directory, execute the following commands, and then restart FE:

Plain Text

 

By following this guide, you should be able to set up your environment, compile, and debug Apache Doris with greater ease. Happy debugging!

Source:
https://dzone.com/articles/guide-to-building-and-debugging-apache-doris