Skip to content

Commit

Permalink
Make sure mysqlbinlog print all Rows_log_event flags
Browse files Browse the repository at this point in the history
Summary:
Today we only print STMT_END_F flags in RBR events but there are other important events that needs to be printed as well (in my case the one I needed to see was `RELAXED_UNIQUE_CHECKS_F`). This prints all the supported flags and also prints the flags in hex. We also now ASSERTs if there are unknown flags and print "UNKNOWN_FLAG(0xN)" in retail.

Reference Patch: facebook@6afb70642a8

Reviewed By: luqun

Differential Revision: D21954221
  • Loading branch information
yizhang82 authored and inikep committed May 21, 2024
1 parent 4ee80eb commit 0fbfe8a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
31 changes: 30 additions & 1 deletion libbinlogevents/include/rows_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
#ifndef ROWS_EVENT_INCLUDED
#define ROWS_EVENT_INCLUDED

#include <sstream>
#include <vector>
#include "control_events.h"
#include "my_dbug.h"
#include "table_id.h"

/**
Expand Down Expand Up @@ -934,7 +936,12 @@ class Rows_event : public Binary_log_event {
Indicates that rows in this event are complete, that is contain
values for all columns of the table.
*/
COMPLETE_ROWS_F = (1U << 3)
COMPLETE_ROWS_F = (1U << 3),
/**
Flags for everything. Please update when you add new flags.
*/
ALL_FLAGS = STMT_END_F | NO_FOREIGN_KEY_CHECKS_F | RELAXED_UNIQUE_CHECKS_F |
COMPLETE_ROWS_F
};

/**
Expand Down Expand Up @@ -1068,6 +1075,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) {
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");
Expand Down
12 changes: 8 additions & 4 deletions sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11125,9 +11125,11 @@ 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_string(buf, bytes, &my_charset_bin);
return 0;
}
Expand All @@ -11139,10 +11141,12 @@ void Rows_log_event::print_helper(FILE *,
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::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(), last_stmt_event ? " flags: STMT_END_F" : "");
m_table_id.id(), m_flags ? flag_str.c_str() : "");
print_base64(body, print_event_info, !last_stmt_event);
}
}
Expand Down

0 comments on commit 0fbfe8a

Please sign in to comment.