From d537d38bd08f285cb785bb5bac2c7b2c0068f86d Mon Sep 17 00:00:00 2001 From: dongwook-chan Date: Wed, 9 Mar 2022 23:13:51 +0900 Subject: [PATCH] Skip db name parsing if mts_accessed_dbs == 254 I interpreted `mts_accessed_dbs` as db count in PR#360 (released in 0.27). However after reproducing kvitek's exception in Issue#278, I did some more research how it is set: https://github.com/mysql/mysql-server/blob/6846e6b2f72931991cc9fd589dc9946ea2ab58c9/sql/log_event.cc#L3598-L3602 (log_event.h /log_event.cc is responsible for writing low-level binlog, according to https://dev.mysql.com/doc/internals/en/source-files-related-to-the-binary-log.html) Turns out that if the value of the variables equals 254, the variable is no longer interpreted as the db count, but represent a following case: 1. db count equals 1 2. The name of the only db is blank. Therefore, I edited event.py so that after the value 254 is encountered, no further parsing is done regarding db names. So far I have reproduced the issue for `BeginEvent`. However, I have not yet figured out to incorporate into unittest. I will add tests ASAP. --- pymysqlreplication/event.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pymysqlreplication/event.py b/pymysqlreplication/event.py index 870204c2..dd04ac0e 100644 --- a/pymysqlreplication/event.py +++ b/pymysqlreplication/event.py @@ -257,6 +257,17 @@ def _read_status_vars_value_for_key(self, key): self.host = self.packet.read(host_len) elif key == Q_UPDATED_DB_NAMES: # 0x0C mts_accessed_dbs = self.packet.read_uint8() + """ + mts_accessed_dbs < 254: + `mts_accessed_dbs` is equal to the number of dbs + acessed by the query event. + mts_accessed_dbs == 254: + This is the case where the number of dbs accessed + is 1 and the name of the only db is "" + Since no further parsing required(empty name), return. + """ + if mts_accessed_dbs == 254: + return dbs = [] for i in range(mts_accessed_dbs): db = self.packet.read_string()