Percona XtraDB Cluster (PXC) is a database clustering solution for MySQL. It ensures high availability, prevents downtime and data loss, and provides linear scalability for a growing environment.
Lately, the number of questions about how to build Percona software has increased. More and more people try to add their own patches, add some modifications, and build software by themselves. But this raises the question of how to do this in the same way as Percona does, as sometimes the compiler flag can make a drastic impact on the final binary. This is a really essential question and let’s look at how we build Percona XtraDB Cluster here at Percona.
At the first glance, the building process is not something difficult. Everyone knows that magic make install all
command and suppose that as a result everything will be built and installed on the system. But databases are very essential for applications and it is needed to do everything carefully.
Let’s divide the build process into the stages:
- Prepare build environments
- Prepare source tarballs
- Prepare source package
- Prepare binary packages
We can skip the third stage, but in this case, we wouldn’t be able to make repeatable builds so I would suggest always creating source packages.
So let’s move forward and discuss each step.
One of the key points during a build is that the environment should be clean and it is necessary to install all needed dependencies, and so on. For each version, the dependency list would be different. How do you get the correct dependency list? You can get all build requirements from the spec file (on rpm-based systems) or from the control file( on deb-based systems).
As for source tarball, you can easily do the following:
- Get source tarball from the website
We publish source tarball for each release we issue, and you can easily get it for any released version (this is the link for the 8.0.28 version):
- Download tarball from GitHub
Here is the link:
You can use build instructions from our website and proceed with the compilation process:
https://www.percona.com/doc/percona-xtradb-cluster/LATEST/install/compile.html#compile
So everything looks easy. But what is the way we use, internally, to prepare our release packages? As I mentioned earlier, each compiler option can make a significant effect.
Everyone tries to make life easier and automate all tasks. It is great, as automation is one of the keys to success as you can work on other tasks once the release build is in progress. So we have created a build script that is used for making builds. It can be found in the PXC GitHub repo and can be used by anyone to make his own builds.
This script can install all needed dependencies for the build environment, create binary tarballs, source RPMs and debs, RPMs, debs itself, and the binary tarball. So it covers all build cycles. So how do we use it?
The script has various params:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | --builddir=DIR Absolute path to the dir where all actions will be performed --get_sources Source will be downloaded from github --build_src_rpm If it is 1 src rpm will be built --build_source_deb If it is 1 source deb package will be built --build_rpm If it is 1 rpm will be built --build_deb If it is 1 deb will be built --build_tarball If it is 1 tarball will be built --install_deps Install build dependencies(root privileges are required) --branch Branch for build --repo Repo for build --rpm_release RPM version( default = 1) --deb_release DEB version( default = 1) --debug Build debug tarball |
So let’s see how we can make the build process easier:
1. Download the build script:
1 | wget https://raw.githubusercontent.com/percona/percona-xtradb-cluster/8.0/build-ps/pxc_builder.sh |
2. Create a build directory where you are going to perform all build actions:
1 | mkdir /tmp/BUILD_PXC |
3. Install dependencies(please note root permissions are required):
1 | sudo ./pxc_builder.sh --builddir=/tmp/BUILD_PXC --install_deps=1 |
4. Download source code:
– From Percona repo (it is used by default):
1 | ./pxc_builder.sh --builddir=/tmp/BUILD_PXC --get_sources=1 --branch=Percona-XtraDB-Cluster-8.0.28-19 |
– From your own repo and branch:
1 | ./pxc_builder.sh --builddir=/tmp/BUILD_PXC --get_sources=1 --branch=<your_branch_name> --repo=<link_to_your_repo_on_github> |
5. Prepare src rpm:
1 | ./pxc_builder.sh --builddir=/tmp/BUILD_PXC --build_src_rpm=1 |
Please note if you already have your source tarball, just create a directory named source_tarball in the build directory and put it into it.
6. Prepare source deb:
1 | ./pxc_builder.sh --builddir=/tmp/BUILD_PXC --build_source_deb=1 |
Please note if you already have your source tarball, just create a directory named source_tarball in the build directory and put it into it.
7. Prepare rpm:
1 | ./pxc_builder.sh --builddir=/tmp/BUILD_PXC --build_rpm=1 |
8. Prepare deb:
1 | ./pxc_builder.sh --builddir=/tmp/BUILD_PXC --build_deb=1 |
9. Prepare tarball:
1 | ./pxc_builder.sh --builddir=/tmp/BUILD_PXC –build_tarball=1 |
So as you can see, the build procedure becomes easier and you don’t need to think about what dependencies are needed, what cmake params should be used, etc. This build script will make everything for you and will use all build flags (if you didn’t change them in your sources) that we use for release builds.
What if you cloned the repo, patched a few files and just want to build what you have?
Hi Yves!
Here is the command:
./pxc_builder.sh --builddir=/tmp/BUILD_PXC --get_sources=1 --branch=<your_branch_name> --repo=<link_to_your_repo_on_github>
So in this case you should point script to your repo and your branch
If you have your sources locally – well in this case you should modify the script as such scenario isn’t covered.
I suggest keeping all changes in source control otherwise it would be mess 😉
How to do make install instead of building rpm or deb packages?