Skip to content

Commit f7c4932

Browse files
PS-10239 feature: Add support for processing GTID_LOG events
https://perconadev.atlassian.net/browse/PS-10239 Added new template specializations for 'generic_post_header_impl' and 'generic_body_impl' for 'code_type::gtid_log' ('GTID_LOG' event). Reworked / generalized 'util::extract_xxx()` series of functions - they now have corresponding "checked" versions that verify whether required number of bytes is available in the input data span and return false otherwise. Added 'util::extract_packed_int_from_byte_span_checked()' helper function that extracts 'std::uint64_t' integer from its packed network representation (MySQL-specific format). Added 'binsrv/gtid/common_types.hpp' file with basic typedefs for future GTID structures. 'binsrv::events::flag_type' renamed to 'binsrv::events::common_header_flag_type'.
1 parent 15bb282 commit f7c4932

18 files changed

Lines changed: 908 additions & 61 deletions

CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ set(source_files
9696
src/binsrv/event/common_header.hpp
9797
src/binsrv/event/common_header.cpp
9898

99+
src/binsrv/event/common_header_flag_type_fwd.hpp
100+
src/binsrv/event/common_header_flag_type.hpp
101+
99102
src/binsrv/event/empty_body_fwd.hpp
100103
src/binsrv/event/empty_body.hpp
101104
src/binsrv/event/empty_body.cpp
@@ -108,9 +111,6 @@ set(source_files
108111
src/binsrv/event/event.hpp
109112
src/binsrv/event/event.cpp
110113

111-
src/binsrv/event/flag_type_fwd.hpp
112-
src/binsrv/event/flag_type.hpp
113-
114114
src/binsrv/event/footer_fwd.hpp
115115
src/binsrv/event/footer.hpp
116116
src/binsrv/event/footer.cpp
@@ -129,6 +129,17 @@ set(source_files
129129
src/binsrv/event/generic_post_header_fwd.hpp
130130
src/binsrv/event/generic_post_header.hpp
131131

132+
src/binsrv/event/gtid_log_flag_type_fwd.hpp
133+
src/binsrv/event/gtid_log_flag_type.hpp
134+
135+
src/binsrv/event/gtid_log_body_impl_fwd.hpp
136+
src/binsrv/event/gtid_log_body_impl.hpp
137+
src/binsrv/event/gtid_log_body_impl.cpp
138+
139+
src/binsrv/event/gtid_log_post_header_impl_fwd.hpp
140+
src/binsrv/event/gtid_log_post_header_impl.hpp
141+
src/binsrv/event/gtid_log_post_header_impl.cpp
142+
132143
src/binsrv/event/protocol_traits_fwd.hpp
133144
src/binsrv/event/protocol_traits.hpp
134145
src/binsrv/event/protocol_traits.cpp
@@ -159,6 +170,9 @@ set(source_files
159170
src/binsrv/event/unknown_post_header.hpp
160171
src/binsrv/event/unknown_post_header.cpp
161172

173+
# gtid data structure files
174+
src/binsrv/gtid/common_types.hpp
175+
162176
# binlog files
163177
src/binsrv/basic_logger_fwd.hpp
164178
src/binsrv/basic_logger.hpp
@@ -299,9 +313,8 @@ set(source_files
299313

300314
add_executable(binlog_server ${source_files})
301315
target_link_libraries(binlog_server
302-
PUBLIC
303-
binlog_server_compiler_flags
304316
PRIVATE
317+
binlog_server_compiler_flags
305318
Boost::headers Boost::url
306319
ZLIB::ZLIB
307320
MySQL::client

src/app.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
#include "binsrv/time_unit.hpp"
5252

5353
#include "binsrv/event/code_type.hpp"
54+
#include "binsrv/event/common_header_flag_type.hpp"
5455
#include "binsrv/event/event.hpp"
55-
#include "binsrv/event/flag_type.hpp"
5656
#include "binsrv/event/protocol_traits_fwd.hpp"
5757
#include "binsrv/event/reader_context.hpp"
5858

@@ -325,7 +325,7 @@ void process_binlog_event(const binsrv::event::event &current_event,
325325
const auto code = current_common_header.get_type_code();
326326

327327
const auto is_artificial{current_common_header.get_flags().has_element(
328-
binsrv::event::flag_type::artificial)};
328+
binsrv::event::common_header_flag_type::artificial)};
329329
const auto is_pseudo{current_common_header.get_next_event_position_raw() ==
330330
0U};
331331

src/binsrv/event/common_header.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <boost/date_time/posix_time/time_formatters.hpp>
2727

2828
#include "binsrv/event/code_type.hpp"
29-
#include "binsrv/event/flag_type.hpp"
29+
#include "binsrv/event/common_header_flag_type.hpp"
3030

3131
#include "util/byte_span_extractors.hpp"
3232
#include "util/byte_span_fwd.hpp"
@@ -106,8 +106,8 @@ common_header::get_readable_type_code() const noexcept {
106106
return to_string_view(get_type_code());
107107
}
108108

109-
[[nodiscard]] flag_set common_header::get_flags() const noexcept {
110-
return flag_set{get_flags_raw()};
109+
[[nodiscard]] common_header_flag_set common_header::get_flags() const noexcept {
110+
return common_header_flag_set{get_flags_raw()};
111111
}
112112

113113
[[nodiscard]] std::string common_header::get_readable_flags() const {

src/binsrv/event/common_header.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <string_view>
2525

2626
#include "binsrv/event/code_type_fwd.hpp"
27-
#include "binsrv/event/flag_type_fwd.hpp"
27+
#include "binsrv/event/common_header_flag_type_fwd.hpp"
2828
#include "binsrv/event/protocol_traits_fwd.hpp"
2929

3030
#include "util/byte_span_fwd.hpp"
@@ -66,7 +66,7 @@ class [[nodiscard]] common_header {
6666
}
6767

6868
[[nodiscard]] std::uint16_t get_flags_raw() const noexcept { return flags_; }
69-
[[nodiscard]] flag_set get_flags() const noexcept;
69+
[[nodiscard]] common_header_flag_set get_flags() const noexcept;
7070
[[nodiscard]] std::string get_readable_flags() const;
7171

7272
private:

src/binsrv/event/flag_type.hpp renamed to src/binsrv/event/common_header_flag_type.hpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
// along with this program; if not, write to the Free Software
1414
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1515

16-
#ifndef BINSRV_EVENT_FLAG_TYPE_HPP
17-
#define BINSRV_EVENT_FLAG_TYPE_HPP
16+
#ifndef BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_HPP
17+
#define BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_HPP
1818

19-
#include "binsrv/event/flag_type_fwd.hpp" // IWYU pragma: export
19+
#include "binsrv/event/common_header_flag_type_fwd.hpp" // IWYU pragma: export
2020

2121
#include <algorithm>
2222
#include <array>
@@ -40,40 +40,41 @@ namespace binsrv::event {
4040
// closed).
4141
// Events received via network stream should never have this flag set.
4242
// clang-format off
43-
#define BINSRV_EVENT_FLAG_TYPE_XY_SEQUENCE() \
44-
BINSRV_EVENT_FLAG_TYPE_XY_MACRO(binlog_in_use , 0x001U), \
45-
BINSRV_EVENT_FLAG_TYPE_XY_MACRO(thread_specific, 0x004U), \
46-
BINSRV_EVENT_FLAG_TYPE_XY_MACRO(suppress_use , 0x008U), \
47-
BINSRV_EVENT_FLAG_TYPE_XY_MACRO(artificial , 0x020U), \
48-
BINSRV_EVENT_FLAG_TYPE_XY_MACRO(relay_log , 0x040U), \
49-
BINSRV_EVENT_FLAG_TYPE_XY_MACRO(ignorable , 0x080U), \
50-
BINSRV_EVENT_FLAG_TYPE_XY_MACRO(no_filter , 0x100U), \
51-
BINSRV_EVENT_FLAG_TYPE_XY_MACRO(mts_isolate , 0x200U)
43+
#define BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_SEQUENCE() \
44+
BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO(binlog_in_use , 0x001U), \
45+
BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO(thread_specific, 0x004U), \
46+
BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO(suppress_use , 0x008U), \
47+
BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO(artificial , 0x020U), \
48+
BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO(relay_log , 0x040U), \
49+
BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO(ignorable , 0x080U), \
50+
BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO(no_filter , 0x100U), \
51+
BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO(mts_isolate , 0x200U)
5252
// clang-format on
5353

54-
#define BINSRV_EVENT_FLAG_TYPE_XY_MACRO(X, Y) X = Y
54+
#define BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO(X, Y) X = Y
5555
// NOLINTNEXTLINE(readability-enum-initial-value,cert-int09-c)
56-
enum class flag_type : std::uint16_t {
57-
BINSRV_EVENT_FLAG_TYPE_XY_SEQUENCE(),
56+
enum class common_header_flag_type : std::uint16_t {
57+
BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_SEQUENCE(),
5858
delimiter
5959
};
60-
#undef BINSRV_EVENT_FLAG_TYPE_XY_MACRO
60+
#undef BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO
6161

62-
inline std::string_view to_string_view(flag_type code) noexcept {
62+
inline std::string_view to_string_view(common_header_flag_type code) noexcept {
6363
using namespace std::string_view_literals;
64-
using nv_pair = std::pair<flag_type, std::string_view>;
65-
#define BINSRV_EVENT_FLAG_TYPE_XY_MACRO(X, Y) \
66-
nv_pair { flag_type::X, #X##sv }
67-
static constexpr std::array labels{BINSRV_EVENT_FLAG_TYPE_XY_SEQUENCE(),
68-
nv_pair{flag_type::delimiter, ""sv}};
69-
#undef BINSRV_EVENT_FLAG_TYPE_XY_MACRO
64+
using nv_pair = std::pair<common_header_flag_type, std::string_view>;
65+
#define BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO(X, Y) \
66+
nv_pair { common_header_flag_type::X, #X##sv }
67+
static constexpr std::array labels{
68+
BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_SEQUENCE(),
69+
nv_pair{common_header_flag_type::delimiter, ""sv}};
70+
#undef BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_MACRO
7071
// NOLINTNEXTLINE(llvm-qualified-auto,readability-qualified-auto)
7172
const auto fnd{std::ranges::find(labels, code, &nv_pair::first)};
7273
return fnd == std::end(labels) ? ""sv : fnd->second;
7374
}
74-
#undef BINSRV_EVENT_FLAG_TYPE_XY_SEQUENCE
75+
#undef BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_XY_SEQUENCE
7576
// NOLINTEND(cppcoreguidelines-macro-usage)
7677

7778
} // namespace binsrv::event
7879

79-
#endif // BINSRV_EVENT_FLAG_TYPE_HPP
80+
#endif // BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_HPP
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2023-2024 Percona and/or its affiliates.
2+
//
3+
// This program is free software; you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License, version 2.0,
5+
// as published by the Free Software Foundation.
6+
//
7+
// This program is distributed in the hope that it will be useful,
8+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
// GNU General Public License, version 2.0, for more details.
11+
//
12+
// You should have received a copy of the GNU General Public License
13+
// along with this program; if not, write to the Free Software
14+
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
#ifndef BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_FWD_HPP
17+
#define BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_FWD_HPP
18+
19+
#include <cstdint>
20+
21+
#include "util/flag_set_fwd.hpp"
22+
23+
namespace binsrv::event {
24+
25+
// NOLINTNEXTLINE(readability-enum-initial-value,cert-int09-c)
26+
enum class common_header_flag_type : std::uint16_t;
27+
28+
using common_header_flag_set = util::flag_set<common_header_flag_type>;
29+
30+
} // namespace binsrv::event
31+
32+
#endif // BINSRV_EVENT_COMMON_HEADER_FLAG_TYPE_FWD_HPP

src/binsrv/event/event.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
#include "binsrv/event/footer.hpp" // IWYU pragma: export
3737
#include "binsrv/event/format_description_body_impl.hpp" // IWYU pragma: export
3838
#include "binsrv/event/format_description_post_header_impl.hpp" // IWYU pragma: export
39-
#include "binsrv/event/generic_body.hpp" // IWYU pragma: export
40-
#include "binsrv/event/generic_post_header.hpp" // IWYU pragma: export
39+
#include "binsrv/event/generic_body.hpp" // IWYU pragma: export
40+
#include "binsrv/event/generic_post_header.hpp" // IWYU pragma: export
41+
#include "binsrv/event/gtid_log_body_impl.hpp" // IWYU pragma: export
42+
#include "binsrv/event/gtid_log_post_header_impl.hpp" // IWYU pragma: export
4143
#include "binsrv/event/reader_context_fwd.hpp"
4244
#include "binsrv/event/rotate_body_impl.hpp" // IWYU pragma: export
4345
#include "binsrv/event/rotate_post_header_impl.hpp" // IWYU pragma: export

0 commit comments

Comments
 (0)