From 6afb70642a8f45059f8c21726f15320c5c4cbff6 Mon Sep 17 00:00:00 2001 From: Herman Lee Date: Fri, 19 Jun 2020 12:21:23 -0700 Subject: [PATCH] Update SHOW BINLOG EVENTS to print event flags Summary: Update the show binlog events command to also print out event flags, similar to mysqlbinlog. Squash with D21954221 Reviewed By: yizhang82 Differential Revision: D22144023 fbshipit-source-id: 3eff1e8247a --- libbinlogevents/include/rows_event.h | 23 +++++++++++++++++++++++ sql/log_event.cc | 28 +++++++--------------------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/libbinlogevents/include/rows_event.h b/libbinlogevents/include/rows_event.h index 2ae9ff6a2191..5d3e55b7a9be 100644 --- a/libbinlogevents/include/rows_event.h +++ b/libbinlogevents/include/rows_event.h @@ -34,6 +34,7 @@ #ifndef ROWS_EVENT_INCLUDED #define ROWS_EVENT_INCLUDED +#include #include #include "control_events.h" #include "table_id.h" @@ -1068,6 +1069,28 @@ class Rows_event : public Binary_log_event { unsigned long get_width() const { return m_width; } + std::string get_enum_flag_string() const { + std::stringstream flag_str; + +#define PARSE_FLAG(__str__, __flag__) \ + if (m_flags & __flag__) { \ + __str__ << " " #__flag__; \ + } + + flag_str << " flags:"; + PARSE_FLAG(flag_str, STMT_END_F); + PARSE_FLAG(flag_str, NO_FOREIGN_KEY_CHECKS_F); + PARSE_FLAG(flag_str, RELAXED_UNIQUE_CHECKS_F); + PARSE_FLAG(flag_str, COMPLETE_ROWS_F); + auto unknown_flags = (m_flags & ~ALL_FLAGS); + if (unknown_flags) { + DBUG_ASSERT(false); + flag_str << " UNKNOWN_FLAG("; + flag_str << std::hex << "0x" << unknown_flags << ")"; + } + return flag_str.str(); + } + static std::string get_flag_string(enum_flag flag) { std::string str = ""; if (flag & STMT_END_F) str.append(" Last event of the statement"); diff --git a/sql/log_event.cc b/sql/log_event.cc index 35351075f9f9..7ae62a3ede98 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -10787,42 +10787,28 @@ bool Rows_log_event::write_data_body(Basic_ostream *ostream) { int Rows_log_event::pack_info(Protocol *protocol) { char buf[256]; - char const *const flagstr = get_flags(STMT_END_F) ? " flags: STMT_END_F" : ""; - size_t bytes = - snprintf(buf, sizeof(buf), "table_id: %llu%s", m_table_id.id(), flagstr); + std::string flagstr; + if (m_flags) flagstr = get_enum_flag_string(); + + size_t bytes = snprintf(buf, sizeof(buf), "table_id: %llu%s", m_table_id.id(), + flagstr.c_str()); protocol->store(buf, bytes, &my_charset_bin); return 0; } #endif // MYSQL_SERVER #ifndef MYSQL_SERVER -#define PARSE_FLAG(str, flag) \ - if (get_flags(flag)) { \ - str << " " #flag; \ - } - void Rows_log_event::print_helper(FILE *, PRINT_EVENT_INFO *print_event_info) const { IO_CACHE *const head = &print_event_info->head_cache; IO_CACHE *const body = &print_event_info->body_cache; if (!print_event_info->short_form) { - std::stringstream flag_str; - flag_str << " flags:"; - PARSE_FLAG(flag_str, STMT_END_F); - PARSE_FLAG(flag_str, NO_FOREIGN_KEY_CHECKS_F); - PARSE_FLAG(flag_str, RELAXED_UNIQUE_CHECKS_F); - PARSE_FLAG(flag_str, COMPLETE_ROWS_F); - auto unknown_flags = (m_flags & ~ALL_FLAGS); - if (unknown_flags) { - DBUG_ASSERT(false); - flag_str << " UNKNOWN_FLAG("; - flag_str << std::hex << "0x" << unknown_flags << ")"; - } + std::string flag_str = get_enum_flag_string(); bool const last_stmt_event = get_flags(STMT_END_F); print_header(head, print_event_info, !last_stmt_event); my_b_printf(head, "\t%s: table id %llu%s\n", get_type_str(), - m_table_id.id(), m_flags ? flag_str.str().c_str() : ""); + m_table_id.id(), m_flags ? flag_str.c_str() : ""); print_base64(body, print_event_info, !last_stmt_event); } }