@@ -176,7 +176,6 @@ def __init__(
176176 report_slave = None ,
177177 slave_uuid = None ,
178178 pymysql_wrapper = None ,
179- fail_on_table_metadata_unavailable = False ,
180179 slave_heartbeat = None ,
181180 is_mariadb = False ,
182181 annotate_rows_event = False ,
@@ -210,9 +209,6 @@ def __init__(
210209 report_slave: Report slave in SHOW SLAVE HOSTS.
211210 slave_uuid: Report slave_uuid or replica_uuid in SHOW SLAVE HOSTS(MySQL 8.0.21-) or
212211 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
216212 slave_heartbeat: (seconds) Should master actively send heartbeat on
217213 connection. This also reduces traffic in GTID
218214 replication on replication resumption (in case
@@ -249,9 +245,9 @@ def __init__(
249245 self .__allowed_events = self ._allowed_event_list (
250246 only_events , ignored_events , filter_non_implemented_events
251247 )
252- self .__fail_on_table_metadata_unavailable = fail_on_table_metadata_unavailable
253248 self .__ignore_decode_errors = ignore_decode_errors
254249 self .__verify_checksum = verify_checksum
250+ self .__optional_meta_data = False
255251
256252 # We can't filter on packet level TABLE_MAP and rotate event because
257253 # we need them for handling other operations
@@ -295,7 +291,6 @@ def close(self):
295291 if self .__connected_ctl :
296292 # break reference cycle between stream reader and underlying
297293 # mysql connection object
298- self ._ctl_connection ._get_table_information = None
299294 self ._ctl_connection .close ()
300295 self .__connected_ctl = False
301296
@@ -306,9 +301,9 @@ def __connect_to_ctl(self):
306301 self ._ctl_connection_settings ["cursorclass" ] = DictCursor
307302 self ._ctl_connection_settings ["autocommit" ] = True
308303 self ._ctl_connection = self .pymysql_wrapper (** self ._ctl_connection_settings )
309- self ._ctl_connection ._get_table_information = self .__get_table_information
310304 self ._ctl_connection ._get_dbms = self .__get_dbms
311305 self .__connected_ctl = True
306+ self .__check_optional_meta_data ()
312307
313308 def __checksum_enabled (self ):
314309 """Return True if binlog-checksum = CRC32. Only for MySQL > 5.6"""
@@ -553,6 +548,30 @@ def __set_mariadb_settings(self):
553548
554549 return prelude
555550
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+
556575 def fetchone (self ):
557576 while True :
558577 if self .end_log_pos and self .is_past_end_log_pos :
@@ -596,9 +615,9 @@ def fetchone(self):
596615 self .__only_schemas ,
597616 self .__ignored_schemas ,
598617 self .__freeze_schema ,
599- self .__fail_on_table_metadata_unavailable ,
600618 self .__ignore_decode_errors ,
601619 self .__verify_checksum ,
620+ self .__optional_meta_data ,
602621 )
603622
604623 if binlog_event .event_type == ROTATE_EVENT :
@@ -715,44 +734,13 @@ def _allowed_event_list(
715734 pass
716735 return frozenset (events )
717736
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-
750737 def __get_dbms (self ):
751738 if not self .__connected_ctl :
752739 self .__connect_to_ctl ()
753740
754741 cur = self ._ctl_connection .cursor ()
755742 cur .execute ("SELECT VERSION();" )
743+
756744 version_info = cur .fetchone ().get ("VERSION()" , "" )
757745
758746 if "MariaDB" in version_info :
0 commit comments