mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-31761: mariadb-binlog prints fractional timestamp part incorrectly
Fractional part < 100000 microseconds was printed without leading zeros, causing such timestamps to be applied incorrectly in mariadb-binlog | mysql Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
This commit is contained in:
@@ -1286,3 +1286,31 @@ ERROR: Bad syntax in rewrite-db: empty FROM db
|
||||
|
||||
ERROR: Bad syntax in rewrite-db: empty FROM db
|
||||
|
||||
#
|
||||
# MDEV-31761: mariadb-binlog prints fractional timestamp part incorrectly
|
||||
#
|
||||
SET SESSION binlog_format= MIXED;
|
||||
RESET MASTER;
|
||||
SET time_zone= '+02:00';
|
||||
CREATE TABLE t (a INT,
|
||||
b TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6));
|
||||
set SESSION timestamp= 1689978980.012345;
|
||||
INSERT INTO t (a) VALUES (1);
|
||||
SELECT * from t;
|
||||
a b
|
||||
1 2023-07-22 00:36:20.012345
|
||||
FLUSH BINARY LOGS;
|
||||
SET SESSION timestamp= 1689978980.567890;
|
||||
SET SESSION binlog_format= ROW;
|
||||
UPDATE t SET a = 2;
|
||||
FLUSH BINARY LOGS;
|
||||
SET SESSION binlog_format= STATEMENT;
|
||||
DROP TABLE t;
|
||||
SELECT * FROM t;
|
||||
a b
|
||||
1 2023-07-22 00:36:20.012345
|
||||
SELECT * FROM t;
|
||||
a b
|
||||
2 2023-07-22 00:36:20.567890
|
||||
DROP TABLE t;
|
||||
SET time_zone= default;
|
||||
|
@@ -637,3 +637,37 @@ FLUSH LOGS;
|
||||
--exec $MYSQL_BINLOG --rewrite-db=" ->" --short-form $MYSQLD_DATADIR/master-bin.000001 2>&1
|
||||
|
||||
--exec $MYSQL_BINLOG --rewrite-db=" test -> foo " --short-form $MYSQLD_DATADIR/master-bin.000001 > /dev/null 2> $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-31761: mariadb-binlog prints fractional timestamp part incorrectly
|
||||
--echo #
|
||||
|
||||
SET SESSION binlog_format= MIXED;
|
||||
|
||||
RESET MASTER;
|
||||
SET time_zone= '+02:00';
|
||||
CREATE TABLE t (a INT,
|
||||
b TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6));
|
||||
set SESSION timestamp= 1689978980.012345;
|
||||
INSERT INTO t (a) VALUES (1);
|
||||
SELECT * from t;
|
||||
FLUSH BINARY LOGS;
|
||||
SET SESSION timestamp= 1689978980.567890;
|
||||
SET SESSION binlog_format= ROW;
|
||||
UPDATE t SET a = 2;
|
||||
FLUSH BINARY LOGS;
|
||||
SET SESSION binlog_format= STATEMENT;
|
||||
|
||||
# Replay to see that timestamps are applied correctly.
|
||||
# The bug was that leading zeros on the fractional part were not included in
|
||||
# the mysqlbinlog output, so 1689978980.012345 was applied as 1689978980.12345.
|
||||
|
||||
DROP TABLE t;
|
||||
--let $datadir= `select @@datadir`
|
||||
--exec $MYSQL_BINLOG $datadir/master-bin.000001 | $MYSQL test
|
||||
SELECT * FROM t;
|
||||
--exec $MYSQL_BINLOG $datadir/master-bin.000002 | $MYSQL test
|
||||
SELECT * FROM t;
|
||||
DROP TABLE t;
|
||||
SET time_zone= default;
|
||||
|
@@ -1851,8 +1851,11 @@ bool Query_log_event::print_query_header(IO_CACHE* file,
|
||||
end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
|
||||
if (when_sec_part && when_sec_part <= TIME_MAX_SECOND_PART)
|
||||
{
|
||||
*end++= '.';
|
||||
end=int10_to_str(when_sec_part, end, 10);
|
||||
char buff2[1 + 6 + 1];
|
||||
/* Ensure values < 100000 are printed with leading zeros, MDEV-31761. */
|
||||
snprintf(buff2, sizeof(buff2), ".%06lu", when_sec_part);
|
||||
DBUG_ASSERT(strlen(buff2) == 1 + 6);
|
||||
end= strmov(end, buff2);
|
||||
}
|
||||
end= strmov(end, print_event_info->delimiter);
|
||||
*end++='\n';
|
||||
|
Reference in New Issue
Block a user