Skip to content

Building CockroachDB

aborkar-ibm edited this page Oct 31, 2022 · 39 revisions

Building CockroachDB

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

  • Ubuntu (18.04, 20.04. 22.04)
  • RHEL (7.8, 7.9, 8.4, 8.6, 9.0)

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/22.1.7/build_crdb.sh

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

In case of any errors, check logs for more details or go to STEP 1.2 to follow the manual build steps.

1.2) Install the Dependencies

export SOURCE_ROOT=/<source_root>/
  • Ubuntu (18.04, 20.04)

    sudo apt-get update && sudo apt-get -y install autoconf automake wget make libssl-dev libncurses5-dev bison xz-utils patch g++ curl git python libresolv-wrapper
  • Ubuntu 22.04

    sudo apt-get update && sudo apt-get -y install autoconf automake wget make libssl-dev libncurses5-dev bison xz-utils patch g++ curl git python3 cmake libresolv-wrapper
  • RHEL (7.8, 7.9)

    sudo subscription-manager repos --enable=rhel-7-server-for-system-z-rhscl-rpms
    sudo yum install -y devtoolset-7-gcc-c++ devtoolset-7-gcc git ncurses-devel make cmake automake bison patch wget tar xz zip unzip java-11-openjdk-devel python3 zlib-devel openssl-devel gettext-devel diffutils
    
    source /opt/rh/devtoolset-7/enable
  • RHEL (8.4, 8.6)

    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
  • RHEL 9.0

    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

1.3) Build and install CMake (For Ubuntu 18.04, Ubuntu 20.04, RHEL 7.x, RHEL 8.x)

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.4) 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.5) Build and Install Bazel

  • Ubuntu

    wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Bazel/5.1.1/build_bazel.sh
    bash build_bazel.sh -y
    export PATH=$SOURCE_ROOT/dist/bazel/output/:$PATH
    bazel --version
  • RHEL

    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.6) Build and Install CockroachDB

  • Download source code

    cd $SOURCE_ROOT
    git clone https://github.com/cockroachdb/cockroach
    cd cockroach
    git checkout v22.1.7
    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/22.1.7/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
    ./dev doctor
    ./dev build
    bazel build c-deps:libgeos
    sudo mkdir -p /usr/local/lib/cockroach
    sudo cp _bazel/bin/c-deps/libgeos/lib/libgeos.so /usr/local/lib/cockroach/
    sudo cp _bazel/bin/c-deps/libgeos/lib/libgeos_c.so /usr/local/lib/cockroach/
    export PATH=$SOURCE_ROOT/cockroach:$PATH

Step 2: Testing (Optional)

cd $SOURCE_ROOT/cockroach
for PKG in acceptance base bench blobs cli clusterversion compose config geo gossip jobs keys kv roachpb rpc security server settings spanconfig sql startupmigrations storage testutils ts ui util workload
do
    printf -- "Testing pkg/$PKG ... \n"
    ./dev test pkg/$PKG
done

Note:

  • 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.

    • github.com/cockroachdb/cockroach/pkg/geo
  • The following tests failed the same way on amd64:

    • github.com/cockroachdb/cockroach/pkg/acceptance
    • github.com/cockroachdb/cockroach/pkg/cli
    • github.com/cockroachdb/cockroach/pkg/compose

Step 3: Verify

cockroach version

Output should look like:

Build Tag:        v22.1.7-dirty
Build Time:       2022/10/07 19:49:54
Distribution:     CCL
Platform:         linux s390x (s390x-linux-gnu)
Go Version:       go1.17.10
C Compiler:       gcc 11.2.0
Build Commit ID:  a346e7a64510df370cc945f2c771f0702cf1129d
Build Type:       development

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

References:

Clone this wiki locally