@@ -176,7 +176,6 @@ def __init__(
176
176
report_slave = None ,
177
177
slave_uuid = None ,
178
178
pymysql_wrapper = None ,
179
- fail_on_table_metadata_unavailable = False ,
180
179
slave_heartbeat = None ,
181
180
is_mariadb = False ,
182
181
annotate_rows_event = False ,
@@ -210,9 +209,6 @@ def __init__(
210
209
report_slave: Report slave in SHOW SLAVE HOSTS.
211
210
slave_uuid: Report slave_uuid or replica_uuid in SHOW SLAVE HOSTS(MySQL 8.0.21-) or
212
211
SHOW REPLICAS(MySQL 8.0.22+) depends on your MySQL version.
213
- fail_on_table_metadata_unavailable: Should raise exception if we
214
- can't get table information on
215
- row_events
216
212
slave_heartbeat: (seconds) Should master actively send heartbeat on
217
213
connection. This also reduces traffic in GTID
218
214
replication on replication resumption (in case
@@ -249,9 +245,9 @@ def __init__(
249
245
self .__allowed_events = self ._allowed_event_list (
250
246
only_events , ignored_events , filter_non_implemented_events
251
247
)
252
- self .__fail_on_table_metadata_unavailable = fail_on_table_metadata_unavailable
253
248
self .__ignore_decode_errors = ignore_decode_errors
254
249
self .__verify_checksum = verify_checksum
250
+ self .__optional_meta_data = False
255
251
256
252
# We can't filter on packet level TABLE_MAP and rotate event because
257
253
# we need them for handling other operations
@@ -295,7 +291,6 @@ def close(self):
295
291
if self .__connected_ctl :
296
292
# break reference cycle between stream reader and underlying
297
293
# mysql connection object
298
- self ._ctl_connection ._get_table_information = None
299
294
self ._ctl_connection .close ()
300
295
self .__connected_ctl = False
301
296
@@ -306,9 +301,9 @@ def __connect_to_ctl(self):
306
301
self ._ctl_connection_settings ["cursorclass" ] = DictCursor
307
302
self ._ctl_connection_settings ["autocommit" ] = True
308
303
self ._ctl_connection = self .pymysql_wrapper (** self ._ctl_connection_settings )
309
- self ._ctl_connection ._get_table_information = self .__get_table_information
310
304
self ._ctl_connection ._get_dbms = self .__get_dbms
311
305
self .__connected_ctl = True
306
+ self .__check_optional_meta_data ()
312
307
313
308
def __checksum_enabled (self ):
314
309
"""Return True if binlog-checksum = CRC32. Only for MySQL > 5.6"""
@@ -553,6 +548,30 @@ def __set_mariadb_settings(self):
553
548
554
549
return prelude
555
550
551
+ def __check_optional_meta_data (self ):
552
+ cur = self ._ctl_connection .cursor ()
553
+ cur .execute ("SHOW VARIABLES LIKE 'BINLOG_ROW_METADATA';" )
554
+ value = cur .fetchone ()
555
+ if value is None : # BinLog Variable Not exist It means Not Supported Version
556
+ logging .log (
557
+ logging .WARN ,
558
+ """
559
+ Before using MARIADB 10.5.0 and MYSQL 8.0.14 versions,
560
+ use python-mysql-replication version Before 1.0 version """ ,
561
+ )
562
+ else :
563
+ value = value .get ("Value" , "" )
564
+ if value .upper () != "FULL" :
565
+ logging .log (
566
+ logging .WARN ,
567
+ """
568
+ Setting The Variable Value BINLOG_ROW_METADATA = FULL
569
+ By Applying this, provide properly mapped column information on UPDATE,DELETE,INSERT.
570
+ """ ,
571
+ )
572
+ else :
573
+ self .__optional_meta_data = True
574
+
556
575
def fetchone (self ):
557
576
while True :
558
577
if self .end_log_pos and self .is_past_end_log_pos :
@@ -596,9 +615,9 @@ def fetchone(self):
596
615
self .__only_schemas ,
597
616
self .__ignored_schemas ,
598
617
self .__freeze_schema ,
599
- self .__fail_on_table_metadata_unavailable ,
600
618
self .__ignore_decode_errors ,
601
619
self .__verify_checksum ,
620
+ self .__optional_meta_data ,
602
621
)
603
622
604
623
if binlog_event .event_type == ROTATE_EVENT :
@@ -715,44 +734,13 @@ def _allowed_event_list(
715
734
pass
716
735
return frozenset (events )
717
736
718
- def __get_table_information (self , schema , table ):
719
- for i in range (1 , 3 ):
720
- try :
721
- if not self .__connected_ctl :
722
- self .__connect_to_ctl ()
723
-
724
- cur = self ._ctl_connection .cursor ()
725
- cur .execute (
726
- """
727
- SELECT
728
- COLUMN_NAME, COLLATION_NAME, CHARACTER_SET_NAME,
729
- COLUMN_COMMENT, COLUMN_TYPE, COLUMN_KEY, ORDINAL_POSITION,
730
- DATA_TYPE, CHARACTER_OCTET_LENGTH
731
- FROM
732
- information_schema.columns
733
- WHERE
734
- table_schema = %s AND table_name = %s
735
- """ ,
736
- (schema , table ),
737
- )
738
- result = sorted (cur .fetchall (), key = lambda x : x ["ORDINAL_POSITION" ])
739
- cur .close ()
740
-
741
- return result
742
- except pymysql .OperationalError as error :
743
- code , message = error .args
744
- if code in MYSQL_EXPECTED_ERROR_CODES :
745
- self .__connected_ctl = False
746
- continue
747
- else :
748
- raise error
749
-
750
737
def __get_dbms (self ):
751
738
if not self .__connected_ctl :
752
739
self .__connect_to_ctl ()
753
740
754
741
cur = self ._ctl_connection .cursor ()
755
742
cur .execute ("SELECT VERSION();" )
743
+
756
744
version_info = cur .fetchone ().get ("VERSION()" , "" )
757
745
758
746
if "MariaDB" in version_info :
0 commit comments