|
| 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 |
0 commit comments