|
Pinba Engine 2.11.3
MySQL Storage Engine for PHP Performance Statistics
|
This project builds a storage engine plugin with CMake and C++23. It targets both MySQL and MariaDB from a single source tree, selected at configure time with PINBA_DB_FLAVOR (mysql — the default — or mariadb). Supported target series:
A plugin is ABI-bound to the server it is built against: a .so built for MySQL will not load into MariaDB and vice versa, and the source-header version must match the runtime server's minor version. See Building for MariaDB below for the MariaDB-specific steps; the rest of this guide covers the default MySQL flavor.
Required tools and libraries:
protoc, headers, and library).mysql.h, libmysqlclient).sql/handler.h.Ubuntu 24.04 example:
The engine decodes the Pinba UDP wire format with the C++ Protocol Buffers runtime (libprotobuf, 3.x). CMake locates it via find_package(Protobuf) and generates pinba.pb.{h,cc} from pinba.proto with protobuf_generate_cpp.
C++ protobuf is used on purpose: the engine is a MySQL 8 plugin built with CMake/C++23, and MySQL itself ships and links the C++ protobuf runtime, so reusing it keeps the toolchain and ABI aligned with the host server.
The legacy data path (data.cc, ha_pinba.cc, pool.cc, ...) works on plain C-style structs (Pinba__Request and friends) declared in the hand-written src/pinba.pb-c.h. src/pinba.pb-c.cc is a thin shim that converts a decoded C++ Pinba::Request into that flat C struct, so the data path did not have to be rewritten during the MySQL 8 migration. This is not the protobuf-c (C) runtime — only the struct shape resembles it.
Relationship with the PHP extension: the pinba_extension client genuinely uses the protobuf-c (C) runtime, which is the right fit for a lean PHP C extension. The two projects intentionally use different protobuf runtimes; the only shared, stable contract is pinba.proto. Keep both copies of pinba.proto field-compatible — only append fields, never renumber or retype.
A plugin build requires MySQL server headers, not only the client development package. Use one of these sources:
mysql-source-8.0 or mysql-source-8.4;-DPINBA_DOWNLOAD_MYSQL_SOURCE=ON.Explicit source tree:
Opt-in source download:
The MySQL source archive is large, so downloading it is intentionally opt-in. Pinned version, URL, and hash are defined in CMakeLists.txt per target series.
Default target series is 8.0. Set PINBA_MYSQL_SERIES for LTS 8.4 builds:
MariaDB is a separate server with its own internal C++ handler API, so the plugin is built from the same sources but against MariaDB's server headers, guarded internally by #ifdef MARIADB_BASE_VERSION. Select it with -DPINBA_DB_FLAVOR=mariadb and pick the series with PINBA_MYSQL_SERIES (10.5, 10.11, or 11.8).
Like MySQL, a plugin build needs the server source headers (sql/handler.h and the generated my_config.h, mysql_version.h, mysqld_error.h, …), not just the client dev package. The MariaDB source tarball ships only *.in templates for the generated ones, so a short run of MariaDB's own CMake is needed to produce them — a full server build is not required. scripts/prepare-mariadb-headers.sh automates this:
Requires curl, tar, cmake, a C/C++ compiler, and OpenSSL headers (libssl-dev / openssl-devel); WITH_SSL=system uses OpenSSL, so GnuTLS is not needed.
Expected output: build-mariadb/ha_pinba.so, exporting _maria_plugin_declarations_ (verify with nm -D build-mariadb/ha_pinba.so | grep _maria_plugin_declarations_).
Install into the server's plugin directory and load it exactly as for MySQL, using the mariadb client:
An end-to-end SQL smoke test (plugin active, all report tables, dynamic tag/percentile reports) is available and is what CI runs:
Preferred command:
Equivalent explicit command:
Expected output: build/ha_pinba.so.
Minimum check after code changes:
Static analysis and repository hooks:
CMake generates build/compile_commands.json by default. The pre-push hooks also use cppcheck and clang-tidy; install the tools locally when working on C/C++ changes.
Use the MySQL-reported plugin directory instead of hard-coding a distro path:
If INSTALL PLUGIN returns ‘ERROR 1125 (HY000): Function 'pinba’ already exists`, the plugin is already registered in MySQL. For a rebuild/reinstall, unload it first, replace the shared object, and install it again:
If MySQL refuses to unload the plugin because it is in use, stop active sessions using Pinba tables and retry. If needed during local development, restart MySQL after UNINSTALL PLUGIN and before replacing ha_pinba.so.
To check whether Pinba is already installed: