From 6487daa4a9c4ce6700e9fcaa2e1fc5031910923b Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 29 Apr 2020 06:28:06 +0000 Subject: [PATCH 1/3] Issue 8550: Check for a good table_definition cache value --- src/Database/DBA.php | 11 +++++++++++ src/Database/Database.php | 15 +++++++++++++++ src/Module/Admin/Summary.php | 10 ++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/Database/DBA.php b/src/Database/DBA.php index 9c3c3a52e..9825d06c6 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -741,6 +741,17 @@ class DBA return DI::dba()->processlist(); } + /** + * Fetch a database variable + * + * @param string $name + * @return string content + */ + public static function getVariable(string $name) + { + return DI::dba()->getVariable($name); + } + /** * Checks if $array is a filled array with at least one entry. * diff --git a/src/Database/Database.php b/src/Database/Database.php index db906bd01..9892fc19a 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -1645,6 +1645,21 @@ class Database return (["list" => $statelist, "amount" => $processes]); } + /** + * Fetch a database variable + * + * @param string $name + * @return string content + */ + public function getVariable(string $name) + { + $result = $this->fetchFirst("SHOW GLOBAL VARIABLES WHERE `Variable_name` = ?", $name); + if (!isset($result['Value'])) { + return null; + } + return $result['Value']; + } + /** * Checks if $array is a filled array with at least one entry. * diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index f676792d8..7bd7901f7 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -55,6 +55,16 @@ class Summary extends BaseAdmin $warningtext[] = DI::l10n()->t('Your DB still runs with InnoDB tables in the Antelope file format. You should change the file format to Barracuda. Friendica is using features that are not provided by the Antelope format. See here for a guide that may be helpful converting the table engines. You may also use the command php bin/console.php dbstructure toinnodb of your Friendica installation for an automatic conversion.
', 'https://dev.mysql.com/doc/refman/5.7/en/innodb-file-format.html'); } + // Avoid the database error 1615 "Prepared statement needs to be re-prepared", see https://github.com/friendica/friendica/issues/8550 + $table_definition_cache = DBA::getVariable('table_definition_cache'); + $table_open_cache = DBA::getVariable('table_open_cache'); + if (!empty($table_definition_cache) && !empty($table_open_cache)) { + $suggested_definition_cache = max(400, round($table_open_cache / 2, 1)); + if ($suggested_definition_cache > $table_definition_cache) { + $warningtext[] = DI::l10n()->t('Your table_definition_cache is too low (%d). This can lead to the database error "Prepared statement needs to be re-prepared". Please set it at least to %d (or -1 for autosizing). See here for more information.
', $table_definition_cache, $suggested_definition_cache, 'https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_table_definition_cache'); + } + } + // Check if github.com/friendica/master/VERSION is higher then // the local version of Friendica. Check is opt-in, source may be master or devel branch if (DI::config()->get('system', 'check_new_version_url', 'none') != 'none') { From e1d21e736a08840ce8a96b33fe233aee781e5647 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 29 Apr 2020 19:13:23 +0200 Subject: [PATCH 2/3] Update src/Database/Database.php Co-Authored-By: Hypolite Petovan --- src/Database/Database.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 9892fc19a..ad0c85796 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -1654,10 +1654,7 @@ class Database public function getVariable(string $name) { $result = $this->fetchFirst("SHOW GLOBAL VARIABLES WHERE `Variable_name` = ?", $name); - if (!isset($result['Value'])) { - return null; - } - return $result['Value']; + return $result['Value'] ?? null; } /** From d67b9cb693cbce4df0d1b9b5889a053eb5714bee Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 5 May 2020 16:01:20 +0000 Subject: [PATCH 3/3] Formula according to documentation --- src/Module/Admin/Summary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index 7bd7901f7..4aaeaaec0 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -59,7 +59,7 @@ class Summary extends BaseAdmin $table_definition_cache = DBA::getVariable('table_definition_cache'); $table_open_cache = DBA::getVariable('table_open_cache'); if (!empty($table_definition_cache) && !empty($table_open_cache)) { - $suggested_definition_cache = max(400, round($table_open_cache / 2, 1)); + $suggested_definition_cache = min(400 + round($table_open_cache / 2, 1), 2000); if ($suggested_definition_cache > $table_definition_cache) { $warningtext[] = DI::l10n()->t('Your table_definition_cache is too low (%d). This can lead to the database error "Prepared statement needs to be re-prepared". Please set it at least to %d (or -1 for autosizing). See here for more information.
', $table_definition_cache, $suggested_definition_cache, 'https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_table_definition_cache'); }