#!/usr/bin/env bash # Verification for: mysql-scalability-and-performance-tuning-how-to-guide # Self-contained. Boots TWO throwaway mysqld 8.4.10 instances (source + replica) on scratch # datadirs/ports, wires up real GTID-based replication, proves data flows and that a replica # enforces super_read_only, then tears both down. Never touches an already-running server. # Missing mysqld, port conflicts, or no network for the doc-quote check -> SKIP, not FAIL. # # Override with: MYSQLD_BIN=/path/to/mysqld MYSQL_BASEDIR=/path/to/basedir ./verify-...sh set -u PASS=0; FAIL=0; SKIP=0; CONTENT=0 ok() { echo "PASS $*"; PASS=$((PASS+1)); } no() { echo "FAIL $*"; FAIL=$((FAIL+1)); } skip() { echo "SKIP $*"; SKIP=$((SKIP+1)); } content() { echo "CONTENT $*"; CONTENT=$((CONTENT+1)); } echo "=== MySQL replication (scale-out) — claim verification ===" echo "date: $(date -u '+%Y-%m-%dT%H:%M:%SZ') host: $(uname -srm)" echo SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/hw_rw_repl.XXXXXX")" PIDS=() cleanup() { for p in "${PIDS[@]:-}"; do [ -n "$p" ] && kill -0 "$p" 2>/dev/null && kill "$p" 2>/dev/null done sleep 1 for p in "${PIDS[@]:-}"; do [ -n "$p" ] && kill -0 "$p" 2>/dev/null && kill -9 "$p" 2>/dev/null done rm -rf "$SCRATCH" } trap cleanup EXIT MYSQLD_BIN="${MYSQLD_BIN:-$(command -v mysqld 2>/dev/null || echo /opt/homebrew/bin/mysqld)}" MYSQL_BIN="${MYSQL_BIN:-$(command -v mysql 2>/dev/null || echo mysql)}" if [ ! -x "$MYSQLD_BIN" ]; then skip "mysqld binary not found — all scratch-instance replication checks skipped" MYSQLD_OK=0 else MYSQLD_OK=1 fi MYSQL_BASEDIR="${MYSQL_BASEDIR:-$(dirname "$(dirname "$MYSQLD_BIN")")}" PORT_BASE=$(( (($$ % 5000) + 40000) )) SRC_PORT=$PORT_BASE REP_PORT=$((PORT_BASE + 1)) SRC_SOCK="/tmp/hw_rw_repl_src_$$.sock" REP_SOCK="/tmp/hw_rw_repl_rep_$$.sock" SRC="$MYSQL_BIN -u root -h 127.0.0.1 -P $SRC_PORT" REP="$MYSQL_BIN -u root -h 127.0.0.1 -P $REP_PORT" REPL_OK=0 if [ "$MYSQLD_OK" -eq 1 ]; then mkdir -p "$SCRATCH/source" "$SCRATCH/replica" "$MYSQLD_BIN" --no-defaults --initialize-insecure --datadir="$SCRATCH/source" --basedir="$MYSQL_BASEDIR" >"$SCRATCH/src_init.log" 2>&1 "$MYSQLD_BIN" --no-defaults --initialize-insecure --datadir="$SCRATCH/replica" --basedir="$MYSQL_BASEDIR" >"$SCRATCH/rep_init.log" 2>&1 "$MYSQLD_BIN" --no-defaults --datadir="$SCRATCH/source" --basedir="$MYSQL_BASEDIR" \ --socket="$SRC_SOCK" --port=$SRC_PORT --pid-file="$SCRATCH/source.pid" \ --server-id=1 --log-bin=mysql-bin --gtid-mode=ON --enforce-gtid-consistency=ON \ --bind-address=127.0.0.1 --loose-mysqlx=OFF >"$SCRATCH/source.log" 2>&1 & PIDS+=("$!") "$MYSQLD_BIN" --no-defaults --datadir="$SCRATCH/replica" --basedir="$MYSQL_BASEDIR" \ --socket="$REP_SOCK" --port=$REP_PORT --pid-file="$SCRATCH/replica.pid" \ --server-id=2 --log-bin=mysql-bin --gtid-mode=ON --enforce-gtid-consistency=ON \ --bind-address=127.0.0.1 --loose-mysqlx=OFF >"$SCRATCH/replica.log" 2>&1 & PIDS+=("$!") i=0; SRC_UP=0 while [ $i -lt 30 ]; do $SRC -e 'SELECT 1' >/dev/null 2>&1 && { SRC_UP=1; break; }; sleep 1; i=$((i+1)); done i=0; REP_UP=0 while [ $i -lt 30 ]; do $REP -e 'SELECT 1' >/dev/null 2>&1 && { REP_UP=1; break; }; sleep 1; i=$((i+1)); done if [ "$SRC_UP" -eq 1 ] && [ "$REP_UP" -eq 1 ]; then REPL_OK=1 fi fi if [ "$REPL_OK" -eq 1 ]; then $SRC -e "CREATE USER 'repl'@'127.0.0.1' IDENTIFIED BY 'ReplW16pass!';" >/dev/null 2>&1 $SRC -e "GRANT REPLICATION SLAVE ON *.* TO 'repl'@'127.0.0.1';" >/dev/null 2>&1 $REP -e "CHANGE REPLICATION SOURCE TO SOURCE_HOST='127.0.0.1', SOURCE_PORT=$SRC_PORT, SOURCE_USER='repl', SOURCE_PASSWORD='ReplW16pass!', SOURCE_AUTO_POSITION=1, GET_SOURCE_PUBLIC_KEY=1;" >/dev/null 2>&1 $REP -e "START REPLICA;" >/dev/null 2>&1 sleep 3 ST="$($REP --vertical -e "SHOW REPLICA STATUS" 2>/dev/null)" IO_RUN="$(printf '%s' "$ST" | awk -F': ' '/Replica_IO_Running:/{print $2; exit}')" SQL_RUN="$(printf '%s' "$ST" | awk -F': ' '/Replica_SQL_Running:/{print $2; exit}')" echo " Replica_IO_Running=$IO_RUN Replica_SQL_Running=$SQL_RUN" # ------------------------------------------------------------------------- # CLAIM 1: GTID-based replication comes up and both threads run. # ------------------------------------------------------------------------- if [ "$IO_RUN" = "Yes" ] && [ "$SQL_RUN" = "Yes" ]; then ok "C1 GTID-based replication is running (Replica_IO_Running=Yes, Replica_SQL_Running=Yes)" else no "C1 replication did not come up: IO=$IO_RUN SQL=$SQL_RUN" fi # ------------------------------------------------------------------------- # CLAIM 2: a write on the source is visible on the replica. # ------------------------------------------------------------------------- $SRC -e "CREATE DATABASE IF NOT EXISTS hw_verify_repl;" >/dev/null 2>&1 $SRC hw_verify_repl -e "CREATE TABLE IF NOT EXISTS orders (id INT PRIMARY KEY, total DECIMAL(10,2));" >/dev/null 2>&1 $SRC hw_verify_repl -e "DELETE FROM orders WHERE id > 0;" >/dev/null 2>&1 $SRC hw_verify_repl -e "INSERT INTO orders VALUES (1, 99.50), (2, 42.00), (3, 17.25);" >/dev/null 2>&1 sleep 2 REP_ROWS="$($REP hw_verify_repl -N -B -e "SELECT COUNT(*) FROM orders;" 2>/dev/null)" if [ "${REP_ROWS:-0}" = "3" ]; then ok "C2 3 rows inserted on the source appear on the replica (never written to directly)" else no "C2 expected 3 rows on replica, found: ${REP_ROWS:-none}" fi # ------------------------------------------------------------------------- # CLAIM 3: measured replication lag for a 100,000-row batch (informational, # not a specific number to assert — just that it completes and is # bounded). # ------------------------------------------------------------------------- $SRC hw_verify_repl -e "CREATE TABLE IF NOT EXISTS bulk_test (id INT PRIMARY KEY, v INT);" >/dev/null 2>&1 $SRC hw_verify_repl -e "DELETE FROM bulk_test WHERE id > 0;" >/dev/null 2>&1 T0=$(date +%s.%N) $SRC hw_verify_repl -e " SET SESSION cte_max_recursion_depth=200000; INSERT INTO bulk_test (id, v) WITH RECURSIVE n(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM n WHERE x < 100000) SELECT x, x*2 FROM n;" >/dev/null 2>&1 T1=$(date +%s.%N) SRC_CNT="$($SRC hw_verify_repl -N -B -e "SELECT COUNT(*) FROM bulk_test;" 2>/dev/null)" CAUGHT_UP=0 i=0 while [ $i -lt 60 ]; do REP_CNT="$($REP hw_verify_repl -N -B -e "SELECT COUNT(*) FROM bulk_test;" 2>/dev/null)" if [ "$REP_CNT" = "$SRC_CNT" ]; then T2=$(date +%s.%N) LAG="$(awk -v a="$T1" -v b="$T2" 'BEGIN{printf "%.3f", b-a}')" echo " 100,000-row batch: insert=$(awk -v a="$T0" -v b="$T1" 'BEGIN{printf "%.3f", b-a}')s, replica caught up after=${LAG}s" CAUGHT_UP=1 break fi sleep 0.5 i=$((i+1)) done if [ "$CAUGHT_UP" -eq 1 ]; then ok "C3 replica caught up to a 100,000-row batch insert within 30s (measured above; not a number to assert generally)" else no "C3 replica did not catch up to the 100,000-row batch within 30s" fi # ------------------------------------------------------------------------- # CLAIM 4: super_read_only on the replica blocks a direct write. # ------------------------------------------------------------------------- $REP -e "SET GLOBAL super_read_only = ON;" >/dev/null 2>&1 WRITE_OUT="$($REP hw_verify_repl -e "INSERT INTO orders VALUES (4, 5.00);" 2>&1)" if printf '%s' "$WRITE_OUT" | grep -qi 'super-read-only'; then ok "C4 a direct write to the replica is rejected once super_read_only=ON" else no "C4 expected a super-read-only rejection, got: $WRITE_OUT" fi $SRC -e "SHUTDOWN;" >/dev/null 2>&1 $REP -e "SHUTDOWN;" >/dev/null 2>&1 sleep 1 else skip "C1/C2/C3/C4 replication checks (could not boot both scratch mysqld instances)" fi # --------------------------------------------------------------------------- # CLAIM 5: the manual's semisynchronous-replication guarantee, quoted # correctly (needs network). # --------------------------------------------------------------------------- detag() { python3 -c 'import sys,re,html; t=html.unescape(re.sub(r"<[^>]+>"," ",sys.stdin.read())); print(re.sub(r"\s+"," ",t))'; } SEMISYNC_PAGE="$(curl -s --max-time 25 https://dev.mysql.com/doc/refman/8.4/en/replication-semisync.html | detag || true)" if [ -z "$SEMISYNC_PAGE" ]; then skip "C5 semisynchronous replication guarantee wording (needs network)" elif printf '%s' "$SEMISYNC_PAGE" | grep -qi 'all the transactions that it has committed have been transmitted to at least one replica'; then ok "C5 manual: semisync guarantees committed transactions were transmitted to at least one replica before commit returns" else no "C5 could not find the documented semisynchronous-replication guarantee wording" fi # --------------------------------------------------------------------------- # CONTENT regression guards. # --------------------------------------------------------------------------- SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ARTICLE="$SELF_DIR/mysql-scalability-and-performance-tuning-how-to-guide.html" if [ -f "$ARTICLE" ]; then # The article is expected to QUOTE the fabricated case studies while explicitly disowning them # (hard rule 5: own prior errors explicitly) — so check for the disclosure, not the absence of # the quoted phrase. if grep -qi 'financial company' "$ARTICLE" && grep -qi 'invented\|fabricat\|deleted' "$ARTICLE"; then content "article quotes the fabricated case studies while explicitly disowning them" else no "article does not clearly own/disclose the deleted fabricated case studies" fi grep -q 'SOURCE_AUTO_POSITION' "$ARTICLE" && content "article documents GTID auto-position replication setup" || no "article missing GTID setup reference" # Merged 2026-08-12 from the retired how-to-optimize-for-read-heavy-operations page: the # Amazon named-company fabrication must be owned (quoted + explicitly disowned), not silently # dropped or silently repeated as if true. if grep -qi 'Amazon' "$ARTICLE" && grep -qi 'not evidence for what Amazon' "$ARTICLE"; then content "article owns the retired page's Amazon named-company fabrication correction" else no "article does not clearly own the merged-in Amazon named-company fabrication correction" fi else skip "article HTML not found next to this script — content regression checks skipped (expected when downloaded standalone from /verify/)" fi echo echo "=== summary: PASS=$PASS FAIL=$FAIL SKIP=$SKIP CONTENT=$CONTENT ===" [ "$FAIL" -eq 0 ]