Skip to content

Commit

Permalink
fix krowinski#115 for mysql 8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao29 committed May 5, 2024
1 parent 6150f0e commit 1d794b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/MySQLReplication/BinLog/BinLogSocketConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,14 @@ private function getBinlogStream(): void
$this->executeSQL('SET @master_binlog_checksum = @@global.binlog_checksum');
}


if ($this->config->heartbeatPeriod > 0.00) {
// master_heartbeat_period is in nanoseconds
$this->executeSQL('SET @master_heartbeat_period = ' . $this->config->heartbeatPeriod * 1000000000);
if(version_compare($this->repository->getVersion(),"8.4.0")>=0){
$this->executeSQL('SET @source_heartbeat_period = ' . $this->config->heartbeatPeriod * 1000000000);
}else{
$this->executeSQL('SET @master_heartbeat_period = ' . $this->config->heartbeatPeriod * 1000000000);
}

$this->logger->info('Heartbeat period set to ' . $this->config->heartbeatPeriod . ' seconds');
}
Expand Down
21 changes: 11 additions & 10 deletions src/MySQLReplication/Repository/MySQLRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,22 @@ public function isCheckSum(): bool

public function getVersion(): string
{
$r = '';
$versions = $this->getConnection()
->fetchAllAssociative('SHOW VARIABLES LIKE "version%"');

foreach ($versions as $version) {
$r .= $version['Value'];
}
$res = $this->getConnection()
->fetchAssociative('SHOW VARIABLES LIKE "version"');

return $r;
return $res['Value']??"";
}

public function getMasterStatus(): MasterStatusDTO
{
$data = $this->getConnection()
->fetchAssociative('SHOW MASTER STATUS');
var_dump($this->getVersion());
if(version_compare($this->getVersion(),"8.4.0")>=0){
$data = $this->getConnection()
->fetchAssociative('SHOW BINARY LOG STATUS');
}else{
$data = $this->getConnection()
->fetchAssociative('SHOW MASTER STATUS');
}
if (empty($data)) {
throw new BinLogException(
MySQLReplicationException::BINLOG_NOT_ENABLED,
Expand Down

0 comments on commit 1d794b4

Please sign in to comment.