From 65adcb37529aca05a3898e5261cb18ac471b8fe1 Mon Sep 17 00:00:00 2001 From: Anton Avramov Date: Thu, 15 Feb 2024 11:58:56 -0500 Subject: [PATCH 1/3] Add support for MariaDbGTIDList event --- src/MySQLReplication/Definitions/ConstEventsNames.php | 1 + src/MySQLReplication/Event/Event.php | 2 ++ src/MySQLReplication/Event/EventSubscribers.php | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/src/MySQLReplication/Definitions/ConstEventsNames.php b/src/MySQLReplication/Definitions/ConstEventsNames.php index 1f83bc9..482595e 100644 --- a/src/MySQLReplication/Definitions/ConstEventsNames.php +++ b/src/MySQLReplication/Definitions/ConstEventsNames.php @@ -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'; } diff --git a/src/MySQLReplication/Event/Event.php b/src/MySQLReplication/Event/Event.php index 94f36c7..04c2bb4 100644 --- a/src/MySQLReplication/Event/Event.php +++ b/src/MySQLReplication/Event/Event.php @@ -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 diff --git a/src/MySQLReplication/Event/EventSubscribers.php b/src/MySQLReplication/Event/EventSubscribers.php index f2b39c9..8f2803b 100644 --- a/src/MySQLReplication/Event/EventSubscribers.php +++ b/src/MySQLReplication/Event/EventSubscribers.php @@ -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; @@ -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', ]; @@ -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); From cc326437651726c561fd7e0c832ea569b62ec00b Mon Sep 17 00:00:00 2001 From: Anton Avramov Date: Thu, 15 Feb 2024 12:08:10 -0500 Subject: [PATCH 2/3] Fix missing files --- .../Event/DTO/MariaDbGtidListDTO.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/MySQLReplication/Event/DTO/MariaDbGtidListDTO.php diff --git a/src/MySQLReplication/Event/DTO/MariaDbGtidListDTO.php b/src/MySQLReplication/Event/DTO/MariaDbGtidListDTO.php new file mode 100644 index 0000000..136f5df --- /dev/null +++ b/src/MySQLReplication/Event/DTO/MariaDbGtidListDTO.php @@ -0,0 +1,50 @@ +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; + } + +} From 8fce85e174423b8006389b60a525b11adf207c69 Mon Sep 17 00:00:00 2001 From: Anton Avramov Date: Thu, 15 Feb 2024 12:08:42 -0500 Subject: [PATCH 3/3] Fix missing files --- .../Event/MariaDbGtidListEvent.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/MySQLReplication/Event/MariaDbGtidListEvent.php diff --git a/src/MySQLReplication/Event/MariaDbGtidListEvent.php b/src/MySQLReplication/Event/MariaDbGtidListEvent.php new file mode 100644 index 0000000..5b3da20 --- /dev/null +++ b/src/MySQLReplication/Event/MariaDbGtidListEvent.php @@ -0,0 +1,29 @@ +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 + ); + } +}