Replace replication statements with new terminology

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 <mauricio@mfauth.net>
This commit is contained in:
Maurício Meneghini Fauth 2024-10-25 12:24:14 -03:00
parent 070414a6ec
commit 12efd0a0fe
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
8 changed files with 60 additions and 28 deletions

View File

@ -35,10 +35,7 @@ class BinlogController extends AbstractController
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

View File

@ -466,10 +466,7 @@ class Menu
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);
}

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Query;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\DbalInterface;
use PhpMyAdmin\Util;
use function in_array;
@ -254,4 +255,18 @@ class Compatibility
{
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';
}
}

View File

@ -8,6 +8,7 @@ declare(strict_types=1);
namespace PhpMyAdmin;
use PhpMyAdmin\Dbal\ResultInterface;
use PhpMyAdmin\Query\Compatibility;
use function explode;
use function mb_strtoupper;
@ -62,7 +63,7 @@ class Replication
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 @@ class Replication
$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 @@ class Replication
{
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 = [];

View File

@ -76,8 +76,10 @@ class ReplicationGui
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 @@ class ReplicationGui
): 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 @@ class ReplicationGui
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;');

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace PhpMyAdmin;
use PhpMyAdmin\Query\Compatibility;
use function count;
use function explode;
use function sprintf;
@ -117,11 +119,7 @@ final class ReplicationInfo
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 @@ final class ReplicationInfo
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 @@ final class ReplicationInfo
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');
}
}

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Query;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\DbalInterface;
use PhpMyAdmin\Query\Compatibility;
use PHPUnit\Framework\TestCase;
@ -63,4 +64,24 @@ class CompatibilityTest extends TestCase
'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<int, array{string, int, string}> */
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'];
}
}

View File

@ -603,7 +603,7 @@ class DbiDummy implements DbiExtension
'result' => [['1']],
],
[
'query' => 'SHOW MASTER LOGS',
'query' => 'SHOW BINARY LOGS',
'result' => [
[
'Log_name' => 'index1',