Debian Codegraph @

storage/innobase/include/lob0pages.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 2016, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27 #ifndef lob0pages_h
28 #define lob0pages_h
29
30 #include "lob0first.h"
31
32 namespace lob {
33
34 /** The LOB data page carrying the user data. */
35 struct data_page_t : public basic_page_t {
36 static const ulint OFFSET_VERSION = FIL_PAGE_DATA;
37 static const ulint OFFSET_DATA_LEN = OFFSET_VERSION + 1;
38 static const ulint OFFSET_TRX_ID = OFFSET_DATA_LEN + 4;
39 static const ulint LOB_PAGE_DATA = OFFSET_TRX_ID + 6;
40
41 data_page_t() = default;
42
43 /** Constructor. */
44 data_page_t(buf_block_t *block, mtr_t *mtr) : basic_page_t(block, mtr) {
45 page_type_t type = get_page_type();
46 ut_a(type == FIL_PAGE_TYPE_LOB_DATA);
47 }
48
49 data_page_t(buf_block_t *block, mtr_t *mtr, dict_index_t *index)
50 : basic_page_t(block, mtr, index) {}
51
52 data_page_t(mtr_t *mtr, dict_index_t *index)
53 : basic_page_t(nullptr, mtr, index) {}
54
55 /** Constructor.
56 @param[in] block the buffer block.*/
57 data_page_t(buf_block_t *block) : basic_page_t(block, nullptr, nullptr) {}
58
59 /** Allocate a LOB data page.
60 @param[in] alloc_mtr Mini-transaction to be used for allocation of LOB page.
61 @param[in] is_bulk true if bulk operation.
62 @return allocated buffer block or nullptr */
63 buf_block_t *alloc(mtr_t *alloc_mtr, bool is_bulk);
64
65 buf_block_t *load_x(page_no_t page_no);
66
67 void set_version_0() {
68 mlog_write_ulint(frame() + OFFSET_VERSION, 0, MLOG_1BYTE, m_mtr);
69 }
70
71 void dealloc() {
72 btr_page_free_low(m_index, m_block, ULINT_UNDEFINED, m_mtr);
73 m_block = nullptr;
74 }
75
76 void set_page_type() {
77 ut_ad(m_mtr != nullptr);
78
79 mlog_write_ulint(frame() + FIL_PAGE_TYPE, FIL_PAGE_TYPE_LOB_DATA,
80 MLOG_2BYTES, m_mtr);
81 }
82
83 void set_trx_id(trx_id_t id) {
84 byte *ptr = frame() + OFFSET_TRX_ID;
85 mach_write_to_6(ptr, id);
86 mlog_log_string(ptr, 6, m_mtr);
87 }
88
89 /** Write the trx identifier to the header, without
90 generating redo log.
91 @param[in] id the transaction identifier.*/
92 void set_trx_id_no_redo(trx_id_t id) {
93 byte *ptr = frame() + OFFSET_TRX_ID;
94 mach_write_to_6(ptr, id);
95 }
96
97 static ulint payload() {
98 return (UNIV_PAGE_SIZE - LOB_PAGE_DATA - FIL_PAGE_DATA_END);
99 }
100
101 byte *data_begin() const { return (frame() + LOB_PAGE_DATA); }
102
103 /** Create a new data page and replace some or all parts of the old data
104 with data.
105 @param[in] trx Current transaction.
106 @param[in] offset Offset where replace begins.
107 @param[in,out] ptr Pointer to new data.
108 @param[in] want Amount of data the caller wants to replace.
109 @param[in] mtr Mini-transaction context.
110 @return the buffer block of the new data page. */
111 buf_block_t *replace(trx_t *trx, ulint offset, const byte *&ptr, ulint &want,
112 mtr_t *mtr);
113
114 /** Replace some or all parts of the data inline.
115 @param[in] offset Offset where replace begins.
116 @param[in,out] ptr Pointer to new data.
117 @param[in] want Amount of data the caller wants to replace.
118 @param[in] mtr Mini-transaction context. */
119 void replace_inline(ulint offset, const byte *&ptr, ulint &want, mtr_t *mtr);
120
121 ulint get_data_len() const {
122 return (mach_read_from_4(frame() + OFFSET_DATA_LEN));
123 }
124
125 void set_data_len(ulint len) {
126 ut_ad(m_mtr != nullptr);
127
128 mlog_write_ulint(frame() + OFFSET_DATA_LEN, len, MLOG_4BYTES, m_mtr);
129 }
130
131 /** Read data from the data page.
132 @param[in] offset read begins at this offset.
133 @param[out] ptr the output buffer.
134 @param[in] want bytes to read
135 @return bytes actually read. */
136 ulint read(ulint offset, byte *ptr, ulint want);
137
138 /** Write data into a data page.
139 @param[in,out] data the data to be written. it will be updated to
140 point to the byte not yet written.
141 @param[in,out] len length of data to be written.
142 @return amount of data actually written into the page. */
143 ulint write(const byte *&data, ulint &len);
144
145 /** Append given data in data page.
146 @param[in] trxid transaction doing append.
147 @param[in,out] data data to be appended.
148 @param[in,out] len length of data.
149 @return number of bytes appended. */
150 ulint append(trx_id_t trxid, byte *&data, ulint &len);
151
152 std::pair<ulint, byte *> insert_middle(trx_t *trx, ulint offset, byte *&data,
153 ulint &len, buf_block_t *&new_block);
154
155 buf_block_t *remove_middle(trx_t *trx, ulint offset, ulint &len);
156
157 ulint max_space_available() const { return (payload()); }
158
159 ulint space_left() const;
160 };
161
162 } /* namespace lob */
163
164 #endif /* lob0pages_h */