-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreader_context.hpp
More file actions
123 lines (103 loc) · 4.2 KB
/
reader_context.hpp
File metadata and controls
123 lines (103 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright (c) 2023-2024 Percona and/or its affiliates.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, version 2.0,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License, version 2.0, for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef BINSRV_EVENT_READER_CONTEXT_HPP
#define BINSRV_EVENT_READER_CONTEXT_HPP
#include "binsrv/event/reader_context_fwd.hpp" // IWYU pragma: export
#include <cstdint>
#include "binsrv/replication_mode_type_fwd.hpp"
#include "binsrv/gtids/gtid.hpp"
#include "binsrv/event/common_header_fwd.hpp"
#include "binsrv/event/event_fwd.hpp"
#include "binsrv/event/protocol_traits.hpp"
namespace binsrv::event {
class [[nodiscard]] reader_context {
friend class event;
public:
reader_context(std::uint32_t encoded_server_version, bool verify_checksum,
replication_mode_type replication_mode);
[[nodiscard]] std::uint32_t
get_current_encoded_server_version() const noexcept {
return encoded_server_version_;
}
[[nodiscard]] bool get_current_verify_checksum() const noexcept {
return verify_checksum_;
}
[[nodiscard]] std::size_t
get_current_post_header_length(code_type code) const noexcept;
[[nodiscard]] std::uint32_t get_current_position() const noexcept {
return position_;
}
[[nodiscard]] bool has_transaction_gtid() const noexcept {
return !transaction_gtid_.is_empty();
}
[[nodiscard]] const gtids::gtid &get_transaction_gtid() const noexcept {
return transaction_gtid_;
}
[[nodiscard]] bool is_at_transaction_boundary() const noexcept {
return (state_ == state_type::any_other_expected &&
current_transaction_length_ == expected_transaction_length_) ||
(state_ == state_type::rotate_artificial_expected);
}
private:
// this class implements the logic of the following state machine
// (
// ROTATE(artificial)
// FORMAT_DESCRIPTION
// PREVIOUS_GTIDS_LOG?
// ((ANONYMOUS_GTID_LOG | GTID_LOG | GTID_TAGGED_LOG) <ANY>*)*
// (ROTATE | STOP)?
// )+
enum class state_type : std::uint8_t {
rotate_artificial_expected,
format_description_expected,
previous_gtids_expected,
gtid_log_expected,
any_other_expected,
rotate_or_stop_expected
};
state_type state_{state_type::rotate_artificial_expected};
std::uint32_t encoded_server_version_;
bool verify_checksum_;
replication_mode_type replication_mode_;
post_header_length_container post_header_lengths_{};
std::uint32_t position_{0U};
gtids::gtid transaction_gtid_{};
std::uint32_t expected_transaction_length_{0U};
std::uint32_t current_transaction_length_{0U};
void process_event(const event ¤t_event);
[[nodiscard]] bool
process_event_in_rotate_artificial_expected_state(const event ¤t_event);
[[nodiscard]] bool process_event_in_format_description_expected_state(
const event ¤t_event);
[[nodiscard]] bool
process_event_in_previous_gtids_expected_state(const event ¤t_event);
[[nodiscard]] bool
process_event_in_gtid_log_expected_state(const event ¤t_event);
[[nodiscard]] bool
process_event_in_any_other_expected_state(const event ¤t_event);
[[nodiscard]] bool
process_event_in_rotate_or_stop_expected_state(const event ¤t_event);
void validate_position(const common_header &common_header) const;
void validate_position_and_advance(const common_header &common_header);
void reset_position();
void start_transaction(const event ¤t_event);
void update_transaction(const common_header &common_header);
void finish_transaction();
[[nodiscard]] static const post_header_length_container &
get_hardcoded_post_header_lengths(
std::uint32_t encoded_server_version) noexcept;
};
} // namespace binsrv::event
#endif // BINSRV_EVENT_READER_CONTEXT_HPP