File tree Expand file tree Collapse file tree 6 files changed +83
-5
lines changed Expand file tree Collapse file tree 6 files changed +83
-5
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ public function connectToStream()
112112 private function serverInfo ()
113113 {
114114 BinLogServerInfo::parsePackage ($ this ->getPacket (false ));
115+ BinLogServerInfo::parseVersion ($ this ->mySQLRepository ->getVersion ());
115116 }
116117
117118 /**
Original file line number Diff line number Diff line change 33namespace MySQLReplication \BinLog ;
44
55/**
6+ * todo ugly class, for refactoring
67 * Class BinLogServerInfo
78 * @package MySQLReplication\BinLog
89 */
910class BinLogServerInfo
1011{
12+ const MYSQL_VERSION_MARIADB = 'MariaDB ' ;
13+ const MYSQL_VERSION_PERCONA = 'Percona ' ;
14+ const MYSQL_VERSION_GENERIC = 'MySQL ' ;
1115 /**
1216 * @var array
1317 */
@@ -91,6 +95,7 @@ public static function parsePackage($pack)
9195 {
9296 self ::$ serverInfo ['auth_plugin_name ' ] .= $ pack [$ j ];
9397 }
98+ self ::$ serverInfo ['version_name ' ] = self ::MYSQL_VERSION_GENERIC ;
9499 }
95100
96101 /**
@@ -100,4 +105,31 @@ public static function getSalt()
100105 {
101106 return self ::$ serverInfo ['salt ' ];
102107 }
108+
109+ /**
110+ * @see http://stackoverflow.com/questions/37317869/determine-if-mysql-or-percona-or-mariadb
111+ * @param string $version
112+ */
113+ public static function parseVersion ($ version )
114+ {
115+ if ('' !== $ version )
116+ {
117+ if (false !== strpos ($ version , self ::MYSQL_VERSION_MARIADB ))
118+ {
119+ self ::$ serverInfo ['version_name ' ] = self ::MYSQL_VERSION_MARIADB ;
120+ }
121+ else if (false !== strpos ($ version , self ::MYSQL_VERSION_PERCONA ))
122+ {
123+ self ::$ serverInfo ['version_name ' ] = self ::MYSQL_VERSION_PERCONA ;
124+ }
125+ }
126+ }
127+
128+ /**
129+ * @return string
130+ */
131+ public static function getVersion ()
132+ {
133+ return self ::$ serverInfo ['version_name ' ];
134+ }
103135}
Original file line number Diff line number Diff line change 55/**
66 * Class ConstEventType
77 * @package MySQLReplication\Definitions
8+ * @see https://dev.mysql.com/doc/internals/en/binlog-event-type.html
89 */
910class ConstEventType
1011{
Original file line number Diff line number Diff line change 33namespace MySQLReplication \Event ;
44
55use MySQLReplication \BinaryDataReader \Exception \BinaryDataReaderException ;
6+ use MySQLReplication \BinLog \BinLogServerInfo ;
67use MySQLReplication \Event \DTO \QueryDTO ;
78
89/**
910 * Class QueryEvent
1011 * @package MySQLReplication\Event
12+ * @see https://dev.mysql.com/doc/internals/en/query-event.html
1113 */
1214class QueryEvent extends EventCommon
1315{
@@ -26,7 +28,7 @@ public function makeQueryDTO()
2628 $ schema = $ this ->binaryDataReader ->read ($ schemaLength );
2729 $ this ->binaryDataReader ->advance (1 );
2830 $ query = $ this ->binaryDataReader ->read (
29- $ this ->eventInfo ->getSize () - 13 - $ statusVarsLength - $ schemaLength - 1
31+ $ this ->eventInfo ->getSize () - $ this -> getSizeToRemoveByVersion () - $ statusVarsLength - $ schemaLength - 1
3032 );
3133
3234 return new QueryDTO (
@@ -36,4 +38,16 @@ public function makeQueryDTO()
3638 $ query
3739 );
3840 }
41+
42+ /**
43+ * @return int
44+ */
45+ private function getSizeToRemoveByVersion ()
46+ {
47+ if (BinLogServerInfo::MYSQL_VERSION_MARIADB === BinLogServerInfo::getVersion ())
48+ {
49+ return 13 ;
50+ }
51+ return 36 ;
52+ }
3953}
Original file line number Diff line number Diff line change 22
33namespace MySQLReplication \Event ;
44
5+ use MySQLReplication \BinaryDataReader \Exception \BinaryDataReaderException ;
6+ use MySQLReplication \BinLog \BinLogServerInfo ;
57use MySQLReplication \Event \DTO \RotateDTO ;
68
79/**
810 * Class RotateEvent
911 * @package MySQLReplication\Event
12+ * @see https://dev.mysql.com/doc/internals/en/rotate-event.html
1013 */
11- class RotateEvent extends EventCommon
14+ class RotateEvent extends EventCommon
1215{
1316 /**
17+ * @throws BinaryDataReaderException
1418 * @return RotateDTO
1519 */
1620 public function makeRotateEventDTO ()
1721 {
1822 $ pos = $ this ->binaryDataReader ->readUInt64 ();
1923 $ binFileName = $ this ->binaryDataReader ->read (
20- $ this ->eventInfo ->getSizeNoHeader () - 8
24+ $ this ->eventInfo ->getSizeNoHeader () - $ this -> getSizeToRemoveByVersion ()
2125 );
2226
2327 return new RotateDTO (
@@ -26,4 +30,16 @@ public function makeRotateEventDTO()
2630 $ binFileName
2731 );
2832 }
33+
34+ /**
35+ * @return int
36+ */
37+ private function getSizeToRemoveByVersion ()
38+ {
39+ if (BinLogServerInfo::MYSQL_VERSION_MARIADB !== BinLogServerInfo::getVersion ())
40+ {
41+ return 8 ;
42+ }
43+ return 0 ;
44+ }
2945}
Original file line number Diff line number Diff line change @@ -56,7 +56,8 @@ public function getFields($schema, $table)
5656 */
5757 public function getConnection ()
5858 {
59- if (false === $ this ->connection ->ping ()) {
59+ if (false === $ this ->connection ->ping ())
60+ {
6061 $ this ->connection ->close ();
6162 $ this ->connection ->connect ();
6263 }
@@ -74,6 +75,19 @@ public function isCheckSum()
7475 return isset ($ res ['Value ' ]);
7576 }
7677
78+ /**
79+ * @return string
80+ */
81+ public function getVersion ()
82+ {
83+ $ res = $ this ->getConnection ()->fetchAssoc ('SHOW VARIABLES LIKE "version_comment" ' );
84+ if (!empty ($ res ['Value ' ]))
85+ {
86+ return $ res ['Value ' ];
87+ }
88+ return '' ;
89+ }
90+
7791 /**
7892 * File
7993 * Position
@@ -87,4 +101,4 @@ public function getMasterStatus()
87101 {
88102 return $ this ->getConnection ()->fetchAssoc ('SHOW MASTER STATUS ' );
89103 }
90- }
104+ }
You can’t perform that action at this time.
0 commit comments