Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MariaDbGTIDList event #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/MySQLReplication/Definitions/ConstEventsNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ConstEventsNames
public const UPDATE = 'update';
public const WRITE = 'write';
public const MARIADB_GTID = 'mariadb gtid';
public const MARIADB_GTID_LIST = 'mariadb gtid list';
public const FORMAT_DESCRIPTION = 'format description';
public const HEARTBEAT = 'heartbeat';
}
50 changes: 50 additions & 0 deletions src/MySQLReplication/Event/DTO/MariaDbGtidListDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace MySQLReplication\Event\DTO;

use MySQLReplication\Definitions\ConstEventsNames;
use MySQLReplication\Event\EventInfo;

class MariaDbGtidListDTO extends EventDTO
{
private $type = ConstEventsNames::MARIADB_GTID_LIST;
private $mariaDbGtidList;

public function __construct(
EventInfo $eventInfo,
string $mariaDbGtidList
) {
parent::__construct($eventInfo);

$this->mariaDbGtidList = $mariaDbGtidList;
}

public function __toString(): string
{
return PHP_EOL .
'=== Event ' . $this->getType() . ' === ' . PHP_EOL .
'Date: ' . $this->eventInfo->getDateTime() . PHP_EOL .
'Log position: ' . $this->eventInfo->getPos() . PHP_EOL .
'Event size: ' . $this->eventInfo->getSize() . PHP_EOL .
'Global Transaction ID: ' . $this->mariaDbGtidList . PHP_EOL;
}


public function getType(): string
{
return $this->type;
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return get_object_vars($this);
}

public function getMariaDbGtidList(): string
{
return $this->mariaDbGtidList;
}

}
2 changes: 2 additions & 0 deletions src/MySQLReplication/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public function consume(): void
$eventDTO = new HeartbeatDTO($eventInfo);
} elseif (ConstEventType::MARIA_GTID_EVENT === $eventInfo->getType()) {
$eventDTO = (new MariaDbGtidEvent($eventInfo, $binaryDataReader))->makeMariaDbGTIDLogDTO();
} elseif (ConstEventType::MARIA_GTID_LIST_EVENT === $eventInfo->getType()) {
$eventDTO = (new MariaDbGtidListEvent($eventInfo, $binaryDataReader))->makeMariaDbGTIDListDTO();
}

// check for ignore and permitted events
Expand Down
7 changes: 7 additions & 0 deletions src/MySQLReplication/Event/EventSubscribers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use MySQLReplication\Event\DTO\GTIDLogDTO;
use MySQLReplication\Event\DTO\HeartbeatDTO;
use MySQLReplication\Event\DTO\MariaDbGtidLogDTO;
use MySQLReplication\Event\DTO\MariaDbGtidListDTO;
use MySQLReplication\Event\DTO\QueryDTO;
use MySQLReplication\Event\DTO\RotateDTO;
use MySQLReplication\Event\DTO\TableMapDTO;
Expand All @@ -32,6 +33,7 @@ public static function getSubscribedEvents(): array
ConstEventsNames::XID => 'onXID',
ConstEventsNames::WRITE => 'onWrite',
ConstEventsNames::MARIADB_GTID => 'onMariaDbGtid',
ConstEventsNames::MARIADB_GTID_LIST => 'onMariaDbGtidList',
ConstEventsNames::FORMAT_DESCRIPTION => 'onFormatDescription',
ConstEventsNames::HEARTBEAT => 'onHeartbeat',
];
Expand Down Expand Up @@ -86,6 +88,11 @@ public function onMariaDbGtid(MariaDbGtidLogDTO $event): void
$this->allEvents($event);
}

public function onMariaDbGtidList(MariaDbGtidListDTO $event): void
{
$this->allEvents($event);
}

public function onFormatDescription(FormatDescriptionEventDTO $event): void
{
$this->allEvents($event);
Expand Down
29 changes: 29 additions & 0 deletions src/MySQLReplication/Event/MariaDbGtidListEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

namespace MySQLReplication\Event;

use MySQLReplication\Event\DTO\MariaDbGtidListDTO;

class MariaDbGtidListEvent extends EventCommon
{
public function makeMariaDbGTIDListDTO(): MariaDbGtidListDTO
{
$gtid_count = $this->binaryDataReader->readUInt32();
$gtid_list = [];
for($i=0;$i < $gtid_count;$i++) {
$domainId = $this->binaryDataReader->readUInt32();
$serverId = $this->binaryDataReader->readUInt32();
$seq = $this->binaryDataReader->readUInt64();
array_push($gtid_list,$domainId . '-' . $serverId . '-' . $seq);
}
$mariaDbGtidList = implode(',', $gtid_list);

//$this->eventInfo->getBinLogCurrent()->setMariaDbGtid($mariaDbGtid);

return new MariaDbGtidListDTO(
$this->eventInfo,
$mariaDbGtidList
);
}
}