From 14fb3ef3c9674d1e0887d4931d410690c70303ad Mon Sep 17 00:00:00 2001 From: "taehun.kim" Date: Fri, 1 Dec 2023 17:27:22 +0900 Subject: [PATCH 1/7] Add properties in gtid event Motivation: GtidEvent is aleady implemented but there are missing 6 properties. If we respect these properties, user can use GtidEvent with more convenient. Motivation: - Fix(event.py): Add two properties. - Add(test_basic.py): Add test for GtidEvent. Result: for now on, user can use read_immediate_commit_timestamp and read_original_commit_timestamp properties. --- pymysqlreplication/event.py | 23 +++++++++++++++++++ pymysqlreplication/tests/test_basic.py | 31 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/pymysqlreplication/event.py b/pymysqlreplication/event.py index 82b899745..435dc1fb8 100644 --- a/pymysqlreplication/event.py +++ b/pymysqlreplication/event.py @@ -108,6 +108,29 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs) self.last_committed = struct.unpack(" Date: Fri, 1 Dec 2023 22:51:21 +0900 Subject: [PATCH 2/7] Fix lint --- pymysqlreplication/event.py | 32 ++++++++++++++++++-------- pymysqlreplication/tests/test_basic.py | 3 ++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/pymysqlreplication/event.py b/pymysqlreplication/event.py index 435dc1fb8..020994c95 100644 --- a/pymysqlreplication/event.py +++ b/pymysqlreplication/event.py @@ -108,20 +108,34 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs) self.last_committed = struct.unpack(" Date: Mon, 4 Dec 2023 12:30:02 +0900 Subject: [PATCH 3/7] Resolves in code review --- pymysqlreplication/tests/base.py | 4 ++++ pymysqlreplication/tests/test_basic.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/pymysqlreplication/tests/base.py b/pymysqlreplication/tests/base.py index b8988ce0d..c805b6402 100644 --- a/pymysqlreplication/tests/base.py +++ b/pymysqlreplication/tests/base.py @@ -74,6 +74,10 @@ def isMySQL57(self): version = float(self.getMySQLVersion().rsplit(".", 1)[0]) return version == 5.7 + def isMySQL57AndMore(self): + version = float(self.getMySQLVersion().rsplit(".", 1)[0]) + return version >= 5.7 + def isMySQL80AndMore(self): version = float(self.getMySQLVersion().rsplit(".", 1)[0]) return version >= 8.0 diff --git a/pymysqlreplication/tests/test_basic.py b/pymysqlreplication/tests/test_basic.py index 640906d5f..d978ad80a 100644 --- a/pymysqlreplication/tests/test_basic.py +++ b/pymysqlreplication/tests/test_basic.py @@ -1488,6 +1488,8 @@ def test_gtid_event(self): server_id=1024, only_events=[GtidEvent], ) + if not self.isMySQL57AndMore(): + self.skipTest("Mysql version is under 5.7") self.execute( "CREATE TABLE IF NOT EXISTS test (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255))" ) From e6b2a543ec0b0083e40b0b8eefdb2bca3a0ad579 Mon Sep 17 00:00:00 2001 From: kimtaehun <46879264+Bue-von-hon@users.noreply.github.com> Date: Tue, 5 Dec 2023 16:04:58 +0900 Subject: [PATCH 4/7] Update pymysqlreplication/tests/test_basic.py Co-authored-by: sean.k1 (Umhyunsik) --- pymysqlreplication/tests/test_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymysqlreplication/tests/test_basic.py b/pymysqlreplication/tests/test_basic.py index d978ad80a..289b9984b 100644 --- a/pymysqlreplication/tests/test_basic.py +++ b/pymysqlreplication/tests/test_basic.py @@ -1486,7 +1486,7 @@ def test_gtid_event(self): self.stream = BinLogStreamReader( self.database, server_id=1024, - only_events=[GtidEvent], + only_events=[GtidEvent, FORMAT_DESCRIPTION_EVENT], ) if not self.isMySQL57AndMore(): self.skipTest("Mysql version is under 5.7") From a35b3444b29cc0b30e78e2ad0c9f08dd45f089f7 Mon Sep 17 00:00:00 2001 From: kimtaehun <46879264+Bue-von-hon@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:15:35 +0900 Subject: [PATCH 5/7] Update pymysqlreplication/tests/test_basic.py Co-authored-by: sean.k1 (Umhyunsik) --- pymysqlreplication/tests/test_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymysqlreplication/tests/test_basic.py b/pymysqlreplication/tests/test_basic.py index 289b9984b..e88ba196d 100644 --- a/pymysqlreplication/tests/test_basic.py +++ b/pymysqlreplication/tests/test_basic.py @@ -1486,7 +1486,7 @@ def test_gtid_event(self): self.stream = BinLogStreamReader( self.database, server_id=1024, - only_events=[GtidEvent, FORMAT_DESCRIPTION_EVENT], + only_events=[GtidEvent, FormatDescriptionEvent], ) if not self.isMySQL57AndMore(): self.skipTest("Mysql version is under 5.7") From 76c35d13bd44ed7723d7c4d1f74ea307172b038c Mon Sep 17 00:00:00 2001 From: Bue-von-hon Date: Wed, 6 Dec 2023 17:01:39 +0900 Subject: [PATCH 6/7] Resolves in code review --- pymysqlreplication/tests/test_basic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pymysqlreplication/tests/test_basic.py b/pymysqlreplication/tests/test_basic.py index e88ba196d..558b2e49a 100644 --- a/pymysqlreplication/tests/test_basic.py +++ b/pymysqlreplication/tests/test_basic.py @@ -1493,8 +1493,9 @@ def test_gtid_event(self): self.execute( "CREATE TABLE IF NOT EXISTS test (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255))" ) + format_description_event = self.stream.fetchone() gtid_event = self.stream.fetchone() - + self.assertIsInstance(format_description_event, FormatDescriptionEvent) self.assertIsInstance(gtid_event, GtidEvent) self.assertIsInstance(gtid_event.event_type, int) self.assertIsInstance(gtid_event.sid, bytes) From 3b182d701c03338658ffc9c959024204aa59f30c Mon Sep 17 00:00:00 2001 From: Bue-von-hon Date: Mon, 11 Dec 2023 13:11:25 +0900 Subject: [PATCH 7/7] Fix mysql versionfor test --- pymysqlreplication/tests/base.py | 7 +++++-- pymysqlreplication/tests/test_basic.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pymysqlreplication/tests/base.py b/pymysqlreplication/tests/base.py index c805b6402..62972decc 100644 --- a/pymysqlreplication/tests/base.py +++ b/pymysqlreplication/tests/base.py @@ -74,9 +74,12 @@ def isMySQL57(self): version = float(self.getMySQLVersion().rsplit(".", 1)[0]) return version == 5.7 - def isMySQL57AndMore(self): + def isMySQL801AndMore(self): version = float(self.getMySQLVersion().rsplit(".", 1)[0]) - return version >= 5.7 + version_detail = int(self.getMySQLVersion().rsplit(".", 1)[1]) + if version > 8.0: + return True + return version == 8.0 and version_detail >= 10 def isMySQL80AndMore(self): version = float(self.getMySQLVersion().rsplit(".", 1)[0]) diff --git a/pymysqlreplication/tests/test_basic.py b/pymysqlreplication/tests/test_basic.py index 558b2e49a..8c3835c04 100644 --- a/pymysqlreplication/tests/test_basic.py +++ b/pymysqlreplication/tests/test_basic.py @@ -1488,8 +1488,8 @@ def test_gtid_event(self): server_id=1024, only_events=[GtidEvent, FormatDescriptionEvent], ) - if not self.isMySQL57AndMore(): - self.skipTest("Mysql version is under 5.7") + if not self.isMySQL801AndMore(): + self.skipTest("Mysql version is under 8.0.1") self.execute( "CREATE TABLE IF NOT EXISTS test (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255))" )