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

Improve MySQLReplication BinaryDataReader #11

Closed
wants to merge 1 commit into from
Closed

Improve MySQLReplication BinaryDataReader #11

wants to merge 1 commit into from

Conversation

huangdijia
Copy link

fix #10

  • Add support for reading 64-bit unsigned integers
  • Change the return type of readUInt56() from string to int

- Add support for reading 64-bit unsigned integers
- Change the return type of `readUInt56()` from `string` to `int`
@huangdijia
Copy link
Author

也不晓得这样处理是否合理

@Moln
Copy link
Owner

Moln commented Mar 21, 2023

@huangdijia 能提供出现问题时的 MySQL 版本和PHP版本吗?
看问题应该是使用set类型时出错,方便提供表结构中该字段的定义吗?

@huangdijia
Copy link
Author

CHARSET=latin1 的字段就会报错

@Moln
Copy link
Owner

Moln commented Apr 12, 2023

CHARSET=latin1 的字段就会报错

需要提供具体, mysql版本, 创建表语句
不然没办法复现问题.

@blueidealirui
Copy link

blueidealirui commented Apr 13, 2023

错误信息:
image
image

Mysql版本:5.7.22

建表语句:

CREATE TABLE `my_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL COMMENT '會員ID',
  `community_id` int(11) NOT NULL DEFAULT '0' COMMENT '社区ID',
  `cases_id` int(11) NOT NULL COMMENT '建案id',
  `status` tinyint(2) NOT NULL COMMENT '狀態: 0 未使用 1 已過期 2 開啟 3 已成交 4 已成交',
  `closed` tinyint(2) NOT NULL COMMENT '是否關閉: 0 未關閉 1 關閉中 2 回收站',
  `living` set('depart','advstore','market','night','park','school','hospital','police') NOT NULL DEFAULT '' COMMENT '生活機能',
  `housetype` tinyint(2) NOT NULL COMMENT '經辦者',
  `isdeleted` tinyint(1) NOT NULL COMMENT '是否删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

@Moln
Copy link
Owner

Moln commented Apr 17, 2023

错误信息: image image

Mysql版本:5.7.22

建表语句:

CREATE TABLE `my_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL COMMENT '會員ID',
  `community_id` int(11) NOT NULL DEFAULT '0' COMMENT '社区ID',
  `cases_id` int(11) NOT NULL COMMENT '建案id',
  `status` tinyint(2) NOT NULL COMMENT '狀態: 0 未使用 1 已過期 2 開啟 3 已成交 4 已成交',
  `closed` tinyint(2) NOT NULL COMMENT '是否關閉: 0 未關閉 1 關閉中 2 回收站',
  `living` set('depart','advstore','market','night','park','school','hospital','police') NOT NULL DEFAULT '' COMMENT '生活機能',
  `housetype` tinyint(2) NOT NULL COMMENT '經辦者',
  `isdeleted` tinyint(1) NOT NULL COMMENT '是否删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

这是我改变 tests/Integration/TypesTest.php 测试代码, 但是结果是通过的.

    /**
     * @test
     */
    public function shouldBeSet(): void
    {
        $createQuery = <<<EOT
CREATE TABLE `my_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL COMMENT '會員ID',
  `community_id` int(11) NOT NULL DEFAULT '0' COMMENT '社区ID',
  `cases_id` int(11) NOT NULL COMMENT '建案id',
  `status` tinyint(2) NOT NULL COMMENT '狀態: 0 未使用 1 已過期 2 開啟 3 已成交 4 已成交',
  `closed` tinyint(2) NOT NULL COMMENT '是否關閉: 0 未關閉 1 關閉中 2 回收站',
  `living` set('depart','advstore','market','night','park','school','hospital','police') NOT NULL DEFAULT '' COMMENT '生活機能',
  `housetype` tinyint(2) NOT NULL COMMENT '經辦者',
  `isdeleted` tinyint(1) NOT NULL COMMENT '是否删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
EOT;
        ;
        $insertQuery = 'INSERT INTO my_table VALUES(null, 1, 1, 1, 1, 1, "park,school", 1, 0)';

        $event = $this->createAndInsertValue($createQuery, $insertQuery);

        self::assertEquals(['park', 'school'], $event->getValues()[0]['living']);
    }

根据#10 的堆栈分析: 得到的 living set 类型, 种类长度是64位. 但现实是不可能的.
我这想到的原因: 大概率是使用了 swoole 协程, 多个协程共同读取 socket数据导致 数据读取长度错位.
建议保证一个协程, 使用一个 socket , 也就是 MySQLReplicationFactory 对象.

@huangdijia
Copy link
Author

我测试了,跟协程环境没有关系,确实存在 $size 8 not handled 这个问题。

@Moln
Copy link
Owner

Moln commented Apr 24, 2023

我测试了,跟协程环境没有关系,确实存在 $size 8 not handled 这个问题。

提供下PHP版本。

@huangdijia
Copy link
Author

$ php -v
PHP 8.1.18 (cli) (built: Apr 12 2023 12:31:46) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.18, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.18, Copyright (c), by Zend Technologies

@Moln
Copy link
Owner

Moln commented Apr 24, 2023

@huangdijia 希望能提供下单元测试,这个是我本机的 docker mysql:5.7, 配合上面我提供的单元测试, 我这是没测试问题来

docker run -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 mysql:5.7 --default-authentication-plugin=mysql_native_password --server-id=1 --log_bin --expire_logs_days=10 --max_binlog_size=100M --binlog-format=row

@huangdijia huangdijia closed this Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MySQLReplication\BinaryDataReader\BinaryDataReaderException: $size 8 not handled
3 participants