Bug #114286 Using Clone Recovery for addInstance on MySQL Innodb Cluster uses 100% Memory
| Submitted: | 8 Mar 2024 18:15 | Modified: | 9 Apr 2024 18:49 |
|---|---|---|---|
| Reporter: | Marvin Warble | Email Updates: | |
| Status: | Can't repeat | Impact on me: | |
| Category: | MySQL Server | Severity: | S1 (Critical) |
| Version: | 8.0.36 | OS: | Debian (12) |
| Assigned to: | MySQL Verification Team | CPU Architecture: | x86 |
| Tags: | InnoDB Cluster | ||
[8 Mar 2024 18:15]
Marvin Warble
[11 Mar 2024 11:26]
MySQL Verification Team
Hi Mr. Warble, This is a forum for the reports with a fully repeatable test cases. Until we get a fully repeatable test case from you, we can not start to process your report. Thanks in advance ......
[12 Mar 2024 3:38]
MySQL Verification Team
Are all MySQL Servers in question 8.0.36? I just recently tested something else and I cloned a 300G database no problem. I do not recommend myself cloning but it did work for me with a 300G database and some 5000 databases. It was a "test setup" so not a real data but nothing much better than that I could recreate for this test. Can you share a full configuration?
[12 Mar 2024 11:58]
Marvin Warble
Thanks. Due to some serious time constraints at the moment, unable to setup a full test setup myself. Yes, all servers are 8.0.36 If you don't mind, could you test one other thing? I believe I noticed the problem when I switched innodb_files_per_table = OFF.
[12 Mar 2024 13:52]
MySQL Verification Team
I'll test, but with that many databases I would not recommend that. Since this is not a 10min test, can you share a full config so we have higher chance of reproduction?
[12 Mar 2024 17:17]
Marvin Warble
All servers configured the same, except server ID. [mysql] default-character-set = utf8mb4 [mysqld] server-id=1 datadir=/data/mysql socket=/var/run/mysqld/mysqld.sock log-error=/var/log/mysql/error.log pid-file=/var/run/mysqld/mysqld.pid early-plugin-load=keyring_file.so keyring_file_data=/var/lib/mysql/keyring-data/keyring log-bin skip-name-resolve character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci federated wait_timeout = 120 lock_wait_timeout = 60 ssl-ca=/data/mysql/ca.pem ssl-cert=/data/mysql/server-cert.pem ssl-key=/data/mysql/server-key.pem log-error-verbosity=1 # Changed for Innodb Cluster binlog_transaction_dependency_tracking = WRITESET enforce_gtid_consistency = ON gtid_mode = ON #group_replication_single_primary_mode = OFF # # * Fine Tuning # key_buffer_size = 500M max_allowed_packet = 500M # CACHES AND LIMITS # tmp_table_size = 1G max_heap_table_size = 1G max_connections = 20000 thread_cache_size = 2500 open_files_limit = 1024000 table_definition_cache = 1024 table_open_cache = 50000 table_open_cache_instances = 16 # INNODB # default_storage_engine=InnoDB innodb_flush_method = O_DIRECT innodb_redo_log_capacity = 10737418240 innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 10G innodb_log_file_size = 1G innodb_file_per_table = OFF innodb_buffer_pool_size = 16G innodb_buffer_pool_instances = 15 innodb_read_io_threads = 12 innodb_write_io_threads = 12 innodb_commit_concurrency = 0 innodb_thread_concurrency = 0 innodb_doublewrite = ON innodb_lru_scan_depth = 256 innodb_autoinc_lock_mode = 2
[12 Mar 2024 17:19]
Marvin Warble
The reason I have files per table turned off is that server initialization was taking an extremely long time with it turned on; 1 to 2 hours. With it turned off it takes less than 5 minutes.
[9 Apr 2024 18:49]
MySQL Verification Team
I did not manage to reproduce this. Might be more combination of filesystem and huge numbers of files than a bug in MySQL. Testing with filesystems that can handle more files like reiserfs/xfs/zfs might solve the problem. I cannot reproduce the issue myself.
[26 Nov 13:22]
Daniel Wilhelm
We ran into what looks like the same problem, and the memory growth of the donor can be reproduced in a small setup: it depends on the number of tables on the donor, not on the amount of data.
Observed on a real data set (8.4.11, about 23,000 schemas with roughly 1 million tables in total, 640 GB, innodb_buffer_pool_size = 1G on a test host with 24 GB RAM): the donor mysqld is at 1.3 GB resident memory before the clone. As soon as another instance clones from it, it grows by several GB per minute; in one run the kernel OOM killer terminated it at 21.4 GB, 6.5 minutes after the clone had started.
How to repeat:
The script at the end of this comment starts two instances on one host (--no-defaults, 256M buffer pool), creates SCHEMAS x TABLES empty tables on the donor (CREATE TABLE t (id INT PRIMARY KEY, v VARCHAR(50))), runs CLONE INSTANCE on the recipient and prints the resident memory of the donor before and after.
BASEDIR=/path/to/mysql SCHEMAS=1000 TABLES=18 EXTRA="--innodb-file-per-table=OFF" ./clone-mem-repro.sh
Results with a Percona build of 8.4.11 (see the note below), innodb_file_per_table=OFF as in the original report, Linux aarch64:
tables data directory donor RSS before -> after clone growth
0 203 MB 712 -> 722 MiB +10 MiB
1 1035 MB 727 -> 733 MiB +6 MiB (control: SCHEMAS=1 TABLES=1 FILL_MB=700, one table with about 800 MB)
6,000 351 MB 764 -> 826 MiB +62 MiB
18,000 575 MB 870 -> 1012 MiB +142 MiB
36,000 955 MB 1022 -> 1285 MiB +263 MiB
- The growth is linear in the number of tables: about 7 KB per table for these minimal two-column tables. The amount of data does not matter (control run).
- The memory is not released after the clone has finished (checked for 30 seconds).
- It is not accounted for by the performance_schema memory instrumentation: SUM(CURRENT_NUMBER_OF_BYTES_USED) over memory_summary_global_by_event_name changes by 1 MiB in each run.
- "Dictionary memory allocated" in SHOW ENGINE INNODB STATUS does not change, and Opened_tables / Opened_table_definitions hardly move, so the tables are not opened through the table cache.
- clone_block_ddl = ON makes no difference.
- With general tablespaces the result is the same for 18,000 tables in 1,000 or in 3,000 tablespaces, so it is the number of tables and not the number of tablespaces or files.
Extrapolated to 1 million tables this is at least 7 GB for empty two-column tables, and real tables with more columns and indexes will need more per table - which is consistent with the growth seen on the real data set, and probably with the ~9,000 databases of the original report.
Note on the build: all of this was measured with Percona builds of 8.4.11 (8.4.11-12.1), not with an Oracle binary. The real data set runs Percona XtraDB Cluster, where a joining node starts the same CLONE INSTANCE through its clone state transfer; the last three observations in the list were made in a small test cluster of that kind. The table above was measured with two standalone instances started with --no-defaults (no Galera involved, default allocator). The script only needs mysqld, mysql and mysqladmin from a tarball, so checking it against an Oracle binary should take a couple of minutes.
---------- clone-mem-repro.sh ----------
#!/bin/bash
#
# Donor memory during CLONE INSTANCE grows with the number of tables.
#
# Starts two mysqld instances (donor and recipient) from a MySQL tarball,
# creates SCHEMAS x TABLES empty tables on the donor, clones the donor into
# the recipient and prints the resident memory of the donor mysqld before
# and after the clone.
#
# BASEDIR=/path/to/mysql-8.4.x-linux-glibc2.28-x86_64 SCHEMAS=1000 TABLES=18 ./clone-mem-repro.sh
#
# Control run with the same amount of data in a single table:
# BASEDIR=... SCHEMAS=1 TABLES=1 FILL_MB=700 ./clone-mem-repro.sh
#
# Without BASEDIR the mysqld, mysql and mysqladmin found in PATH are used.
# Linux only (reads /proc). Run as a non-root user. Needs about 1 GB in $WORK
# for 18000 tables.
set -u
BASEDIR="${BASEDIR:-}"
SCHEMAS="${SCHEMAS:-1000}"
TABLES="${TABLES:-18}"
WORK="${WORK:-/tmp/clone-mem-repro}"
EXTRA="${EXTRA:-}" # additional mysqld options for both instances
WAIT="${WAIT:-60}" # seconds to keep watching the donor after the clone
FILL_MB="${FILL_MB:-0}" # control run: additionally one table with about this much data
D="$WORK/donor"; R="$WORK/recipient"
rm -rf "$WORK"; mkdir -p "$WORK"
if [ -n "$BASEDIR" ]; then PATH="$BASEDIR/bin:$PATH"; EXTRA="--basedir=$BASEDIR $EXTRA"; fi
common="--no-defaults --plugin-load-add=mysql_clone.so
--innodb-buffer-pool-size=256M --skip-log-bin --mysqlx=OFF
--performance-schema=ON --log-error-verbosity=2 $EXTRA"
mysqld $common --datadir="$D" --initialize-insecure 2> "$WORK/init-d.err" || { tail "$WORK/init-d.err"; exit 1; }
mysqld $common --datadir="$R" --initialize-insecure 2> "$WORK/init-r.err" || { tail "$WORK/init-r.err"; exit 1; }
mysqld $common --datadir="$D" --port=13001 --socket="$WORK/d.sock" --pid-file="$WORK/d.pid" --log-error="$WORK/d.err" &
mysqld $common --datadir="$R" --port=13002 --socket="$WORK/r.sock" --pid-file="$WORK/r.pid" --log-error="$WORK/r.err" &
donor="mysql --no-defaults -uroot -S $WORK/d.sock"
recipient="mysql --no-defaults -uroot -S $WORK/r.sock"
for i in $(seq 1 120); do
if $donor -e 'SELECT 1' > /dev/null 2>&1 && $recipient -e 'SELECT 1' > /dev/null 2>&1; then break; fi
sleep 1
done
$donor -N -e "SELECT CONCAT('version ', @@version, ' ', @@version_comment, ', innodb_file_per_table ', @@innodb_file_per_table, ', innodb_flush_method ', @@innodb_flush_method)" || { tail "$WORK/d.err"; exit 1; }
# SCHEMAS x TABLES empty tables
t0=$SECONDS
for i in $(seq 1 "$SCHEMAS"); do
printf 'CREATE DATABASE s_%d; ' "$i"
for t in $(seq 1 "$TABLES"); do printf 'CREATE TABLE s_%d.t%d (id INT PRIMARY KEY, v VARCHAR(50)); ' "$i" "$t"; done
echo
done | $donor
if [ "$FILL_MB" -gt 0 ]; then
$donor -e "CREATE DATABASE filler; CREATE TABLE filler.t (id BIGINT AUTO_INCREMENT PRIMARY KEY, v VARCHAR(1000))"
for i in $(seq 1 $((FILL_MB / 100))); do
$donor -e "SET SESSION cte_max_recursion_depth = 1000000; INSERT INTO filler.t (v) WITH RECURSIVE s (n) AS (SELECT 1 UNION ALL SELECT n + 1 FROM s WHERE n < 100000) SELECT REPEAT('x', 1000) FROM s"
done
fi
echo "tables: $($donor -N -e "SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA LIKE 's\_%'") in $SCHEMAS schemas (created in $((SECONDS - t0)) s), data directory $(du -sm "$D" | cut -f1) MB"
$donor -e "CREATE USER clone_user@'127.0.0.1' IDENTIFIED BY 'clone_pw'; GRANT BACKUP_ADMIN ON *.* TO clone_user@'127.0.0.1';"
mem() { # resident / anonymous memory of the donor mysqld, and what performance_schema accounts for
awk '/^VmRSS/ {r = $2} /^RssAnon/ {a = $2} END {printf "RSS %d MiB (anonymous %d MiB)", r / 1024, a / 1024}' "/proc/$(cat "$WORK/d.pid")/status"
printf ', performance_schema total %s MiB\n' "$($donor -N -e 'SELECT ROUND(SUM(CURRENT_NUMBER_OF_BYTES_USED) / 1048576) FROM performance_schema.memory_summary_global_by_event_name')"
}
sleep 10
echo "donor before clone: $(mem)"
t0=$SECONDS
$recipient -e "SET GLOBAL clone_valid_donor_list = '127.0.0.1:13001'; CLONE INSTANCE FROM clone_user@'127.0.0.1':13001 IDENTIFIED BY 'clone_pw';" 2>&1 \
| grep -v 'ERROR 3707' # (the recipient is not started by a supervisor, so it shuts down instead of restarting)
echo "clone finished after $((SECONDS - t0)) s: $(grep -c 'Clone' "$WORK/r.err") clone lines in the recipient log, last: $(grep 'Clone' "$WORK/r.err" | tail -n 1 | cut -c1-160)"
echo "donor after clone: $(mem)"
sleep "$WAIT"
echo "donor $WAIT s after the clone: $(mem)"
mysqladmin --no-defaults -uroot -S "$WORK/d.sock" shutdown
mysqladmin --no-defaults -uroot -S "$WORK/r.sock" shutdown 2> /dev/null
wait
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.045 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.