stoneatom / stonedb

StoneDB is an Open-Source MySQL HTAP and MySQL-Native DataBase for OLTP, Real-Time Analytics, a counterpart of MySQLHeatWave. (https://stonedb.io)

Home Page:https://stonedb.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug: When the format of binlog is row, the load data statement cannot be recorded.

adofsauron opened this issue · comments

commented

Have you read the Contributing Guidelines on issues?

Please confirm if bug report does NOT exists already ?

  • I confirm there is no existing issue for this

Describe the problem

# cat /tmp/aaa.csv
1,AAA
2,BBB

mysql> show variables like 'binlog_format';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW   |
+---------------+-------+
1 row in set (0.00 sec)

mysql> create table aaa(id int,name varchar(5));
Query OK, 0 rows affected (0.11 sec)

mysql> load data infile '/tmp/aaa.csv' into table aaa FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
Query OK, 2 rows affected (0.08 sec)
Records: 2  Deleted: 0  Skipped: 0  Warnings: 0

mysql> select * from aaa;
+------+------+
| id   | name |
+------+------+
|    1 | AAA  |
|    2 | BBB  |
+------+------+
2 rows in set (0.00 sec)

### parse binlog
# /opt/stonedb57/install/bin/mysqlbinlog --base64-output=decode-rows -vv binlog.000003
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#230614  2:07:59 server id 1  end_log_pos 123 CRC32 0x276e7bd4  Start: binlog v 4, server v 5.7.36-StoneDB-v1.0.1 created 230614  2:07:59
# Warning: this binlog is either in use or was not closed properly.
# at 123
#230614  2:07:59 server id 1  end_log_pos 194 CRC32 0xe6bbb0c6  Previous-GTIDs
# 8d83d267-004d-11ee-b38d-002228b9f6f0:1-2
# at 194
#230614  2:08:32 server id 1  end_log_pos 259 CRC32 0x1a21de6b  GTID    last_committed=0        sequence_number=1       rbr_only=no
SET @@SESSION.GTID_NEXT= '8d83d267-004d-11ee-b38d-002228b9f6f0:3'/*!*/;
# at 259
#230614  2:08:32 server id 1  end_log_pos 369 CRC32 0xf908f07c  Query   thread_id=4     exec_time=0     error_code=0
use `db`/*!*/;
SET TIMESTAMP=1686708512/*!*/;
SET @@session.pseudo_thread_id=4/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1344274432/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=45/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
create table aaa(id int,name varchar(5))
/*!*/;
# at 369
#230614  2:08:47 server id 1  end_log_pos 434 CRC32 0x54bd9dbf  GTID    last_committed=1        sequence_number=2       rbr_only=no
SET @@SESSION.GTID_NEXT= '8d83d267-004d-11ee-b38d-002228b9f6f0:4'/*!*/;
# at 434
#230614  2:08:47 server id 1  end_log_pos 504 CRC32 0x82cff7cf  Query   thread_id=4     exec_time=0     error_code=0
SET TIMESTAMP=1686708527/*!*/;
BEGIN
/*!*/;
WARNING: Ignoring Execute_load_query since there is no Begin_load_query event for file_id: 0
# at 504
# at 726
#230614  2:08:47 server id 1  end_log_pos 797 CRC32 0x2c0a9ff2  Query   thread_id=4     exec_time=0     error_code=0
SET TIMESTAMP=1686708527/*!*/;
COMMIT
/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

Expected behavior

### INSERT INTO `db`.`aaa`
### SET
###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
###   @2='AAA' /* VARSTRING(5) meta=5 nullable=1 is_null=0 */
### INSERT INTO `db`.`aaa`
### SET
###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
###   @2='BBB' /* VARSTRING(5) meta=5 nullable=1 is_null=0 */

How To Reproduce

No response

Environment

./mysqld Ver 5.7.36-StoneDB-v1.0.1 for Linux on x86_64 (build-)
build information as follow:
Repository address: https://github.com/stoneatom/stonedb.git:stonedb-5.7-dev
Branch name: stonedb-5.7-dev
Last commit ID: 1f43e44
Last commit time: Date: Wed May 31 17:34:21 2023 +0800
Build time: Date: Thu Jun 1 07:20:38 UTC 2023

Are you interested in submitting a PR to solve the problem?

  • Yes, I will!
commented
  if (!print_event_info->short_form)
  {
    print_header(head, print_event_info, FALSE);
    my_b_printf(head, "\tStart: binlog v %d, server v %s created ", binlog_version, server_version);
    print_timestamp(head, NULL);
    if (created)
      my_b_printf(head, " at startup");
    my_b_printf(head, "\n");
    if (common_header->flags & LOG_EVENT_BINLOG_IN_USE_F)
      my_b_printf(head,
                  "# Warning: this binlog is either in use or was not "
                  "closed properly.\n");
  }
commented
/*
   This flag only makes sense for Format_description_event. It is set
   when the event is written, and *reset* when a binlog file is
   closed (yes, it's the only case when MySQL modifies an already written
   part of the binlog).  Thus it is a reliable indicator that the binlog was
   closed correctly.  (Stop_event is not enough, there's always a
   small chance that mysqld crashes in the middle of insert and end of
   the binlog would look like a Stop_event).

   This flag is used to detect a restart after a crash, and to provide
   "unbreakable" binlog. The problem is that on a crash storage engines
   rollback automatically, while binlog does not.  To solve this we use this
   flag and automatically append ROLLBACK to every non-closed binlog (append
   virtually, on reading, file itself is not changed). If this flag is found,
   mysqlbinlog simply prints "ROLLBACK". Replication master does not abort on
   binlog corruption, but takes it as EOF, and replication slave forces a
   rollback in this case.

   Note, that old binlogs does not have this flag set, so we get a
   a backward-compatible behaviour.
*/
#define LOG_EVENT_BINLOG_IN_USE_F       0x1
commented
    if (common_header->flags & LOG_EVENT_BINLOG_IN_USE_F)
      my_b_printf(head,
                  "# Warning: this binlog is either in use or was not "
                  "closed properly.\n");
set binlog_format=statment

###binlog
...
LOAD DATA LOCAL INFILE '/tmp/SQL_LOAD_MB-1-1' INTO TABLE `aaa` FIELDS TERMINATED BY ',' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`id`, `name`)
...