Skip to content

Commit

Permalink
Merge pull request phpmyadmin#19334 from MauricioFauth/replication-te…
Browse files Browse the repository at this point in the history
…rminology

Replace replication statements for new terminology
  • Loading branch information
MauricioFauth authored Oct 31, 2024
2 parents 070414a + 12efd0a commit 90f3c58
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 28 deletions.
5 changes: 1 addition & 4 deletions libraries/classes/Controllers/Server/BinlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions libraries/classes/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
15 changes: 15 additions & 0 deletions libraries/classes/Query/Compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PhpMyAdmin\Query;

use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\DbalInterface;
use PhpMyAdmin\Util;

use function in_array;
Expand Down Expand Up @@ -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';
}
}
11 changes: 4 additions & 7 deletions libraries/classes/Replication.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace PhpMyAdmin;

use PhpMyAdmin\Dbal\ResultInterface;
use PhpMyAdmin\Query\Compatibility;

use function explode;
use function mb_strtoupper;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 . '\',' .
Expand Down Expand Up @@ -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 = [];

Expand Down
11 changes: 7 additions & 4 deletions libraries/classes/ReplicationGui.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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;');
Expand Down
18 changes: 10 additions & 8 deletions libraries/classes/ReplicationInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace PhpMyAdmin;

use PhpMyAdmin\Query\Compatibility;

use function count;
use function explode;
use function sprintf;
Expand Down Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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');
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/classes/Query/CompatibilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PhpMyAdmin\Tests\Query;

use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\DbalInterface;
use PhpMyAdmin\Query\Compatibility;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -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<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'];
}
}
2 changes: 1 addition & 1 deletion test/classes/Stubs/DbiDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ private function init(): void
'result' => [['1']],
],
[
'query' => 'SHOW MASTER LOGS',
'query' => 'SHOW BINARY LOGS',
'result' => [
[
'Log_name' => 'index1',
Expand Down

0 comments on commit 90f3c58

Please sign in to comment.