From 18301f15553c2242a0f5eb961dd36c7bf303b5fb Mon Sep 17 00:00:00 2001
From: Christian Heusel <christian@heusel.eu>
Date: Mon, 16 Dec 2024 01:36:33 +0100
Subject: [PATCH] mariadb: Add switch for innodb_snapshot_isolation

With the 11.6.2 release mariadb has made snapshot isolation a default
setting which recently caused issues on the AUR and the Forums, where
the respective database engines would fail due to the table changing
since the last time they read it:

    PHP Fatal error:  Uncaught mysqli_sql_exception: Record has changed since last read in table 'fluxbb_online' in /srv/http/fluxbb/include/dblayer/mysqli_innodb.php:79
    Stack trace:
    #0 /srv/http/fluxbb/include/dblayer/mysqli_innodb.php(79): mysqli_query()
    #1 /srv/http/fluxbb/include/functions.php(485): DBLayer->query()
    #2 /srv/http/fluxbb/include/common.php(162): update_users_online()
    #3 /srv/http/fluxbb/viewtopic.php(10): require('...')
    #4 {main}

We therefore introduce a config switch to restore the old behavior and
apply the changed setting on the two services.

Link: https://mariadb.com/kb/en/mariadb-11-6-2-release-notes/#innodb
Link: https://bbs.archlinux.org/viewtopic.php?id=301802
Signed-off-by: Christian Heusel <christian@heusel.eu>
---
 playbooks/aur.archlinux.org.yml       | 2 +-
 playbooks/bbs.archlinux.org.yml       | 2 +-
 roles/mariadb/templates/server.cnf.j2 | 5 +++++
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/playbooks/aur.archlinux.org.yml b/playbooks/aur.archlinux.org.yml
index a44f93e54..866c3ecbe 100644
--- a/playbooks/aur.archlinux.org.yml
+++ b/playbooks/aur.archlinux.org.yml
@@ -9,7 +9,7 @@
     - { role: promtail }
     - { role: certbot }
     - { role: nginx }
-    - { role: mariadb, mariadb_innodb_buffer_pool_size: '1G' }
+    - { role: mariadb, mariadb_innodb_buffer_pool_size: '1G', mariadb_innodb_disable_snapshot_isolation: true }
     - { role: sudo }
     - { role: valkey }
     - { role: uwsgi }
diff --git a/playbooks/bbs.archlinux.org.yml b/playbooks/bbs.archlinux.org.yml
index 300b685d5..4de3c3cfb 100644
--- a/playbooks/bbs.archlinux.org.yml
+++ b/playbooks/bbs.archlinux.org.yml
@@ -7,7 +7,7 @@
     - { role: root_ssh }
     - { role: certbot }
     - { role: nginx }
-    - { role: mariadb, mariadb_query_cache_type: '0', mariadb_innodb_buffer_pool_size: '512M' }
+    - { role: mariadb, mariadb_query_cache_type: '0', mariadb_innodb_buffer_pool_size: '512M', mariadb_innodb_disable_snapshot_isolation: true }
     - { role: sudo }
     - { role: php_fpm, php_extensions: ['apcu', 'iconv', 'intl', 'mysqli'], zend_extensions: ['opcache'] }
     - { role: fluxbb }
diff --git a/roles/mariadb/templates/server.cnf.j2 b/roles/mariadb/templates/server.cnf.j2
index 1d5bf186e..fbe139146 100644
--- a/roles/mariadb/templates/server.cnf.j2
+++ b/roles/mariadb/templates/server.cnf.j2
@@ -51,6 +51,11 @@ innodb_thread_concurrency = {{ mariadb_innodb_thread_concurrency }}
 innodb_file_per_table
 {% endif %}
 
+{% if mariadb_innodb_disable_snapshot_isolation %}
+# changed to default from OFF to ON with 11.6.2 https://mariadb.com/kb/en/mariadb-11-6-2-release-notes/
+innodb_snapshot_isolation = OFF
+{% endif %}
+
 [mysqldump]
 quick
 max_allowed_packet = 16M
-- 
GitLab