Bug #121820 SHOW BINLOG EVENTS does not stop at end_pos in the active binlog file
Description:
SHOW BINLOG EVENTS reads the end position (end_pos) of the active binlog file when it starts, and should not return events located after it. Currently, it does not stop at end_pos, so the output includes events after that position until the end of the file.
The break condition `ev->common_header->log_pos != last_log_pos` is always false, because `last_log_pos` is assigned from the same event just before the check. This happens with or without binlog transaction compression. With compression, all events embedded in a Transaction_payload_log_event report the payload's log position, so the event loop cannot use `log_pos` to tell whether the next event is still inside the same payload.
How to repeat:
# MTR Test:
###########################################################################
# SHOW BINLOG EVENTS on the active binlog must stop at the published end #
# position (get_binlog_end_pos()) that was read when the command started. #
# #
# Steps: #
# 1) Commit one transaction (T1). #
# 2) Start SHOW BINLOG EVENTS in con1 and pause it right after it has #
# captured end_pos, before it reads any event. #
# 3) Commit more transactions (T2, T3) from the default connection. #
# 4) Resume SHOW BINLOG EVENTS. It must list T1 only. T2 and T3 were #
# committed after end_pos was captured and must not be returned. #
# #
# The test does not depend on the GTID mode: the Gtid / Anonymous_Gtid #
# event type is normalized to Gtid in the output. #
###########################################################################
--source include/have_debug_sync.inc
--source include/have_binlog_format_row.inc
# Setup
RESET BINARY LOGS AND GTIDS;
CREATE TABLE t1 (i INT);
# Only list events after the CREATE TABLE
--let $binlog_file= query_get_value(SHOW BINARY LOG STATUS, File, 1)
--let $start_pos= query_get_value(SHOW BINARY LOG STATUS, Position, 1)
# Step 1: commit T1
INSERT INTO t1 VALUES (1);
# Step 2: con1 starts SHOW BINLOG EVENTS and pauses after end_pos is read
--connect (con1,localhost,root,,)
SET DEBUG_SYNC = "after_show_binlog_event_found_file SIGNAL reached WAIT_FOR go";
--disable_query_log
--send_eval SHOW BINLOG EVENTS IN '$binlog_file' FROM $start_pos
--enable_query_log
# Step 3: commit T2 and T3 while SHOW BINLOG EVENTS is paused
--connection default
SET DEBUG_SYNC = "now WAIT_FOR reached";
INSERT INTO t1 VALUES (2);
INSERT INTO t1 VALUES (3);
# Step 4: resume SHOW BINLOG EVENTS. Expected: the 5 events of T1 only
SET DEBUG_SYNC = "now SIGNAL go";
--connection con1
--replace_column 1 # 2 # 5 # 6 #
--replace_regex /Anonymous_Gtid/Gtid/ /table_id: [0-9]+/table_id: #/ /xid=[0-9]+/xid=#/
--reap
--connection default
# Cleanup
--disconnect con1
SET DEBUG_SYNC = "RESET";
DROP TABLE t1;
Expected: only the 5 events of T1.
Actual (unfixed server): 15 events, the 5 of T1 plus the 5 each of T2 and T3.
Suggested fix:
show_binlog_events() no longer checks log_pos after each event. It passes end_pos to the decompressing stream, which stops before reading any event that starts at or after end_pos. A payload event that starts before end_pos is still returned with all of its embedded events, so no compressed events are cut off. end_pos == 0 means no limit, so existing callers are unchanged.
See attached patch
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.053 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.