Debian Codegraph @

storage/innobase/include/zlob0first.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 zlob0first_h
28 #define zlob0first_h
29
30 #include "fil0types.h"
31 #include "fut0lst.h"
32 #include "lob0impl.h"
33 #include "univ.i"
34
35 namespace lob {
36
37 /** The first page of an zlob. */
38 struct z_first_page_t {
39 /** Version information. One byte. */
40 static const ulint OFFSET_VERSION = FIL_PAGE_DATA;
41
42 /** One byte of flag bits. Currently only one bit (the least
43 significant bit) is used, other 7 bits are available for future use.*/
44 static const ulint OFFSET_FLAGS = FIL_PAGE_DATA + 1;
45
46 /** LOB version. 4 bytes.*/
47 static const uint32_t OFFSET_LOB_VERSION = OFFSET_FLAGS + 1;
48
49 /** The last transaction that modified this LOB. */
50 static const ulint OFFSET_LAST_TRX_ID = OFFSET_LOB_VERSION + 4;
51
52 /** The last transaction that modified this LOB. */
53 static const ulint OFFSET_LAST_UNDO_NO = OFFSET_LAST_TRX_ID + 6;
54
55 /** The length of compressed data stored in this page. */
56 static const ulint OFFSET_DATA_LEN = OFFSET_LAST_UNDO_NO + 4;
57
58 /** The transaction that created data in the data portion. */
59 static const ulint OFFSET_TRX_ID = OFFSET_DATA_LEN + 4;
60
61 /** The next index page. */
62 static const ulint OFFSET_INDEX_PAGE_NO = OFFSET_TRX_ID + 6;
63
64 /** The next frag nodes page. */
65 static const ulint OFFSET_FRAG_NODES_PAGE_NO = OFFSET_INDEX_PAGE_NO + 4;
66
67 /** List of free index entries. */
68 static const ulint OFFSET_FREE_LIST = OFFSET_FRAG_NODES_PAGE_NO + 4;
69
70 /** List of index entries. */
71 static const ulint OFFSET_INDEX_LIST = OFFSET_FREE_LIST + FLST_BASE_NODE_SIZE;
72
73 /** List of free frag entries. */
74 static const ulint OFFSET_FREE_FRAG_LIST =
75 OFFSET_INDEX_LIST + FLST_BASE_NODE_SIZE;
76
77 /** List of frag entries. */
78 static const ulint OFFSET_FRAG_LIST =
79 OFFSET_FREE_FRAG_LIST + FLST_BASE_NODE_SIZE;
80
81 /** Begin of index entries. */
82 static const ulint OFFSET_INDEX_BEGIN =
83 OFFSET_FRAG_LIST + FLST_BASE_NODE_SIZE;
84
85 /** Given the page size, what is the number of index entries the
86 first page can contain. */
87 ulint get_n_index_entries() const;
88
89 /** Given the page size, what is the number of frag entries the
90 first page can contain. */
91 ulint get_n_frag_entries() const;
92
93 ulint size_of_index_entries() const;
94
95 ulint size_of_frag_entries() const {
96 return (z_frag_entry_t::SIZE * get_n_frag_entries());
97 }
98
99 ulint begin_frag_entries() const {
100 return (OFFSET_INDEX_BEGIN + size_of_index_entries());
101 }
102
103 ulint begin_data() const {
104 return (begin_frag_entries() + size_of_frag_entries());
105 }
106
107 bool is_empty() const {
108 flst_base_node_t *flst = index_list();
109 return (flst_get_len(flst) == 0);
110 }
111
112 /** Get the length of the index list.
113 @return length of the index list. */
114 ulint get_index_list_length() const {
115 flst_base_node_t *flst = index_list();
116 return (flst_get_len(flst));
117 }
118
119 void set_version_0() {
120 mlog_write_ulint(frame() + OFFSET_VERSION, 0, MLOG_1BYTE, m_mtr);
121 }
122
123 byte *begin_data_ptr() const { return (frame() + begin_data()); }
124
125 /** Amount of zlob data that can be stored in first page (in bytes). */
126 ulint payload() {
127 page_size_t page_size(dict_table_page_size(m_index->table));
128 ut_ad(begin_data() + FIL_PAGE_DATA_END < page_size.physical());
129 return (page_size.physical() - begin_data() - FIL_PAGE_DATA_END);
130 }
131
132 z_first_page_t() : m_block(nullptr), m_mtr(nullptr), m_index(nullptr) {}
133
134 z_first_page_t(mtr_t *mtr, dict_index_t *index)
135 : m_block(nullptr), m_mtr(mtr), m_index(index) {}
136
137 z_first_page_t(buf_block_t *block) : m_block(block) {}
138
139 z_first_page_t(buf_block_t *block, mtr_t *mtr, dict_index_t *index)
140 : m_block(block), m_mtr(mtr), m_index(index) {}
141
142 buf_block_t *alloc(bool bulk);
143
144 void import(trx_id_t trx_id);
145
146 page_type_t get_page_type() const {
147 return (mach_read_from_2(frame() + FIL_PAGE_TYPE));
148 }
149
150 /** Load the given page number as the first page in x-latch mode.
151 @param[in] page_no the first page number.
152 @return the buffer block of the given page number. */
153 buf_block_t *load_x(page_no_t page_no) {
154 page_id_t page_id(dict_index_get_space(m_index), page_no);
155 page_size_t page_size(dict_table_page_size(m_index->table));
156 m_block =
157 buf_page_get(page_id, page_size, RW_X_LATCH, UT_LOCATION_HERE, m_mtr);
158 return (m_block);
159 }
160
161 /** Load the first page using given mini-transaction. The first page must
162 already be x-latched by the m_mtr.
163 @param[in] mtr the mini-transaction in which first page is to be loaded.
164 @return the buffer block of first page. */
165 buf_block_t *load_x(mtr_t *mtr) const {
166 ut_ad(mtr_memo_contains(m_mtr, m_block, MTR_MEMO_PAGE_X_FIX));
167 buf_block_t *tmp = buf_page_get(m_block->page.id, m_index->get_page_size(),
168 RW_X_LATCH, UT_LOCATION_HERE, mtr);
169 ut_ad(tmp == m_block);
170 return (tmp);
171 }
172
173 /** Load the first page of the compressed LOB with x-latch.
174 @param[in] page_id the page identifier of first page
175 @param[in] page_size the page size information of table.
176 @return buffer block of the first page. */
177 buf_block_t *load_x(const page_id_t &page_id, const page_size_t &page_size);
178
179 /** Load the given page number as the first page in s-latch mode.
180 @param[in] page_no the first page number.
181 @return the buffer block of the given page number. */
182 buf_block_t *load_s(page_no_t page_no) {
183 ut_ad(m_block == nullptr);
184
185 page_id_t page_id(dict_index_get_space(m_index), page_no);
186 page_size_t page_size(dict_table_page_size(m_index->table));
187 m_block =
188 buf_page_get(page_id, page_size, RW_S_LATCH, UT_LOCATION_HERE, m_mtr);
189 return (m_block);
190 }
191
192 /** Deallocate the first page of a compressed LOB. */
193 void dealloc();
194
195 /** Set the FIL_PAGE_NEXT to FIL_NULL. */
196 void set_next_page_null() { set_next_page_no(FIL_NULL, m_mtr); }
197
198 /** Set the FIL_PAGE_PREV to FIL_NULL. */
199 void set_prev_page_null() { set_prev_page_no(FIL_NULL, m_mtr); }
200
201 /** Set the FIL_PAGE_NEXT to the given value.
202 @param[in] page_no the page number to set in FIL_PAGE_NEXT.
203 @param[in] mtr mini trx to be used for this modification. */
204 void set_next_page_no(page_no_t page_no, mtr_t *mtr) {
205 ut_ad(mtr != nullptr);
206 mlog_write_ulint(frame() + FIL_PAGE_NEXT, page_no, MLOG_4BYTES, mtr);
207 }
208
209 /** Set the FIL_PAGE_PREV to the given value.
210 @param[in] page_no the page number to set in FIL_PAGE_PREV.
211 @param[in] mtr mini trx to be used for this modification. */
212 void set_prev_page_no(page_no_t page_no, mtr_t *mtr) {
213 ut_ad(mtr != nullptr);
214 mlog_write_ulint(frame() + FIL_PAGE_PREV, page_no, MLOG_4BYTES, mtr);
215 }
216
217 /** Write the space identifier to the page header, without generating
218 redo log records.
219 @param[in] space_id the space identifier. */
220 void set_space_id_no_redo(space_id_t space_id) {
221 mlog_write_ulint(frame() + FIL_PAGE_SPACE_ID, space_id, MLOG_4BYTES,
222 nullptr);
223 }
224
225 void init() {
226 ut_ad(m_mtr != nullptr);
227
228 set_page_type();
229 set_version_0();
230 set_data_len(0);
231 set_next_page_null();
232 set_prev_page_null();
233 set_trx_id(0);
234 flst_base_node_t *flst = free_list();
235 flst_init(flst, m_mtr);
236 flst_base_node_t *ilst = index_list();
237 flst_init(ilst, m_mtr);
238 flst_base_node_t *free_frag_lst = free_frag_list();
239 flst_init(free_frag_lst, m_mtr);
240 flst_base_node_t *frag_lst = frag_list();
241 flst_init(frag_lst, m_mtr);
242 init_index_entries();
243 init_frag_entries();
244 set_frag_node_page_no(FIL_NULL);
245 set_index_page_no(FIL_NULL);
246 }
247
248 /** Get the amount of zlob data stored in this page. */
249 ulint get_data_len() const {
250 return (mach_read_from_4(frame() + OFFSET_DATA_LEN));
251 }
252
253 /** Get the page number. */
254 page_no_t get_page_no() const { return (m_block->page.id.page_no()); }
255
256 /** Get the page id of the first page of compressed LOB.
257 @return page id of the first page of compressed LOB. */
258 page_id_t get_page_id() const {
259 ut_ad(m_block != nullptr);
260
261 return (m_block->page.id);
262 }
263
264 fil_addr_t get_self_addr() const {
265 page_no_t page_no = get_page_no();
266 uint32_t offset = static_cast<uint32_t>(begin_data());
267 return (fil_addr_t(page_no, offset));
268 }
269
270 /** All the index pages are singly linked with each other, and
271 the first page contains the link to one index page.
272 @param[in] page_no the page number of an index page. */
273 void set_index_page_no(page_no_t page_no) {
274 set_index_page_no(page_no, m_mtr);
275 }
276
277 /** All the index pages are singly linked with each other, and
278 the first page contains the link to one index page.
279 @param[in] page_no the page number of an index page.
280 @param[in] mtr use this mini transaction context for redo logs. */
281 void set_index_page_no(page_no_t page_no, mtr_t *mtr) {
282 ut_ad(m_mtr != nullptr);
283 mlog_write_ulint(frame() + OFFSET_INDEX_PAGE_NO, page_no, MLOG_4BYTES, mtr);
284 }
285
286 /** All the index pages are singly linked with each other, and
287 the first page contains the link to one index page. Get that index
288 page number.
289 @return the index page number. */
290 page_no_t get_index_page_no() const {
291 return (mach_read_from_4(frame() + OFFSET_INDEX_PAGE_NO));
292 }
293
294 /** All the fragment pages are doubly linked with each other, and
295 the first page contains the link to one fragment page in FIL_PAGE_PREV. Get
296 that frag page number.
297 @return the frag page number. */
298 page_no_t get_frag_page_no() const { return (m_block->get_prev_page_no()); }
299
300 /** All the fragment pages are doubly linked with each other, and
301 the first page contains the link to one fragment page in FIL_PAGE_PREV. Get
302 that frag page number.
303 @param[in] mtr Mini-transaction to use for this read operation.
304 @return the frag page number. */
305 page_no_t get_frag_page_no(mtr_t *mtr) const {
306 return (mtr_read_ulint(frame() + FIL_PAGE_PREV, MLOG_4BYTES, mtr));
307 }
308
309 #ifdef UNIV_DEBUG
310 /** Verify that the page number pointed to by FIL_PAGE_PREV of the first page
311 of LOB is indeed a fragment page. It uses its own mtr internally.
312 @return true if it is a fragment page, false otherwise. */
313 bool verify_frag_page_no();
314 #endif /* UNIV_DEBUG */
315
316 /** All the fragment pages (@see z_frag_page_t) are doubly linked with each
317 other, and the first page contains the link to one fragment page in
318 FIL_PAGE_PREV.
319 @param[in] mtr Mini-transaction for this modification.
320 @param[in] page_no The page number of a fragment page. */
321 void set_frag_page_no(mtr_t *mtr, page_no_t page_no) {
322 ut_ad(verify_frag_page_no());
323 set_prev_page_no(page_no, mtr);
324 }
325
326 /** All the fragment pages (@see z_frag_page_t) are doubly linked with each
327 other, and the first page contains the link to one fragment page in
328 FIL_PAGE_PREV.
329 @param[in] page_no the page number of a fragment page. */
330 void set_frag_page_no(page_no_t page_no) {
331 ut_ad(verify_frag_page_no());
332 set_prev_page_no(page_no, m_mtr);
333 }
334
335 /** All the frag node pages (@see z_frag_node_page_t) are singly linked with
336 each other, and the first page contains the link to the last allocated frag
337 node page. The last allocated FIL_PAGE_TYPE_ZLOB_FRAG_ENTRY page will be the
338 first in this list. This list is used to free these pages.
339 @param[in] page_no the page number of an frag node page. */
340 void set_frag_node_page_no(page_no_t page_no) {
341 set_frag_node_page_no(page_no, m_mtr);
342 }
343
344 /** All the frag node pages (@see z_frag_node_page_t) are singly linked with
345 each other, and the first page contains the link to the last allocated frag
346 node page. The last allocated FIL_PAGE_TYPE_ZLOB_FRAG_ENTRY page will be the
347 first in this list. This list is used to free these pages.
348 @param[in] page_no the page number of an frag node page.
349 @param[in] mtr mini trx context to generate redo logs. */
350 void set_frag_node_page_no(page_no_t page_no, mtr_t *mtr) {
351 ut_ad(mtr != nullptr);
352 mlog_write_ulint(frame() + OFFSET_FRAG_NODES_PAGE_NO, page_no, MLOG_4BYTES,
353 mtr);
354 }
355
356 /** Free all the z_frag_page_t pages. All the z_frag_page_t pages are
357 singly linked to each other. The head of the list is maintained in the
358 first page.
359 @return the number of pages freed. */
360 size_t free_all_frag_node_pages();
361
362 /** Free all the index pages.
363 @return the number of pages freed. */
364 size_t free_all_index_pages();
365
366 /** Free all the fragment pages.
367 @return the number of pages freed. */
368 size_t free_all_frag_pages();
369
370 private:
371 /** Free all the fragment pages when the next page of the first LOB page IS
372 NOT USED to link the fragment pages.
373 @return the number of pages freed. */
374 size_t free_all_frag_pages_old();
375
376 /** Free all the fragment pages when the next page of the first LOB page IS
377 USED to link the fragment pages.
378 @return the number of pages freed. */
379 size_t free_all_frag_pages_new();
380
381 public:
382 /** Free all the data pages.
383 @return the number of pages freed. */
384 size_t free_all_data_pages();
385
386 /** All the frag node pages are singly linked with each other, and the
387 first page contains the link to one frag node page. Get that frag node
388 page number.
389 @return the index page number. */
390 page_no_t get_frag_node_page_no() {
391 return (mach_read_from_4(frame() + OFFSET_FRAG_NODES_PAGE_NO));
392 }
393
394 /** Set the page type to FIL_PAGE_TYPE_UNKNOWN. This is done while
395 deallocating this page. */
396 void set_page_type_unknown() {
397 ut_ad(m_mtr != nullptr);
398 mlog_write_ulint(frame() + FIL_PAGE_TYPE, FIL_PAGE_TYPE_UNKNOWN,
399 MLOG_2BYTES, m_mtr);
400 }
401
402 void set_page_type() {
403 ut_ad(m_mtr != nullptr);
404 mlog_write_ulint(frame() + FIL_PAGE_TYPE, FIL_PAGE_TYPE_ZLOB_FIRST,
405 MLOG_2BYTES, m_mtr);
406 }
407
408 void set_data_len(ulint len) {
409 ut_ad(m_mtr != nullptr);
410 mlog_write_ulint(frame() + OFFSET_DATA_LEN, len, MLOG_4BYTES, m_mtr);
411 }
412
413 /** Update the trx id in the header.
414 @param[in] tid the given transaction identifier. */
415 void set_trx_id(trx_id_t tid) {
416 byte *ptr = frame() + OFFSET_TRX_ID;
417 mach_write_to_6(ptr, tid);
418 mlog_log_string(ptr, 6, m_mtr);
419 }
420
421 /** Update the trx id in the header, without generating redo
422 log records.
423 @param[in] tid the given transaction identifier. */
424 void set_trx_id_no_redo(trx_id_t tid) {
425 byte *ptr = frame() + OFFSET_TRX_ID;
426 mach_write_to_6(ptr, tid);
427 }
428
429 /** Initialize the LOB version to 1. */
430 void init_lob_version() {
431 ut_ad(m_mtr != nullptr);
432
433 mlog_write_ulint(frame() + OFFSET_LOB_VERSION, 1, MLOG_4BYTES, m_mtr);
434 }
435
436 /** Get the LOB version
437 @return the LOB version. */
438 uint32_t get_lob_version() {
439 return (mach_read_from_4(frame() + OFFSET_LOB_VERSION));
440 }
441
442 /** Increment LOB version by 1. */
443 uint32_t incr_lob_version();
444
445 /** Get one byte of flags
446 @return one byte of flags. */
447 uint8_t get_flags() { return (mach_read_from_1(frame() + OFFSET_FLAGS)); }
448
449 /** When the bit is set, the LOB is not partially updatable anymore.
450 @return true, if partially updatable.
451 @return false, if partially NOT updatable. */
452 bool can_be_partially_updated() {
453 uint8_t flags = get_flags();
454 return (!(flags & 0x01));
455 }
456
457 /** When the bit is set, the LOB is not partially updatable anymore.
458 Enable the bit.
459 @param[in] trx the current transaction.*/
460 void mark_cannot_be_partially_updated(trx_t *trx);
461
462 void set_last_trx_id(trx_id_t tid) {
463 byte *ptr = frame() + OFFSET_LAST_TRX_ID;
464 mach_write_to_6(ptr, tid);
465 mlog_log_string(ptr, 6, m_mtr);
466 }
467
468 /** Update the last transaction identifier in the header, without
469 generating redo logs.
470 @param[in] tid given transaction identifier.*/
471 void set_last_trx_id_no_redo(trx_id_t tid) {
472 byte *ptr = frame() + OFFSET_LAST_TRX_ID;
473 mach_write_to_6(ptr, tid);
474 }
475
476 void set_last_trx_undo_no(undo_no_t undo_no) {
477 ut_ad(m_mtr != nullptr);
478
479 byte *ptr = frame() + OFFSET_LAST_UNDO_NO;
480 mlog_write_ulint(ptr, undo_no, MLOG_4BYTES, m_mtr);
481 }
482
483 trx_id_t get_last_trx_id() const {
484 byte *ptr = frame() + OFFSET_LAST_TRX_ID;
485 return (mach_read_from_6(ptr));
486 }
487
488 undo_no_t get_last_trx_undo_no() const {
489 byte *ptr = frame() + OFFSET_LAST_UNDO_NO;
490 return (mach_read_from_4(ptr));
491 }
492
493 flst_base_node_t *free_list() const { return (frame() + OFFSET_FREE_LIST); }
494
495 flst_base_node_t *index_list() const { return (frame() + OFFSET_INDEX_LIST); }
496
497 flst_base_node_t *free_frag_list() const {
498 return (frame() + OFFSET_FREE_FRAG_LIST);
499 }
500
501 flst_base_node_t *frag_list() const { return (frame() + OFFSET_FRAG_LIST); }
502
503 void init_frag_entries() {
504 flst_base_node_t *free_frag_lst = free_frag_list();
505 ulint n = get_n_frag_entries();
506 for (ulint i = 0; i < n; ++i) {
507 flst_node_t *ptr = frame() + begin_frag_entries();
508 ptr += (i * z_frag_entry_t::SIZE);
509 z_frag_entry_t frag_entry(ptr, m_mtr);
510 frag_entry.init();
511 frag_entry.push_back(free_frag_lst);
512 }
513 }
514
515 void init_index_entries();
516
517 /** Allocate a fragment of the given size. This involves finding a
518 fragment page, that has space to store len bytes of data. If necessary,
519 allocate a new fragment page.
520 @param[in] bulk true if it is bulk operation
521 (OPCODE_INSERT_BULK), false otherwise.
522 @param[in] len length of data to be stored in
523 fragment page.
524 @param[out] frag_page the fragment page with the needed
525 free space.
526 @param[out] entry fragment page entry representing frag_page.
527 @return fragment identifier within the fragment page.
528 @return FRAG_ID_NULL if fragment could not be allocated. */
529 frag_id_t alloc_fragment(bool bulk, ulint len, z_frag_page_t &frag_page,
530 z_frag_entry_t &entry);
531
532 /** Allocate one index entry. If there is no free index entry,
533 allocate an index page (a page full of z_index_entry_t objects)
534 and service the request.
535 @return the allocated index entry. */
536 z_index_entry_t alloc_index_entry(bool bulk);
537
538 /** Allocate one frag page entry. If there is no free frag
539 entry, allocate an frag node page (a page full of z_frag_entry_t
540 objects) and service the request.
541 @return the allocated frag entry. */
542 z_frag_entry_t alloc_frag_entry(bool bulk);
543
544 /** Print the index entries. */
545 std::ostream &print_index_entries(std::ostream &out) const;
546
547 /** Print the index entries. */
548 std::ostream &print_frag_entries(std::ostream &out) const;
549
550 /** Print the page. */
551 std::ostream &print(std::ostream &out) const;
552
553 byte *frame() const { return (buf_block_get_frame(m_block)); }
554
555 /** Load the page, in x-latch mode, containing the given file address.
556 @param[in] addr given file address
557 @return the file list node pointer. */
558 flst_node_t *addr2ptr_x(fil_addr_t &addr) const {
559 return (addr2ptr_x(addr, m_mtr));
560 }
561
562 /** Load the page, in x-latch mode, containing the given file address.
563 @param[in] addr given file address
564 @param[in] mtr the mini-transaction context to be used.
565 @return the file list node pointer. */
566 flst_node_t *addr2ptr_x(fil_addr_t &addr, mtr_t *mtr) const {
567 space_id_t space = dict_index_get_space(m_index);
568 const page_size_t page_size = dict_table_page_size(m_index->table);
569 return (fut_get_ptr(space, page_size, addr, RW_X_LATCH, mtr));
570 }
571
572 /** Load the page, in s-latch mode, containing the given file address.
573 @param[in] addr given file address
574 @return the file list node pointer. */
575 flst_node_t *addr2ptr_s(fil_addr_t &addr) {
576 space_id_t space = dict_index_get_space(m_index);
577 const page_size_t page_size = dict_table_page_size(m_index->table);
578 return (fut_get_ptr(space, page_size, addr, RW_S_LATCH, m_mtr));
579 }
580
581 /** Load the entry available in the given file address.
582 @param[in] addr file address
583 @param[out] entry the entry to be loaded.*/
584 void load_entry_s(fil_addr_t &addr, z_index_entry_t &entry);
585
586 /** Load the entry available in the given file address.
587 @param[in] addr file address
588 @param[out] entry the entry to be loaded.*/
589 void load_entry_x(fil_addr_t &addr, z_index_entry_t &entry);
590
591 /** Free all the pages of the zlob.
592 @return the total number of pages freed. */
593 size_t destroy();
594
595 /** Free all the pages of the zlob except the first page.
596 @return the total number of pages freed. */
597 size_t make_empty();
598
599 #ifdef UNIV_DEBUG
600 private:
601 /** Validate the LOB. This is a costly function. We need to avoid using
602 this directly, instead call z_first_page_t::validate().
603 @return true if valid, false otherwise. */
604 bool validate_low();
605
606 public:
607 /** Validate the LOB.
608 @return true if valid, false otherwise. */
609 bool validate() {
610 static const uint32_t FREQ = 50;
611 static std::atomic<uint32_t> n{0};
612
613 bool valid = true;
614 if (++n % FREQ == 0) {
615 valid = validate_low();
616 }
617 return (valid);
618 }
619 #endif /* UNIV_DEBUG */
620
621 /** Get the buffer block of the first page of LOB.
622 @return the buffer block of the first page of LOB. */
623 buf_block_t *get_block() const { return (m_block); }
624
625 public:
626 void set_mtr(mtr_t *mtr) { m_mtr = mtr; }
627
628 /** Restart the given mtr. The first page must already be x-latched by the
629 m_mtr.
630 @param[in] mtr the mini-transaction context which is to be restarted. */
631 void restart_mtr(mtr_t *mtr) {
632 ut_ad(mtr != m_mtr);
633
634 mtr_commit(mtr);
635 mtr_start(mtr);
636 mtr->set_log_mode(m_mtr->get_log_mode());
637 load_x(mtr);
638 }
639
640 private:
641 /** The buffer block of the first page. */
642 buf_block_t *m_block;
643
644 /** The mini-transaction context. */
645 mtr_t *m_mtr;
646
647 /** The index dictionary object. */
648 dict_index_t *m_index;
649
650 }; // struct z_first_page_t
651
652 /** Overloading the global output parameter to print object of type
653 z_first_page_t into the given output stream.
654 @param[in,out] out output stream.
655 @param[in] obj object to be printed.
656 @return the output stream. */
657 inline std::ostream &operator<<(std::ostream &out, const z_first_page_t &obj) {
658 return (obj.print(out));
659 }
660
661 } /* namespace lob */
662
663 #endif /* zlob0first_h */