Skip to content

Commit

Permalink
Update SHOW BINLOG EVENTS to print event flags
Browse files Browse the repository at this point in the history
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: 3eff1e8
  • Loading branch information
Herman Lee authored and facebook-github-bot committed Jun 27, 2020
1 parent 7e1918a commit 6afb706
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
23 changes: 23 additions & 0 deletions libbinlogevents/include/rows_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#ifndef ROWS_EVENT_INCLUDED
#define ROWS_EVENT_INCLUDED

#include <sstream>
#include <vector>
#include "control_events.h"
#include "table_id.h"
Expand Down Expand Up @@ -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");
Expand Down
28 changes: 7 additions & 21 deletions sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 6afb706

Please sign in to comment.