Debian Codegraph @

storage/innobase/include/lob0util.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 lob0util_h
28 #define lob0util_h
29
30 #include <stdint.h>
31
32 #include "buf0buf.h"
33 #include "fil0fil.h"
34 #include "fut0lst.h"
35
36 namespace lob {
37
38 /** Number of times an LOB can be partially updated. Once this limit is
39 reached, then the LOB will be fully updated. */
40 const uint32_t MAX_PARTIAL_UPDATE_LIMIT = 1000;
41
42 struct basic_page_t {
43 basic_page_t() : m_block(nullptr), m_mtr(nullptr), m_index(nullptr) {}
44
45 basic_page_t(buf_block_t *block, mtr_t *mtr)
46 : m_block(block), m_mtr(mtr), m_index(nullptr) {}
47
48 basic_page_t(buf_block_t *block, mtr_t *mtr, dict_index_t *index)
49 : m_block(block), m_mtr(mtr), m_index(index) {}
50
51 /** Update the space identifier to given value without generating
52 any redo log records.
53 @param[in] space_id the space identifier. */
54 void set_space_id_no_redo(space_id_t space_id) {
55 mach_write_to_4(frame() + FIL_PAGE_SPACE_ID, space_id);
56 }
57
58 /** Get page number of the current page.
59 @return the page number of the current page. */
60 page_no_t get_page_no() const {
61 ut_ad(m_block != nullptr);
62 return (m_block->page.id.page_no());
63 }
64
65 /** Get the page id of the current page.
66 @return the page id of current page. */
67 page_id_t get_page_id() const {
68 ut_ad(m_block != nullptr);
69 return (m_block->page.id);
70 }
71
72 /** Set the FIL_PAGE_NEXT to the given page number, using the given mini
73 transaction context.
74 @param[in] page_no The page number to set.
75 @param[in] mtr The mini-transaction context. */
76 void set_next_page(page_no_t page_no, mtr_t *mtr) {
77 mlog_write_ulint(frame() + FIL_PAGE_NEXT, page_no, MLOG_4BYTES, mtr);
78 }
79
80 /** Set the FIL_PAGE_NEXT to the given page number.
81 @param[in] page_no The page number to set. */
82 void set_next_page(page_no_t page_no) { set_next_page(page_no, m_mtr); }
83
84 /** Set the FIL_PAGE_NEXT to FIL_NULL. */
85 void set_next_page_null() {
86 ut_ad(m_mtr != nullptr);
87
88 set_next_page(FIL_NULL);
89 }
90
91 page_no_t get_next_page() {
92 return (mach_read_from_4(frame() + FIL_PAGE_NEXT));
93 }
94
95 page_type_t get_page_type() const {
96 return (mach_read_from_2(frame() + FIL_PAGE_TYPE));
97 }
98
99 byte *frame() const { return (buf_block_get_frame(m_block)); }
100
101 flst_node_t *get_flst_node(const fil_addr_t &addr) {
102 ut_ad(!addr.is_null());
103
104 flst_node_t *node = nullptr;
105 if (addr.page == get_page_no()) {
106 node = frame() + addr.boffset;
107 }
108 return (node);
109 }
110
111 static ulint payload();
112 ulint max_space_available();
113
114 /** Get the underlying buffer block.
115 @return the buffer block. */
116 [[nodiscard]] buf_block_t *get_block() const noexcept;
117
118 void set_block(buf_block_t *block) {
119 ut_ad(mtr_memo_contains(m_mtr, block, MTR_MEMO_PAGE_X_FIX) ||
120 mtr_memo_contains(m_mtr, block, MTR_MEMO_PAGE_S_FIX));
121
122 m_block = block;
123 }
124
125 void set_mtr(mtr_t *mtr) { m_mtr = mtr; }
126
127 protected:
128 buf_block_t *m_block;
129 mtr_t *m_mtr;
130 dict_index_t *m_index;
131 };
132
133 [[nodiscard]] inline buf_block_t *basic_page_t::get_block() const noexcept {
134 return m_block;
135 }
136
137 /** Allocate one LOB page.
138 @param[in] index Index in which LOB exists.
139 @param[in] lob_mtr Mini-transaction context.
140 @param[in] hint Hint page number for allocation.
141 @param[in] bulk true if operation is OPCODE_INSERT_BULK,
142 false otherwise.
143 @return the allocated block of the BLOB page or nullptr. */
144 buf_block_t *alloc_lob_page(dict_index_t *index, mtr_t *lob_mtr, page_no_t hint,
145 bool bulk);
146
147 /** Check if the index entry is visible to the given transaction.
148 @param[in] index the index to which LOB belongs.
149 @param[in] trx the transaction reading the index entry.
150 @param[in] entry_trx_id the trx id in the index entry. */
151 bool entry_visible_to(dict_index_t *index, trx_t *trx, trx_id_t entry_trx_id);
152
153 } /* namespace lob */
154
155 #endif /* lob0util_h */