MySQL 26.7.0
Source Code Documentation
data_source.h
Go to the documentation of this file.
1// Copyright (c) 2026, Oracle 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 designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23
24#ifndef MYSQL_CSA_STORAGE_RELAY_LOG_DATA_SOURCE_H
25#define MYSQL_CSA_STORAGE_RELAY_LOG_DATA_SOURCE_H
26
27#include <atomic>
28#include <cstdint>
29#include <cstring>
30#include <memory>
31#include <string>
32#include <vector>
33
35
36namespace mysql::csa {
37
38class Data_source;
39using Data_source_sptr = std::shared_ptr<Data_source>;
40
41/// @brief Represents a cached chunk of data that comes from the specific relay
42/// log file (events / headers may cross boundaries of Data_source, but
43/// one Data_source does not spread across multiple relay log files)
44/// Keeps track of the number of bytes currently in use
46 public:
48 using Data_type = std::vector<uint8_t, Memory_allocator>;
49 /// @brief Construct from a vector of bytes and metadata of the relay log file
50 /// this data was fetched from
51 /// @param data Data_source gets ownership of this data
52 /// @param file_name The relay log file path and name (full path)
53 /// @param file_offset The relay log file offset starting from which data
54 /// was fetched
55 /// @param file_length The number of bytes in the `file_name` file
56 /// @param ends_file True if this data batch ends the file
57 Data_source(Data_type &&data, const std::string &file_name,
58 std::size_t file_offset, std::size_t file_length, bool ends_file);
59 /// @brief Accesses fetched data
60 /// @return Const reference to bytes fetched
61 const Data_type &data() const;
62 /// @brief Accesses raw data (reading)
63 uint8_t *data_raw();
64 /// @brief Obtains data size
65 /// @return data size
66 std::size_t size() const;
67 /// @brief Get source file name
68 /// @return Source file name
69 const std::string &get_file_name() const;
70 /// @brief Get source file length
71 /// @return Source file length (number of bytes in the file)
72 std::size_t get_file_length() const;
73 /// @brief Return current batch file offset
74 /// @return This batch file offset
75 std::size_t get_file_offset() const;
76 /// Checks if this data chunk ends the file
77 /// @return True if this data chunk ends the file, false otherwise
78 bool ends_file() const;
79 /// @brief Destructs object
80 virtual ~Data_source();
81
82 private:
83 /// Cached chunk of data
85 /// Variable to track the number of cached bytes used
86 static std::atomic<std::size_t> m_used_bytes;
87 /// Source relay log name
88 std::string m_file_name{""};
89 /// Source relay log offset
90 std::size_t m_file_offset{0};
91 /// Source file length
92 std::size_t m_file_length{0};
93 /// True if EOF appears after this data chunk
94 bool m_is_eof{false};
95};
96
97} // namespace mysql::csa
98
99#endif // MYSQL_CSA_STORAGE_RELAY_LOG_DATA_SOURCE_H
Represents a cached chunk of data that comes from the specific relay log file (events / headers may c...
Definition: data_source.h:45
Data_source(Data_type &&data, const std::string &file_name, std::size_t file_offset, std::size_t file_length, bool ends_file)
Construct from a vector of bytes and metadata of the relay log file this data was fetched from.
Definition: data_source.cpp:32
const std::string & get_file_name() const
Get source file name.
Definition: data_source.cpp:51
std::vector< uint8_t, Memory_allocator > Data_type
Definition: data_source.h:48
static std::atomic< std::size_t > m_used_bytes
Variable to track the number of cached bytes used.
Definition: data_source.h:86
const Data_type & data() const
Accesses fetched data.
Definition: data_source.cpp:45
std::size_t size() const
Obtains data size.
Definition: data_source.cpp:49
bool m_is_eof
True if EOF appears after this data chunk.
Definition: data_source.h:94
std::size_t get_file_length() const
Get source file length.
Definition: data_source.cpp:53
virtual ~Data_source()
Destructs object.
Definition: data_source.cpp:47
std::size_t m_file_offset
Source relay log offset.
Definition: data_source.h:90
uint8_t * data_raw()
Accesses raw data (reading)
Definition: data_source.cpp:43
bool ends_file() const
Checks if this data chunk ends the file.
Definition: data_source.cpp:57
std::size_t m_file_length
Source file length.
Definition: data_source.h:92
Data_type m_data
Cached chunk of data.
Definition: data_source.h:84
std::size_t get_file_offset() const
Return current batch file offset.
Definition: data_source.cpp:55
std::string m_file_name
Source relay log name.
Definition: data_source.h:88
Allocator class that uses a polymorphic Memory_resource to allocate memory.
std::string file_name(Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0pre_8_0_30.cc:45
Definition: channel.cpp:28
std::shared_ptr< Data_source > Data_source_sptr
Definition: data_source.h:39