Bug #121383 get_event_type_as_string() reports "Unknown" instead of "Heartbeat" for HEARTBEAT_LOG_EVENT_V2 events
Description:
In MySQL 8.0, Log_event::get_type_str() (sql/log_event.cc) is a switch statement that maps both heartbeat protocol versions to the same name:
case binary_log::HEARTBEAT_LOG_EVENT:
case binary_log::HEARTBEAT_LOG_EVENT_V2:
return "Heartbeat";
In 8.4, this was refactored: get_type_str() now delegates to mysql::binlog::event::get_event_type_as_string()
(libs/mysql/binlog/event/binlog_event.cpp), which looks the type up in a std::unordered_map<Log_event_type, const std::string>
populated with individual entries per type. That table includes an entry for the legacy HEARTBEAT_LOG_EVENT (v1, numeric value 27):
{HEARTBEAT_LOG_EVENT, "Heartbeat"},
but has no corresponding entry for HEARTBEAT_LOG_EVENT_V2 (numeric value 41, unchanged from 8.0 - this is the variant actually sent
by default since Binlog_sender uses HEARTBEAT_LOG_EVENT_V2 unless the use_old_heartbeat_version debug point forces the legacy one).
The lookup function's fallback path:
const std::string &get_event_type_as_string(Log_event_type type) {
try {
return event_type_to_string.at(type);
} catch (const std::out_of_range &) {
return event_type_to_string.at(UNKNOWN_EVENT);
}
}
catches the resulting std::out_of_range for HEARTBEAT_LOG_EVENT_V2 and silently returns "Unknown" instead.
The practical impact: any error message, log line, or diagnostic that names a heartbeat-v2 event via
get_type_str()/get_event_type_as_string() misreports it as "Unknown" rather than "Heartbeat" on 8.4+. This makes such messages
actively misleading when diagnosing replication issues — e.g. it surfaced while investigating a separate receiver-thread bug
(Bug#121382 filed separately) where the error text read Event type 'Unknown' is not recognized by the format description event
currently in use. on 8.4, versus the correct Event type 'Heartbeat' is not recognized... on the EOLed v8.0 for the exact same underlying
condition - obscuring the true cause.
How to repeat:
1. Build a debug (-DWITH_DEBUG=1) 8.4 server pair with replication configured.
2. Set a short SOURCE_HEARTBEAT_PERIOD (e.g. 0.1) and let the channel go idle so the source sends heartbeats.
3. Trigger any code path that calls Log_event::get_type_str()/get_event_type_as_string() on a HEARTBEAT_LOG_EVENT_V2 instance - for example, the debug point queue_event_unknown_event_type_by_fd_event in sql/rpl_replica.cc, which causes is_fd_event_saved_in_context_usable_with_event_type() to reject the next event and log it via
Log_event::get_type_str(event_type).
4. Observe the error log reports Event type 'Unknown'... instead of Event type 'Heartbeat'....
Alternatively, a minimal unit-level repro: call
mysql::binlog::event::get_event_type_as_string(mysql::binlog::event::HEARTBEAT_LOG_EVENT_V2) directly and observe it returns "Unknown".
Suggested fix:
Add the missing entry to the map in libs/mysql/binlog/event/binlog_event.cpp:
{HEARTBEAT_LOG_EVENT, "Heartbeat"},
{HEARTBEAT_LOG_EVENT_V2, "Heartbeat"},
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.039 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.
Description: In MySQL 8.0, Log_event::get_type_str() (sql/log_event.cc) is a switch statement that maps both heartbeat protocol versions to the same name: case binary_log::HEARTBEAT_LOG_EVENT: case binary_log::HEARTBEAT_LOG_EVENT_V2: return "Heartbeat"; In 8.4, this was refactored: get_type_str() now delegates to mysql::binlog::event::get_event_type_as_string() (libs/mysql/binlog/event/binlog_event.cpp), which looks the type up in a std::unordered_map<Log_event_type, const std::string> populated with individual entries per type. That table includes an entry for the legacy HEARTBEAT_LOG_EVENT (v1, numeric value 27): {HEARTBEAT_LOG_EVENT, "Heartbeat"}, but has no corresponding entry for HEARTBEAT_LOG_EVENT_V2 (numeric value 41, unchanged from 8.0 - this is the variant actually sent by default since Binlog_sender uses HEARTBEAT_LOG_EVENT_V2 unless the use_old_heartbeat_version debug point forces the legacy one). The lookup function's fallback path: const std::string &get_event_type_as_string(Log_event_type type) { try { return event_type_to_string.at(type); } catch (const std::out_of_range &) { return event_type_to_string.at(UNKNOWN_EVENT); } } catches the resulting std::out_of_range for HEARTBEAT_LOG_EVENT_V2 and silently returns "Unknown" instead. The practical impact: any error message, log line, or diagnostic that names a heartbeat-v2 event via get_type_str()/get_event_type_as_string() misreports it as "Unknown" rather than "Heartbeat" on 8.4+. This makes such messages actively misleading when diagnosing replication issues — e.g. it surfaced while investigating a separate receiver-thread bug (Bug#121382 filed separately) where the error text read Event type 'Unknown' is not recognized by the format description event currently in use. on 8.4, versus the correct Event type 'Heartbeat' is not recognized... on the EOLed v8.0 for the exact same underlying condition - obscuring the true cause. How to repeat: 1. Build a debug (-DWITH_DEBUG=1) 8.4 server pair with replication configured. 2. Set a short SOURCE_HEARTBEAT_PERIOD (e.g. 0.1) and let the channel go idle so the source sends heartbeats. 3. Trigger any code path that calls Log_event::get_type_str()/get_event_type_as_string() on a HEARTBEAT_LOG_EVENT_V2 instance - for example, the debug point queue_event_unknown_event_type_by_fd_event in sql/rpl_replica.cc, which causes is_fd_event_saved_in_context_usable_with_event_type() to reject the next event and log it via Log_event::get_type_str(event_type). 4. Observe the error log reports Event type 'Unknown'... instead of Event type 'Heartbeat'.... Alternatively, a minimal unit-level repro: call mysql::binlog::event::get_event_type_as_string(mysql::binlog::event::HEARTBEAT_LOG_EVENT_V2) directly and observe it returns "Unknown". Suggested fix: Add the missing entry to the map in libs/mysql/binlog/event/binlog_event.cpp: {HEARTBEAT_LOG_EVENT, "Heartbeat"}, {HEARTBEAT_LOG_EVENT_V2, "Heartbeat"},