From 12efd0a0fef053febfffa5694e05de3067bf6508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 25 Oct 2024 12:24:14 -0300 Subject: [PATCH] Replace replication statements with new terminology MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SHOW MASTER LOGS was removed in MySQL 8.4.0 and SHOW BINARY LOGS is available since MySQL 4.1.1. As of MySQL 8.2.0, SHOW BINARY LOG STATUS is available. As of MariaDB 10.5.2, SHOW BINLOG STATUS is available. Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../Controllers/Server/BinlogController.php | 5 +---- libraries/classes/Menu.php | 5 +---- libraries/classes/Query/Compatibility.php | 15 +++++++++++++ libraries/classes/Replication.php | 11 ++++------ libraries/classes/ReplicationGui.php | 11 ++++++---- libraries/classes/ReplicationInfo.php | 18 +++++++++------- test/classes/Query/CompatibilityTest.php | 21 +++++++++++++++++++ test/classes/Stubs/DbiDummy.php | 2 +- 8 files changed, 60 insertions(+), 28 deletions(-) diff --git a/libraries/classes/Controllers/Server/BinlogController.php b/libraries/classes/Controllers/Server/BinlogController.php index ae29440a3f3d..8b86dafbc137 100644 --- a/libraries/classes/Controllers/Server/BinlogController.php +++ b/libraries/classes/Controllers/Server/BinlogController.php @@ -35,10 +35,7 @@ public function __construct(ResponseRenderer $response, Template $template, Data parent::__construct($response, $template); $this->dbi = $dbi; - $this->binaryLogs = $this->dbi->fetchResult( - 'SHOW MASTER LOGS', - 'Log_name' - ); + $this->binaryLogs = $this->dbi->fetchResult('SHOW BINARY LOGS', 'Log_name'); } public function __invoke(): void diff --git a/libraries/classes/Menu.php b/libraries/classes/Menu.php index 17d89b05ce97..e4b07971fa9d 100644 --- a/libraries/classes/Menu.php +++ b/libraries/classes/Menu.php @@ -466,10 +466,7 @@ private function getServerTabs(): array if (SessionCache::has('binary_logs')) { $binaryLogs = SessionCache::get('binary_logs'); } else { - $binaryLogs = $this->dbi->fetchResult( - 'SHOW MASTER LOGS', - 'Log_name' - ); + $binaryLogs = $this->dbi->fetchResult('SHOW BINARY LOGS', 'Log_name'); SessionCache::set('binary_logs', $binaryLogs); } diff --git a/libraries/classes/Query/Compatibility.php b/libraries/classes/Query/Compatibility.php index d81040f0e88a..82ae1b4088bf 100644 --- a/libraries/classes/Query/Compatibility.php +++ b/libraries/classes/Query/Compatibility.php @@ -5,6 +5,7 @@ namespace PhpMyAdmin\Query; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Dbal\DbalInterface; use PhpMyAdmin\Util; use function in_array; @@ -254,4 +255,18 @@ public static function hasAccountLocking(bool $isMariaDb, int $version): bool { return $isMariaDb && $version >= 100402 || ! $isMariaDb && $version >= 50706; } + + /** @return non-empty-string */ + public static function getShowBinLogStatusStmt(DbalInterface $dbal): string + { + if ($dbal->isMySql() && $dbal->getVersion() >= 80200) { + return 'SHOW BINARY LOG STATUS'; + } + + if ($dbal->isMariaDB() && $dbal->getVersion() >= 100502) { + return 'SHOW BINLOG STATUS'; + } + + return 'SHOW MASTER STATUS'; + } } diff --git a/libraries/classes/Replication.php b/libraries/classes/Replication.php index 4822332fe70f..acd9f3c0b855 100644 --- a/libraries/classes/Replication.php +++ b/libraries/classes/Replication.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\Dbal\ResultInterface; +use PhpMyAdmin\Query\Compatibility; use function explode; use function mb_strtoupper; @@ -62,7 +63,7 @@ public function replicaControl(string $action, ?string $control, int $link) return -1; } - if ($dbi->isMySql() && $dbi->getVersion() >= 80400) { + if ($dbi->isMySql() && $dbi->getVersion() >= 80022 || $dbi->isMariaDB() && $dbi->getVersion() >= 100501) { return $dbi->tryQuery($action . ' REPLICA ' . $control . ';', $link); } @@ -99,7 +100,7 @@ public function replicaChangePrimary( $this->replicaControl('STOP', null, $link); } - if ($dbi->isMySql() && $dbi->getVersion() >= 80400) { + if ($dbi->isMySql() && $dbi->getVersion() >= 80023) { $out = $dbi->tryQuery( 'CHANGE REPLICATION SOURCE TO ' . 'SOURCE_HOST=\'' . $host . '\',' . @@ -175,11 +176,7 @@ public function replicaBinLogPrimary(int $link): array { global $dbi; - if ($dbi->isMySql() && $dbi->getVersion() >= 80400) { - $data = $dbi->fetchResult('SHOW BINARY LOG STATUS', null, null, $link); - } else { - $data = $dbi->fetchResult('SHOW MASTER STATUS', null, null, $link); - } + $data = $dbi->fetchResult(Compatibility::getShowBinLogStatusStmt($dbi), null, null, $link); $output = []; diff --git a/libraries/classes/ReplicationGui.php b/libraries/classes/ReplicationGui.php index 528116dc78f6..a2a68ada7665 100644 --- a/libraries/classes/ReplicationGui.php +++ b/libraries/classes/ReplicationGui.php @@ -76,8 +76,10 @@ public function getHtmlForPrimaryReplication(): string if (! isset($_POST['repl_clear_scr'])) { $primaryStatusTable = $this->getHtmlForReplicationStatusTable('primary', true, false); - if ($dbi->isMySql() && $dbi->getVersion() >= 80400) { + if ($dbi->isMySql() && $dbi->getVersion() >= 80022) { $replicas = $dbi->fetchResult('SHOW REPLICAS', null, null); + } elseif ($dbi->isMariaDB() && $dbi->getVersion() >= 100501) { + $replicas = $dbi->fetchResult('SHOW REPLICA HOSTS', null, null); } else { $replicas = $dbi->fetchResult('SHOW SLAVE HOSTS', null, null); } @@ -130,9 +132,10 @@ public function getHtmlForReplicaConfiguration( ): string { global $dbi; - if ($dbi->isMySql() && $dbi->getVersion() >= 80400) { + $serverReplicaMultiReplication = []; + if ($dbi->isMariaDB() && $dbi->getVersion() >= 100501) { $serverReplicaMultiReplication = $dbi->fetchResult('SHOW ALL REPLICAS STATUS'); - } else { + } elseif ($dbi->isMariaDB()) { $serverReplicaMultiReplication = $dbi->fetchResult('SHOW ALL SLAVES STATUS'); } @@ -590,7 +593,7 @@ public function handleRequestForReplicaServerControl(): bool if ($_POST['sr_replica_action'] === 'reset') { $qStop = $this->replication->replicaControl('STOP', null, DatabaseInterface::CONNECT_USER); - if ($dbi->isMySql() && $dbi->getVersion() >= 80400) { + if ($dbi->isMySql() && $dbi->getVersion() >= 80022 || $dbi->isMariaDB() && $dbi->getVersion() >= 100501) { $qReset = $dbi->tryQuery('RESET REPLICA;'); } else { $qReset = $dbi->tryQuery('RESET SLAVE;'); diff --git a/libraries/classes/ReplicationInfo.php b/libraries/classes/ReplicationInfo.php index 689cf1e188fd..707a8ad1ebd1 100644 --- a/libraries/classes/ReplicationInfo.php +++ b/libraries/classes/ReplicationInfo.php @@ -4,6 +4,8 @@ namespace PhpMyAdmin; +use PhpMyAdmin\Query\Compatibility; + use function count; use function explode; use function sprintf; @@ -117,11 +119,7 @@ public function load(?string $connection = null): void private function setPrimaryStatus(): void { - if ($this->dbi->isMySql() && $this->dbi->getVersion() >= 80400) { - $this->primaryStatus = $this->dbi->fetchResult('SHOW BINARY LOG STATUS'); - } else { - $this->primaryStatus = $this->dbi->fetchResult('SHOW MASTER STATUS'); - } + $this->primaryStatus = $this->dbi->fetchResult(Compatibility::getShowBinLogStatusStmt($this->dbi)); } public function getPrimaryStatus(): array @@ -131,7 +129,10 @@ public function getPrimaryStatus(): array private function setReplicaStatus(): void { - if ($this->dbi->isMySql() && $this->dbi->getVersion() >= 80400) { + if ( + $this->dbi->isMySql() && $this->dbi->getVersion() >= 80022 + || $this->dbi->isMariaDB() && $this->dbi->getVersion() >= 100501 + ) { $this->replicaStatus = $this->dbi->fetchResult('SHOW REPLICA STATUS'); } else { $this->replicaStatus = $this->dbi->fetchResult('SHOW SLAVE STATUS'); @@ -145,9 +146,10 @@ public function getReplicaStatus(): array private function setMultiPrimaryStatus(): void { - if ($this->dbi->isMySql() && $this->dbi->getVersion() >= 80400) { + $this->multiPrimaryStatus = []; + if ($this->dbi->isMariaDB() && $this->dbi->getVersion() >= 100501) { $this->multiPrimaryStatus = $this->dbi->fetchResult('SHOW ALL REPLICAS STATUS'); - } else { + } elseif ($this->dbi->isMariaDB()) { $this->multiPrimaryStatus = $this->dbi->fetchResult('SHOW ALL SLAVES STATUS'); } } diff --git a/test/classes/Query/CompatibilityTest.php b/test/classes/Query/CompatibilityTest.php index d851e6166201..1f056b12c1a7 100644 --- a/test/classes/Query/CompatibilityTest.php +++ b/test/classes/Query/CompatibilityTest.php @@ -5,6 +5,7 @@ namespace PhpMyAdmin\Tests\Query; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Dbal\DbalInterface; use PhpMyAdmin\Query\Compatibility; use PHPUnit\Framework\TestCase; @@ -63,4 +64,24 @@ public static function providerForTestIsUUIDSupported(): array 'MariaDB 10.7.0' => [true, true, 100700], ]; } + + /** @dataProvider showBinLogStatusProvider */ + public function testGetShowBinLogStatusStmt(string $serverName, int $version, string $expected): void + { + $dbal = self::createStub(DbalInterface::class); + $dbal->method('isMySql')->willReturn($serverName === 'MySQL'); + $dbal->method('isMariaDB')->willReturn($serverName === 'MariaDB'); + $dbal->method('getVersion')->willReturn($version); + self::assertSame($expected, Compatibility::getShowBinLogStatusStmt($dbal)); + } + + /** @return iterable */ + public static function showBinLogStatusProvider(): iterable + { + yield ['MySQL', 80200, 'SHOW BINARY LOG STATUS']; + yield ['MariaDB', 100502, 'SHOW BINLOG STATUS']; + yield ['MySQL', 80199, 'SHOW MASTER STATUS']; + yield ['MariaDB', 100501, 'SHOW MASTER STATUS']; + yield ['MySQL', 100502, 'SHOW BINARY LOG STATUS']; + } } diff --git a/test/classes/Stubs/DbiDummy.php b/test/classes/Stubs/DbiDummy.php index b3f397fec5e0..e47b70b04bb7 100644 --- a/test/classes/Stubs/DbiDummy.php +++ b/test/classes/Stubs/DbiDummy.php @@ -603,7 +603,7 @@ private function init(): void 'result' => [['1']], ], [ - 'query' => 'SHOW MASTER LOGS', + 'query' => 'SHOW BINARY LOGS', 'result' => [ [ 'Log_name' => 'index1',