Building CockroachDB - linux-on-ibm-z/docs GitHub Wiki

Building CockroachDB

The instructions provided below specify the steps to build CockroachDB version 23.1.2 on Linux on IBM Z for the following distributions:

  • RHEL (7.8, 7.9, 8.6, 8.8, 9.0, 9.2)
  • Ubuntu (20.04. 22.04, 23.04, 23.10)

Important Notes:

  • You need to enable the EPEL repositories on RHEL distros. This can be done by installing the epel-release package:

    • RHEL (8.6, 8.8)
    sudo subscription-manager repos --enable codeready-builder-for-rhel-8-$(arch)-rpms
    sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
    
    • RHEL (9.0, 9.2)
    sudo subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms
    sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
    

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

Step 1: Build and Install CockroachDB

1.1) Build using script

If you'd like to build CockroachDB using the manual steps, please go to STEP 1.2.

Use the following commands to build CockroachDB using the build script. Please make sure you have wget installed.

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/CockroachDB/23.1.2/build_crdb.sh

# Build CockroachDB
bash build_crdb.sh   [Provide -t option for executing build with tests]

If the build completes successfully, go to STEP 3. In case of error, check logs for more details or go to STEP 1.2 to follow manual build steps

1.2) Install the Dependencies

export SOURCE_ROOT=/<source_root>/
  • RHEL (7.8, 7.9)

    sudo yum install -y gcc gcc-c++ bzip2 git ncurses-devel make automake bison patch wget tar xz zip unzip java-11-openjdk-devel python3 zlib-devel openssl-devel gettext-devel diffutils keyutils-libs-devel
    
    export LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib/:/usr/lib64:/usr/lib/:$LD_LIBRARY_PATH
    
  • RHEL (8.6, 8.8)

    sudo yum install -y gcc-c++ git ncurses-devel make cmake automake bison patch wget tar xz zip unzip java-11-openjdk-devel python3 zlib-devel diffutils libtool libarchive openssl-devel keyutils-libs-devel
    
  • RHEL (9.0, 9.2)

    sudo yum install -y gcc-c++ git ncurses-devel make cmake automake bison patch wget tar xz zip unzip java-11-openjdk-devel python3 ghc-resolv zlib-devel diffutils libtool libarchive keyutils-libs-devel
    
  • Ubuntu 20.04

    sudo apt-get update && sudo apt-get -y install zip unzip autoconf automake wget make openjdk-11-jdk libssl-dev libncurses5-dev bison xz-utils patch g++ curl git python3 libresolv-wrapper libkeyutils-dev
    
  • Ubuntu (22.04, 23.04)

    sudo apt-get update && sudo apt-get -y install zip unzip autoconf automake wget make openjdk-11-jdk libssl-dev libncurses5-dev bison xz-utils patch g++ curl git python3 cmake netbase libresolv-wrapper libkeyutils-dev
    
  • Ubuntu 23.10

    sudo apt-get update && sudo apt-get -y install zip unzip autoconf automake wget make openjdk-11-jdk libssl-dev libncurses5-dev bison xz-utils patch g++ curl git python3 cmake netbase libresolv-wrapper libkeyutils-dev bzip2
    

1.3) Build and install GCC 10.2.0 (Only for RHEL 7.x and Ubuntu 23.10)

cd $SOURCE_ROOT
ver=10.2.0
wget https://ftp.gnu.org/gnu/gcc/gcc-${ver}/gcc-${ver}.tar.gz
tar xzf gcc-${ver}.tar.gz
cd gcc-${ver}
./contrib/download_prerequisites
mkdir build-gcc
cd build-gcc
../configure --enable-languages=c,c++ --disable-multilib
make -j$(nproc)
sudo make install
Only for RHEL 7.x
sudo ldconfig /usr/local/lib64 /usr/local/lib
sudo mv /usr/bin/gcc /usr/bin/gcc-4.8.5
sudo mv /usr/bin/g++ /usr/bin/g++-4.8.5
sudo mv /usr/bin/c++ /usr/bin/c++-4.8.5
sudo update-alternatives --install /usr/bin/cc cc /usr/local/bin/gcc 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/gcc 40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/local/bin/g++ 40
sudo update-alternatives --install /usr/bin/c++ c++ /usr/local/bin/c++ 40
export CC=/usr/local/bin/gcc
export CXX=/usr/local/bin/g++

1.4) Build and install CMake (For RHEL 7.x, Ubuntu 20.04)

cd $SOURCE_ROOT
wget https://github.com/Kitware/CMake/releases/download/v3.23.3/cmake-3.23.3.tar.gz
tar -xzf cmake-3.23.3.tar.gz
cd cmake-3.23.3
./bootstrap
make
sudo make install
cmake --version

1.5) Build and install Git (Only for RHEL 7.x)

cd $SOURCE_ROOT
wget https://github.com/git/git/archive/refs/tags/v2.27.1.tar.gz
tar -xzf v2.27.1.tar.gz
cd git-2.27.1
make configure
./configure --prefix=/usr
make
sudo make install
git --version

1.6) Build and Install Bazel

cd $SOURCE_ROOT
mkdir bazel && cd bazel
wget https://github.com/bazelbuild/bazel/releases/download/5.1.1/bazel-5.1.1-dist.zip
unzip -q bazel-5.1.1-dist.zip
chmod -R +w .
curl -sSL https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Bazel/5.1.1/patch/bazel.patch | patch -p1
bash ./compile.sh
export PATH=$PATH:$SOURCE_ROOT/bazel/output/
bazel --version

1.7) Build and Install resolv_wrapper (RHEL only)

cd $SOURCE_ROOT
wget https://ftp.samba.org/pub/cwrap/resolv_wrapper-1.1.7.tar.gz
tar zxf resolv_wrapper-1.1.7.tar.gz
cd resolv_wrapper-1.1.7
mkdir obj
cd obj
cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
make
sudo make install

1.8) Build and Install CockroachDB

  • Download source code

    cd $SOURCE_ROOT
    git clone https://github.com/cockroachdb/cockroach
    cd cockroach
    git checkout v23.1.2
    git submodule update --init --recursive    # Fetch the submodules
    
  • Apply patches to code using below commands:

    cd $SOURCE_ROOT/cockroach
    wget -O $SOURCE_ROOT/cockroachdb.patch https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/CockroachDB/23.1.2/patch/crdb.patch
    git apply --reject --whitespace=fix $SOURCE_ROOT/cockroachdb.patch
    
  • Build and install

    cd $SOURCE_ROOT/cockroach
    echo 'build --remote_cache=http://127.0.0.1:9867' > ~/.bazelrc
    echo 'build --config=dev
    build --config nolintonbuild' > .bazelrc.user
    echo "test --test_tmpdir=$SOURCE_ROOT/cockroach/tmp" >> .bazelrc.user
    ./dev doctor
    ./dev build
    bazel build c-deps:libgeos --config force_build_cdeps
    sudo cp cockroach /usr/local/bin
    sudo mkdir -p /usr/local/lib/cockroach
    sudo cp _bazel/bin/c-deps/libgeos_foreign/lib/libgeos.so /usr/local/lib/cockroach/
    sudo cp _bazel/bin/c-deps/libgeos_foreign/lib/libgeos_c.so /usr/local/lib/cockroach/
    export PATH=$SOURCE_ROOT/cockroach:$PATH
    

Step 2: Testing (Optional)

cd $SOURCE_ROOT/cockroach
./dev test -v

There are currently known test failures on s390x.

Many tests check for exact floating point values however due to optimizations on the s390x platform that cause small differences, tests in these packages will fail.

  • pkg/ccl/logictestccl (TestTenantLogic_geospatial)
  • pkg/geo/geomfn
  • pkg/sql/logictest (TestLogic_geospatial)
  • pkg/sql/opt/exec/execbuilder (TestExecBuild_geospatial)
  • pkg/sql/sem/eval
  • pkg/sql/sem/eval_test

Tests in these packages fail because of platform dependent filenames in the stack traces.

  • pkg/util/log/logcrash

Tests in this package fail due to platform dependent hash function values.

  • pkg/sql/colflow

These specific tests in the pkg/sql package fail because the binary encoding of the sql plan is platform dependent but the plan is correct and is decoded correctly.

  • pkg/sql/opt/exec/execbuilder/tests/5node
    • TestExecBuild_dist_vectorize
    • TestExecBuild_explain_analyze_plans
    • TestLogic_distsql_stats
  • pkg/sql/logictest/tests/5node
    • TestLogic_distsql_stats

Test related to upgrade will fail because it downloads CockroachDB binary tar which is not available to s390x.

  • //pkg/sql/logictest/tests/cockroach-go-testserver-upgrade-to-master:cockroach-go-testserver-upgrade-to-master_test

Note: Some test cases might experience time out problem. They should pass after increasing the timeout and run the test again. To run individual test with an increased time out. For example, pkg/bench/rttanalysis could fail due to timeout, we increase timeout in BUILD.bazel as well as provide --test_timeout flag to the command:

diff --git a/pkg/bench/rttanalysis/BUILD.bazel b/pkg/bench/rttanalysis/BUILD.bazel
index b1d724d0c0..c1da50df44 100644
--- a/pkg/bench/rttanalysis/BUILD.bazel
+++ b/pkg/bench/rttanalysis/BUILD.bazel
@@ -52,7 +52,7 @@ go_test(
         "validate_benchmark_data_test.go",
         "virtual_table_bench_test.go",
     ],
-    args = ["-test.timeout=895s"],
+    args = ["-test.timeout=3600s"],
     data = glob(["testdata/**"]),
     embed = [":rttanalysis"],
     shard_count = 16,     
cd $SOURCE_ROOT/cockroach
./dev test pkg/bench/rttanalysis -v -- --test_timeout=3600

Step 3: Verify

cockroach version

Output should look like:

Build Tag:        v23.1.2-dev
Build Time:
Distribution:     CCL
Platform:         linux s390x
Go Version:       go1.19.4
C Compiler:       gcc 11.3.1 20221121 (Red Hat 11.3.1-4)

Please visit this link to start a local cluster and CockroachDB SQL.

References: