Skip to content

Commit 8ba6f63

Browse files
PS-10240 feature: Add support for processing ANONYMOUS_GTID_LOG events (#74)
https://perconadev.atlassian.net/browse/PS-10240 Common post header and body data structures for 'GTID_LOG' and 'ANONYMOUS_GTID_LOG' events extracted into 'binsrv::event::gtid_log_post_header' and 'binsrv::event::gtid_log_body' classes respectively. 'binsrv::event::generic_post_header_impl' / 'binsrv::event::generic_body_impl' specializations for both 'code_type::gtid_log' and 'code_type::anonymous_gtid_log' reimplemented via redirection ('using redirect_type = gtid_log_post_header' / 'using redirect_type = gtid_log_body').
1 parent 0baa63a commit 8ba6f63

16 files changed

Lines changed: 418 additions & 186 deletions

CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ set(source_files
8686
src/app_version.hpp
8787

8888
# binlog event data structure files
89+
src/binsrv/event/anonymous_gtid_log_body_impl_fwd.hpp
90+
src/binsrv/event/anonymous_gtid_log_body_impl.hpp
91+
92+
src/binsrv/event/anonymous_gtid_log_post_header_impl_fwd.hpp
93+
src/binsrv/event/anonymous_gtid_log_post_header_impl.hpp
94+
8995
src/binsrv/event/checksum_algorithm_type_fwd.hpp
9096
src/binsrv/event/checksum_algorithm_type.hpp
9197

@@ -132,13 +138,19 @@ set(source_files
132138
src/binsrv/event/gtid_log_flag_type_fwd.hpp
133139
src/binsrv/event/gtid_log_flag_type.hpp
134140

141+
src/binsrv/event/gtid_log_body_fwd.hpp
142+
src/binsrv/event/gtid_log_body.hpp
143+
src/binsrv/event/gtid_log_body.cpp
144+
135145
src/binsrv/event/gtid_log_body_impl_fwd.hpp
136146
src/binsrv/event/gtid_log_body_impl.hpp
137-
src/binsrv/event/gtid_log_body_impl.cpp
147+
148+
src/binsrv/event/gtid_log_post_header_fwd.hpp
149+
src/binsrv/event/gtid_log_post_header.hpp
150+
src/binsrv/event/gtid_log_post_header.cpp
138151

139152
src/binsrv/event/gtid_log_post_header_impl_fwd.hpp
140153
src/binsrv/event/gtid_log_post_header_impl.hpp
141-
src/binsrv/event/gtid_log_post_header_impl.cpp
142154

143155
src/binsrv/event/protocol_traits_fwd.hpp
144156
src/binsrv/event/protocol_traits.hpp
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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_ANONYMOUS_GTID_LOG_BODY_IMPL_HPP
17+
#define BINSRV_EVENT_ANONYMOUS_GTID_LOG_BODY_IMPL_HPP
18+
19+
#include "binsrv/event/anonymous_gtid_log_body_impl_fwd.hpp" // IWYU pragma: export
20+
21+
#include "binsrv/event/gtid_log_body.hpp"
22+
23+
namespace binsrv::event {
24+
25+
template <>
26+
class [[nodiscard]] generic_body_impl<code_type::anonymous_gtid_log> {
27+
public:
28+
using redirect_type = gtid_log_body;
29+
};
30+
31+
} // namespace binsrv::event
32+
33+
#endif // BINSRV_EVENT_ANONYMOUS_GTID_LOG_BODY_IMPL_HPP
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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_ANONYMOUS_GTID_LOG_BODY_IMPL_FWD_HPP
17+
#define BINSRV_EVENT_ANONYMOUS_GTID_LOG_BODY_IMPL_FWD_HPP
18+
19+
#include "binsrv/event/code_type.hpp"
20+
#include "binsrv/event/generic_body_fwd.hpp"
21+
22+
namespace binsrv::event {
23+
24+
template <> class generic_body_impl<code_type::anonymous_gtid_log>;
25+
26+
} // namespace binsrv::event
27+
28+
#endif // BINSRV_EVENT_ANONYMOUS_GTID_LOG_BODY_IMPL_FWD_HPP
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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_ANONYMOUS_GTID_LOG_POST_HEADER_IMPL_HPP
17+
#define BINSRV_EVENT_ANONYMOUS_GTID_LOG_POST_HEADER_IMPL_HPP
18+
19+
#include "binsrv/event/anonymous_gtid_log_post_header_impl_fwd.hpp" // IWYU pragma: export
20+
21+
#include "binsrv/event/gtid_log_post_header.hpp"
22+
23+
namespace binsrv::event {
24+
25+
template <>
26+
class [[nodiscard]] generic_post_header_impl<code_type::anonymous_gtid_log> {
27+
public:
28+
using redirect_type = gtid_log_post_header;
29+
};
30+
31+
} // namespace binsrv::event
32+
33+
#endif // BINSRV_EVENT_ANONYMOUS_GTID_LOG_POST_HEADER_IMPL_HPP
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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_ANONYMOUS_GTID_LOG_POST_HEADER_IMPL_FWD_HPP
17+
#define BINSRV_EVENT_ANONYMOUS_GTID_LOG_POST_HEADER_IMPL_FWD_HPP
18+
19+
#include "binsrv/event/code_type.hpp"
20+
#include "binsrv/event/generic_post_header_fwd.hpp"
21+
22+
namespace binsrv::event {
23+
24+
template <> class generic_post_header_impl<code_type::anonymous_gtid_log>;
25+
26+
} // namespace binsrv::event
27+
28+
#endif // BINSRV_EVENT_ANONYMOUS_GTID_LOG_POST_HEADER_IMPL_FWD_HPP

src/binsrv/event/event.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <boost/mp11/integer_sequence.hpp>
3232
#include <boost/mp11/list.hpp>
3333

34+
#include "binsrv/event/anonymous_gtid_log_body_impl.hpp" // IWYU pragma: export
35+
#include "binsrv/event/anonymous_gtid_log_post_header_impl.hpp" // IWYU pragma: export
3436
#include "binsrv/event/code_type.hpp"
3537
#include "binsrv/event/common_header.hpp" // IWYU pragma: export
3638
#include "binsrv/event/footer.hpp" // IWYU pragma: export
Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
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-
#include "binsrv/event/gtid_log_body_impl.hpp"
16+
#include "binsrv/event/gtid_log_body.hpp"
1717

1818
#include <cstdint>
1919
#include <ctime>
@@ -27,17 +27,14 @@
2727
#include <boost/date_time/posix_time/ptime.hpp>
2828
#include <boost/date_time/posix_time/time_formatters_limited.hpp>
2929

30-
#include "binsrv/event/code_type.hpp"
31-
3230
#include "util/byte_span.hpp"
3331
#include "util/byte_span_extractors.hpp"
3432
#include "util/exception_location_helpers.hpp"
3533
#include "util/semantic_version.hpp"
3634

3735
namespace binsrv::event {
3836

39-
generic_body_impl<code_type::gtid_log>::generic_body_impl(
40-
util::const_byte_span portion) {
37+
gtid_log_body::gtid_log_body(util::const_byte_span portion) {
4138
// TODO: rework with direct member initialization
4239

4340
// make sure we did OK with data members reordering
@@ -105,8 +102,8 @@ generic_body_impl<code_type::gtid_log>::generic_body_impl(
105102
"extra bytes in the gtid_log event body");
106103
}
107104
}
108-
[[nodiscard]] std::string generic_body_impl<
109-
code_type::gtid_log>::get_readable_immediate_commit_timestamp() const {
105+
[[nodiscard]] std::string
106+
gtid_log_body::get_readable_immediate_commit_timestamp() const {
110107
// threre is still no way to get string representationof the
111108
// std::chrono::high_resolution_clock::time_point using standard stdlib means,
112109
// so using boost::posix_time::ptime here
@@ -118,31 +115,26 @@ generic_body_impl<code_type::gtid_log>::generic_body_impl(
118115
}
119116

120117
[[nodiscard]] util::semantic_version
121-
generic_body_impl<code_type::gtid_log>::get_original_server_version()
122-
const noexcept {
118+
gtid_log_body::get_original_server_version() const noexcept {
123119
return util::semantic_version{get_original_server_version_raw()};
124120
}
125121

126122
[[nodiscard]] std::string
127-
generic_body_impl<code_type::gtid_log>::get_readable_original_server_version()
128-
const {
123+
gtid_log_body::get_readable_original_server_version() const {
129124
return get_original_server_version().get_string();
130125
}
131126

132127
[[nodiscard]] util::semantic_version
133-
generic_body_impl<code_type::gtid_log>::get_immediate_server_version()
134-
const noexcept {
128+
gtid_log_body::get_immediate_server_version() const noexcept {
135129
return util::semantic_version{get_immediate_server_version_raw()};
136130
}
137131

138132
[[nodiscard]] std::string
139-
generic_body_impl<code_type::gtid_log>::get_readable_immediate_server_version()
140-
const {
133+
gtid_log_body::get_readable_immediate_server_version() const {
141134
return get_immediate_server_version().get_string();
142135
}
143136

144-
std::ostream &operator<<(std::ostream &output,
145-
const generic_body_impl<code_type::gtid_log> &obj) {
137+
std::ostream &operator<<(std::ostream &output, const gtid_log_body &obj) {
146138
output << "immediate_commit_timestamp: "
147139
<< obj.get_readable_immediate_commit_timestamp();
148140
if (obj.has_original_commit_timestamp()) {

src/binsrv/event/gtid_log_body.hpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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_GTID_LOG_BODY_HPP
17+
#define BINSRV_EVENT_GTID_LOG_BODY_HPP
18+
19+
#include "binsrv/event/gtid_log_body_fwd.hpp" // IWYU pragma: export
20+
21+
#include <chrono>
22+
#include <cstdint>
23+
#include <limits>
24+
#include <string>
25+
#include <string_view>
26+
27+
#include "util/byte_span_fwd.hpp"
28+
#include "util/common_optional_types.hpp"
29+
#include "util/semantic_version_fwd.hpp"
30+
31+
namespace binsrv::event {
32+
33+
class [[nodiscard]] gtid_log_body {
34+
public:
35+
explicit gtid_log_body(util::const_byte_span portion);
36+
37+
[[nodiscard]] std::uint64_t
38+
get_immediate_commit_timestamp_raw() const noexcept {
39+
return immediate_commit_timestamp_;
40+
}
41+
[[nodiscard]] std::chrono::high_resolution_clock::time_point
42+
get_immediate_commit_timestamp() const noexcept {
43+
return std::chrono::high_resolution_clock::time_point{
44+
std::chrono::microseconds(get_immediate_commit_timestamp_raw())};
45+
}
46+
[[nodiscard]] std::string get_readable_immediate_commit_timestamp() const;
47+
[[nodiscard]] bool has_original_commit_timestamp() const noexcept {
48+
return original_commit_timestamp_ != unset_commit_timestamp;
49+
}
50+
[[nodiscard]] std::uint64_t
51+
get_original_commit_timestamp_raw() const noexcept {
52+
return original_commit_timestamp_;
53+
}
54+
55+
[[nodiscard]] bool has_transaction_length() const noexcept {
56+
return transaction_length_ != unset_transaction_length;
57+
}
58+
[[nodiscard]] std::uint64_t get_transaction_length_raw() const noexcept {
59+
return transaction_length_;
60+
}
61+
62+
[[nodiscard]] bool has_original_server_version() const noexcept {
63+
return original_server_version_ != unset_server_version;
64+
}
65+
[[nodiscard]] std::uint32_t get_original_server_version_raw() const noexcept {
66+
return original_server_version_;
67+
}
68+
[[nodiscard]] util::semantic_version
69+
get_original_server_version() const noexcept;
70+
[[nodiscard]] std::string get_readable_original_server_version() const;
71+
72+
[[nodiscard]] bool has_immediate_server_version() const noexcept {
73+
return immediate_server_version_ != unset_server_version;
74+
}
75+
[[nodiscard]] std::uint32_t
76+
get_immediate_server_version_raw() const noexcept {
77+
return immediate_server_version_;
78+
}
79+
[[nodiscard]] util::semantic_version
80+
get_immediate_server_version() const noexcept;
81+
[[nodiscard]] std::string get_readable_immediate_server_version() const;
82+
83+
[[nodiscard]] bool has_commit_group_ticket() const noexcept {
84+
return commit_group_ticket_ != unset_commit_group_ticket;
85+
}
86+
[[nodiscard]] std::uint64_t get_commit_group_ticket_raw() const noexcept {
87+
return commit_group_ticket_;
88+
}
89+
90+
private:
91+
static constexpr std::uint64_t unset_commit_timestamp{
92+
std::numeric_limits<std::uint64_t>::max()};
93+
static constexpr std::uint64_t unset_transaction_length{
94+
std::numeric_limits<std::uint64_t>::max()};
95+
static constexpr std::uint32_t unset_server_version{
96+
std::numeric_limits<std::uint32_t>::max()};
97+
static constexpr std::uint64_t unset_commit_group_ticket{
98+
std::numeric_limits<std::uint64_t>::max()};
99+
100+
static constexpr std::size_t commit_timestamp_field_length{7U};
101+
static constexpr std::size_t server_version_field_length{4U};
102+
static constexpr std::size_t commit_group_ticket_field_length{8};
103+
104+
std::uint64_t immediate_commit_timestamp_{unset_commit_timestamp}; // 0
105+
std::uint64_t original_commit_timestamp_{unset_commit_timestamp}; // 1
106+
std::uint64_t transaction_length_{unset_transaction_length}; // 2
107+
std::uint32_t original_server_version_{unset_server_version}; // 3
108+
std::uint32_t immediate_server_version_{unset_server_version}; // 4
109+
std::uint64_t commit_group_ticket_{unset_commit_group_ticket}; // 5
110+
};
111+
112+
} // namespace binsrv::event
113+
114+
#endif // BINSRV_EVENT_GTID_LOG_BODY_HPP
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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_GTID_LOG_BODY_FWD_HPP
17+
#define BINSRV_EVENT_GTID_LOG_BODY_FWD_HPP
18+
19+
#include <iosfwd>
20+
21+
namespace binsrv::event {
22+
23+
class gtid_log_body;
24+
25+
std::ostream &operator<<(std::ostream &output, const gtid_log_body &obj);
26+
27+
} // namespace binsrv::event
28+
29+
#endif // BINSRV_EVENT_GTID_LOG_BODY_FWD_HPP

0 commit comments

Comments
 (0)