Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix int2byte() import and performence update. #346

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pymysqlreplication/binlogstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pymysql.constants.COMMAND import COM_BINLOG_DUMP, COM_REGISTER_SLAVE
from pymysql.cursors import DictCursor
from pymysql.util import int2byte
from six import int2byte

from .packet import BinLogPacketWrapper
from .constants.BINLOG import TABLE_MAP_EVENT, ROTATE_EVENT
Expand All @@ -32,6 +32,9 @@
MYSQL_EXPECTED_ERROR_CODES = [2013, 2006]


loose_version = LooseVersion("0.6")


class ReportSlave(object):

"""Represent the values that you may report when connecting as a slave
Expand Down Expand Up @@ -260,7 +263,7 @@ def _register_slave(self):

packet = self.report_slave.encoded(self.__server_id)

if pymysql.__version__ < LooseVersion("0.6"):
if pymysql.__version__ < loose_version:
self._stream_connection.wfile.write(packet)
self._stream_connection.wfile.flush()
self._stream_connection.read_packet()
Expand Down Expand Up @@ -408,7 +411,7 @@ def __connect_to_stream(self):
# encoded_data
prelude += gtid_set.encoded()

if pymysql.__version__ < LooseVersion("0.6"):
if pymysql.__version__ < loose_version:
self._stream_connection.wfile.write(prelude)
self._stream_connection.wfile.flush()
else:
Expand All @@ -425,7 +428,7 @@ def fetchone(self):
self.__connect_to_ctl()

try:
if pymysql.__version__ < LooseVersion("0.6"):
if pymysql.__version__ < loose_version:
pkt = self._stream_connection.read_packet()
else:
pkt = self._stream_connection._read_packet()
Expand Down
2 changes: 1 addition & 1 deletion pymysqlreplication/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import struct
import datetime

from pymysql.util import byte2int, int2byte
from six import byte2int, int2byte


class BinLogEvent(object):
Expand Down
2 changes: 1 addition & 1 deletion pymysqlreplication/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import struct

from pymysql.util import byte2int
from six import byte2int

from pymysqlreplication import constants, event, row_event

Expand Down
16 changes: 13 additions & 3 deletions pymysqlreplication/row_event.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-

import sys
import struct
import decimal
import datetime
import json
# import json

from pymysql.util import byte2int
from six import byte2int
from pymysql.charset import charset_by_name

from .event import BinLogEvent
Expand Down Expand Up @@ -531,6 +532,12 @@ def _dump(self):
row["after_values"][key]))



_need_byte2int = False
if sys.version.startswith('2') or sys.version.startswith('3.4'):
_need_byte2int = True


class TableMapEvent(BinLogEvent):
"""This event describes the structure of a table.
It's sent before a change happens on a table.
Expand Down Expand Up @@ -594,6 +601,9 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
self.packet.read_length_coded_binary()
for i in range(0, len(column_types)):
column_type = column_types[i]
if _need_byte2int:
column_type = byte2int(column_types[i])

try:
column_schema = self.column_schemas[ordinal_pos_loc]

Expand All @@ -617,7 +627,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
'COLUMN_TYPE': 'BLOB', # we don't know what it is, so let's not do anything with it.
'COLUMN_KEY': '',
}
col = Column(byte2int(column_type), column_schema, from_packet)
col = Column(column_type, column_schema, from_packet)
self.columns.append(col)

self.table_obj = Table(self.column_schemas, self.table_id, self.schema,
Expand Down
2 changes: 1 addition & 1 deletion pymysqlreplication/tests/binlogfilereader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'''Read binlog files'''
import struct

from pymysql.util import byte2int
from six import byte2int
from pymysqlreplication import constants
from pymysqlreplication.event import FormatDescriptionEvent
from pymysqlreplication.event import QueryEvent
Expand Down
1 change: 1 addition & 0 deletions pymysqlreplication/tests/test_data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
else:
import unittest

import json
from decimal import Decimal

from pymysqlreplication.tests import base
Expand Down