MySQL 26.10.0
Source Code Documentation
btr0mtib.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2023, 2026, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/btr0mtib.h
29
30 Multi Threaded Index Build (MTIB) using BUF_BLOCK_MEMORY and dedicated
31 Bulk_flusher threads.
32
33 Created 09/Feb/2023 Annamalai Gurusami
34 *************************************************************************/
35
36#ifndef btr0mtib_h
37#define btr0mtib_h
38
39#include <cstddef>
40#include <vector>
41
42#include "api0api.h"
43#include "btr0load.h"
44#include "ddl0impl-compare.h"
45#include "dict0dict.h"
46#include "lob0bulk.h"
47#include "lob0lob.h"
48#include "page0cur.h"
49#include "row0mysql.h"
50#include "ut0class_life_cycle.h"
51#include "ut0new.h"
52#include "ut0object_cache.h"
53
54/* The Btree_multi namespace is used for multi-threaded parallel index build. */
55namespace Btree_multi {
56
57// Forward declaration.
58class Page_load;
59class Btree_load;
60struct Page_stat;
61
62using Blob_context = void *;
63
64namespace bulk {
65class Blob_inserter;
66} // namespace bulk
67
68/** Allocate, use, manage and flush one extent pages (FSP_EXTENT_SIZE). */
70 using Page_range_t = std::pair<page_no_t, page_no_t>;
71
72 /** Constructor.
73 @param[in] btree_load B-tree loader object.
74 @param[in] is_leaf true if this is part of leaf segment, false if this is
75 part of non-leaf (or top) segment. */
76 Page_extent(Btree_load *btree_load, const bool is_leaf);
77
78 /** Destructor. */
80
81 /** Next page number to be used. */
83
84 /** Page numbers of the pages that has been allocated in this extent.
85 The page range is [p1, p2), where p2 is not included. */
87
88 /** All the page loaders of the used pages. */
89 std::vector<Page_load *> m_page_loads;
90
91 bool is_btree_load_nullptr() const { return m_btree_load == nullptr; }
92
93 public:
94 /** Create an object of type Page_extent in the heap. */
95 static Page_extent *create(Btree_load *btree_load, const bool is_leaf,
96 const bool is_blob);
97
98 /** Release the page extent. Delete if not cached.
99 @param[in] extent extent to release */
100 static void drop(Page_extent *extent);
101
102 /** Number of pages in this extent. */
103 page_no_t page_count() const;
104
105 /** Reset the range with the given value.
106 @param[in] range new range value to be used. */
107 void reset_range(const Page_range_t &range);
108
109 /** Calculate the number of used pages.
110 return the number of used pages. */
111 size_t used_pages() const { return m_page_no - m_range.first; }
112
113 void get_page_numbers(std::vector<page_no_t> &page_numbers) const;
114
115 /** Get the index of the first unused page load.
116 @return index of the first unused page load. */
117 size_t last() const { return m_page_no - m_range.first; }
118
119 /** Check if the range is valid.
120 @return true if the range is valid, false otherwise. */
121 bool is_valid() const;
122
123 bool is_null() const {
124 return (m_range.first == FIL_NULL) && (m_range.second == FIL_NULL);
125 }
126
127 public:
128 /** Member of Page_extent. The index of page_load objects in the m_page_loads
129 corresponds to the page_no in the m_range. Here, check if a page_no already
130 has a Page_load object.
131 @param[in] page_no page_no for which we are looking for Page_load obj.
132 @return Page_load object if available, nullptr otherwise. */
134
135 /** Member of Page_extent. Associate the given page_no and the page load
136 object.
137 @param[in] page_no page number to associate.
138 @param[in] page_load page load object to associate. */
139 void set_page_load(page_no_t page_no, Page_load *page_load);
140
142
143 /** Initialize the next page number to be allocated. The page range should
144 have been already initialized. */
145 void init();
146
147 /** Check if no more pages are there to be used.
148 @return true if the page extent is completely used.
149 @return false if the page extent has more pages to be used. */
150 bool is_fully_used() const { return m_page_no == m_range.second; }
151
152 /** Check if there are any pages used.
153 @return true if at least one page is used.
154 @return false if no pages are used in this extent.*/
155 bool is_any_used() const {
156 ut_ad(m_page_no == m_range.first || m_page_loads.size() > 0);
157 return m_page_no > m_range.first;
158 }
159
160 public:
161 /** Allocate a page number. */
163
164 /** Save a page_load. */
165 void append(Page_load *page_load);
166
167 /** Flush the used pages to disk. It also frees the unused pages back to the
168 segment.
169 @param[in,out] node space file node
170 @return On success, return DB_SUCCESS. */
171 dberr_t flush(fil_node_t *node);
172
173 /** Flush one page at a time. This can be used when scatter/gather i/o is
174 not available for use.
175 @param[in,out] node space file node
176 @return On success, return DB_SUCCESS. */
178
179 /** Flush 1 extent pages at a time. Internally it will call OS dependent
180 API (either bulk_flush_win() on Windows or bulk_flush_linux() on other
181 operating systems.
182 @param[in,out] node space file node
183 @return DB_SUCCESS on success, error code on failure. */
185
186#ifdef UNIV_LINUX
187 /** Flush 1 extent pages at a time. Uses pwritev() i/o API.
188 @param[in,out] node space file node
189 @return DB_SUCCESS on success, error code on failure. */
190 dberr_t bulk_flush_linux(fil_node_t *node);
191#endif /* UNIV_LINUX */
192
193 /** Free all resources. */
195
196 /** Free any cached page load entries. */
197 void destroy_cached();
198
199 space_id_t space() const;
200
201 /** Mark the extent as cached. Flush thread should not free this extent. */
202 void set_cached() { m_is_cached.store(true); }
203
204 /** Set and unset free state of a cached extent.
205 @param[in] free state to be set */
206 void set_state(bool free) { m_is_free.store(free); }
207
208 /** @return true iff the cached element is in free state. */
209 bool is_free() const { return m_is_free.load(); }
210
211 /** @return true iff it is a cached extent. */
212 bool is_cached() const { return m_is_cached.load(); }
213
214 /** Reset page load cache to free all. */
216
217 public:
218 std::ostream &print(std::ostream &out) const;
219
220 /** Mark that this extent is used for blobs. */
221 void set_blob() { m_is_blob = true; }
222
223 /** Check if this is a blob extent.
224 @return true if it is a blob extent. */
225 bool is_blob() const { return m_is_blob; }
226
227 /** Free the BUF_BLOCK_MEMORY blocks used by this extent. */
228 void free_memory_blocks();
229
230#ifdef UNIV_DEBUG
231 /** True if this extent has been handed over to the bulk flusher. */
232 std::atomic_bool m_is_owned_by_bulk_flusher{false};
233#endif /* UNIV_DEBUG */
234
235 private:
237
238 /** true if this extent belongs to leaf segment. */
239 bool m_is_leaf{true};
240
241 /** true iff the extent is cached. */
242 std::atomic_bool m_is_cached{false};
243 /** true if the cached entry is free to be used. */
244 std::atomic_bool m_is_free{true};
245 /** Cached page loads. */
246 std::vector<Page_load *> m_cached_page_loads;
247 /** Next cached page load index. */
249
250 /** True if this extent is used for blobs. */
251 bool m_is_blob{false};
252
253 friend struct Level_ctx;
254};
255
257 std::vector<page_no_t> &page_numbers) const {
258 for (page_no_t i = m_range.first; i < m_page_no; ++i) {
259 page_numbers.push_back(i);
260 }
261}
262
264 Page_load *page_load) {
265 ut_ad(page_no >= m_range.first);
266 ut_ad(page_no < m_range.second);
267 const size_t idx = page_no - m_range.first;
268 if (idx == m_page_loads.size()) {
269 m_page_loads.push_back(page_load);
270 } else {
271 ut_ad(idx <= m_page_loads.size());
272 ut_ad(m_page_loads[idx] == nullptr);
273 m_page_loads[idx] = page_load;
274 }
275 ut_ad(m_page_loads.size() > 0);
276}
277
279 ut_ad(page_no >= m_range.first);
280 ut_ad(page_no < m_range.second);
281 const size_t idx = page_no - m_range.first;
282 if (m_page_loads.empty() || m_page_loads.size() <= idx) {
283 return nullptr;
284 }
285 return m_page_loads[idx];
286}
287
291 m_range.first = FIL_NULL;
292 m_range.second = FIL_NULL;
293 m_btree_load = nullptr;
294}
295
296inline bool Page_extent::is_valid() const {
297 ut_ad(m_range.first != 0);
298 ut_ad(m_range.second != 0);
299 if (is_null()) {
300 return true;
301 }
302 ut_ad(m_range.first < m_range.second);
303 ut_ad((m_range.second - m_range.first) <= FSP_EXTENT_SIZE);
304 return m_range.first < m_range.second;
305}
306
307inline std::ostream &Page_extent::print(std::ostream &out) const {
308 out << "[Page_extent: this=" << (void *)this
309 << ", m_range.first=" << m_range.first
310 << ", m_range.second=" << m_range.second
311 << ", page_loads=" << m_page_loads.size() << "]" << std::endl;
312 return out;
313}
314
315inline std::ostream &operator<<(std::ostream &out, const Page_extent &obj) {
316 return obj.print(out);
317}
318
320 ut_ad(range.first != 0);
321 ut_ad(range.second != 0);
322 ut_ad(range.first != FIL_NULL);
323 ut_ad(range.second != FIL_NULL);
324 m_range = range;
325 m_page_no = m_range.first;
326}
327
329 ut_ad(is_valid());
331
332 if (m_page_no == m_range.second) {
333 return FIL_NULL;
334 }
335 return m_page_no++;
336}
337
338inline void Page_extent::init() {
339 ut_ad(m_range.first != 0);
340 ut_ad(m_range.second != 0);
341 ut_ad(m_range.first != FIL_NULL);
342 ut_ad(m_range.second != FIL_NULL);
343 m_page_no = m_range.first;
344 m_page_loads.reserve(page_count());
345}
346
348 return m_range.second - m_range.first;
349}
350
351/** Context information for each level. */
352struct Level_ctx {
353 /** Static member function construct a Level_ctx object.
354 @param[in] index dictionary index object.
355 @param[in] level the B-tree level of this context object.
356 @param[in] btree_load a back pointer to the Btree_load object to which this
357 Level_ctx object is a part of.
358 @return level context object on success, nullptr on error. */
359 static Level_ctx *create(dict_index_t *index, size_t level,
360 Btree_load *btree_load);
361
362 /** Static member function to destroy a Level_ctx object.
363 @param[in] obj the Level_ctx object to destroy. */
364 static void destroy(Level_ctx *obj);
365
366 /** Constructor
367 @param[in] index dictionary index object.
368 @param[in] level the B-tree level of this context object.
369 @param[in] btree_load a back pointer to the Btree_load object to which this
370 Level_ctx object is a part of.*/
371 Level_ctx(dict_index_t *index, size_t level, Btree_load *btree_load)
372 : m_index(index),
373 m_level(level),
375 m_btree_load(btree_load) {}
376
377 /** Destructor. */
378 ~Level_ctx();
379
380 /** Initialize.
381 @return DB_SUCCESS on success, an error code on failure. */
382 dberr_t init();
383
384 /** Check if this is leaf level.
385 @return true if this is leaf level, false otherwise. */
386 bool is_leaf() const { return m_level == 0; }
387
389
390 /** Free the current page load. */
391 void free_page_load();
392
393 /** Allocate a page number. Subsequently a Page_load will be created with the
394 allocated page number.
395 @param[out] page_no page number that was allocated.
396 @return DB_SUCCESS on success, error code on failure.*/
398
399 /** Allocate one extent in the relevant file segment. No associated buffer
400 blocks are allocated.
401 @return DB_SUCCESS on success, error code on failure.*/
403
404 /** Allocate private memory buffer (BUF_BLOCK_MEMORY) block for given page
405 number. */
406 [[nodiscard]] buf_block_t *alloc(const page_no_t new_page_no) noexcept;
407
408 void set_current_page_load(Page_load *sibling);
409
410 Page_load *get_page_load() const;
411
412 trx_id_t get_trx_id() const;
413
414 /** The current extent that is being loaded. */
416
417 /** Build the extent cache. */
418 void build_extent_cache();
419
420 /** Load one extent from extent cache.
421 @return true iff successful. */
423
424 /** Build page loader cache for current exent. */
425 void build_page_cache();
426
427 /** Get a free page loader from cache
428 @return page loader or nullptr if not found. */
430
431 /** Pre allocated extents to prevent repeated allocation and free. */
432 std::vector<Page_extent *> m_cached_extents;
433
434 /** The page_no of the first page in this level. */
436
437 /** The page_no of the last page in this level. */
439
440 /** The index which is being built. */
442
443 /** The B-tree level whose context information is stored in this obj. */
444 const size_t m_level{};
445
446 /** The Page_load of the current page being loaded. */
448
449 /** A back pointer to conceptually higher level btree load object. */
451
452 /** Number of pages allocated at this level. */
454
455 /** Number of extents allocated at this level. */
457
458 /** True if the current extent is full. */
459 bool m_extent_full{true};
460
461#ifdef UNIV_DEBUG
462 bool is_page_tracked(const page_no_t &page_no) const;
463 std::vector<page_no_t> m_pages_allocated;
464#endif /* UNIV_DEBUG */
465};
466
468
470 m_page_load = sibling;
471}
472
474 public:
475 enum class Type {
476 /** Allocate by Page */
477 PAGE,
478 /** Allocate by extent. */
479 EXTENT
480 };
481
482 /** Destructor to ensure thread stop. */
484
485 /** Check size and set extent allocator size parameters
486 @param[in] table InnoDB dictionary table object
487 @param[in] index InnoDB index being built.
488 @param[in] trx transaction performing bulk load
489 @param[in] size total data size to be loaded
490 @param[in] num_threads number of concurrent threads
491 @param[in] in_pages if true, allocate in pages
492 @return tablespace extend size in bytes. */
493 uint64_t init(dict_table_t *table, dict_index_t *index, trx_t *trx,
494 size_t size, size_t num_threads, bool in_pages);
495
496 /* Start extent allocator thread. */
497 void start();
498
499 /** Stop extent allocator thread, if active. */
500 void stop();
501
502 /** Allocate a page range - currently ans Extent.
503 @param[in] is_leaf true if leaf segment, otherwise non-leaf segment
504 @param[in] alloc_page if true, allocate in pages otherwise allocate extent
505 @param[out] range page range
506 @param[in,out] fn_wait_begin begin callback if wait is needed
507 @param[in,out] fn_wait_end end callback if wait is needed
508 @return Innodb error code. */
509 dberr_t allocate(bool is_leaf, bool alloc_page, Page_range_t &range,
510 std::function<void()> &fn_wait_begin,
511 std::function<void()> &fn_wait_end);
512
513 private:
514 /** Upper bound for max ranges. */
515 static constexpr size_t S_MAX_RANGES = 2 * 1024;
516
517 /** Maximum size by which the tablespace is extended each time. */
518 static constexpr size_t S_BULK_EXTEND_SIZE_MAX = 64;
519
521 /** Initialize cache.
522 @param[in] max_range maximum number of extents to cache. */
523 void init(size_t max_range);
524
525 /** @return true if no available extent to consume. */
526 inline bool is_empty() const { return (m_num_allocated == m_num_consumed); }
527
528 /** @return true if cache is full and no more extents can be added. */
529 inline bool is_full() const {
531 }
532
533 /** Check for number of extents to be allocated and cached.
534 @param[out] num_alloc number of extents to allocate
535 @param[out] num_free number of free extents
536 @return true if succesful. */
537 bool check(size_t &num_alloc, size_t &num_free) const;
538
539 /** Get one page range from the cache.
540 @param[out] range the allocated page range
541 @param[out] alloc_trigger true, if need to trigger allocator
542 @return true if extent is successfully returned from cache. */
543 bool get_range(Page_range_t &range, bool &alloc_trigger);
544
545 /** Set allocated range(extent) in cache.
546 @param[in] index position of the range
547 @param[in] range page range to be set */
548 void set_range(size_t index, Page_range_t &range);
549
550 /** Cached page ranges already allocated to the segment. */
551 std::array<Page_range_t, S_MAX_RANGES> m_ranges;
552
553 /** Maximum number of ranges to pre-allocate. */
555
556 /** Total number of ranges allocated. */
557 std::atomic<size_t> m_num_allocated{0};
558
559 /** Total number of ranges allocated. */
560 std::atomic<size_t> m_num_consumed{0};
561 };
562
563 /** Extent thread executor.
564 @return innodb error code. */
565 dberr_t run();
566
567 /** Allocate extents and fill the cache.
568 @param[in] is_leaf true if leaf segment, otherwise non-leaf segment
569 @param[in] num_extents number of extents to allocate
570 @return innodb error code. */
571 dberr_t allocate_extents(bool is_leaf, size_t num_extents);
572
573 /** Allocator wait function. */
574 void allocator_wait() const;
575
576 /** Check if leaf and non-leaf extent cache needs to be filled.
577 @param[out] n_leaf number of leaf extents to allocate
578 @param[out] n_non_leaf number of non-leaf extents to allocate
579 @param[out] trigger true if consumers should be triggered
580 @return true if allocator should stop. */
581 bool check(size_t &n_leaf, size_t &n_non_leaf, bool &trigger);
582
583 /** Allocate one extent.
584 @param[in] is_leaf true if leaf segment, otherwise non-leaf segment
585 @param[in,out] mtr mini tranaction to be used for allocation
586 @param[out] range page rannge for the extent
587 @return innodb error code. */
588 dberr_t allocate_extent(bool is_leaf, mtr_t &mtr, Page_range_t &range);
589
590 /** Allocate one page.
591 @param[in] is_leaf true if leaf segment, otherwise non-leaf segment
592 @param[out] range page rannge for the page
593 @return innodb error code. */
594 dberr_t allocate_page(bool is_leaf, Page_range_t &range);
595
596#ifdef UNIV_DEBUG
597 /** Synchronize a query interruption when a newly allocated range reuses a
598 freed page still present in the buffer pool.
599 @param[in] range newly allocated page range */
601#endif /* UNIV_DEBUG */
602
603 /** Evict any buffer-pool incarnation of a newly allocated page range.
604 MTIB pages bypass the buffer pool until they are flushed, so an older
605 incarnation must not remain visible while the range is privately owned.
606 @param[in] range newly allocated page range */
608
609 /** @return true if operation is interrupted. */
610 bool is_interrupted();
611
612 private:
613 /** Bulk extent allocator. */
614 std::thread m_thread;
615
616 /** Number of times consumer(s) had to wait. */
617 mutable size_t m_consumer_wait_count{};
618
619 /** Number of times allocator had to wait. */
620 mutable size_t m_allocator_wait_count{};
621
622 /** Total consumer wait time in micro seconds. */
623 mutable std::chrono::microseconds m_consumer_wait_time;
624
625 /** Total allocator wait time in micro seconds. */
626 mutable std::chrono::microseconds m_allocator_wait_time;
627
628 /** Page range type. */
630
631 /** Cached leaf extents. */
633
634 /** Cached non-leaf extents. */
636
637 /** This mutex protects the m_queue. */
638 mutable std::mutex m_mutex;
639
640 /** Condition variable for allocator thread. */
641 mutable std::condition_variable m_allocator_condition;
642
643 /** Condition variable for extent consumer threads. */
644 mutable std::condition_variable m_consumer_condition;
645
646 /** Flag to indicate if the bulk allocator thread should stop. */
647 bool m_stop{false};
648
649 /** Error code, protected by m_mutex */
651
652 /** Innodb dictionary table object. */
655
656 /** Innodb transaction - used for checking interrupt. */
658
659 /** Number of concurrent consumers. */
661};
662
664 public:
665 /** Thread main function.
666 @return innodb error code. */
667 dberr_t run();
668
669 /** Start a new thread to do the flush work.
670 @param[in] space_id space for flushing pages to
671 @param[in] index loader index
672 @param[in] queue_size flusher queue size */
673 void start(space_id_t space_id, size_t index, size_t queue_size);
674
675 /** Add a page extent to the bulk flush queue.
676 @param[in,out] page_extent extent to be added to the queue
677 @param[in,out] fn_wait_begin begin callback if wait is needed
678 @param[in,out] fn_wait_end end callback if wait is needed */
679 void add(Page_extent *page_extent, std::function<void()> &fn_wait_begin,
680 std::function<void()> &fn_wait_end);
681
682 /** Check for flusher error and wake up flusher thread.
683 @return Innodb error code. */
685
686 /** Wait till the bulk flush thread stops. */
687 void wait_to_stop();
688
689 /** Wake the bulk flush thread and wait until all submitted extents have
690 been flushed. */
691 void wait_for_idle();
692
693 /** Get the maximum allowed queue size.
694 @return the maximum allowed queue size. */
695 size_t get_max_queue_size() const { return m_max_queue_size; }
696
697 /** Destructor. */
699
700 /** @return true iff error has occurred. */
701 bool is_error() const { return m_is_error.load(); }
702
703 /** @return error code */
704 dberr_t get_error() const;
705
706 void add_to_free_queue(Page_extent *page_extent);
707
709
710 private:
711 /** Move queued work to the queue used exclusively by the bulk flush thread.
712 @return true if work was moved. */
713 bool is_work_available();
714
715 /** Do the actual work of flushing.
716 @param[in,out] node space file node */
717 void do_work(fil_node_t *node);
718
719 /** Check if the bulk flush thread should stop working. */
720 bool should_i_stop() const { return m_stop.load(); }
721
722 /** When no work is available, put the thread to sleep. */
723 void wait();
724
725 /** Print useful information to the server log file while exiting. */
726 void info();
727
728 /** This queue is protected by the m_mutex. */
729 std::vector<Page_extent *> m_queue;
730
731 /** This mutex protects the m_queue. */
732 mutable std::mutex m_mutex;
733
734 /** Condition variable to wait upon. */
735 mutable std::condition_variable m_condition;
736
737 /** Number of queued or in-progress extent flushes, protected by m_mutex. */
739
740 /** This queue is protected by the m_free_mutex. It is used to cache the
741 Page_extent objects that have been flushed and ready for re-use. */
742 std::vector<Page_extent *> m_free_queue;
743
744 /** This mutex protects the m_free_queue. */
745 mutable std::mutex m_free_mutex;
746
747 /** Flag to indicate if the bulk flusher thread should stop. If true, the
748 bulk flusher thread will stop after emptying the queue. If false, the
749 bulk flusher thread will go to sleep after emptying the queue. */
750 std::atomic<bool> m_stop{false};
751
752 /** Set if error is encountered during flush. */
753 std::atomic<bool> m_is_error{false};
754
755 /** Error code, protected by m_mutex */
757
758 /** Set error code.
759 @param[in] error_code error code to set. It could be DB_SUCCESS.*/
760 void set_error(dberr_t error_code);
761
762 /** Private queue (private to the bulk flush thread) containing the extents to
763 flush. */
764 std::vector<Page_extent *> m_priv_queue;
765
766 /** Bulk flusher thread. */
767 std::thread m_flush_thread;
768
769 /** Number of times slept */
770 size_t m_n_sleep{};
771
772 /** Total sleep time in micro seconds. */
773 std::chrono::microseconds m_wait_time;
774
775 /** The sleep duration in milliseconds. */
777
778 /** Maximum queue size, defaults to 4 */
780
781 /** Number of pages flushed. */
783
784 /** Bulk flusher is specific to a tablespace for now. */
786
787 /** Flusher ID. */
788 size_t m_id{};
789
790#ifdef UNIV_DEBUG
791 public:
792 /** Vector of page numbers that are flushed by this Bulk_flusher object. */
793 std::vector<page_no_t> m_flushed_page_nos;
794#endif /* UNIV_DEBUG */
795};
796
797namespace bulk {
798
799class Blob_handle;
800
801/** Used to insert many blobs into InnoDB. */
803 public:
804 /** Constructor.
805 @param[in] btree_load the B-tree into which blobs are inserted. */
806 Blob_inserter(Btree_load &btree_load);
807
809
810 /** Initialize by allocating necessary resources.
811 @return DB_SUCCESS on success or a failure error code. */
812 dberr_t init();
813
814 void finish();
815
817 Blob_context blob_ctx;
818 dberr_t err = open_blob(blob_ctx, ref);
819 if (err != DB_SUCCESS) {
820 return err;
821 }
822 const byte *data = (const byte *)dfield->data;
823 err = write_blob(blob_ctx, ref, data, dfield->len);
824 if (err != DB_SUCCESS) {
825 return err;
826 }
827 return close_blob(blob_ctx, ref);
828 }
829
830 /** Create a blob.
831 @param[out] blob_ctx pointer to an opaque object representing a blob.
832 @param[out] ref blob reference to be placed in the record.
833 @return DB_SUCCESS on success or a failure error code. */
835
836 /** Write data into the blob.
837 @param[in] blob_ctx pointer to blob into which data is written.
838 @param[out] ref blob reference to be placed in the record.
839 @param[in] data buffer containing data to be written
840 @param[in] len length of the data to be written.
841 @return DB_SUCCESS on success or a failure error code. */
842 dberr_t write_blob(Blob_context blob_ctx, lob::ref_t &ref, const byte *data,
843 size_t len);
844
845 /** Indicate that the blob has been completed, so that resources can be
846 removed, and as necessary flushing can be done.
847 @param[in] blob_ctx pointer to blob which has been completely written.
848 @param[out] ref a blob ref object.
849 @return DB_SUCCESS on success or a failure error code. */
851
852 /** Allocate a LOB first page
853 @return a LOB first page. */
855
856 /** Allocate a data page
857 @return a LOB data page. */
859
860 /** Allocate a LOB index page.
861 @return a LOB index page. */
863
864 /** Get the current transaction id.
865 @return the current transaction id. */
866 trx_id_t get_trx_id() const;
867
869 return ctx == m_blob_handle.get();
870 }
871
872 private:
874
876
878
879 /** Page extent from which to allocate first pages of blobs.
880 @ref lob::bulk::first_page_t. */
882
884
885 /** Page extent from which to allocate data pages of blobs.
886 @ref lob::bulk::data_page_t. */
888
889 /** Page extent from which to allocate index pages of blobs.
890 @ref lob::bulk::node_page_t. */
891 std::list<Page_extent *> m_index_extents;
892
893 /** The current blob being inserted. */
895
896 /** Cache of Page_load objects. */
898
899 /** Cache of Page_extent objects. */
901
902 /** Only one blob handle per sub-tree */
904};
905
906} /* namespace bulk */
907
908/** @note We should call commit(false) for a Page_load object, which is not in
909m_page_loaders after page_commit, and we will commit or abort Page_load
910objects in function "finish". */
912 public:
913 /** Merge multiple Btree_load sub-trees together. */
914 class Merger;
915
916 /** Class used to read the target table when the table is not empty. We bulk
917 load into a duplicate and migrate the data into it. */
918 class Table_reader;
919
921 return m_full_blob_inserter.insert_blob(ref, dfield);
922 }
923
924 /** Create a blob.
925 @param[out] blob_ctx pointer to an opaque object representing a blob.
926 @param[out] ref blob reference to be placed in the record.
927 @return DB_SUCCESS on success or a failure error code. */
929 return m_blob_inserter.open_blob(blob_ctx, ref);
930 }
931
932 /** Write data into the blob.
933 @param[in] blob_ctx pointer to blob into which data is written.
934 @param[in,out] ref blob reference of the current blob
935 @param[in] data buffer containing data to be written
936 @param[in] len length of the data to be written.
937 @return DB_SUCCESS on success or a failure error code. */
938 dberr_t write_blob(Blob_context blob_ctx, lob::ref_t &ref, const byte *data,
939 size_t len) {
940 return m_blob_inserter.write_blob(blob_ctx, ref, data, len);
941 }
942
943 /** Indicate that the blob has been completed, so that resources can be
944 removed, and as necessary flushing can be done.
945 @param[in] blob_ctx pointer to blob which has been completely written.
946 @param[out] ref blob reference of the closed blob.
947 @return DB_SUCCESS on success or a failure error code. */
949 return m_blob_inserter.close_blob(blob_ctx, ref);
950 }
951
952 public:
953 using Level_ctxs = std::vector<Level_ctx *, ut::allocator<Level_ctx *>>;
954
955 /** Helper to set wait callbacks for the current scope. */
957 public:
958 using Function = std::function<void()>;
959 friend class Btree_load;
960
962 : m_btree_load(btree_load) {
965 }
966
968 m_btree_load->m_fn_wait_begin = nullptr;
969 m_btree_load->m_fn_wait_end = nullptr;
970 }
971
972 private:
973 /** Btree Load for the wait callbacks. */
975 };
976
977 /** Constructor
978 @param[in] index B-tree index.
979 @param[in] trx Transaction object.
980 @param[in] loader_num loader index
981 @param[in] flush_queue_size bulk flusher queue size
982 @param[in] allocator extent allocator */
983 Btree_load(dict_index_t *index, trx_t *trx, size_t loader_num,
984 size_t flush_queue_size,
985 Bulk_extent_allocator &allocator) noexcept;
986
987 /** Destructor */
989
990 /** Initialize. Allocates the m_heap_order memory heap.
991 @return DB_SUCCESS on success or an error code on failure. */
992 dberr_t init();
993
994#ifdef UNIV_DEBUG
995 /** Save flushed page numbers for debugging purposes.
996 @param[in] page_no page number of the page that is flushed. */
998 m_bulk_flusher.m_flushed_page_nos.push_back(page_no);
999 }
1000
1001#endif /* UNIV_DEBUG */
1002
1003 /** Check if the index build operation has been interrupted.
1004 @return true if the index build operation is interrupted, false otherwise.*/
1005 bool is_interrupted() const;
1006
1007 /** Trigger flusher thread and check for error.
1008 @return Innodb error code. */
1010
1011 bool is_pk() const { return m_index->is_clustered(); }
1012
1013 /** Get the index object.
1014 @return index object. */
1015 dict_index_t *index() const { return m_index; }
1016
1017 const char *get_table_name() const { return m_index->table->name.m_name; }
1018
1019 /** Get the root page number of this tree/subtree.
1020 @return the root page number of this tree/subtree. */
1022
1023 /** Get the level of the root page.
1024 @return the level of the root page. */
1025 size_t get_root_level() const { return m_root_level; }
1026
1027 /** Get information about root page. */
1028 void get_root_page_stat(Page_stat &stat);
1029
1030 /** Get the transaction id.
1031 @return the transaction id. */
1032 trx_id_t get_trx_id() const;
1033
1035
1036 /** Btree bulk load finish. We commit the last page in each level
1037 and copy the last page in top level to the root page of the index
1038 if no error occurs.
1039 @param[in] is_err Whether bulk load was successful until now
1040 @param[in] subtree true if a subtree is being built, false otherwise.
1041 @return error code */
1042 [[nodiscard]] dberr_t finish(bool is_err, const bool subtree) noexcept;
1043
1044 /** Insert a tuple to a page in a level
1045 @param[in] dtuple Tuple to insert
1046 @param[in] level B-tree level
1047 @return error code */
1048 [[nodiscard]] dberr_t insert(dtuple_t *dtuple, size_t level) noexcept;
1049
1050 /** Split the right most block of the tree at the given level.
1051 @param[in,out] block the right most block at the given level.
1052 @param[in] level level of the given block.
1053 @param[in] node_ptr node pointer to be inserted in the block after
1054 splitting.
1055 @param[in] mtr mini transaction context.
1056 @param[in,out] highest_level highest level among all the subtrees.*/
1057 void split_rightmost(buf_block_t *block, size_t level, dtuple_t *node_ptr,
1058 mtr_t *mtr, size_t &highest_level);
1059
1060 /** Split the left most block of the tree at the given level.
1061 @param[in,out] block the left most block at the given level. it will be
1062 updated with the new left most block.
1063 @param[in] level level of the given block.
1064 @param[in] node_ptr node pointer to be inserted in the block after
1065 splitting.
1066 @param[in] mtr mini transaction context.
1067 @param[in,out] highest_level highest level among all the subtrees.*/
1068 void split_leftmost(buf_block_t *&block, size_t level, dtuple_t *node_ptr,
1069 mtr_t *mtr, size_t &highest_level);
1070
1071 private:
1072 /** Set the root page on completion.
1073 @param[in] last_page_no Last page number (the new root).
1074 @return DB_SUCCESS or error code. */
1075 [[nodiscard]] dberr_t load_root_page(page_no_t last_page_no) noexcept;
1076
1077 public:
1078 /** Commit(finish) a page. We set next/prev page no, insert a node pointer to
1079 father page if needed, and commit mini-transaction.
1080 @param[in] page_load Page to commit
1081 @param[in] next_page_load Next page
1082 @param[in] insert_father Flag whether need to insert node ptr
1083 @return error code */
1084 [[nodiscard]] dberr_t page_commit(Page_load *page_load,
1085 Page_load *next_page_load,
1086 bool insert_father) noexcept;
1087
1088 /** Prepare space to insert a tuple.
1089 @param[in,out] page_load Page bulk that will be used to store the record.
1090 It may be replaced if there is not enough space
1091 to hold the record.
1092 @param[in] level B-tree level
1093 @param[in] rec_size Record size
1094 @return error code */
1095 [[nodiscard]] dberr_t prepare_space(Page_load *&page_load, size_t level,
1096 size_t rec_size) noexcept;
1097
1098 /** Insert a tuple to a page.
1099 @param[in] page_load Page bulk object
1100 @param[in] tuple Tuple to insert
1101 @param[in] big_rec Big record vector, maybe NULL if there is no
1102 Data to be stored externally.
1103 @param[in] rec_size Record size
1104 @return error code */
1105 [[nodiscard]] dberr_t insert(Page_load *page_load, dtuple_t *tuple,
1106 big_rec_t *big_rec, size_t rec_size) noexcept;
1107
1108 /** Btree page bulk load finish. Commits the last page in each level
1109 if no error occurs. Also releases all page bulks.
1110 @param[in] is_err Whether bulk load was successful until now
1111 @param[out] last_page_no Last page number
1112 @return error code */
1113 [[nodiscard]] dberr_t finalize_page_loads(bool is_err,
1114 page_no_t &last_page_no) noexcept;
1115
1116 public:
1117 /** Allocate an extent.
1118 @param[in,out] page_range the range of pages allocated.
1119 @param[in] level btree level for which pages are allocated.
1120 @return status code. */
1121 dberr_t alloc_extent(Page_range_t &page_range, size_t level);
1122
1123 /** Initiate a direct file write operation.
1124 @param[in] block block to be written to disk.
1125 @return error code. */
1126 [[nodiscard]] dberr_t fil_io(buf_block_t *block) noexcept;
1127
1128 /** Flush the blob pages.
1129 @return status code. */
1131
1132 /** Add the given block the internal cache of blocks.
1133 @param[in] block the block to be cached. */
1134 inline void block_put(buf_block_t *block);
1135
1136 /** Remove the given block from the internal cache of blocks.
1137 @param[in] page_no the page number of block to be removed from cache. */
1138 inline void block_remove(const page_no_t page_no);
1139
1140 /** Search for a BUF_BLOCK_MEMORY block with given page number in the local
1141 cache.
1142 @param[in] page_no the page number of block to be fetched.
1143 @return buffer block with given page number. */
1144 [[nodiscard]] inline buf_block_t *block_get(page_no_t page_no) const noexcept;
1145
1146 /** Evict all the pages in the given range from the buffer pool.
1147 @param[in] range range of page numbers.
1148 @param[in] dirty_is_ok it is OK for a page to be dirty. */
1149 void force_evict(const Page_range_t &range, const bool dirty_is_ok = true);
1150
1151 public:
1152 /** Check if a new level is needed. */
1153 bool is_new_level(size_t level) const { return level >= m_level_ctxs.size(); }
1154
1155 /** Last page numbers of each level. */
1156 std::vector<page_no_t, ut::allocator<page_no_t>> m_last_page_nos{};
1157
1158 /** First page numbers of each level. */
1159 std::vector<page_no_t, ut::allocator<page_no_t>> m_first_page_nos{};
1160
1161 /** Get the level context object.
1162 @param[in] level the level number. level 0 is leaf level.
1163 @return the level context object. */
1164 Level_ctx *get_level(size_t level) const;
1165
1166 /** Page numbers of the pages that has been allocated in the leaf level.
1167 The page range is [p1, p2), where p2 is not included. */
1169
1170 /** Page numbers of the pages that has been allocated in the non-leaf level.
1171 The page range is [p1, p2), where p2 is not included. */
1173
1176
1177 /** State of the index. Used for asserting at the end of a
1178 bulk load operation to ensure that the online status of the
1179 index does not change */
1181
1182 /** Number of extents allocated for this B-tree. */
1184
1185 /** Number of pages allocated for this B-tree. */
1187
1188 public:
1189 std::ostream &print_left_pages(std::ostream &out) const;
1190 std::ostream &print_right_pages(std::ostream &out) const;
1191
1192 dberr_t check_key_overlap(const Btree_load *r_btree) const;
1193
1194#ifdef UNIV_DEBUG
1195 void print_tree_pages() const;
1196 std::string print_pages_in_level(const size_t level) const;
1197 /** Check size and validate index of limited size.
1198 @param[in] index Index to validate
1199 @return true if successful. */
1200 static bool validate_index(dict_index_t *index);
1201#endif /* UNIV_DEBUG */
1202
1203 /** All allocated extents registers with Btree_load. */
1204 void track_extent(Page_extent *page_extent);
1205
1206 /** Add fully used extents to the bulk flusher. Call this whenever a new
1207 Page_load is allocated, with finish set to false. Only in
1208 Btree_load::finish(), the finish argument will be true.
1209 @param[in] finish if true, add all the tracked extents to the bulk flusher,
1210 irrespective of whether it is fully used or not. */
1211 void add_to_bulk_flusher(bool finish = false);
1212
1213 /** Add blob extents to the bulk flusher and wait till they are flushed. */
1215
1216 /** Add the given page extent object to the bulk flusher.
1217 @param[in] page_extent the extent to be flushed. */
1218 void add_to_bulk_flusher(Page_extent *page_extent);
1219
1220 /** Check if transparent page compression (TPC) is enabled.
1221 @return true if TPC is enabled. */
1222 bool is_tpc_enabled() const;
1223
1224 /** Check if transparent page encryption (TPE) is enabled.
1225 @return true if TPE is enabled. */
1226 bool is_tpe_enabled() const;
1227
1228 /** @return get flush queue size limit. */
1231 }
1232
1233 /** If the data is already sorted and checked for duplicates, then we can
1234 disable doing it again. */
1236
1238
1241 }
1242
1243 private:
1244 /** Page allocation type. We allocate in extents by default. */
1247
1248 /** Number of records inserted. */
1249 uint64_t m_n_recs{};
1250
1251 /** B-tree index */
1253
1255
1256 /** Transaction id */
1258
1259 /** Root page level */
1261
1262 /** Context information for each level of the B-tree. The leaf level is at
1263 m_level_ctxs[0]. */
1265
1266 /** Reference to global extent allocator. */
1268
1269 /** Extents that are being tracked. */
1270 std::list<Page_extent *> m_extents_tracked;
1271
1272 /** If true, check if data is inserted in sorted order. */
1273 bool m_check_order{true};
1274
1275 /** Memory heap to be used for sort order checks. */
1277
1278 /** Function object to compare two tuples. */
1280
1281 /** The previous tuple that has been inserted. */
1283
1284 bool is_extent_tracked(const Page_extent *page_extent) const;
1285
1286 /** Loader number. */
1288
1290
1291 /* Begin wait callback function. */
1293
1294 /* End wait callback function. */
1296
1297 /** Blob inserter to handle the externally stored fields of InnoDB. This
1298 is used when blobs are inserted using multiple calls like open_blob(),
1299 write_blob() and close_blob(). */
1301
1302 /** Need another blob inserter to store blobs with a single call using
1303 insert_blob() */
1305
1306 /* Dedicated thread to flush pages. */
1308
1310};
1311
1313 public:
1314 using Btree_loads = std::vector<Btree_load *, ut::allocator<Btree_load *>>;
1315
1316 Merger(const size_t n_threads, Btree_loads &loads, dict_index_t *index,
1317 const trx_t *trx)
1318 : m_n_threads(n_threads),
1319 m_btree_loads(loads),
1320 m_index(index),
1321 m_trx(trx),
1323
1324 dberr_t merge(bool sort);
1325
1326 private:
1327 /** Get the maximum free space available in an empty page in bytes.
1328 @return the maximum free space available in an empty page. */
1329 size_t get_max_free() const {
1331 }
1332
1333 /** Remove any empty sub-trees with no records. */
1334 void remove_empty_subtrees();
1335
1336#ifdef UNIV_DEBUG
1337 /** Validate sub-tree boundaries. */
1338 void validate_boundaries();
1339
1340#endif /* UNIV_DEBUG */
1341
1342 /** Stich sub-trees together to form a tree with one or multiple
1343 nodes at highest leve.
1344 @param[out] highest_level highest level of the merged tree.
1345 @return innodb error code. */
1346 dberr_t subtree_link_levels(size_t &highest_level);
1347
1348 /** Create root node for the stiched sub-trees by combining the nodes
1349 at highest level creating another level if required.
1350 @param[in] highest_level highest level of the merged tree.
1351 @return innodb error code. */
1352 dberr_t add_root_for_subtrees(const size_t highest_level);
1353
1354 /** Insert the given list of node pointers into pages at the given level.
1355 @param[in,out] all_node_ptrs list of node pointers
1356 @param[in,out] total_node_ptrs_size total space in bytes needed to insert
1357 all the node pointers.
1358 @param[in] level the level at which the node pointers are inserted.
1359 @return DB_SUCCESS if successful.
1360 @return error code on failure. */
1361 dberr_t insert_node_ptrs(std::vector<dtuple_t *> &all_node_ptrs,
1362 size_t &total_node_ptrs_size, size_t level);
1363
1364 /** Load the left page and update its FIL_PAGE_NEXT.
1365 @param[in] l_page_no left page number
1366 @param[in] r_page_no right page number. */
1367 void link_right_sibling(const page_no_t l_page_no, const page_no_t r_page_no);
1368
1369 private:
1370 /** Number of loader threads. */
1371 const size_t m_n_threads;
1372
1373 /** Refernce to the subtrees to be merged. */
1375
1376 /** Index which is being built. */
1378
1379 /** Transaction making the changes. */
1380 const trx_t *m_trx{};
1381
1382 /** Memory heap to store node pointers. */
1384};
1385
1387 const Page_extent *page_extent) const {
1388 for (auto e : m_extents_tracked) {
1389 if (page_extent == e) {
1390 return true;
1391 }
1392 }
1393 return false;
1394}
1395
1396/** The proper function call sequence of Page_load is as below:
1397-- Page_load::init
1398-- Page_load::insert
1399-- Page_load::finish
1400-- Page_load::commit */
1402 public:
1404
1405 /** Ctor.
1406 @param[in] index B-tree index
1407 @param[in] btree_load btree object to which this page belongs. */
1408 Page_load(dict_index_t *index, Btree_load *btree_load);
1409
1410 /** Destructor. */
1412
1413 /** Check if page is corrupted.
1414 @return true if corrupted, false otherwise. */
1415 bool is_corrupted() const;
1416
1417 /** Print the child page numbers. */
1419
1420 /** Check if state of this page is BUF_BLOCK_MEMORY.
1421 @return true if page state is BUF_BLOCK_MEMORY, false otherwise.*/
1422 bool is_memory() const { return m_block->is_memory(); }
1423
1424 /** A static member function to create this object.
1425 @param[in] btree_load the bulk load object to which this Page_load belongs.
1426 @param[in] page_extent page extent to which this page belongs. */
1427 static Page_load *create(Btree_load *btree_load, Page_extent *page_extent);
1428
1429 /** Release the page loader. Delete if not cached.
1430 @param[in] page_load page loader to delete. */
1431 static void drop(Page_load *page_load);
1432
1433 /** Constructor
1434 @param[in] index B-tree index
1435 @param[in] trx_id Transaction id
1436 @param[in] page_no Page number
1437 @param[in] level Page level
1438 @param[in] observer Flush observer
1439 @param[in] btree_load btree object to which this page belongs. */
1441 size_t level, Flush_observer *observer,
1442 Btree_load *btree_load = nullptr) noexcept
1443 : m_index(index),
1444 m_trx_id(trx_id),
1445 m_page_no(page_no),
1446 m_level(level),
1448 m_flush_observer(observer),
1449 m_btree_load(btree_load) {
1451 }
1452
1453 /** Set the transaction id.
1454 @param[in] trx_id the transaction id to used. */
1455 void set_trx_id(const trx_id_t trx_id) { m_trx_id = trx_id; }
1456
1457 /** Get the current transaction identifier.
1458 @return the current transaction identifier.*/
1459 trx_id_t get_trx_id() const { return m_trx_id; }
1460
1461 /** Set the flush observer.
1462 @param[in] observer the flush observer object to use. */
1464 m_flush_observer = observer;
1465 }
1466
1467 bool is_leaf() const { return m_level == 0; }
1468
1469 /** Set the page number of this object. */
1470 void set_page_no(const page_no_t page_no);
1471
1472 void set_leaf_seg(const fseg_header_t *hdr) {
1474 }
1475 void set_top_seg(const fseg_header_t *hdr) {
1477 }
1478
1479 /** Initialize members and allocate page if needed and start mtr.
1480 @note Must be called and only once right after constructor.
1481 @return error code */
1482 [[nodiscard]] dberr_t init() noexcept;
1483 [[nodiscard]] dberr_t init_mem(const page_no_t new_page_no,
1484 Page_extent *page_extent) noexcept;
1485
1486 /** Initialize a memory block to be used for storing blobs.
1487 @param[in] page_no the page number to be set in the memory block.
1488 @param[in] page_extent extent to which this page belongs.
1489 @return DB_SUCCESS on success, error code on failure.*/
1490 [[nodiscard]] dberr_t init_mem_blob(const page_no_t page_no,
1491 Page_extent *page_extent) noexcept;
1492
1493 /** Allocate a page for this Page_load object.
1494 @return DB_SUCCESS on success, error code on failure. */
1496
1497 /** Re-initialize this page. */
1498 [[nodiscard]] dberr_t reinit() noexcept;
1499
1500 /** Reset this object so that Page_load::init() can be called again on this
1501 object. */
1502 void reset() noexcept;
1503
1504 /** Insert a tuple in the page.
1505 @param[in] tuple Tuple to insert
1506 @param[in] big_rec External record
1507 @param[in] rec_size Record size
1508 @return error code */
1509 [[nodiscard]] dberr_t insert(const dtuple_t *tuple, const big_rec_t *big_rec,
1510 size_t rec_size) noexcept;
1511
1512 /** Mark end of insertion to the page. Scan records to set page dirs,
1513 and set page header members. The scan is incremental (slots and records
1514 which assignment could be "finalized" are not checked again. Check the
1515 m_slotted_rec_no usage, note it could be reset in some cases like
1516 during split.
1517 Note: we refer to page_copy_rec_list_end_to_created_page.*/
1518 void finish() noexcept;
1519
1520 /** Commit mtr for a page
1521 @return DB_SUCCESS on success, error code on failure. */
1523
1524 /** Commit mtr for a page */
1525 void rollback() noexcept;
1526
1527 /** Check whether the record needs to be stored externally.
1528 @return false if the entire record can be stored locally on the page */
1529 [[nodiscard]] bool need_ext(const dtuple_t *tuple,
1530 size_t rec_size) const noexcept;
1531
1532 /** Store externally the first possible field of the given tuple.
1533 @return true if a field was stored externally, false if it was not possible
1534 to store any of the fields externally. */
1535 [[nodiscard]] bool make_ext(dtuple_t *tuple);
1536
1537 /** Get node pointer
1538 @return node pointer */
1539 [[nodiscard]] dtuple_t *get_node_ptr() noexcept;
1540
1541 /** Get node pointer
1542 @param[in] heap allocate node pointer in the given heap.
1543 @return node pointer */
1544 [[nodiscard]] dtuple_t *get_node_ptr(mem_heap_t *heap) noexcept;
1545
1546 /** Copy all records from page.
1547 @param[in] src_page Page with records to copy. */
1548 size_t copy_all(const page_t *src_page) noexcept;
1549
1550 /** Distribute all records from this page to the given pages.
1551 @param[in,out] to_pages array of Page_load objects.
1552 return total number of records processed. */
1553 size_t copy_to(std::vector<Page_load *> &to_pages);
1554
1555 /** Set next page
1556 @param[in] next_page_no Next page no */
1557 void set_next(page_no_t next_page_no) noexcept;
1558
1559 /** Set previous page
1560 @param[in] prev_page_no Previous page no */
1561 void set_prev(page_no_t prev_page_no) noexcept;
1562
1563 /** Get previous page (FIL_PAGE_PREV). */
1565
1566 /** Start mtr and latch block */
1568
1569 /** Check if required space is available in the page for the rec
1570 to be inserted. We check fill factor & padding here.
1571 @param[in] rec_size Required space
1572 @return true if space is available */
1573 [[nodiscard]] inline bool is_space_available(size_t rec_size) const noexcept;
1574
1575 /** Get the page number of this page load object.
1576 @return the page number of this page load object. */
1577 [[nodiscard]] page_no_t get_page_no() const noexcept { return m_page_no; }
1578
1579 [[nodiscard]] page_id_t get_page_id() const noexcept {
1580 return m_block->page.id;
1581 }
1582
1583 /** Get the physical page size of the underlying tablespace.
1584 @return the physical page size of the tablespace. */
1585 size_t get_page_size() const noexcept;
1586
1587 /** Get the table space ID.
1588 @return the table space ID. */
1589 space_id_t space() const noexcept;
1590
1591#ifdef UNIV_DEBUG
1592 /** Obtain tablespace id from the frame and the buffer block and ensure that
1593 they are the same.
1594 @return true if space id is same in both places. */
1595 bool verify_space_id() const;
1596#endif /* UNIV_DEBUG */
1597
1598 /** Get page level */
1599 [[nodiscard]] size_t get_level() const noexcept { return m_level; }
1600
1601 /** Set the level of this page. */
1602 void set_level(size_t level) noexcept { m_level = level; }
1603
1604 /** Get record no */
1605 [[nodiscard]] size_t get_rec_no() const { return m_rec_no; }
1606
1607 /** Get page */
1608 [[nodiscard]] const page_t *get_page() const noexcept {
1610 }
1611
1612 [[nodiscard]] page_t *get_page() noexcept {
1614 }
1615
1616 public:
1617 void init_for_writing();
1618 size_t get_data_size() const { return page_get_data_size(m_page); }
1619
1620#ifdef UNIV_DEBUG
1621 /** Check if index is X locked
1622 @return true if index is locked. */
1624#endif /* UNIV_DEBUG */
1625
1626 /** Copy given and all following records.
1627 @param[in] first_rec First record to copy */
1628 size_t copy_records(const rec_t *first_rec) noexcept;
1629
1630 /** Insert a record in the page, check for duplicates too.
1631 @param[in] rec Record
1632 @param[in] offsets Record offsets
1633 @return DB_SUCCESS or error code. */
1634 dberr_t insert(const rec_t *rec, Rec_offsets offsets) noexcept;
1635
1636 public:
1637 /** Store external record
1638 Since the record is not logged yet, so we don't log update to the record.
1639 the blob data is logged first, then the record is logged in bulk mode.
1640 @param[in] big_rec External record
1641 @param[in] offsets Record offsets
1642 @return error code */
1643 [[nodiscard]] dberr_t store_ext(const big_rec_t *big_rec,
1644 Rec_offsets offsets) noexcept;
1645
1646 /** Set the REC_INFO_MIN_REC_FLAG on the first user record in this page.
1647 @param[in] mtr mini transaction context. */
1648 void set_min_rec_flag(mtr_t *mtr);
1649
1650 /** Set the REC_INFO_MIN_REC_FLAG on the first user record in this page. */
1651 void set_min_rec_flag();
1652 bool is_min_rec_flag() const;
1653
1654 /** Set the level context object for this page load
1655 @param[in] level_ctx the level context object. */
1656 void set_level_ctx(Level_ctx *level_ctx) { m_level_ctx = level_ctx; }
1657
1658 /** Check if this page load object contains a level context object.
1659 @return true if the page load contains a level context object.
1660 @return false if the page load does NOT contain a level context object.*/
1661 bool has_level_ctx() const { return m_level_ctx != nullptr; }
1662
1663 /** Free the memory block. */
1664 void free();
1665
1667
1669
1670 void set_page_extent(Page_extent *page_extent) {
1671 m_page_extent = page_extent;
1672 }
1673
1674 /** Mark the Page load as cached. Flush thread should not free this Page. */
1675 void set_cached() { m_is_cached.store(true); }
1676
1677 /** @return true iff it is a cached Page Load. */
1678 bool is_cached() const { return m_is_cached.load(); }
1679
1680 private:
1681 /** Memory heap for internal allocation */
1683
1684 /** The index B-tree */
1686
1687 /** The min-transaction */
1689
1690 /** The transaction id */
1692
1693 /** The buffer block */
1695
1696 /** The page */
1698
1699 /** The current rec, just before the next insert rec */
1701
1702 /** The page no */
1704
1705 /** The page level in B-tree */
1706 size_t m_level{};
1707
1708 /** Flag: is page in compact format */
1709 const bool m_is_comp{};
1710
1711 /** The heap top in page for next insert */
1712 byte *m_heap_top{};
1713
1714 /** User record no */
1715 size_t m_rec_no{};
1716
1717 /** The free space left in the page */
1719
1720 /** The reserved space for fill factor */
1722
1723 /** Total data in the page */
1725
1726 /** The modify clock value of the buffer block
1727 when the block is re-pinned */
1728 uint64_t m_modify_clock{};
1729
1730 /** Flush observer */
1732
1733 /** Last record assigned to a slot. */
1735
1736 /** Number of records assigned to slots. */
1738
1739 /** Page modified flag. */
1741
1743
1745
1747
1748 /** true iff the Page load is cached. */
1749 std::atomic_bool m_is_cached{false};
1750
1751 friend class Btree_load;
1752};
1753
1755 return get_node_ptr(m_heap);
1756}
1757
1759
1760inline size_t Page_load::get_page_size() const noexcept {
1761 const page_size_t page_size = m_index->get_page_size();
1762 return page_size.physical();
1763}
1764
1765inline Level_ctx *Btree_load::get_level(size_t level) const {
1766 ut_a(m_level_ctxs.size() > level);
1767 return m_level_ctxs[level];
1768}
1769
1770/** Information about a buffer page. */
1772 /** Number of user records in the page. */
1773 size_t m_n_recs;
1774
1775 /** Number of bytes of data. */
1777};
1778
1779inline void Page_extent::append(Page_load *page_load) {
1780 ut_ad(page_load->get_block() != nullptr);
1781 ut_ad(page_load->is_memory());
1782 ut_ad(page_load->get_page_no() >= m_range.first);
1783 ut_ad(page_load->get_page_no() < m_range.second);
1784 for (auto &iter : m_page_loads) {
1785 if (iter->get_page_no() == page_load->get_page_no()) {
1786 /* Page already appended. Don't append again. */
1787 return;
1788 }
1789 }
1791 m_page_loads.push_back(page_load);
1792}
1793
1795 return m_btree_load->get_trx_id();
1796}
1797
1799 return m_btree_load->index()->space;
1800}
1801
1802inline Page_extent::Page_extent(Btree_load *btree_load, const bool is_leaf)
1803 : m_page_no(FIL_NULL),
1804 m_range(FIL_NULL, FIL_NULL),
1805 m_btree_load(btree_load),
1806 m_is_leaf(is_leaf) {
1808}
1809
1811 const bool is_leaf, bool skip_track) {
1812 Page_extent *p = ut::new_withkey<Page_extent>(UT_NEW_THIS_FILE_PSI_KEY,
1813 btree_load, is_leaf);
1814 if (!skip_track) {
1815 btree_load->track_extent(p);
1816 }
1817 p->m_is_cached.store(false);
1818 return p;
1819}
1820
1821inline void Page_extent::drop(Page_extent *extent) {
1822 if (extent == nullptr) {
1823 return;
1824 }
1825 if (extent->is_cached()) {
1826 ut_a(!extent->is_free());
1827 bool free = true;
1828 extent->set_state(free);
1829 return;
1830 }
1831 ut::delete_(extent);
1832}
1833
1834/** Function object to compare two Btree_load objects. */
1837 bool operator()(const Btree_load *l_btree, const Btree_load *r_btree);
1839};
1840
1841#ifdef UNIV_DEBUG
1844#endif /* UNIV_DEBUG */
1845
1847 for (auto page_load : m_page_loads) {
1848 page_load->free();
1849 }
1850}
1851
1852namespace bulk {
1854 return m_btree_load.get_trx_id();
1855}
1856} /* namespace bulk */
1857
1858} /* namespace Btree_multi */
1859
1860#endif /* btr0mtib_h */
InnoDB Native API.
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:49
uint32_t page_no_t
Page number.
Definition: api0api.h:47
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
std::pair< page_no_t, page_no_t > Page_range_t
Definition: btr0btr.h:134
The B-tree bulk load.
static buf_frame_t * buf_block_get_frame(const buf_block_t *block)
Gets a pointer to the memory frame of a block.
Definition: btr0load.h:51
Definition: btr0mtib.h:1312
Merger(const size_t n_threads, Btree_loads &loads, dict_index_t *index, const trx_t *trx)
Definition: btr0mtib.h:1316
Btree_loads & m_btree_loads
Refernce to the subtrees to be merged.
Definition: btr0mtib.h:1374
std::vector< Btree_load *, ut::allocator< Btree_load * > > Btree_loads
Definition: btr0mtib.h:1314
const trx_t * m_trx
Transaction making the changes.
Definition: btr0mtib.h:1380
dict_index_t * m_index
Index which is being built.
Definition: btr0mtib.h:1377
void validate_boundaries()
Validate sub-tree boundaries.
Definition: btr0mtib.cc:2787
dberr_t insert_node_ptrs(std::vector< dtuple_t * > &all_node_ptrs, size_t &total_node_ptrs_size, size_t level)
Insert the given list of node pointers into pages at the given level.
Definition: btr0mtib.cc:3253
size_t get_max_free() const
Get the maximum free space available in an empty page in bytes.
Definition: btr0mtib.h:1329
void remove_empty_subtrees()
Remove any empty sub-trees with no records.
Definition: btr0mtib.cc:2774
dberr_t add_root_for_subtrees(const size_t highest_level)
Create root node for the stiched sub-trees by combining the nodes at highest level creating another l...
Definition: btr0mtib.cc:3095
Scoped_heap m_tuple_heap
Memory heap to store node pointers.
Definition: btr0mtib.h:1383
dberr_t merge(bool sort)
Definition: btr0mtib.cc:2713
const size_t m_n_threads
Number of loader threads.
Definition: btr0mtib.h:1371
void link_right_sibling(const page_no_t l_page_no, const page_no_t r_page_no)
Load the left page and update its FIL_PAGE_NEXT.
Definition: btr0mtib.cc:3225
dberr_t subtree_link_levels(size_t &highest_level)
Stich sub-trees together to form a tree with one or multiple nodes at highest leve.
Definition: btr0mtib.cc:2797
Helper to set wait callbacks for the current scope.
Definition: btr0mtib.h:956
~Wait_callbacks()
Definition: btr0mtib.h:967
Wait_callbacks(Btree_load *btree_load, Function &begin, Function &end)
Definition: btr0mtib.h:961
Btree_load * m_btree_load
Btree Load for the wait callbacks.
Definition: btr0mtib.h:974
std::function< void()> Function
Definition: btr0mtib.h:958
Definition: btr0mtib.h:911
~Btree_load() noexcept
Destructor.
Definition: btr0mtib.cc:1657
bulk::Blob_inserter m_full_blob_inserter
Need another blob inserter to store blobs with a single call using insert_blob()
Definition: btr0mtib.h:1304
dict_index_t * m_index
B-tree index.
Definition: btr0mtib.h:1252
Bulk_flusher m_bulk_flusher
Definition: btr0mtib.h:1307
dberr_t finish(bool is_err, const bool subtree) noexcept
Btree bulk load finish.
Definition: btr0mtib.cc:2010
Flush_observer * get_flush_observer() const
Definition: btr0mtib.cc:1653
dberr_t load_root_page(page_no_t last_page_no) noexcept
Set the root page on completion.
Definition: btr0mtib.cc:1886
dberr_t trigger_flusher() const
Trigger flusher thread and check for error.
Definition: btr0mtib.h:1009
bool is_tpe_enabled() const
Check if transparent page encryption (TPE) is enabled.
Definition: btr0mtib.cc:2705
Bulk_extent_allocator & m_allocator
Reference to global extent allocator.
Definition: btr0mtib.h:1267
bool is_new_level(size_t level) const
Check if a new level is needed.
Definition: btr0mtib.h:1153
bool is_pk() const
Definition: btr0mtib.h:1011
dberr_t check_key_overlap(const Btree_load *r_btree) const
Definition: btr0mtib.cc:3353
Btree_load(dict_index_t *index, trx_t *trx, size_t loader_num, size_t flush_queue_size, Bulk_extent_allocator &allocator) noexcept
Constructor.
Definition: btr0mtib.cc:1633
dict_index_t * index() const
Get the index object.
Definition: btr0mtib.h:1015
size_t get_max_flush_queue_size() const
Definition: btr0mtib.h:1229
void block_remove(const page_no_t page_no)
Remove the given block from the internal cache of blocks.
dberr_t insert(dtuple_t *dtuple, size_t level) noexcept
Insert a tuple to a page in a level.
Definition: btr0mtib.cc:1782
dtuple_t * m_prev_tuple
The previous tuple that has been inserted.
Definition: btr0mtib.h:1282
void force_evict(const Page_range_t &range, const bool dirty_is_ok=true)
Evict all the pages in the given range from the buffer pool.
Definition: btr0mtib.cc:2113
std::ostream & print_right_pages(std::ostream &out) const
Definition: btr0mtib.cc:2074
size_t m_root_level
Root page level.
Definition: btr0mtib.h:1260
std::vector< page_no_t, ut::allocator< page_no_t > > m_first_page_nos
First page numbers of each level.
Definition: btr0mtib.h:1159
byte m_fseg_hdr_leaf[FSEG_HEADER_SIZE]
Definition: btr0mtib.h:1174
void block_put(buf_block_t *block)
Add the given block the internal cache of blocks.
dberr_t init()
Initialize.
Definition: btr0mtib.cc:2200
void add_blobs_to_bulk_flusher()
Add blob extents to the bulk flusher and wait till they are flushed.
Definition: btr0mtib.cc:1744
Bulk_extent_allocator::Type m_alloc_type
Page allocation type.
Definition: btr0mtib.h:1245
Page_range_t m_page_range_leaf
Page numbers of the pages that has been allocated in the leaf level.
Definition: btr0mtib.h:1168
void get_root_page_stat(Page_stat &stat)
Get information about root page.
Definition: btr0mtib.cc:2118
size_t m_loader_num
Loader number.
Definition: btr0mtib.h:1287
Level_ctxs m_level_ctxs
Context information for each level of the B-tree.
Definition: btr0mtib.h:1264
page_no_t get_subtree_root() const
Get the root page number of this tree/subtree.
Definition: btr0mtib.h:1021
size_t m_stat_n_pages
Number of pages allocated for this B-tree.
Definition: btr0mtib.h:1186
trx_t * m_trx
Transaction id.
Definition: btr0mtib.h:1257
dberr_t flush_blobs() noexcept
Flush the blob pages.
dberr_t open_blob(Blob_context &blob_ctx, lob::ref_t &ref)
Create a blob.
Definition: btr0mtib.h:928
mem_heap_t * m_heap_order
Memory heap to be used for sort order checks.
Definition: btr0mtib.h:1276
dberr_t prepare_space(Page_load *&page_load, size_t level, size_t rec_size) noexcept
Prepare space to insert a tuple.
Definition: btr0mtib.cc:1665
std::list< Page_extent * > m_extents_tracked
Extents that are being tracked.
Definition: btr0mtib.h:1270
void track_page_flush(page_no_t page_no)
Save flushed page numbers for debugging purposes.
Definition: btr0mtib.h:997
std::ostream & print_left_pages(std::ostream &out) const
Definition: btr0mtib.cc:2065
ddl::Compare_key m_compare_key
Function object to compare two tuples.
Definition: btr0mtib.h:1279
bulk::Blob_inserter m_blob_inserter
Blob inserter to handle the externally stored fields of InnoDB.
Definition: btr0mtib.h:1300
size_t get_root_level() const
Get the level of the root page.
Definition: btr0mtib.h:1025
dberr_t alloc_extent(Page_range_t &page_range, size_t level)
Allocate an extent.
Definition: btr0mtib.cc:731
bool is_extent_tracked(const Page_extent *page_extent) const
Definition: btr0mtib.h:1386
dberr_t insert_blob(lob::ref_t &ref, const dfield_t *dfield)
Definition: btr0mtib.h:920
bool m_check_order
If true, check if data is inserted in sorted order.
Definition: btr0mtib.h:1273
bool is_tpc_enabled() const
Check if transparent page compression (TPC) is enabled.
Definition: btr0mtib.cc:2695
static bool validate_index(dict_index_t *index)
Check size and validate index of limited size.
Definition: btr0mtib.cc:1990
trx_id_t get_trx_id() const
Get the transaction id.
Definition: btr0mtib.cc:1651
void disable_check_order()
If the data is already sorted and checked for duplicates, then we can disable doing it again.
Definition: btr0mtib.h:1235
bool is_interrupted() const
Check if the index build operation has been interrupted.
Definition: btr0mtib.cc:3418
uint64_t m_n_recs
Number of records inserted.
Definition: btr0mtib.h:1249
Wait_callbacks::Function m_fn_wait_begin
Definition: btr0mtib.h:1292
const char * get_table_name() const
Definition: btr0mtib.h:1017
void track_extent(Page_extent *page_extent)
All allocated extents registers with Btree_load.
Definition: btr0mtib.cc:2144
void split_rightmost(buf_block_t *block, size_t level, dtuple_t *node_ptr, mtr_t *mtr, size_t &highest_level)
Split the right most block of the tree at the given level.
Definition: btr0mtib.cc:3435
fil_space_t * m_space
Definition: btr0mtib.h:1254
Page_range_t m_page_range_top
Page numbers of the pages that has been allocated in the non-leaf level.
Definition: btr0mtib.h:1172
Wait_callbacks::Function m_fn_wait_end
Definition: btr0mtib.h:1295
void add_to_bulk_flusher(bool finish=false)
Add fully used extents to the bulk flusher.
Definition: btr0mtib.cc:1758
unsigned m_index_online
State of the index.
Definition: btr0mtib.h:1180
byte m_fseg_hdr_top[FSEG_HEADER_SIZE]
Definition: btr0mtib.h:1175
dberr_t page_commit(Page_load *page_load, Page_load *next_page_load, bool insert_father) noexcept
Commit(finish) a page.
Definition: btr0mtib.cc:1592
void split_leftmost(buf_block_t *&block, size_t level, dtuple_t *node_ptr, mtr_t *mtr, size_t &highest_level)
Split the left most block of the tree at the given level.
Definition: btr0mtib.cc:3534
dberr_t fil_io(buf_block_t *block) noexcept
Initiate a direct file write operation.
dberr_t finalize_page_loads(bool is_err, page_no_t &last_page_no) noexcept
Btree page bulk load finish.
Definition: btr0mtib.cc:1854
std::string print_pages_in_level(const size_t level) const
Definition: btr0mtib.cc:1937
void print_tree_pages() const
Definition: btr0mtib.cc:2084
Level_ctx * get_level(size_t level) const
Get the level context object.
Definition: btr0mtib.h:1765
dberr_t close_blob(Blob_context blob_ctx, lob::ref_t &ref)
Indicate that the blob has been completed, so that resources can be removed, and as necessary flushin...
Definition: btr0mtib.h:948
const page_size_t m_page_size
Definition: btr0mtib.h:1289
Bulk_extent_allocator & get_extent_allocator()
Definition: btr0mtib.h:1237
std::vector< Level_ctx *, ut::allocator< Level_ctx * > > Level_ctxs
Definition: btr0mtib.h:953
buf_block_t * block_get(page_no_t page_no) const noexcept
Search for a BUF_BLOCK_MEMORY block with given page number in the local cache.
std::vector< page_no_t, ut::allocator< page_no_t > > m_last_page_nos
Last page numbers of each level.
Definition: btr0mtib.h:1156
bool verify_blob_context(Blob_context ctx) const
Definition: btr0mtib.h:1239
size_t m_stat_n_extents
Number of extents allocated for this B-tree.
Definition: btr0mtib.h:1183
dberr_t write_blob(Blob_context blob_ctx, lob::ref_t &ref, const byte *data, size_t len)
Write data into the blob.
Definition: btr0mtib.h:938
Definition: btr0mtib.h:473
~Bulk_extent_allocator()
Destructor to ensure thread stop.
Definition: btr0mtib.h:483
Extent_cache m_leaf_extents
Cached leaf extents.
Definition: btr0mtib.h:632
dict_table_t * m_table
Innodb dictionary table object.
Definition: btr0mtib.h:653
std::chrono::microseconds m_allocator_wait_time
Total allocator wait time in micro seconds.
Definition: btr0mtib.h:626
size_t m_allocator_wait_count
Number of times allocator had to wait.
Definition: btr0mtib.h:620
size_t m_concurrency
Number of concurrent consumers.
Definition: btr0mtib.h:660
uint64_t init(dict_table_t *table, dict_index_t *index, trx_t *trx, size_t size, size_t num_threads, bool in_pages)
Check size and set extent allocator size parameters.
Definition: btr0mtib.cc:2232
std::condition_variable m_consumer_condition
Condition variable for extent consumer threads.
Definition: btr0mtib.h:644
bool check(size_t &n_leaf, size_t &n_non_leaf, bool &trigger)
Check if leaf and non-leaf extent cache needs to be filled.
Definition: btr0mtib.cc:2541
std::thread m_thread
Bulk extent allocator.
Definition: btr0mtib.h:614
size_t m_consumer_wait_count
Number of times consumer(s) had to wait.
Definition: btr0mtib.h:617
static constexpr size_t S_BULK_EXTEND_SIZE_MAX
Maximum size by which the tablespace is extended each time.
Definition: btr0mtib.h:518
dberr_t allocate(bool is_leaf, bool alloc_page, Page_range_t &range, std::function< void()> &fn_wait_begin, std::function< void()> &fn_wait_end)
Allocate a page range - currently ans Extent.
Definition: btr0mtib.cc:2425
dberr_t m_error
Error code, protected by m_mutex.
Definition: btr0mtib.h:650
static constexpr size_t S_MAX_RANGES
Upper bound for max ranges.
Definition: btr0mtib.h:515
dict_index_t * m_index
Definition: btr0mtib.h:654
trx_t * m_trx
Innodb transaction - used for checking interrupt.
Definition: btr0mtib.h:657
Extent_cache m_non_leaf_extents
Cached non-leaf extents.
Definition: btr0mtib.h:635
void allocator_wait() const
Allocator wait function.
Definition: btr0mtib.cc:2561
void debug_sync_reused_freed_page(const Page_range_t &range)
Synchronize a query interruption when a newly allocated range reuses a freed page still present in th...
Definition: btr0mtib.cc:2341
dberr_t allocate_extent(bool is_leaf, mtr_t &mtr, Page_range_t &range)
Allocate one extent.
Definition: btr0mtib.cc:2420
bool is_interrupted()
Definition: btr0mtib.cc:2336
dberr_t allocate_page(bool is_leaf, Page_range_t &range)
Allocate one page.
Definition: btr0mtib.cc:2369
dberr_t run()
Extent thread executor.
Definition: btr0mtib.cc:2641
void start()
Definition: btr0mtib.cc:2303
std::mutex m_mutex
This mutex protects the m_queue.
Definition: btr0mtib.h:638
Type m_type
Page range type.
Definition: btr0mtib.h:629
Type
Definition: btr0mtib.h:475
bool m_stop
Flag to indicate if the bulk allocator thread should stop.
Definition: btr0mtib.h:647
std::chrono::microseconds m_consumer_wait_time
Total consumer wait time in micro seconds.
Definition: btr0mtib.h:623
void evict_allocated_range(const Page_range_t &range)
Evict any buffer-pool incarnation of a newly allocated page range.
Definition: btr0mtib.cc:2357
dberr_t allocate_extents(bool is_leaf, size_t num_extents)
Allocate extents and fill the cache.
Definition: btr0mtib.cc:2580
void stop()
Stop extent allocator thread, if active.
Definition: btr0mtib.cc:2311
std::condition_variable m_allocator_condition
Condition variable for allocator thread.
Definition: btr0mtib.h:641
Definition: btr0mtib.h:663
dberr_t check_and_notify() const
Check for flusher error and wake up flusher thread.
Definition: btr0mtib.cc:191
dberr_t m_error
Error code, protected by m_mutex.
Definition: btr0mtib.h:756
void add_to_free_queue(Page_extent *page_extent)
Definition: btr0mtib.cc:212
size_t m_pages_flushed
Number of pages flushed.
Definition: btr0mtib.h:782
space_id_t m_space_id
Bulk flusher is specific to a tablespace for now.
Definition: btr0mtib.h:785
std::atomic< bool > m_is_error
Set if error is encountered during flush.
Definition: btr0mtib.h:753
std::atomic< bool > m_stop
Flag to indicate if the bulk flusher thread should stop.
Definition: btr0mtib.h:750
dberr_t get_error() const
Definition: btr0mtib.cc:107
std::vector< Page_extent * > m_free_queue
This queue is protected by the m_free_mutex.
Definition: btr0mtib.h:742
dberr_t run()
Thread main function.
Definition: btr0mtib.cc:264
size_t m_id
Flusher ID.
Definition: btr0mtib.h:788
bool is_error() const
Definition: btr0mtib.h:701
Page_extent * get_free_extent()
Definition: btr0mtib.cc:202
std::mutex m_free_mutex
This mutex protects the m_free_queue.
Definition: btr0mtib.h:745
bool should_i_stop() const
Check if the bulk flush thread should stop working.
Definition: btr0mtib.h:720
size_t m_n_sleep
Number of times slept.
Definition: btr0mtib.h:770
size_t m_pending_flushes
Number of queued or in-progress extent flushes, protected by m_mutex.
Definition: btr0mtib.h:738
std::mutex m_mutex
This mutex protects the m_queue.
Definition: btr0mtib.h:732
~Bulk_flusher()
Destructor.
Definition: btr0mtib.cc:121
void set_error(dberr_t error_code)
Set error code.
Definition: btr0mtib.cc:112
std::vector< Page_extent * > m_queue
This queue is protected by the m_mutex.
Definition: btr0mtib.h:729
void wait_for_idle()
Wake the bulk flush thread and wait until all submitted extents have been flushed.
Definition: btr0mtib.cc:149
std::thread m_flush_thread
Bulk flusher thread.
Definition: btr0mtib.h:767
size_t m_max_queue_size
Maximum queue size, defaults to 4.
Definition: btr0mtib.h:779
void start(space_id_t space_id, size_t index, size_t queue_size)
Start a new thread to do the flush work.
Definition: btr0mtib.cc:93
std::chrono::microseconds m_wait_time
Total sleep time in micro seconds.
Definition: btr0mtib.h:773
bool is_work_available()
Move queued work to the queue used exclusively by the bulk flush thread.
Definition: btr0mtib.cc:248
std::vector< Page_extent * > m_priv_queue
Private queue (private to the bulk flush thread) containing the extents to flush.
Definition: btr0mtib.h:764
void wait_to_stop()
Wait till the bulk flush thread stops.
Definition: btr0mtib.cc:132
std::vector< page_no_t > m_flushed_page_nos
Vector of page numbers that are flushed by this Bulk_flusher object.
Definition: btr0mtib.h:793
size_t get_max_queue_size() const
Get the maximum allowed queue size.
Definition: btr0mtib.h:695
std::condition_variable m_condition
Condition variable to wait upon.
Definition: btr0mtib.h:735
void info()
Print useful information to the server log file while exiting.
Definition: btr0mtib.cc:2217
void wait()
When no work is available, put the thread to sleep.
Definition: btr0mtib.cc:312
void add(Page_extent *page_extent, std::function< void()> &fn_wait_begin, std::function< void()> &fn_wait_end)
Add a page extent to the bulk flush queue.
Definition: btr0mtib.cc:217
static constexpr std::chrono::milliseconds s_sleep_duration
The sleep duration in milliseconds.
Definition: btr0mtib.h:776
void do_work(fil_node_t *node)
Do the actual work of flushing.
Definition: btr0mtib.cc:157
The proper function call sequence of Page_load is as below: – Page_load::init – Page_load::insert – P...
Definition: btr0mtib.h:1401
dberr_t init_mem(const page_no_t new_page_no, Page_extent *page_extent) noexcept
Definition: btr0mtib.cc:993
dberr_t store_ext(const big_rec_t *big_rec, Rec_offsets offsets) noexcept
Store external record Since the record is not logged yet, so we don't log update to the record.
void set_level(size_t level) noexcept
Set the level of this page.
Definition: btr0mtib.h:1602
buf_block_t * get_block()
Definition: btr0mtib.h:1668
space_id_t space() const noexcept
Get the table space ID.
Definition: btr0mtib.h:1758
void rollback() noexcept
Commit mtr for a page.
Definition: btr0mtib.cc:1434
dberr_t init_mem_blob(const page_no_t page_no, Page_extent *page_extent) noexcept
Initialize a memory block to be used for storing blobs.
Definition: btr0mtib.cc:956
bool is_corrupted() const
Check if page is corrupted.
Definition: btr0mtib.cc:357
trx_id_t m_trx_id
The transaction id.
Definition: btr0mtib.h:1691
byte * m_heap_top
The heap top in page for next insert.
Definition: btr0mtib.h:1712
size_t get_level() const noexcept
Get page level.
Definition: btr0mtib.h:1599
rec_t * m_last_slotted_rec
Last record assigned to a slot.
Definition: btr0mtib.h:1734
bool make_ext(dtuple_t *tuple)
Store externally the first possible field of the given tuple.
Definition: btr0mtib.cc:1558
dict_index_t * index()
Definition: btr0mtib.h:1666
void set_level_ctx(Level_ctx *level_ctx)
Set the level context object for this page load.
Definition: btr0mtib.h:1656
void set_trx_id(const trx_id_t trx_id)
Set the transaction id.
Definition: btr0mtib.h:1455
size_t copy_to(std::vector< Page_load * > &to_pages)
Distribute all records from this page to the given pages.
Definition: btr0mtib.cc:1472
size_t copy_records(const rec_t *first_rec) noexcept
Copy given and all following records.
Definition: btr0mtib.cc:1503
void set_flush_observer(Flush_observer *observer)
Set the flush observer.
Definition: btr0mtib.h:1463
void set_page_extent(Page_extent *page_extent)
Definition: btr0mtib.h:1670
size_t get_rec_no() const
Get record no.
Definition: btr0mtib.h:1605
trx_id_t get_trx_id() const
Get the current transaction identifier.
Definition: btr0mtib.h:1459
void set_min_rec_flag()
Set the REC_INFO_MIN_REC_FLAG on the first user record in this page.
Definition: btr0mtib.cc:2094
page_no_t get_page_no() const noexcept
Get the page number of this page load object.
Definition: btr0mtib.h:1577
void set_next(page_no_t next_page_no) noexcept
Set next page.
Definition: btr0mtib.cc:1522
size_t get_page_size() const noexcept
Get the physical page size of the underlying tablespace.
Definition: btr0mtib.h:1760
dict_index_t * m_index
The index B-tree.
Definition: btr0mtib.h:1685
size_t m_slotted_rec_no
Number of records assigned to slots.
Definition: btr0mtib.h:1737
dberr_t insert(const dtuple_t *tuple, const big_rec_t *big_rec, size_t rec_size) noexcept
Insert a tuple in the page.
Definition: btr0mtib.cc:1304
Flush_observer * m_flush_observer
Flush observer.
Definition: btr0mtib.h:1731
bool verify_space_id() const
Obtain tablespace id from the frame and the buffer block and ensure that they are the same.
Definition: btr0mtib.cc:3423
void free()
Free the memory block.
Definition: btr0mtib.cc:2136
uint64_t m_modify_clock
The modify clock value of the buffer block when the block is re-pinned.
Definition: btr0mtib.h:1728
void set_prev(page_no_t prev_page_no) noexcept
Set previous page.
Definition: btr0mtib.cc:1526
bool has_level_ctx() const
Check if this page load object contains a level context object.
Definition: btr0mtib.h:1661
Page_load(dict_index_t *index, Btree_load *btree_load)
Ctor.
Definition: btr0mtib.cc:924
size_t m_rec_no
User record no.
Definition: btr0mtib.h:1715
std::atomic_bool m_is_cached
true iff the Page load is cached.
Definition: btr0mtib.h:1749
static void drop(Page_load *page_load)
Release the page loader.
Definition: btr0mtib.cc:705
bool is_memory() const
Check if state of this page is BUF_BLOCK_MEMORY.
Definition: btr0mtib.h:1422
bool is_leaf() const
Definition: btr0mtib.h:1467
bool is_space_available(size_t rec_size) const noexcept
Check if required space is available in the page for the rec to be inserted.
Definition: btr0mtib.cc:1534
void reset() noexcept
Reset this object so that Page_load::init() can be called again on this object.
Definition: btr0mtib.cc:1137
size_t get_data_size() const
Definition: btr0mtib.h:1618
bool need_ext(const dtuple_t *tuple, size_t rec_size) const noexcept
Check whether the record needs to be stored externally.
Definition: btr0mtib.cc:1576
size_t m_level
The page level in B-tree.
Definition: btr0mtib.h:1706
rec_t * m_cur_rec
The current rec, just before the next insert rec.
Definition: btr0mtib.h:1700
dberr_t alloc() noexcept
Allocate a page for this Page_load object.
Definition: btr0mtib.cc:1086
void set_page_no(const page_no_t page_no)
Set the page number of this object.
Definition: btr0mtib.cc:915
size_t m_reserved_space
The reserved space for fill factor.
Definition: btr0mtib.h:1721
mem_heap_t * m_heap
Memory heap for internal allocation.
Definition: btr0mtib.h:1682
static Page_load * create(Btree_load *btree_load, Page_extent *page_extent)
A static member function to create this object.
Definition: btr0mtib.cc:695
page_id_t get_page_id() const noexcept
Definition: btr0mtib.h:1579
void latch() noexcept
Start mtr and latch block.
Page_extent * m_page_extent
Definition: btr0mtib.h:1746
bool is_cached() const
Definition: btr0mtib.h:1678
page_t * get_page() noexcept
Definition: btr0mtib.h:1612
bool is_index_locked() noexcept
Check if index is X locked.
Definition: btr0mtib.cc:1583
Page_load(dict_index_t *index, trx_id_t trx_id, page_no_t page_no, size_t level, Flush_observer *observer, Btree_load *btree_load=nullptr) noexcept
Constructor.
Definition: btr0mtib.h:1440
void set_top_seg(const fseg_header_t *hdr)
Definition: btr0mtib.h:1475
dberr_t reinit() noexcept
Re-initialize this page.
Definition: btr0mtib.cc:1065
~Page_load() noexcept
Destructor.
Definition: btr0mtib.cc:3407
void set_leaf_seg(const fseg_header_t *hdr)
Definition: btr0mtib.h:1472
bool is_min_rec_flag() const
Definition: btr0mtib.cc:2096
dberr_t commit() noexcept
Commit mtr for a page.
Definition: btr0mtib.cc:1400
size_t copy_all(const page_t *src_page) noexcept
Copy all records from page.
Definition: btr0mtib.cc:1463
size_t m_free_space
The free space left in the page.
Definition: btr0mtib.h:1718
void set_cached()
Mark the Page load as cached.
Definition: btr0mtib.h:1675
const bool m_is_comp
Flag: is page in compact format.
Definition: btr0mtib.h:1709
Btree_load * m_btree_load
Definition: btr0mtib.h:1742
page_no_t get_prev() noexcept
Get previous page (FIL_PAGE_PREV).
Definition: btr0mtib.cc:1530
mtr_t * m_mtr
The min-transaction.
Definition: btr0mtib.h:1688
const page_t * get_page() const noexcept
Get page.
Definition: btr0mtib.h:1608
bool m_modified
Page modified flag.
Definition: btr0mtib.h:1740
buf_block_t * m_block
The buffer block.
Definition: btr0mtib.h:1694
void print_child_page_nos() noexcept
Print the child page numbers.
Definition: btr0mtib.cc:1447
page_no_t m_page_no
The page no.
Definition: btr0mtib.h:1703
Level_ctx * m_level_ctx
Definition: btr0mtib.h:1744
dberr_t init() noexcept
Initialize members and allocate page if needed and start mtr.
Definition: btr0mtib.cc:1169
size_t m_total_data
Total data in the page.
Definition: btr0mtib.h:1724
void init_for_writing()
Definition: btr0mtib.cc:372
void finish() noexcept
Mark end of insertion to the page.
Definition: btr0mtib.cc:1341
page_t * m_page
The page.
Definition: btr0mtib.h:1697
dtuple_t * get_node_ptr() noexcept
Get node pointer.
Definition: btr0mtib.h:1754
Used to insert many blobs into InnoDB.
Definition: btr0mtib.h:802
Page_load * alloc_data_page()
Allocate a data page.
Definition: btr0mtib.cc:3999
Page_range_t m_page_range_first
Definition: btr0mtib.h:883
Page_load * alloc_first_page()
Allocate a LOB first page.
Definition: btr0mtib.cc:3979
Page_load * alloc_index_page()
Allocate a LOB index page.
Definition: btr0mtib.cc:3983
ut::Object_cache< Page_load > m_page_load_cache
Cache of Page_load objects.
Definition: btr0mtib.h:897
Page_extent * alloc_free_extent()
Definition: btr0mtib.cc:3938
Blob_inserter(Btree_load &btree_load)
Constructor.
Definition: btr0mtib.cc:3777
Page_load * alloc_page_from_extent(Page_extent *&m_page_extent)
Definition: btr0mtib.cc:3947
trx_id_t get_trx_id() const
Get the current transaction id.
Definition: btr0mtib.h:1853
~Blob_inserter()
Definition: btr0mtib.cc:4026
Page_extent * m_page_extent_first
Page extent from which to allocate first pages of blobs.
Definition: btr0mtib.h:881
dberr_t write_blob(Blob_context blob_ctx, lob::ref_t &ref, const byte *data, size_t len)
Write data into the blob.
Definition: btr0mtib.cc:3904
ut::Object_cache< Page_extent > m_page_extent_cache
Cache of Page_extent objects.
Definition: btr0mtib.h:900
dberr_t close_blob(Blob_context blob_ctx, lob::ref_t &ref)
Indicate that the blob has been completed, so that resources can be removed, and as necessary flushin...
Definition: btr0mtib.cc:3910
void finish()
Definition: btr0mtib.cc:4007
bool verify_blob_context(Blob_context ctx) const
Definition: btr0mtib.h:868
std::list< Page_extent * > m_index_extents
Page extent from which to allocate index pages of blobs.
Definition: btr0mtib.h:891
Blob_context m_blob
The current blob being inserted.
Definition: btr0mtib.h:894
dberr_t insert_blob(lob::ref_t &ref, const dfield_t *dfield)
Definition: btr0mtib.h:816
dberr_t open_blob(Blob_context &blob_ctx, lob::ref_t &ref)
Create a blob.
Definition: btr0mtib.cc:3899
dberr_t init()
Initialize by allocating necessary resources.
Definition: btr0mtib.cc:3784
Btree_load & m_btree_load
Definition: btr0mtib.h:877
ut::unique_ptr< Blob_handle > m_blob_handle
Only one blob handle per sub-tree.
Definition: btr0mtib.h:903
Page_extent * m_page_extent_data
Page extent from which to allocate data pages of blobs.
Definition: btr0mtib.h:887
We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load....
Definition: buf0flu.h:283
The proper function call sequence of Page_load is as below: – Page_load::init – Page_load::insert – P...
Definition: btr0load.cc:57
A helper RAII wrapper for otherwise difficult to use sequence of:
Definition: rem0rec.h:301
page_id_t id
Page id.
Definition: buf0buf.h:1382
Node of a tablespace encapsulating handle required for any IO operations on this node.
Definition: fil0fil.h:177
Tablespace or log data space.
Definition: fil0fil.h:506
Page identifier.
Definition: buf0types.h:191
Page size descriptor.
Definition: page0size.h:50
size_t physical() const
Retrieve the physical page size (on-disk).
Definition: page0size.h:129
A utility class which, if inherited from, prevents the descendant class from being copied,...
Definition: ut0class_life_cycle.h:41
A class to manage objects of type T.
Definition: ut0object_cache.h:40
const char * p
Definition: ctype-mb.cc:1227
dberr_t
Definition: db0err.h:39
@ DB_SUCCESS
Definition: db0err.h:43
DDL key comparison.
Data dictionary system.
static bool dict_table_is_comp(const dict_table_t *table)
Check whether the table uses the compact page format.
static ulint dict_index_is_spatial(const dict_index_t *index)
Check whether the index is a Spatial Index.
constexpr page_no_t FIL_NULL
'null' (undefined) page offset in the context of file spaces
Definition: fil0fil.h:1502
#define FSP_EXTENT_SIZE
File space extent size in pages page size | file space extent size -------—+--------------------— 4 K...
Definition: fsp0types.h:64
constexpr uint32_t FSEG_HEADER_SIZE
Length of the file system header, in bytes.
Definition: fsp0types.h:94
byte fseg_header_t
Data type for file segment header.
Definition: fsp0types.h:85
#define free(A)
Definition: lexyy.cc:915
For bulk loading large objects.
Implements the large objects (LOB) module.
Definition: btr0mtib.cc:62
void * Blob_context
Definition: btr0mtib.h:62
void bulk_load_enable_slow_io_debug()
Definition: btr0mtib.cc:69
void bulk_load_disable_slow_io_debug()
Definition: btr0mtib.cc:70
std::ostream & operator<<(std::ostream &out, const Page_extent &obj)
Definition: btr0mtib.h:315
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Used for bulk load of data.
Definition: fut0lst.cc:411
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:943
std::chrono::milliseconds milliseconds
Definition: authorize_manager.cc:70
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
const char * begin(const char *const c)
Definition: base64.h:44
size_t size(const char *const c)
Definition: base64.h:46
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
Define std::hash<Gtid>.
Definition: gtid.h:355
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2724
void delete_(T *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::new*() variants.
Definition: ut0new.h:651
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr
The following is a common type that is returned by all the ut::make_unique (non-aligned) specializati...
Definition: ut0new.h:2284
The page cursor.
static ulint page_get_free_space_of_empty(bool comp)
Calculates free space if a page is emptied.
static ulint page_get_data_size(const page_t *page)
Returns the sum of the sizes of the records in the record list excluding the infimum and supremum rec...
constexpr uint32_t PAGE_HEADER
index page header starts at this offset
Definition: page0types.h:53
constexpr uint32_t PAGE_BTR_SEG_LEAF
file segment header for the leaf pages in a B-tree: defined only on the root page of a B-tree,...
Definition: page0types.h:90
constexpr uint32_t PAGE_BTR_SEG_TOP
Definition: page0types.h:98
byte page_t
Type of the index page.
Definition: page0types.h:152
byte rec_t
Definition: rem0types.h:41
Interface between Innobase row operations and MySQL.
Function object to compare two Btree_load objects.
Definition: btr0mtib.h:1835
dict_index_t * m_index
Definition: btr0mtib.h:1838
bool operator()(const Btree_load *l_btree, const Btree_load *r_btree)
Definition: btr0mtib.cc:2155
Btree_load_compare(dict_index_t *index)
Definition: btr0mtib.h:1836
bool is_empty() const
Definition: btr0mtib.h:526
size_t m_max_range
Maximum number of ranges to pre-allocate.
Definition: btr0mtib.h:554
void init(size_t max_range)
Initialize cache.
Definition: btr0mtib.cc:2224
bool check(size_t &num_alloc, size_t &num_free) const
Check for number of extents to be allocated and cached.
Definition: btr0mtib.cc:2522
std::array< Page_range_t, S_MAX_RANGES > m_ranges
Cached page ranges already allocated to the segment.
Definition: btr0mtib.h:551
std::atomic< size_t > m_num_consumed
Total number of ranges allocated.
Definition: btr0mtib.h:560
void set_range(size_t index, Page_range_t &range)
Set allocated range(extent) in cache.
Definition: btr0mtib.cc:2513
std::atomic< size_t > m_num_allocated
Total number of ranges allocated.
Definition: btr0mtib.h:557
bool is_full() const
Definition: btr0mtib.h:529
bool get_range(Page_range_t &range, bool &alloc_trigger)
Get one page range from the cache.
Definition: btr0mtib.cc:2493
Context information for each level.
Definition: btr0mtib.h:352
size_t m_stat_n_extents
Number of extents allocated at this level.
Definition: btr0mtib.h:456
buf_block_t * alloc(const page_no_t new_page_no) noexcept
Allocate private memory buffer (BUF_BLOCK_MEMORY) block for given page number.
Definition: btr0mtib.cc:885
dict_index_t * m_index
The index which is being built.
Definition: btr0mtib.h:441
void build_page_cache()
Build page loader cache for current exent.
Definition: btr0mtib.cc:798
bool load_extent_from_cache()
Load one extent from extent cache.
Definition: btr0mtib.cc:745
dberr_t init()
Initialize.
Definition: btr0mtib.cc:838
Btree_load * m_btree_load
A back pointer to conceptually higher level btree load object.
Definition: btr0mtib.h:450
void set_current_page_load(Page_load *sibling)
Definition: btr0mtib.h:469
page_no_t m_last_page
The page_no of the last page in this level.
Definition: btr0mtib.h:438
~Level_ctx()
Destructor.
Definition: btr0mtib.cc:3405
const size_t m_level
The B-tree level whose context information is stored in this obj.
Definition: btr0mtib.h:444
void build_extent_cache()
Build the extent cache.
Definition: btr0mtib.cc:812
void free_page_load()
Free the current page load.
Definition: btr0mtib.cc:726
Page_load * create_page_load()
Definition: btr0mtib.cc:712
std::vector< page_no_t > m_pages_allocated
Definition: btr0mtib.h:463
trx_id_t get_trx_id() const
Definition: btr0mtib.h:1794
static void destroy(Level_ctx *obj)
Static member function to destroy a Level_ctx object.
Definition: btr0mtib.cc:681
std::vector< Page_extent * > m_cached_extents
Pre allocated extents to prevent repeated allocation and free.
Definition: btr0mtib.h:432
dberr_t alloc_page_num(page_no_t &page_no)
Allocate a page number.
Definition: btr0mtib.cc:614
Level_ctx(dict_index_t *index, size_t level, Btree_load *btree_load)
Constructor.
Definition: btr0mtib.h:371
bool m_extent_full
True if the current extent is full.
Definition: btr0mtib.h:459
dberr_t alloc_extent()
Allocate one extent in the relevant file segment.
Definition: btr0mtib.cc:651
size_t m_stat_n_pages
Number of pages allocated at this level.
Definition: btr0mtib.h:453
bool is_page_tracked(const page_no_t &page_no) const
Definition: btr0mtib.cc:645
Page_load * m_page_load
The Page_load of the current page being loaded.
Definition: btr0mtib.h:447
Page_load * get_page_load_from_cache()
Get a free page loader from cache.
Definition: btr0mtib.cc:780
Page_extent * m_page_extent
The current extent that is being loaded.
Definition: btr0mtib.h:415
page_no_t m_first_page
The page_no of the first page in this level.
Definition: btr0mtib.h:435
Page_load * get_page_load() const
Definition: btr0mtib.h:467
bool is_leaf() const
Check if this is leaf level.
Definition: btr0mtib.h:386
static Level_ctx * create(dict_index_t *index, size_t level, Btree_load *btree_load)
Static member function construct a Level_ctx object.
Definition: btr0mtib.cc:673
Allocate, use, manage and flush one extent pages (FSP_EXTENT_SIZE).
Definition: btr0mtib.h:69
Page_extent(Btree_load *btree_load, const bool is_leaf)
Constructor.
Definition: btr0mtib.h:1802
static void drop(Page_extent *extent)
Release the page extent.
Definition: btr0mtib.h:1821
bool is_blob() const
Check if this is a blob extent.
Definition: btr0mtib.h:225
void set_cached()
Mark the extent as cached.
Definition: btr0mtib.h:202
size_t m_next_cached_page_load_index
Next cached page load index.
Definition: btr0mtib.h:248
void get_page_numbers(std::vector< page_no_t > &page_numbers) const
Definition: btr0mtib.h:256
std::atomic_bool m_is_free
true if the cached entry is free to be used.
Definition: btr0mtib.h:244
std::vector< Page_load * > m_page_loads
All the page loaders of the used pages.
Definition: btr0mtib.h:89
bool is_null() const
Definition: btr0mtib.h:123
bool is_valid() const
Check if the range is valid.
Definition: btr0mtib.h:296
bool m_is_blob
True if this extent is used for blobs.
Definition: btr0mtib.h:251
bool is_any_used() const
Check if there are any pages used.
Definition: btr0mtib.h:155
page_no_t alloc()
Allocate a page number.
Definition: btr0mtib.h:328
void init()
Initialize the next page number to be allocated.
Definition: btr0mtib.h:338
std::ostream & print(std::ostream &out) const
Definition: btr0mtib.h:307
dberr_t destroy()
Free all resources.
Definition: btr0mtib.cc:604
std::pair< page_no_t, page_no_t > Page_range_t
Definition: btr0mtib.h:70
std::vector< Page_load * > m_cached_page_loads
Cached page loads.
Definition: btr0mtib.h:246
size_t used_pages() const
Calculate the number of used pages.
Definition: btr0mtib.h:111
void set_page_load(page_no_t page_no, Page_load *page_load)
Member of Page_extent.
Definition: btr0mtib.h:263
page_no_t page_count() const
Number of pages in this extent.
Definition: btr0mtib.h:347
dberr_t flush_one_by_one(fil_node_t *node)
Flush one page at a time.
Definition: btr0mtib.cc:444
page_no_t m_page_no
Next page number to be used.
Definition: btr0mtib.h:82
void set_blob()
Mark that this extent is used for blobs.
Definition: btr0mtib.h:221
void reset_range(const Page_range_t &range)
Reset the range with the given value.
Definition: btr0mtib.h:319
std::atomic_bool m_is_owned_by_bulk_flusher
True if this extent has been handed over to the bulk flusher.
Definition: btr0mtib.h:232
Page_range_t m_range
Page numbers of the pages that has been allocated in this extent.
Definition: btr0mtib.h:86
bool is_fully_used() const
Check if no more pages are there to be used.
Definition: btr0mtib.h:150
dberr_t flush(fil_node_t *node)
Flush the used pages to disk.
Definition: btr0mtib.cc:536
bool is_free() const
Definition: btr0mtib.h:209
void destroy_cached()
Free any cached page load entries.
Definition: btr0mtib.cc:596
void append(Page_load *page_load)
Save a page_load.
Definition: btr0mtib.h:1779
Page_range_t pages_to_free() const
size_t last() const
Get the index of the first unused page load.
Definition: btr0mtib.h:117
void set_state(bool free)
Set and unset free state of a cached extent.
Definition: btr0mtib.h:206
std::atomic_bool m_is_cached
true iff the extent is cached.
Definition: btr0mtib.h:242
void free_memory_blocks()
Free the BUF_BLOCK_MEMORY blocks used by this extent.
Definition: btr0mtib.h:1846
bool is_btree_load_nullptr() const
Definition: btr0mtib.h:91
dberr_t bulk_flush(fil_node_t *node)
Flush 1 extent pages at a time.
Definition: btr0mtib.cc:522
bool is_cached() const
Definition: btr0mtib.h:212
void reset_cached_page_loads()
Reset page load cache to free all.
Definition: btr0mtib.h:215
space_id_t space() const
Definition: btr0mtib.h:1798
static Page_extent * create(Btree_load *btree_load, const bool is_leaf, const bool is_blob)
Create an object of type Page_extent in the heap.
Definition: btr0mtib.h:1810
Page_load * get_page_load(page_no_t page_no)
Member of Page_extent.
Definition: btr0mtib.h:278
~Page_extent()
Destructor.
Definition: btr0mtib.h:288
Btree_load * m_btree_load
Definition: btr0mtib.h:236
bool m_is_leaf
true if this extent belongs to leaf segment.
Definition: btr0mtib.h:239
Information about a buffer page.
Definition: btr0mtib.h:1771
size_t m_n_recs
Number of user records in the page.
Definition: btr0mtib.h:1773
size_t m_data_size
Number of bytes of data.
Definition: btr0mtib.h:1776
Heap wrapper that destroys the heap instance when it goes out of scope.
Definition: mem0mem.h:432
Storage format for overflow data in a big record, that is, a clustered index record which needs exter...
Definition: data0data.h:865
The buffer control block structure.
Definition: buf0buf.h:1759
buf_page_t page
page information; this must be the first field, so that buf_pool->page_hash can point to buf_page_t o...
Definition: buf0buf.h:1765
bool is_memory() const noexcept
Definition: buf0buf.h:2006
Compare the keys of an index.
Definition: ddl0impl-compare.h:41
Structure for an SQL data field.
Definition: data0data.h:625
unsigned len
data length; UNIV_SQL_NULL if SQL null
Definition: data0data.h:631
void * data
pointer to data
Definition: data0data.h:626
Data structure for an index.
Definition: dict0mem.h:1069
unsigned space
space where the index tree is placed
Definition: dict0mem.h:1086
bool is_clustered() const
Definition: dict0mem.h:1316
dict_table_t * table
back pointer to table
Definition: dict0mem.h:1083
page_size_t get_page_size() const
Get the page size of the tablespace to which this index belongs.
Definition: dict0mem.cc:929
Data structure for a database table.
Definition: dict0mem.h:1927
table_name_t name
Table name.
Definition: dict0mem.h:2002
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:706
The struct 'lob::ref_t' represents an external field reference.
Definition: lob0lob.h:198
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:295
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:174
Definition: gen_lex_token.cc:149
char * m_name
The name in internal representation.
Definition: dict0mem.h:468
Definition: trx0trx.h:670
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:138
#define IF_DEBUG(...)
Definition: univ.i:677
unsigned long int ulint
Definition: univ.i:403
Utilities related to class lifecycle.
#define UT_LOCATION_HERE
Definition: ut0core.h:73
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:109
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:97
Dynamic memory allocation routines and custom allocators specifically crafted to support memory instr...
#define UT_NEW_THIS_FILE_PSI_KEY
Definition: ut0new.h:408
Manage a cache of objects.