MySQL 8.4.11
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 <stddef.h>
40#include <vector>
41
42#include "btr0load.h"
43#include "ddl0impl-compare.h"
44#include "dict0dict.h"
45#include "page0cur.h"
46#include "ut0class_life_cycle.h"
47#include "ut0new.h"
48
49/* The Btree_multi namespace is used for multi-threaded parallel index build. */
50namespace Btree_multi {
51
52// Forward declaration.
53class Page_load;
54class Btree_load;
55struct Page_stat;
56
57/** Allocate, use, manage and flush one extent pages (FSP_EXTENT_SIZE). */
59 using Page_range_t = std::pair<page_no_t, page_no_t>;
60
61 /** Constructor.
62 @param[in] btree_load B-tree loader object.
63 @param[in] is_leaf true if this is part of leaf segment, false if this is
64 part of non-leaf (or top) segment. */
65 Page_extent(Btree_load *btree_load, const bool is_leaf);
66
67 /** Destructor. */
69
70 /** Next page number to be used. */
72
73 /** Page numbers of the pages that has been allocated in this extent.
74 The page range is [p1, p2), where p2 is not included. */
76
77 /** All the page loaders of the used pages. */
78 std::vector<Page_load *> m_page_loads;
79
80 public:
81 /** Create an object of type Page_extent in the heap. */
82 static Page_extent *create(Btree_load *btree_load, const bool is_leaf,
83 const bool is_blob);
84
85 /** Release the page extent. Delete if not cached.
86 @param[in] extent extent to release */
87 static void drop(Page_extent *extent);
88
89 /** Number of pages in this extent. */
90 page_no_t page_count() const;
91
92 /** Reset the range with the given value.
93 @param[in] range new range value to be used. */
94 void reset_range(const Page_range_t &range);
95
96 /** Calculate the number of used pages.
97 return the number of used pages. */
98 size_t used_pages() const { return m_page_loads.size(); }
99
100 /** Check if the range is valid.
101 @return true if the range is valid, false otherwise. */
102 bool is_valid() const;
103
104 bool is_null() const {
105 return (m_range.first == FIL_NULL) && (m_range.second == FIL_NULL);
106 }
107
109
110 /** Initialize the next page number to be allocated. The page range should
111 have been already initialized. */
112 void init();
113
114 /** Check if no more pages are there to be used.
115 @return true if the page extent is completed used.
116 @return false if the page extent has more pages to be used. */
117 bool is_fully_used() const { return m_page_no == m_range.second; }
118 bool is_page_loads_full() const {
119 return m_page_loads.size() == (m_range.second - m_range.first);
120 }
121
122 public:
123 /** Allocate a page number. */
125
126 /** Save a page_load. */
127 void append(Page_load *page_load);
128
129 /** Flush the used pages to disk. It also frees the unused pages back to the
130 segment.
131 @param[in,out] node space file node
132 @param[in,out] iov vector IO array
133 @param[in] iov_size vector IO array size
134 @return On success, return DB_SUCCESS. */
135 dberr_t flush(fil_node_t *node, void *iov, size_t iov_size);
136
137 /** Flush one page at a time. This can be used when scatter/gather i/o is
138 not available for use.
139 @param[in,out] node space file node
140 @return On success, return DB_SUCCESS. */
142
143 /** Flush 1 extent pages at a time. Internally it will call OS dependent
144 API (either bulk_flush_win() on Windows or bulk_flush_linux() on other
145 operating systems.
146 @param[in,out] node space file node
147 @param[in,out] iov vector IO array
148 @param[in] iov_size vector IO array size
149 @return DB_SUCCESS on success, error code on failure. */
150 dberr_t bulk_flush(fil_node_t *node, void *iov [[maybe_unused]],
151 size_t iov_size [[maybe_unused]]);
152
153#ifdef UNIV_LINUX
154 /** Flush 1 extent pages at a time. Uses pwritev() i/o API.
155 @param[in,out] node space file node
156 @param[in,out] iov vector IO array
157 @param[in] iov_size vector IO array size
158 @return DB_SUCCESS on success, error code on failure. */
159 dberr_t bulk_flush_linux(fil_node_t *node, struct iovec *iov,
160 size_t iov_size);
161#endif /* UNIV_LINUX */
162
163 /** Free all resources. */
165
166 /** Free any cached page load entries. */
167 void destroy_cached();
168
169 space_id_t space() const;
170
171 /** Mark the extent as cached. Flush thread should not free this extent. */
172 void set_cached() { m_is_cached.store(true); }
173
174 /** Set and unset free state of a cached extent.
175 @param[in] free state to be set */
176 void set_state(bool free) { m_is_free.store(free); }
177
178 /** @return true iff the cached element is in free state. */
179 bool is_free() const { return m_is_free.load(); }
180
181 /** @return true iff it is a cached extent. */
182 bool is_cached() const { return m_is_cached.load(); }
183
184 /** Reaset page load cache to free all. */
186
187 public:
188 std::ostream &print(std::ostream &out) const;
189
190 private:
192 const bool m_is_leaf; /* true if this extent belongs to leaf segment. */
193 /** true iff the the extent is cached. */
194 std::atomic_bool m_is_cached{false};
195 /** true if the cached entry is free to be used. */
196 std::atomic_bool m_is_free{true};
197 /** Cached page loads. */
198 std::vector<Page_load *> m_cached_page_loads;
199 /** Next cached page load index. */
201
202 friend struct Level_ctx;
203};
204
207 m_range.first = FIL_NULL;
208 m_range.second = FIL_NULL;
209 m_btree_load = nullptr;
210}
211
212inline bool Page_extent::is_valid() const {
213 ut_ad(m_range.first != 0);
214 ut_ad(m_range.second != 0);
215 if (is_null()) {
216 return true;
217 }
218 ut_ad(m_range.first < m_range.second);
219 ut_ad((m_range.second - m_range.first) <= FSP_EXTENT_SIZE);
220 return m_range.first < m_range.second;
221}
222
223inline std::ostream &Page_extent::print(std::ostream &out) const {
224 out << "[Page_extent: this=" << (void *)this
225 << ", m_range.first=" << m_range.first
226 << ", m_range.second=" << m_range.second
227 << ", page_loads=" << m_page_loads.size() << "]" << std::endl;
228 return out;
229}
230
231inline std::ostream &operator<<(std::ostream &out, const Page_extent &obj) {
232 return obj.print(out);
233}
234
236 ut_ad(range.first != 0);
237 ut_ad(range.second != 0);
238 ut_ad(range.first != FIL_NULL);
239 ut_ad(range.second != FIL_NULL);
240 m_range = range;
241 m_page_no = m_range.first;
242}
243
245 ut_ad(is_valid());
246 if (m_page_no == m_range.second) {
247 return FIL_NULL;
248 }
249 return m_page_no++;
250}
251
252inline void Page_extent::init() {
253 ut_ad(m_range.first != 0);
254 ut_ad(m_range.second != 0);
255 ut_ad(m_range.first != FIL_NULL);
256 ut_ad(m_range.second != FIL_NULL);
257 m_page_no = m_range.first;
258}
259
261 return m_range.second - m_range.first;
262}
263
264/** Context information for each level. */
265struct Level_ctx {
266 /** Static member function construct a Level_ctx object.
267 @param[in] index dictionary index object.
268 @param[in] level the B-tree level of this context object.
269 @param[in] btree_load a back pointer to the Btree_load object to which this
270 Level_ctx object is a part of.
271 @return level context object on success, nullptr on error. */
272 static Level_ctx *create(dict_index_t *index, size_t level,
273 Btree_load *btree_load);
274
275 /** Static member function to destroy a Level_ctx object.
276 @param[in] obj the Level_ctx object to destroy. */
277 static void destroy(Level_ctx *obj);
278
279 /** Constructor
280 @param[in] index dictionary index object.
281 @param[in] level the B-tree level of this context object.
282 @param[in] btree_load a back pointer to the Btree_load object to which this
283 Level_ctx object is a part of.*/
284 Level_ctx(dict_index_t *index, size_t level, Btree_load *btree_load)
285 : m_index(index),
286 m_level(level),
288 m_btree_load(btree_load) {}
289
290 /** Destructor. */
291 ~Level_ctx();
292
293 /** Initialize.
294 @return DB_SUCCESS on success, an error code on failure. */
295 dberr_t init();
296
297 /** Check if this is leaf level.
298 @return true if this is leaf level, false otherwise. */
299 bool is_leaf() const { return m_level == 0; }
300
302
303 /** Free the current page load. */
304 void free_page_load();
305
306 /** Allocate a page number. Subsequently a Page_load will be created with the
307 allocated page number.
308 @param[out] page_no page number that was allocated.
309 @return DB_SUCCESS on success, error code on failure.*/
311
312 /** Allocate one extent in the relevant file segment. No associated buffer
313 blocks are allocated.
314 @return DB_SUCCESS on success, error code on failure.*/
316
317 /** Allocate private memory buffer (BUF_BLOCK_MEMORY) block for given page
318 number. */
319 [[nodiscard]] buf_block_t *alloc(const page_no_t new_page_no) noexcept;
320
321 void set_current_page_load(Page_load *sibling);
322
323 Page_load *get_page_load() const;
324
325 trx_id_t get_trx_id() const;
326
327 /** The current extent that is being loaded. */
329
330 /** Build the extent cache. */
331 void build_extent_cache();
332
333 /** Load one extent from extent cache.
334 @return true iff successful. */
336
337 /** Build page loader cache for current exent. */
338 void build_page_cache();
339
340 /** Get a free page loader from cache
341 @return page loader or nullptr if not found. */
343
344 /** Pre allocated extents to prevent repeated allocation and free. */
345 std::vector<Page_extent *> m_cached_extents;
346
347 /** The page_no of the first page in this level. */
349
350 /** The page_no of the last page in this level. */
352
353 /** The index which is being built. */
355
356 /** The B-tree level whose context information is stored in this obj. */
357 const size_t m_level{};
358
359 /** The Page_load of the current page being loaded. */
361
362 /** A back pointer to conceptually higher level btree load object. */
364
365 /** Number of pages allocated at this level. */
367
368 /** Number of extents allocated at this level. */
370
371 /** True if the current extent is full. */
372 bool m_extent_full{true};
373
374#ifdef UNIV_DEBUG
375 bool is_page_tracked(const page_no_t &page_no) const;
376 std::vector<page_no_t> m_pages_allocated;
377#endif /* UNIV_DEBUG */
378};
379
381
383 m_page_load = sibling;
384}
385
387 public:
388 enum class Type {
389 /** Allocate by Page */
390 PAGE,
391 /** Allocate by extent. */
392 EXTENT
393 };
394
395 /** Destructor to ensure thread stop. */
397
398 /** Check size and set extent allocator size parameters
399 @param[in] table Innodb dictionary table object
400 @param[in] trx transaction performing bulk load
401 @param[in] size total data size to be loaded
402 @param[in] num_threads number of concurrent threads
403 @param[in] in_pages if true, allocate in pages
404 @return tablespace extend size in bytes. */
405 uint64_t init(dict_table_t *table, trx_t *trx, size_t size,
406 size_t num_threads, bool in_pages);
407
408 /* Start extent allocator thread. */
409 void start();
410
411 /** Stop extent allocator thread, if active. */
412 void stop();
413
414 /** Allocate a page range - currently ans Extent.
415 @param[in] is_leaf true if leaf segment, otherwise non-leaf segment
416 @param[in] alloc_page if true, allocate in pages otherwise allocate extent
417 @param[out] range page range
418 @param[in,out] fn_wait_begin begin callback if wait is needed
419 @param[in,out] fn_wait_end end callback if wait is needed
420 @return Innodb error code. */
421 dberr_t allocate(bool is_leaf, bool alloc_page, Page_range_t &range,
422 std::function<void()> &fn_wait_begin,
423 std::function<void()> &fn_wait_end);
424
425 private:
426 /** Upper bound for max ranges. */
427 static constexpr size_t S_MAX_RANGES = 2 * 1024;
428
429 /** Maximum size by which the tablespace is extended each time. */
430 static constexpr size_t S_BULK_EXTEND_SIZE_MAX = 64;
431
433 /** Initialize cache.
434 @param[in] max_range miaximum number of extents to cache. */
435 void init(size_t max_range);
436
437 /** @return true if no available extent to consume. */
438 inline bool is_empty() const { return (m_num_allocated == m_num_consumed); }
439
440 /** @return true if cache is full and no more extents can be added. */
441 inline bool is_full() const {
443 }
444
445 /** Check for number of extents to be allocated and cached.
446 @param[out] num_alloc number of extents to allocate
447 @param[out] num_free number of free extents
448 @return true if succesful. */
449 bool check(size_t &num_alloc, size_t &num_free) const;
450
451 /** Get one page range from the cache.
452 @param[out] range the allocated page range
453 @param[out] alloc_trigger true, if need to trigger allocator
454 @return true if extent is successfully returned from cache. */
455 bool get_range(Page_range_t &range, bool &alloc_trigger);
456
457 /** Set allocated range(extent) in cache.
458 @param[in] index position of the range
459 @param[in] range page range to be set */
460 void set_range(size_t index, Page_range_t &range);
461
462 /** Cached page ranges already allocated to the segment. */
463 std::array<Page_range_t, S_MAX_RANGES> m_ranges;
464
465 /** Maximum number of ranges to pre-allocate. */
467
468 /** Total number of ranges allocated. */
469 std::atomic<size_t> m_num_allocated{0};
470
471 /** Total number of ranges allocated. */
472 std::atomic<size_t> m_num_consumed{0};
473 };
474
475 /** Exetent thread executor.
476 @return innodb error code. */
477 dberr_t run();
478
479 /** Allocate extents and fill the cache.
480 @param[in] is_leaf true if leaf segment, otherwise non-leaf segment
481 @param[in] num_extents number of extents to allocate
482 @return innodb error code. */
483 dberr_t allocate_extents(bool is_leaf, size_t num_extents);
484
485 /** Allocator wait function. */
486 void allocator_wait() const;
487
488 /** Check if leaf and non-leaf extent cache needs to be filled.
489 @param[out] n_leaf number of leaf extents to allocate
490 @param[out] n_non_leaf number of non-leaf extents to allocate
491 @param[out] trigger true if consumers should be triggered
492 @return true if allocator should stop. */
493 bool check(size_t &n_leaf, size_t &n_non_leaf, bool &trigger);
494
495 /** Allocate one extent.
496 @param[in] is_leaf true if leaf segment, otherwise non-leaf segment
497 @param[in,out] mtr mini tranaction to be used for allocation
498 @param[out] range page rannge for the extent
499 @return innodb error code. */
500 dberr_t allocate_extent(bool is_leaf, mtr_t &mtr, Page_range_t &range);
501
502 /** Allocate one page.
503 @param[in] is_leaf true if leaf segment, otherwise non-leaf segment
504 @param[out] range page rannge for the page
505 @return innodb error code. */
506 dberr_t allocate_page(bool is_leaf, Page_range_t &range);
507
508 /** @return true if operation is interrupted. */
509 bool is_interrupted();
510
511 private:
512 /** Bulk extent allocator. */
513 std::thread m_thread;
514
515 /** Number of times consumer(s) had to wait. */
516 mutable size_t m_consumer_wait_count{};
517
518 /** Number of times allocator had to wait. */
519 mutable size_t m_allocator_wait_count{};
520
521 /** Total consumer wait time in micro seconds. */
522 mutable std::chrono::microseconds m_consumer_wait_time;
523
524 /** Total allocator wait time in micro seconds. */
525 mutable std::chrono::microseconds m_allocator_wait_time;
526
527 /** Page range type. */
529
530 /** Cached leaf extents. */
532
533 /** Cached non-leaf extents. */
535
536 /** This mutex protects the m_queue. */
537 mutable std::mutex m_mutex;
538
539 /** Condition variable for allocator thread. */
540 mutable std::condition_variable m_allocator_condition;
541
542 /** Condition variable for extent consumer threads. */
543 mutable std::condition_variable m_consumer_condition;
544
545 /** Flag to indicate if the bulk allocator thread should stop. */
546 bool m_stop{false};
547
548 /** Error code, protected by m_mutex */
550
551 /** Innodb dictionary table object. */
553
554 /** Innodb transaction - used for checking interrupt. */
556
557 /** Number of concurrent consumers. */
559};
560
562 public:
563 /** Thread main function.
564 @return innodb error code. */
565 dberr_t run();
566
567 /** Check if work is available for the bulk flusher thread.
568 @return true if work is available. */
569 bool is_work_available();
570
571 /** Start a new thread to do the flush work.
572 @param[in] space_id space for flushing pages to
573 @param[in] index loader index
574 @param[in] queue_size flusher queue size */
575 void start(space_id_t space_id, size_t index, size_t queue_size);
576
577 /** Add a page extent to the bulk flush queue.
578 @param[in,out] page_extent extent to be added to the queue
579 @param[in,out] fn_wait_begin begin callback if wait is needed
580 @param[in,out] fn_wait_end end callback if wait is needed */
581 void add(Page_extent *page_extent, std::function<void()> &fn_wait_begin,
582 std::function<void()> &fn_wait_end);
583
584 /** Check for flusher error and wake up flusher thread.
585 @return Innodb error code. */
587
588 /** Wait till the bulk flush thread stops. */
589 void wait_to_stop();
590
591 /** Get the maximum allowed queue size.
592 @return the maximum allowed queue size. */
593 size_t get_max_queue_size() const { return m_max_queue_size; }
594
595 /** Destructor. */
597
598 /** @return true iff error has occurred. */
599 bool is_error() const { return m_is_error.load(); }
600
601 /** @return error code */
602 dberr_t get_error() const;
603
604 private:
605 /** Do the actual work of flushing.
606 @param[in,out] node space file node
607 @param[in,out] iov vector IO array
608 @param[in] iov_size vector IO array size */
609 void do_work(fil_node_t *node, void *iov, size_t iov_size);
610
611 /** Check if the bulk flush thread should stop working. */
612 bool should_i_stop() const { return m_stop.load(); }
613
614 /** When no work is available, put the thread to sleep. */
615 void wait();
616
617 /** Print useful information to the server log file while exiting. */
618 void info();
619
620 /** This queue is protected by the m_mutex. */
621 std::vector<Page_extent *> m_queue;
622
623 /** This mutex protects the m_queue. */
624 mutable std::mutex m_mutex;
625
626 /** Condition variable to wait upon. */
627 mutable std::condition_variable m_condition;
628
629 /** Flag to indicate if the bulk flusher thread should stop. If true, the
630 bulk flusher thread will stop after emptying the queue. If false, the
631 bulk flusher thread will go to sleep after emptying the queue. */
632 std::atomic<bool> m_stop{false};
633
634 /** Set if error is encountered during flush. */
635 std::atomic<bool> m_is_error{false};
636
637 /** Error code, protected by m_mutex */
639
640 /** Set error code.
641 @param[in] error_code error code to set. It could be DB_SUCCESS.*/
642 void set_error(dberr_t error_code);
643
644 /** Private queue (private to the bulk flush thread) containing the extents to
645 flush. */
646 std::vector<Page_extent *> m_priv_queue;
647
648 /** Bulk flusher thread. */
649 std::thread m_flush_thread;
650
651 /** Number of times slept */
652 size_t m_n_sleep{};
653
654 /** Total sleep time in micro seconds. */
655 std::chrono::microseconds m_wait_time;
656
657 /** The sleep duration in milliseconds. */
658 static constexpr std::chrono::milliseconds s_sleep_duration{100};
659
660 /** Maximum queue size, defaults to 4 */
662
663 /** Number of pages flushed. */
665
666 /** Bulk flusher is specific to a tablespace for now. */
668
669 /** Flusher ID. */
670 size_t m_id{};
671
672#ifdef UNIV_DEBUG
673 public:
674 /** Vector of page numbers that are flushed by this Bulk_flusher object. */
675 std::vector<page_no_t> m_flushed_page_nos;
676#endif /* UNIV_DEBUG */
677};
678
679/** @note We should call commit(false) for a Page_load object, which is not in
680m_page_loaders after page_commit, and we will commit or abort Page_load
681objects in function "finish". */
683 public:
684 /** Merge multiple Btree_load sub-trees together. */
685 class Merger;
686
687 public:
690 std::vector<Page_loader_ptr, ut::allocator<Page_loader_ptr>>;
691 using Level_ctxs = std::vector<Level_ctx *, ut::allocator<Level_ctx *>>;
692
693 /** Helper to set wait callbacks for the current scope. */
695 public:
696 using Function = std::function<void()>;
697 friend class Btree_load;
698
700 : m_btree_load(btree_load) {
703 }
704
706 m_btree_load->m_fn_wait_begin = nullptr;
707 m_btree_load->m_fn_wait_end = nullptr;
708 }
709
710 private:
711 /** Btree Load for the wait callbacks. */
713 };
714
715 /** Constructor
716 @param[in] index B-tree index.
717 @param[in] trx Transaction object.
718 @param[in] loader_num loader index
719 @param[in] flush_queue_size bulk flusher queue size
720 @param[in] allocator extent allocator */
721 Btree_load(dict_index_t *index, trx_t *trx, size_t loader_num,
722 size_t flush_queue_size,
723 Bulk_extent_allocator &allocator) noexcept;
724
725 /** Destructor */
726 ~Btree_load() noexcept;
727
728 /** Initialize. Allocates the m_heap_order memory heap.
729 @return DB_SUCCESS on success or an error code on failure. */
730 dberr_t init();
731
732#ifdef UNIV_DEBUG
733 /** Save flushed page numbers for debugging purposes.
734 @param[in] page_no page number of the page that is flushed. */
736 m_bulk_flusher.m_flushed_page_nos.push_back(page_no);
737 }
738#endif /* UNIV_DEBUG */
739
740 /** Check if the index build operation has been interrupted.
741 @return true if the index build operation is interrupted, false otherwise.*/
742 bool is_interrupted() const;
743
744 /** Trigger flusher thread and check for error.
745 @return Innodb error code. */
747
748 /** Get the index object.
749 @return index object. */
750 dict_index_t *index() const { return m_index; }
751
752 const char *get_table_name() const { return m_index->table->name.m_name; }
753
754 /** Get the root page number of this tree/subtree.
755 @return the root page number of this tree/subtree. */
756 page_no_t get_subtree_root() const { return m_first_page_nos.back(); }
757
758 /** Get the level of the root page.
759 @return the level of the root page. */
760 size_t get_root_level() const { return m_root_level; }
761
762 /** Get information about root page. */
763 void get_root_page_stat(Page_stat &stat);
764
765 /** Get the transaction id.
766 @return the transaction id. */
767 trx_id_t get_trx_id() const;
768
769 /** Btree bulk load finish. We commit the last page in each level
770 and copy the last page in top level to the root page of the index
771 if no error occurs.
772 @param[in] is_err Whether bulk load was successful until now
773 @param[in] subtree true if a subtree is being built, false otherwise.
774 @return error code */
775 [[nodiscard]] dberr_t finish(bool is_err, const bool subtree) noexcept;
776
777 /** Insert a tuple to a page in a level
778 @param[in] dtuple Tuple to insert
779 @param[in] level B-tree level
780 @return error code */
781 [[nodiscard]] dberr_t insert(dtuple_t *dtuple, size_t level) noexcept;
782
783 /** Split the right most block of the tree at the given level.
784 @param[in,out] block the right most block at the given level.
785 @param[in] level level of the given block.
786 @param[in] node_ptr node pointer to be inserted in the block after
787 splitting.
788 @param[in] mtr mini transaction context.
789 @param[in,out] highest_level highest level among all the subtrees.*/
790 void split_rightmost(buf_block_t *block, size_t level, dtuple_t *node_ptr,
791 mtr_t *mtr, size_t &highest_level);
792
793 /** Split the left most block of the tree at the given level.
794 @param[in,out] block the left most block at the given level. it will be
795 updated with the new left most block.
796 @param[in] level level of the given block.
797 @param[in] node_ptr node pointer to be inserted in the block after
798 splitting.
799 @param[in] mtr mini transaction context.
800 @param[in,out] highest_level highest level among all the subtrees.*/
801 void split_leftmost(buf_block_t *&block, size_t level, dtuple_t *node_ptr,
802 mtr_t *mtr, size_t &highest_level);
803
804 private:
805 /** Set the root page on completion.
806 @param[in] last_page_no Last page number (the new root).
807 @return DB_SUCCESS or error code. */
808 [[nodiscard]] dberr_t load_root_page(page_no_t last_page_no) noexcept;
809
810 public:
811 /** Commit(finish) a page. We set next/prev page no, insert a node pointer to
812 father page if needed, and commit mini-transaction.
813 @param[in] page_load Page to commit
814 @param[in] next_page_load Next page
815 @param[in] insert_father Flag whether need to insert node ptr
816 @return error code */
817 [[nodiscard]] dberr_t page_commit(Page_load *page_load,
818 Page_load *next_page_load,
819 bool insert_father) noexcept;
820
821 /** Prepare space to insert a tuple.
822 @param[in,out] page_load Page bulk that will be used to store the record.
823 It may be replaced if there is not enough space
824 to hold the record.
825 @param[in] level B-tree level
826 @param[in] rec_size Record size
827 @return error code */
828 [[nodiscard]] dberr_t prepare_space(Page_load *&page_load, size_t level,
829 size_t rec_size) noexcept;
830
831 /** Insert a tuple to a page.
832 @param[in] page_load Page bulk object
833 @param[in] tuple Tuple to insert
834 @param[in] big_rec Big record vector, maybe NULL if there is no
835 Data to be stored externally.
836 @param[in] rec_size Record size
837 @return error code */
838 [[nodiscard]] dberr_t insert(Page_load *page_load, dtuple_t *tuple,
839 big_rec_t *big_rec, size_t rec_size) noexcept;
840
841 /** Btree page bulk load finish. Commits the last page in each level
842 if no error occurs. Also releases all page bulks.
843 @param[in] is_err Whether bulk load was successful until now
844 @param[out] last_page_no Last page number
845 @return error code */
846 [[nodiscard]] dberr_t finalize_page_loads(bool is_err,
847 page_no_t &last_page_no) noexcept;
848
849 public:
850 /** Allocate an extent.
851 @param[in,out] page_range the range of pages allocated.
852 @param[in] level btree level for which pages are allocated.
853 @return status code. */
854 dberr_t alloc_extent(Page_range_t &page_range, size_t level);
855
856 /** Initiate a direct file write operation.
857 @param[in] block block to be written to disk.
858 @return error code. */
859 [[nodiscard]] dberr_t fil_io(buf_block_t *block) noexcept;
860
861 /** Flush the blob pages.
862 @return status code. */
863 [[nodiscard]] dberr_t flush_blobs() noexcept;
864
865 /** Add the given block the internal cache of blocks.
866 @param[in] block the block to be cached. */
867 inline void block_put(buf_block_t *block);
868
869 /** Remove the given block from the internal cache of blocks.
870 @param[in] page_no the page number of block to be removed from cache. */
871 inline void block_remove(const page_no_t page_no);
872
873 /** Search for a BUF_BLOCK_MEMORY block with given page number in the local
874 cache.
875 @param[in] page_no the page number of block to be fetched.
876 @return buffer block with given page number. */
877 [[nodiscard]] inline buf_block_t *block_get(page_no_t page_no) const noexcept;
878
879 /** Evict all the pages in the given range from the buffer pool.
880 @param[in] range range of page numbers.
881 @param[in] dirty_is_ok it is OK for a page to be dirty. */
882 void force_evict(const Page_range_t &range, const bool dirty_is_ok = true);
883
884 public:
885 /** Check if a new level is needed. */
886 bool is_new_level(size_t level) const { return level >= m_level_ctxs.size(); }
887
888 /** Last page numbers of each level. */
889 std::vector<page_no_t, ut::allocator<page_no_t>> m_last_page_nos{};
890
891 /** First page numbers of each level. */
892 std::vector<page_no_t, ut::allocator<page_no_t>> m_first_page_nos{};
893
894 /** Get the level context object.
895 @param[in] level the level number. level 0 is leaf level.
896 @return the level context object. */
897 Level_ctx *get_level(size_t level) const;
898
899 /** Page numbers of the pages that has been allocated in the leaf level.
900 The page range is [p1, p2), where p2 is not included. */
902
903 /** Page numbers of the pages that has been allocated in the non-leaf level.
904 The page range is [p1, p2), where p2 is not included. */
906
909
910 /** State of the index. Used for asserting at the end of a
911 bulk load operation to ensure that the online status of the
912 index does not change */
914
915 /** Number of extents allocated for this B-tree. */
917
918 /** Number of pages allocated for this B-tree. */
919 size_t m_stat_n_pages{0};
920
921 public:
922 std::ostream &print_left_pages(std::ostream &out) const;
923 std::ostream &print_right_pages(std::ostream &out) const;
924
925 dberr_t check_key_overlap(const Btree_load *r_btree) const;
926
927#ifdef UNIV_DEBUG
928 void print_tree_pages() const;
929 std::string print_pages_in_level(const size_t level) const;
930 /** Check size and validate index of limited size.
931 @param[in] index Index to validate
932 @return true if successful. */
933 static bool validate_index(dict_index_t *index);
934#endif /* UNIV_DEBUG */
935
936 /** All allocated extents registers with Btree_load. */
937 void track_extent(Page_extent *page_extent);
938
939 /** Add fully used extents to the bulk flusher. Call this whenever a new
940 Page_load is allocated, with finish set to false. Only in
941 Btree_load::finish(), the finish argument will be true.
942 @param[in] finish if true, add all the tracked extents to the bulk flusher,
943 irrespective of whether it is fully used or not. */
944 void add_to_bulk_flusher(bool finish = false);
945
946 /** Add the given page extent object to the bulk flusher.
947 @param[in] page_extent the extent to be flushed. */
948 void add_to_bulk_flusher(Page_extent *page_extent);
949
950 /** Check if transparent page compression (TPC) is enabled.
951 @return true if TPC is enabled. */
952 bool is_tpc_enabled() const;
953
954 /** Check if transparent page encryption (TPE) is enabled.
955 @return true if TPE is enabled. */
956 bool is_tpe_enabled() const;
957
958 /** @return get flush queue size limit. */
961 }
962
963 /** If the data is already sorted and checked for duplicates, then we can
964 disable doing it again. */
966
967 private:
968 /** Page allocation type. We allocate in extents by default. */
971
972 /** Number of records inserted. */
973 uint64_t m_n_recs{};
974
975 /** B-tree index */
977
979
980 /** Transaction id */
982
983 /** Root page level */
984 size_t m_root_level{};
985
986 private:
987 /** Context information for each level of the B-tree. The leaf level is at
988 m_level_ctxs[0]. */
990
991 /* Dedicated thread to flush pages. */
993
994 /** Reference to global extent allocator. */
996
997 /** Extents that are being tracked. */
998 std::list<Page_extent *> m_extents_tracked;
999
1000 /** If true, check if data is inserted in sorted order. */
1001 bool m_check_order{true};
1002
1003 /** Memory heap to be used for sort order checks. */
1005
1006 /** Function object to compare two tuples. */
1008
1009 /** The previous tuple that has been inserted. */
1011
1012 bool is_extent_tracked(const Page_extent *page_extent) const;
1013
1014 /** Loader number. */
1016
1018
1019 /* Begin wait callback function. */
1021
1022 /* End wait callback function. */
1024};
1025
1027 public:
1028 using Btree_loads = std::vector<Btree_load *, ut::allocator<Btree_load *>>;
1029
1031 : m_btree_loads(loads),
1032 m_index(index),
1033 m_trx(trx),
1035
1036 dberr_t merge(bool sort);
1037
1038 private:
1039 /** Get the maximum free space available in an empty page in bytes.
1040 @return the maximum free space available in an empty page. */
1041 size_t get_max_free() const {
1043 }
1044
1045 /** Remove any empty sub-trees with no records. */
1046 void remove_empty_subtrees();
1047
1048#ifdef UNIV_DEBUG
1049 /** Validate sub-tree boundaries. */
1050 void validate_boundaries();
1051
1052#endif /* UNIV_DEBUG */
1053
1054 /** Stich sub-trees together to form a tree with one or multiple
1055 nodes at highest leve.
1056 @param[out] highest_level highest level of the merged tree.
1057 @return innodb error code. */
1058 dberr_t subtree_link_levels(size_t &highest_level);
1059
1060 /** Create root node for the stiched sub-trees by combining the nodes
1061 at highest level creating another level if required.
1062 @param[in] highest_level highest level of the merged tree.
1063 @return innodb error code. */
1064 dberr_t add_root_for_subtrees(const size_t highest_level);
1065
1066 /** Insert the given list of node pointers into pages at the given level.
1067 @param[in,out] all_node_ptrs list of node pointers
1068 @param[in,out] total_node_ptrs_size total space in bytes needed to insert
1069 all the node pointers.
1070 @param[in] level the level at which the node pointers are inserted.
1071 @return DB_SUCCESS if successful.
1072 @return error code on failure. */
1073 dberr_t insert_node_ptrs(std::vector<dtuple_t *> &all_node_ptrs,
1074 size_t &total_node_ptrs_size, size_t level);
1075
1076 /** Load the left page and update its FIL_PAGE_NEXT.
1077 @param[in] l_page_no left page number
1078 @param[in] r_page_no right page number. */
1079 void link_right_sibling(const page_no_t l_page_no, const page_no_t r_page_no);
1080
1081 private:
1082 /** Refernce to the subtrees to be merged. */
1084
1085 /** Index which is being built. */
1087
1088 /** Transaction making the changes. */
1090
1091 /** Memory heap to store node pointers. */
1093};
1094
1096 const Page_extent *page_extent) const {
1097 for (auto e : m_extents_tracked) {
1098 if (page_extent == e) {
1099 return true;
1100 }
1101 }
1102 return false;
1103}
1104
1105/** The proper function call sequence of Page_load is as below:
1106-- Page_load::init
1107-- Page_load::insert
1108-- Page_load::finish
1109-- Page_load::commit */
1111 public:
1113
1114 /** Ctor.
1115 @param[in] index B-tree index
1116 @param[in] btree_load btree object to which this page belongs. */
1117 Page_load(dict_index_t *index, Btree_load *btree_load);
1118
1119 /** Destructor. */
1120 ~Page_load() noexcept;
1121
1122 /** Check if page is corrupted.
1123 @return true if corrupted, false otherwise. */
1124 bool is_corrupted() const;
1125
1126 /** Print the child page numbers. */
1127 void print_child_page_nos() noexcept;
1128
1129 /** Check if state of this page is BUF_BLOCK_MEMORY.
1130 @return true if page state is BUF_BLOCK_MEMORY, false otherwise.*/
1131 bool is_memory() const { return m_block->is_memory(); }
1132
1133 /** A static member function to create this object.
1134 @param[in] btree_load the bulk load object to which this Page_load belongs.
1135 @param[in] page_extent page extent to which this page belongs. */
1136 static Page_load *create(Btree_load *btree_load, Page_extent *page_extent);
1137
1138 /** Release the page loader. Delete if not cached.
1139 @param[in] page_load page loader to delete. */
1140 static void drop(Page_load *page_load);
1141
1142 /** Constructor
1143 @param[in] index B-tree index
1144 @param[in] trx_id Transaction id
1145 @param[in] page_no Page number
1146 @param[in] level Page level
1147 @param[in] observer Flush observer
1148 @param[in] btree_load btree object to which this page belongs. */
1150 size_t level, Flush_observer *observer,
1151 Btree_load *btree_load = nullptr) noexcept
1152 : m_index(index),
1153 m_trx_id(trx_id),
1154 m_page_no(page_no),
1155 m_level(level),
1157 m_flush_observer(observer),
1158 m_btree_load(btree_load) {
1160 }
1161
1162 /** Set the transaction id.
1163 @param[in] trx_id the transaction id to used. */
1164 void set_trx_id(const trx_id_t trx_id) { m_trx_id = trx_id; }
1165
1166 /** Set the flush observer.
1167 @param[in] observer the flush observer object to use. */
1169 m_flush_observer = observer;
1170 }
1171
1172 bool is_leaf() const { return m_level == 0; }
1173
1174 /** Set the page number of this object. */
1175 void set_page_no(const page_no_t page_no);
1176
1177 void set_leaf_seg(const fseg_header_t *hdr) {
1179 }
1180 void set_top_seg(const fseg_header_t *hdr) {
1182 }
1183
1184 /** Initialize members and allocate page if needed and start mtr.
1185 @note Must be called and only once right after constructor.
1186 @return error code */
1187 [[nodiscard]] dberr_t init() noexcept;
1188 [[nodiscard]] dberr_t init_mem(const page_no_t new_page_no,
1189 Page_extent *page_extent) noexcept;
1190
1191 /** Allocate a page for this Page_load object.
1192 @return DB_SUCCESS on success, error code on failure. */
1193 dberr_t alloc() noexcept;
1194
1195 /** Re-initialize this page. */
1196 [[nodiscard]] dberr_t reinit() noexcept;
1197
1198 /** Reset this object so that Page_load::init() can be called again on this
1199 object. */
1200 void reset() noexcept;
1201
1202 /** Insert a tuple in the page.
1203 @param[in] tuple Tuple to insert
1204 @param[in] big_rec External record
1205 @param[in] rec_size Record size
1206 @return error code */
1207 [[nodiscard]] dberr_t insert(const dtuple_t *tuple, const big_rec_t *big_rec,
1208 size_t rec_size) noexcept;
1209
1210 /** Mark end of insertion to the page. Scan records to set page dirs,
1211 and set page header members. The scan is incremental (slots and records
1212 which assignment could be "finalized" are not checked again. Check the
1213 m_slotted_rec_no usage, note it could be reset in some cases like
1214 during split.
1215 Note: we refer to page_copy_rec_list_end_to_created_page.*/
1216 void finish() noexcept;
1217
1218 /** Commit mtr for a page
1219 @return DB_SUCCESS on success, error code on failure. */
1220 dberr_t commit() noexcept;
1221
1222 /** Commit mtr for a page */
1223 void rollback() noexcept;
1224
1225 /** Check whether the record needs to be stored externally.
1226 @return false if the entire record can be stored locally on the page */
1227 [[nodiscard]] bool need_ext(const dtuple_t *tuple,
1228 size_t rec_size) const noexcept;
1229
1230 /** Get node pointer
1231 @return node pointer */
1232 [[nodiscard]] dtuple_t *get_node_ptr() noexcept;
1233
1234 /** Get node pointer
1235 @param[in] heap allocate node pointer in the given heap.
1236 @return node pointer */
1237 [[nodiscard]] dtuple_t *get_node_ptr(mem_heap_t *heap) noexcept;
1238
1239 /** Copy all records from page.
1240 @param[in] src_page Page with records to copy. */
1241 size_t copy_all(const page_t *src_page) noexcept;
1242
1243 /** Distribute all records from this page to the given pages.
1244 @param[in,out] to_pages array of Page_load objects.
1245 return total number of records processed. */
1246 size_t copy_to(std::vector<Page_load *> &to_pages);
1247
1248 /** Set next page
1249 @param[in] next_page_no Next page no */
1250 void set_next(page_no_t next_page_no) noexcept;
1251
1252 /** Set previous page
1253 @param[in] prev_page_no Previous page no */
1254 void set_prev(page_no_t prev_page_no) noexcept;
1255
1256 /** Get previous page (FIL_PAGE_PREV). */
1257 page_no_t get_prev() noexcept;
1258
1259 /** Start mtr and latch block */
1260 void latch() noexcept;
1261
1262 /** Check if required space is available in the page for the rec
1263 to be inserted. We check fill factor & padding here.
1264 @param[in] rec_size Required space
1265 @return true if space is available */
1266 [[nodiscard]] inline bool is_space_available(size_t rec_size) const noexcept;
1267
1268 /** Get page no */
1269 [[nodiscard]] page_no_t get_page_no() const noexcept { return m_page_no; }
1270 [[nodiscard]] page_id_t get_page_id() const noexcept {
1271 return m_block->page.id;
1272 }
1273
1274 /** Get the physical page size of the underlying tablespace.
1275 @return the physical page size of the tablespace. */
1276 size_t get_page_size() const noexcept;
1277
1278 /** Get the table space ID.
1279 @return the table space ID. */
1280 space_id_t space() const noexcept;
1281
1282#ifdef UNIV_DEBUG
1283 /** Obtain tablespace id from the frame and the buffer block and ensure that
1284 they are the same.
1285 @return true if space id is same in both places. */
1286 bool verify_space_id() const;
1287#endif /* UNIV_DEBUG */
1288
1289 /** Get page level */
1290 [[nodiscard]] size_t get_level() const noexcept { return m_level; }
1291
1292 /** Set the level of this page. */
1293 void set_level(size_t level) noexcept { m_level = level; }
1294
1295 /** Get record no */
1296 [[nodiscard]] size_t get_rec_no() const { return m_rec_no; }
1297
1298 /** Get page */
1299 [[nodiscard]] const page_t *get_page() const noexcept {
1301 }
1302
1303 [[nodiscard]] page_t *get_page() noexcept {
1305 }
1306
1307 public:
1308 void init_for_writing();
1309 size_t get_data_size() const { return page_get_data_size(m_page); }
1310
1311#ifdef UNIV_DEBUG
1312 /** Check if index is X locked
1313 @return true if index is locked. */
1314 bool is_index_locked() noexcept;
1315#endif /* UNIV_DEBUG */
1316
1317 /** Copy given and all following records.
1318 @param[in] first_rec First record to copy */
1319 size_t copy_records(const rec_t *first_rec) noexcept;
1320
1321 /** Insert a record in the page, check for duplicates too.
1322 @param[in] rec Record
1323 @param[in] offsets Record offsets
1324 @return DB_SUCCESS or error code. */
1325 dberr_t insert(const rec_t *rec, Rec_offsets offsets) noexcept;
1326
1327 public:
1328 /** Store external record
1329 Since the record is not logged yet, so we don't log update to the record.
1330 the blob data is logged first, then the record is logged in bulk mode.
1331 @param[in] big_rec External record
1332 @param[in] offsets Record offsets
1333 @return error code */
1334 [[nodiscard]] dberr_t store_ext(const big_rec_t *big_rec,
1335 Rec_offsets offsets) noexcept;
1336
1337 /** Set the REC_INFO_MIN_REC_FLAG on the first user record in this page.
1338 @param[in] mtr mini transaction context. */
1339 void set_min_rec_flag(mtr_t *mtr);
1340
1341 /** Set the REC_INFO_MIN_REC_FLAG on the first user record in this page. */
1342 void set_min_rec_flag();
1343 bool is_min_rec_flag() const;
1344
1345 /** Set the level context object for this page load
1346 @param[in] level_ctx the level context object. */
1347 void set_level_ctx(Level_ctx *level_ctx) { m_level_ctx = level_ctx; }
1348
1349 /** Check if this page load object contains a level context object.
1350 @return true if the page load contains a level context object.
1351 @return false if the page load does NOT contain a level context object.*/
1352 bool has_level_ctx() const { return m_level_ctx != nullptr; }
1353
1354 /** Free the memory block. */
1355 void free();
1356
1358
1360
1361 void set_page_extent(Page_extent *page_extent) {
1362 m_page_extent = page_extent;
1363 }
1364
1365 /** Mark the Page load as cached. Flush thread should not free this Page. */
1366 void set_cached() { m_is_cached.store(true); }
1367
1368 /** @return true iff it is a cached Page Load. */
1369 bool is_cached() const { return m_is_cached.load(); }
1370
1371 private:
1372 /** Memory heap for internal allocation */
1374
1375 /** The index B-tree */
1377
1378 /** The min-transaction */
1380
1381 /** The transaction id */
1383
1384 /** The buffer block */
1386
1387 /** The page */
1389
1390 /** The current rec, just before the next insert rec */
1392
1393 /** The page no */
1395
1396 /** The page level in B-tree */
1397 size_t m_level{};
1398
1399 /** Flag: is page in compact format */
1400 const bool m_is_comp{};
1401
1402 /** The heap top in page for next insert */
1403 byte *m_heap_top{};
1404
1405 /** User record no */
1406 size_t m_rec_no{};
1407
1408 /** The free space left in the page */
1410
1411 /** The reserved space for fill factor */
1413
1414 /** Total data in the page */
1416
1417 /** The modify clock value of the buffer block
1418 when the block is re-pinned */
1419 uint64_t m_modify_clock{};
1420
1421 /** Flush observer */
1423
1424 /** Last record assigned to a slot. */
1426
1427 /** Number of records assigned to slots. */
1429
1430 /** Page modified flag. */
1432
1434
1436
1438
1439 /** true iff the the Page load is cached. */
1440 std::atomic_bool m_is_cached{false};
1441
1442 friend class Btree_load;
1443};
1444
1446 return get_node_ptr(m_heap);
1447}
1448
1449inline space_id_t Page_load::space() const noexcept { return m_index->space; }
1450
1451inline size_t Page_load::get_page_size() const noexcept {
1452 const page_size_t page_size = m_index->get_page_size();
1453 return page_size.physical();
1454}
1455
1456inline Level_ctx *Btree_load::get_level(size_t level) const {
1457 ut_a(m_level_ctxs.size() > level);
1458 return m_level_ctxs[level];
1459}
1460
1461/** Information about a buffer page. */
1463 /** Number of user records in the page. */
1464 size_t m_n_recs;
1465
1466 /** Number of bytes of data. */
1468};
1469
1470inline void Page_extent::append(Page_load *page_load) {
1471 ut_ad(page_load->get_block() != nullptr);
1472 ut_ad(page_load->is_memory());
1473 ut_ad(page_load->get_page_no() >= m_range.first);
1474 ut_ad(page_load->get_page_no() < m_range.second);
1476 for (auto &iter : m_page_loads) {
1477 if (iter->get_page_no() == page_load->get_page_no()) {
1478 /* Page already appended. Don't append again. */
1479 return;
1480 }
1481 }
1482 m_page_loads.push_back(page_load);
1483}
1484
1486 return m_btree_load->get_trx_id();
1487}
1488
1490 return m_btree_load->index()->space;
1491}
1492
1493inline Page_extent::Page_extent(Btree_load *btree_load, const bool is_leaf)
1494 : m_page_no(FIL_NULL),
1495 m_range(FIL_NULL, FIL_NULL),
1496 m_btree_load(btree_load),
1497 m_is_leaf(is_leaf) {}
1498
1500 const bool is_leaf, bool skip_track) {
1501 Page_extent *p = ut::new_withkey<Page_extent>(UT_NEW_THIS_FILE_PSI_KEY,
1502 btree_load, is_leaf);
1503 if (!skip_track) {
1504 btree_load->track_extent(p);
1505 }
1506 p->m_is_cached.store(false);
1507 return p;
1508}
1509
1510inline void Page_extent::drop(Page_extent *extent) {
1511 if (extent == nullptr) {
1512 return;
1513 }
1514 if (extent->is_cached()) {
1515 ut_a(!extent->is_free());
1516 bool free = true;
1517 extent->set_state(free);
1518 return;
1519 }
1520 ut::delete_(extent);
1521}
1522
1523/** Function object to compare two Btree_load objects. */
1526 bool operator()(const Btree_load *l_btree, const Btree_load *r_btree);
1528};
1529
1530#ifdef UNIV_DEBUG
1533#endif /* UNIV_DEBUG */
1534
1535} /* namespace Btree_multi */
1536
1537#endif /* btr0mtib_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:48
uint32_t page_no_t
Page number.
Definition: api0api.h:46
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
std::pair< page_no_t, page_no_t > Page_range_t
Definition: btr0btr.h:131
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:1026
Btree_loads & m_btree_loads
Refernce to the subtrees to be merged.
Definition: btr0mtib.h:1083
std::vector< Btree_load *, ut::allocator< Btree_load * > > Btree_loads
Definition: btr0mtib.h:1028
dict_index_t * m_index
Index which is being built.
Definition: btr0mtib.h:1086
void validate_boundaries()
Validate sub-tree boundaries.
Definition: btr0mtib.cc:2549
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:3015
size_t get_max_free() const
Get the maximum free space available in an empty page in bytes.
Definition: btr0mtib.h:1041
Merger(Btree_loads &loads, dict_index_t *index, trx_t *trx)
Definition: btr0mtib.h:1030
void remove_empty_subtrees()
Remove any empty sub-trees with no records.
Definition: btr0mtib.cc:2536
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:2857
Scoped_heap m_tuple_heap
Memory heap to store node pointers.
Definition: btr0mtib.h:1092
dberr_t merge(bool sort)
Definition: btr0mtib.cc:2482
trx_t * m_trx
Transaction making the changes.
Definition: btr0mtib.h:1089
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:2987
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:2559
Helper to set wait callbacks for the current scope.
Definition: btr0mtib.h:694
~Wait_callbacks()
Definition: btr0mtib.h:705
Wait_callbacks(Btree_load *btree_load, Function &begin, Function &end)
Definition: btr0mtib.h:699
Btree_load * m_btree_load
Btree Load for the wait callbacks.
Definition: btr0mtib.h:712
std::function< void()> Function
Definition: btr0mtib.h:696
Definition: btr0mtib.h:682
~Btree_load() noexcept
Destructor.
Definition: btr0mtib.cc:1504
dict_index_t * m_index
B-tree index.
Definition: btr0mtib.h:976
Bulk_flusher m_bulk_flusher
Definition: btr0mtib.h:992
dberr_t finish(bool is_err, const bool subtree) noexcept
Btree bulk load finish.
Definition: btr0mtib.cc:1835
dberr_t load_root_page(page_no_t last_page_no) noexcept
Set the root page on completion.
Definition: btr0mtib.cc:1711
dberr_t trigger_flusher() const
Trigger flusher thread and check for error.
Definition: btr0mtib.h:746
bool is_tpe_enabled() const
Check if transparent page encryption (TPE) is enabled.
Definition: btr0mtib.cc:2474
Bulk_extent_allocator & m_allocator
Reference to global extent allocator.
Definition: btr0mtib.h:995
bool is_new_level(size_t level) const
Check if a new level is needed.
Definition: btr0mtib.h:886
dberr_t check_key_overlap(const Btree_load *r_btree) const
Definition: btr0mtib.cc:3115
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:1488
dict_index_t * index() const
Get the index object.
Definition: btr0mtib.h:750
size_t get_max_flush_queue_size() const
Definition: btr0mtib.h:959
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:1608
dtuple_t * m_prev_tuple
The previous tuple that has been inserted.
Definition: btr0mtib.h:1010
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:1932
std::ostream & print_right_pages(std::ostream &out) const
Definition: btr0mtib.cc:1893
size_t m_root_level
Root page level.
Definition: btr0mtib.h:984
std::vector< page_no_t, ut::allocator< page_no_t > > m_first_page_nos
First page numbers of each level.
Definition: btr0mtib.h:892
byte m_fseg_hdr_leaf[FSEG_HEADER_SIZE]
Definition: btr0mtib.h:907
void block_put(buf_block_t *block)
Add the given block the internal cache of blocks.
dberr_t init()
Initialize.
Definition: btr0mtib.cc:2023
Bulk_extent_allocator::Type m_alloc_type
Page allocation type.
Definition: btr0mtib.h:969
Page_range_t m_page_range_leaf
Page numbers of the pages that has been allocated in the leaf level.
Definition: btr0mtib.h:901
void get_root_page_stat(Page_stat &stat)
Get information about root page.
Definition: btr0mtib.cc:1943
size_t m_loader_num
Loader number.
Definition: btr0mtib.h:1015
Level_ctxs m_level_ctxs
Context information for each level of the B-tree.
Definition: btr0mtib.h:989
page_no_t get_subtree_root() const
Get the root page number of this tree/subtree.
Definition: btr0mtib.h:756
size_t m_stat_n_pages
Number of pages allocated for this B-tree.
Definition: btr0mtib.h:919
trx_t * m_trx
Transaction id.
Definition: btr0mtib.h:981
dberr_t flush_blobs() noexcept
Flush the blob pages.
mem_heap_t * m_heap_order
Memory heap to be used for sort order checks.
Definition: btr0mtib.h:1004
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:1512
std::list< Page_extent * > m_extents_tracked
Extents that are being tracked.
Definition: btr0mtib.h:998
void track_page_flush(page_no_t page_no)
Save flushed page numbers for debugging purposes.
Definition: btr0mtib.h:735
std::ostream & print_left_pages(std::ostream &out) const
Definition: btr0mtib.cc:1884
ddl::Compare_key m_compare_key
Function object to compare two tuples.
Definition: btr0mtib.h:1007
size_t get_root_level() const
Get the level of the root page.
Definition: btr0mtib.h:760
dberr_t alloc_extent(Page_range_t &page_range, size_t level)
Allocate an extent.
Definition: btr0mtib.cc:691
bool is_extent_tracked(const Page_extent *page_extent) const
Definition: btr0mtib.h:1095
bool m_check_order
If true, check if data is inserted in sorted order.
Definition: btr0mtib.h:1001
bool is_tpc_enabled() const
Check if transparent page compression (TPC) is enabled.
Definition: btr0mtib.cc:2464
static bool validate_index(dict_index_t *index)
Check size and validate index of limited size.
Definition: btr0mtib.cc:1815
trx_id_t get_trx_id() const
Get the transaction id.
Definition: btr0mtib.cc:1502
void disable_check_order()
If the data is already sorted and checked for duplicates, then we can disable doing it again.
Definition: btr0mtib.h:965
bool is_interrupted() const
Check if the index build operation has been interrupted.
Definition: btr0mtib.cc:3180
uint64_t m_n_recs
Number of records inserted.
Definition: btr0mtib.h:973
Wait_callbacks::Function m_fn_wait_begin
Definition: btr0mtib.h:1020
ut::unique_ptr< Page_load > Page_loader_ptr
Definition: btr0mtib.h:688
const char * get_table_name() const
Definition: btr0mtib.h:752
void track_extent(Page_extent *page_extent)
All allocated extents registers with Btree_load.
Definition: btr0mtib.cc:1967
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:3197
fil_space_t * m_space
Definition: btr0mtib.h:978
Page_range_t m_page_range_top
Page numbers of the pages that has been allocated in the non-leaf level.
Definition: btr0mtib.h:905
Wait_callbacks::Function m_fn_wait_end
Definition: btr0mtib.h:1023
void add_to_bulk_flusher(bool finish=false)
Add fully used extents to the bulk flusher.
Definition: btr0mtib.cc:1588
unsigned m_index_online
State of the index.
Definition: btr0mtib.h:913
byte m_fseg_hdr_top[FSEG_HEADER_SIZE]
Definition: btr0mtib.h:908
dberr_t page_commit(Page_load *page_load, Page_load *next_page_load, bool insert_father) noexcept
Commit(finish) a page.
Definition: btr0mtib.cc:1447
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:3296
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:1679
std::string print_pages_in_level(const size_t level) const
Definition: btr0mtib.cc:1762
void print_tree_pages() const
Definition: btr0mtib.cc:1903
Level_ctx * get_level(size_t level) const
Get the level context object.
Definition: btr0mtib.h:1456
const page_size_t m_page_size
Definition: btr0mtib.h:1017
std::vector< Level_ctx *, ut::allocator< Level_ctx * > > Level_ctxs
Definition: btr0mtib.h:691
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:889
std::vector< Page_loader_ptr, ut::allocator< Page_loader_ptr > > Page_loaders
Definition: btr0mtib.h:690
size_t m_stat_n_extents
Number of extents allocated for this B-tree.
Definition: btr0mtib.h:916
Definition: btr0mtib.h:386
~Bulk_extent_allocator()
Destructor to ensure thread stop.
Definition: btr0mtib.h:396
Extent_cache m_leaf_extents
Cached leaf extents.
Definition: btr0mtib.h:531
dict_table_t * m_table
Innodb dictionary table object.
Definition: btr0mtib.h:552
std::chrono::microseconds m_allocator_wait_time
Total allocator wait time in micro seconds.
Definition: btr0mtib.h:525
size_t m_allocator_wait_count
Number of times allocator had to wait.
Definition: btr0mtib.h:519
size_t m_concurrency
Number of concurrent consumers.
Definition: btr0mtib.h:558
std::condition_variable m_consumer_condition
Condition variable for extent consumer threads.
Definition: btr0mtib.h:543
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:2322
std::thread m_thread
Bulk extent allocator.
Definition: btr0mtib.h:513
size_t m_consumer_wait_count
Number of times consumer(s) had to wait.
Definition: btr0mtib.h:516
static constexpr size_t S_BULK_EXTEND_SIZE_MAX
Maximum size by which the tablespace is extended each time.
Definition: btr0mtib.h:430
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:2206
dberr_t m_error
Error code, protected by m_mutex.
Definition: btr0mtib.h:549
static constexpr size_t S_MAX_RANGES
Upper bound for max ranges.
Definition: btr0mtib.h:427
trx_t * m_trx
Innodb transaction - used for checking interrupt.
Definition: btr0mtib.h:555
Extent_cache m_non_leaf_extents
Cached non-leaf extents.
Definition: btr0mtib.h:534
void allocator_wait() const
Allocator wait function.
Definition: btr0mtib.cc:2342
dberr_t allocate_extent(bool is_leaf, mtr_t &mtr, Page_range_t &range)
Allocate one extent.
Definition: btr0mtib.cc:2200
bool is_interrupted()
Definition: btr0mtib.cc:2150
dberr_t allocate_page(bool is_leaf, Page_range_t &range)
Allocate one page.
Definition: btr0mtib.cc:2154
dberr_t run()
Exetent thread executor.
Definition: btr0mtib.cc:2410
void start()
Definition: btr0mtib.cc:2117
std::mutex m_mutex
This mutex protects the m_queue.
Definition: btr0mtib.h:537
Type m_type
Page range type.
Definition: btr0mtib.h:528
Type
Definition: btr0mtib.h:388
uint64_t init(dict_table_t *table, trx_t *trx, size_t size, size_t num_threads, bool in_pages)
Check size and set extent allocator size parameters.
Definition: btr0mtib.cc:2047
bool m_stop
Flag to indicate if the bulk allocator thread should stop.
Definition: btr0mtib.h:546
std::chrono::microseconds m_consumer_wait_time
Total consumer wait time in micro seconds.
Definition: btr0mtib.h:522
dberr_t allocate_extents(bool is_leaf, size_t num_extents)
Allocate extents and fill the cache.
Definition: btr0mtib.cc:2361
void stop()
Stop extent allocator thread, if active.
Definition: btr0mtib.cc:2125
std::condition_variable m_allocator_condition
Condition variable for allocator thread.
Definition: btr0mtib.h:540
Definition: btr0mtib.h:561
void do_work(fil_node_t *node, void *iov, size_t iov_size)
Do the actual work of flushing.
Definition: btr0mtib.cc:109
dberr_t check_and_notify() const
Check for flusher error and wake up flusher thread.
Definition: btr0mtib.cc:127
dberr_t m_error
Error code, protected by m_mutex.
Definition: btr0mtib.h:638
size_t m_pages_flushed
Number of pages flushed.
Definition: btr0mtib.h:664
space_id_t m_space_id
Bulk flusher is specific to a tablespace for now.
Definition: btr0mtib.h:667
std::atomic< bool > m_is_error
Set if error is encountered during flush.
Definition: btr0mtib.h:635
std::atomic< bool > m_stop
Flag to indicate if the bulk flusher thread should stop.
Definition: btr0mtib.h:632
dberr_t get_error() const
Definition: btr0mtib.cc:78
dberr_t run()
Thread main function.
Definition: btr0mtib.cc:179
size_t m_id
Flusher ID.
Definition: btr0mtib.h:670
bool is_error() const
Definition: btr0mtib.h:599
bool should_i_stop() const
Check if the bulk flush thread should stop working.
Definition: btr0mtib.h:612
size_t m_n_sleep
Number of times slept.
Definition: btr0mtib.h:652
std::mutex m_mutex
This mutex protects the m_queue.
Definition: btr0mtib.h:624
~Bulk_flusher()
Destructor.
Definition: btr0mtib.cc:92
void set_error(dberr_t error_code)
Set error code.
Definition: btr0mtib.cc:83
std::vector< Page_extent * > m_queue
This queue is protected by the m_mutex.
Definition: btr0mtib.h:621
std::thread m_flush_thread
Bulk flusher thread.
Definition: btr0mtib.h:649
size_t m_max_queue_size
Maximum queue size, defaults to 4.
Definition: btr0mtib.h:661
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:64
std::chrono::microseconds m_wait_time
Total sleep time in micro seconds.
Definition: btr0mtib.h:655
bool is_work_available()
Check if work is available for the bulk flusher thread.
Definition: btr0mtib.cc:163
std::vector< Page_extent * > m_priv_queue
Private queue (private to the bulk flush thread) containing the extents to flush.
Definition: btr0mtib.h:646
void wait_to_stop()
Wait till the bulk flush thread stops.
Definition: btr0mtib.cc:103
std::vector< page_no_t > m_flushed_page_nos
Vector of page numbers that are flushed by this Bulk_flusher object.
Definition: btr0mtib.h:675
size_t get_max_queue_size() const
Get the maximum allowed queue size.
Definition: btr0mtib.h:593
std::condition_variable m_condition
Condition variable to wait upon.
Definition: btr0mtib.h:627
void info()
Print useful information to the server log file while exiting.
Definition: btr0mtib.cc:2032
void wait()
When no work is available, put the thread to sleep.
Definition: btr0mtib.cc:240
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:138
static constexpr std::chrono::milliseconds s_sleep_duration
The sleep duration in milliseconds.
Definition: btr0mtib.h:658
The proper function call sequence of Page_load is as below: – Page_load::init – Page_load::insert – P...
Definition: btr0mtib.h:1110
dberr_t init_mem(const page_no_t new_page_no, Page_extent *page_extent) noexcept
Definition: btr0mtib.cc:891
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:1293
buf_block_t * get_block()
Definition: btr0mtib.h:1359
space_id_t space() const noexcept
Get the table space ID.
Definition: btr0mtib.h:1449
void rollback() noexcept
Commit mtr for a page.
Definition: btr0mtib.cc:1310
bool is_corrupted() const
Check if page is corrupted.
Definition: btr0mtib.cc:285
trx_id_t m_trx_id
The transaction id.
Definition: btr0mtib.h:1382
byte * m_heap_top
The heap top in page for next insert.
Definition: btr0mtib.h:1403
size_t get_level() const noexcept
Get page level.
Definition: btr0mtib.h:1290
rec_t * m_last_slotted_rec
Last record assigned to a slot.
Definition: btr0mtib.h:1425
dict_index_t * index()
Definition: btr0mtib.h:1357
void set_level_ctx(Level_ctx *level_ctx)
Set the level context object for this page load.
Definition: btr0mtib.h:1347
void set_trx_id(const trx_id_t trx_id)
Set the transaction id.
Definition: btr0mtib.h:1164
size_t copy_to(std::vector< Page_load * > &to_pages)
Distribute all records from this page to the given pages.
Definition: btr0mtib.cc:1348
size_t copy_records(const rec_t *first_rec) noexcept
Copy given and all following records.
Definition: btr0mtib.cc:1379
void set_flush_observer(Flush_observer *observer)
Set the flush observer.
Definition: btr0mtib.h:1168
void set_page_extent(Page_extent *page_extent)
Definition: btr0mtib.h:1361
size_t get_rec_no() const
Get record no.
Definition: btr0mtib.h:1296
void set_min_rec_flag()
Set the REC_INFO_MIN_REC_FLAG on the first user record in this page.
Definition: btr0mtib.cc:1913
page_no_t get_page_no() const noexcept
Get page no.
Definition: btr0mtib.h:1269
void set_next(page_no_t next_page_no) noexcept
Set next page.
Definition: btr0mtib.cc:1398
size_t get_page_size() const noexcept
Get the physical page size of the underlying tablespace.
Definition: btr0mtib.h:1451
dict_index_t * m_index
The index B-tree.
Definition: btr0mtib.h:1376
size_t m_slotted_rec_no
Number of records assigned to slots.
Definition: btr0mtib.h:1428
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:1193
Flush_observer * m_flush_observer
Flush observer.
Definition: btr0mtib.h:1422
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:3185
void free()
Free the memory block.
Definition: btr0mtib.cc:1961
uint64_t m_modify_clock
The modify clock value of the buffer block when the block is re-pinned.
Definition: btr0mtib.h:1419
void set_prev(page_no_t prev_page_no) noexcept
Set previous page.
Definition: btr0mtib.cc:1402
bool has_level_ctx() const
Check if this page load object contains a level context object.
Definition: btr0mtib.h:1352
Page_load(dict_index_t *index, Btree_load *btree_load)
Ctor.
Definition: btr0mtib.cc:884
size_t m_rec_no
User record no.
Definition: btr0mtib.h:1406
std::atomic_bool m_is_cached
true iff the the Page load is cached.
Definition: btr0mtib.h:1440
static void drop(Page_load *page_load)
Release the page loader.
Definition: btr0mtib.cc:665
bool is_memory() const
Check if state of this page is BUF_BLOCK_MEMORY.
Definition: btr0mtib.h:1131
bool is_leaf() const
Definition: btr0mtib.h:1172
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:1410
void reset() noexcept
Reset this object so that Page_load::init() can be called again on this object.
Definition: btr0mtib.cc:1028
size_t get_data_size() const
Definition: btr0mtib.h:1309
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:1431
size_t m_level
The page level in B-tree.
Definition: btr0mtib.h:1397
rec_t * m_cur_rec
The current rec, just before the next insert rec.
Definition: btr0mtib.h:1391
dberr_t alloc() noexcept
Allocate a page for this Page_load object.
Definition: btr0mtib.cc:981
void set_page_no(const page_no_t page_no)
Set the page number of this object.
Definition: btr0mtib.cc:875
size_t m_reserved_space
The reserved space for fill factor.
Definition: btr0mtib.h:1412
mem_heap_t * m_heap
Memory heap for internal allocation.
Definition: btr0mtib.h:1373
static Page_load * create(Btree_load *btree_load, Page_extent *page_extent)
A static member function to create this object.
Definition: btr0mtib.cc:655
page_id_t get_page_id() const noexcept
Definition: btr0mtib.h:1270
void latch() noexcept
Start mtr and latch block.
Page_extent * m_page_extent
Definition: btr0mtib.h:1437
bool is_cached() const
Definition: btr0mtib.h:1369
page_t * get_page() noexcept
Definition: btr0mtib.h:1303
bool is_index_locked() noexcept
Check if index is X locked.
Definition: btr0mtib.cc:1438
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:1149
void set_top_seg(const fseg_header_t *hdr)
Definition: btr0mtib.h:1180
dberr_t reinit() noexcept
Re-initialize this page.
Definition: btr0mtib.cc:960
~Page_load() noexcept
Destructor.
Definition: btr0mtib.cc:3169
void set_leaf_seg(const fseg_header_t *hdr)
Definition: btr0mtib.h:1177
bool is_min_rec_flag() const
Definition: btr0mtib.cc:1915
dberr_t commit() noexcept
Commit mtr for a page.
Definition: btr0mtib.cc:1280
size_t copy_all(const page_t *src_page) noexcept
Copy all records from page.
Definition: btr0mtib.cc:1339
size_t m_free_space
The free space left in the page.
Definition: btr0mtib.h:1409
void set_cached()
Mark the Page load as cached.
Definition: btr0mtib.h:1366
const bool m_is_comp
Flag: is page in compact format.
Definition: btr0mtib.h:1400
Btree_load * m_btree_load
Definition: btr0mtib.h:1433
page_no_t get_prev() noexcept
Get previous page (FIL_PAGE_PREV).
Definition: btr0mtib.cc:1406
mtr_t * m_mtr
The min-transaction.
Definition: btr0mtib.h:1379
const page_t * get_page() const noexcept
Get page.
Definition: btr0mtib.h:1299
bool m_modified
Page modified flag.
Definition: btr0mtib.h:1431
buf_block_t * m_block
The buffer block.
Definition: btr0mtib.h:1385
void print_child_page_nos() noexcept
Print the child page numbers.
Definition: btr0mtib.cc:1323
page_no_t m_page_no
The page no.
Definition: btr0mtib.h:1394
Level_ctx * m_level_ctx
Definition: btr0mtib.h:1435
dberr_t init() noexcept
Initialize members and allocate page if needed and start mtr.
Definition: btr0mtib.cc:1060
size_t m_total_data
Total data in the page.
Definition: btr0mtib.h:1415
void init_for_writing()
Definition: btr0mtib.cc:300
void finish() noexcept
Mark end of insertion to the page.
Definition: btr0mtib.cc:1225
page_t * m_page
The page.
Definition: btr0mtib.h:1388
dtuple_t * get_node_ptr() noexcept
Get node pointer.
Definition: btr0mtib.h:1445
We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load....
Definition: buf0flu.h:270
The proper function call sequence of Page_load is as below: – Page_load::init – Page_load::insert – P...
Definition: btr0load.cc:54
A helper RAII wrapper for otherwise difficult to use sequence of:
Definition: rem0rec.h:292
page_id_t id
Page id.
Definition: buf0buf.h:1388
Page identifier.
Definition: buf0types.h:207
Page size descriptor.
Definition: page0size.h:50
size_t physical() const
Retrieve the physical page size (on-disk).
Definition: page0size.h:121
A utility class which, if inherited from, prevents the descendant class from being copied,...
Definition: ut0class_life_cycle.h:41
const char * p
Definition: ctype-mb.cc:1235
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.
bool is_blob(enum_field_types sql_type)
Definition: field.h:4767
constexpr page_no_t FIL_NULL
'null' (undefined) page offset in the context of file spaces
Definition: fil0fil.h:1183
#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
Definition: btr0mtib.cc:56
void bulk_load_enable_slow_io_debug()
Definition: btr0mtib.cc:60
void bulk_load_disable_slow_io_debug()
Definition: btr0mtib.cc:61
std::ostream & operator<<(std::ostream &out, const Page_extent &obj)
Definition: btr0mtib.h:231
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
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
Definition: gcs_xcom_synode.h:64
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2879
void delete_(T *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::new*() variants.
Definition: ut0new.h:810
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:2443
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
Function object to compare two Btree_load objects.
Definition: btr0mtib.h:1524
dict_index_t * m_index
Definition: btr0mtib.h:1527
bool operator()(const Btree_load *l_btree, const Btree_load *r_btree)
Definition: btr0mtib.cc:1978
Btree_load_compare(dict_index_t *index)
Definition: btr0mtib.h:1525
bool is_empty() const
Definition: btr0mtib.h:438
size_t m_max_range
Maximum number of ranges to pre-allocate.
Definition: btr0mtib.h:466
void init(size_t max_range)
Initialize cache.
Definition: btr0mtib.cc:2039
bool check(size_t &num_alloc, size_t &num_free) const
Check for number of extents to be allocated and cached.
Definition: btr0mtib.cc:2303
std::array< Page_range_t, S_MAX_RANGES > m_ranges
Cached page ranges already allocated to the segment.
Definition: btr0mtib.h:463
std::atomic< size_t > m_num_consumed
Total number of ranges allocated.
Definition: btr0mtib.h:472
void set_range(size_t index, Page_range_t &range)
Set allocated range(extent) in cache.
Definition: btr0mtib.cc:2294
std::atomic< size_t > m_num_allocated
Total number of ranges allocated.
Definition: btr0mtib.h:469
bool is_full() const
Definition: btr0mtib.h:441
bool get_range(Page_range_t &range, bool &alloc_trigger)
Get one page range from the cache.
Definition: btr0mtib.cc:2274
Context information for each level.
Definition: btr0mtib.h:265
size_t m_stat_n_extents
Number of extents allocated at this level.
Definition: btr0mtib.h:369
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:845
dict_index_t * m_index
The index which is being built.
Definition: btr0mtib.h:354
void build_page_cache()
Build page loader cache for current exent.
Definition: btr0mtib.cc:758
bool load_extent_from_cache()
Load one extent from extent cache.
Definition: btr0mtib.cc:705
dberr_t init()
Initialize.
Definition: btr0mtib.cc:798
Btree_load * m_btree_load
A back pointer to conceptually higher level btree load object.
Definition: btr0mtib.h:363
void set_current_page_load(Page_load *sibling)
Definition: btr0mtib.h:382
page_no_t m_last_page
The page_no of the last page in this level.
Definition: btr0mtib.h:351
~Level_ctx()
Destructor.
Definition: btr0mtib.cc:3167
const size_t m_level
The B-tree level whose context information is stored in this obj.
Definition: btr0mtib.h:357
void build_extent_cache()
Build the extent cache.
Definition: btr0mtib.cc:772
void free_page_load()
Free the current page load.
Definition: btr0mtib.cc:686
Page_load * create_page_load()
Definition: btr0mtib.cc:672
std::vector< page_no_t > m_pages_allocated
Definition: btr0mtib.h:376
trx_id_t get_trx_id() const
Definition: btr0mtib.h:1485
static void destroy(Level_ctx *obj)
Static member function to destroy a Level_ctx object.
Definition: btr0mtib.cc:641
std::vector< Page_extent * > m_cached_extents
Pre allocated extents to prevent repeated allocation and free.
Definition: btr0mtib.h:345
dberr_t alloc_page_num(page_no_t &page_no)
Allocate a page number.
Definition: btr0mtib.cc:575
Level_ctx(dict_index_t *index, size_t level, Btree_load *btree_load)
Constructor.
Definition: btr0mtib.h:284
bool m_extent_full
True if the current extent is full.
Definition: btr0mtib.h:372
dberr_t alloc_extent()
Allocate one extent in the relevant file segment.
Definition: btr0mtib.cc:612
size_t m_stat_n_pages
Number of pages allocated at this level.
Definition: btr0mtib.h:366
bool is_page_tracked(const page_no_t &page_no) const
Definition: btr0mtib.cc:606
Page_load * m_page_load
The Page_load of the current page being loaded.
Definition: btr0mtib.h:360
Page_load * get_page_load_from_cache()
Get a free page loader from cache.
Definition: btr0mtib.cc:740
Page_extent * m_page_extent
The current extent that is being loaded.
Definition: btr0mtib.h:328
page_no_t m_first_page
The page_no of the first page in this level.
Definition: btr0mtib.h:348
Page_load * get_page_load() const
Definition: btr0mtib.h:380
bool is_leaf() const
Check if this is leaf level.
Definition: btr0mtib.h:299
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:633
Allocate, use, manage and flush one extent pages (FSP_EXTENT_SIZE).
Definition: btr0mtib.h:58
Page_extent(Btree_load *btree_load, const bool is_leaf)
Constructor.
Definition: btr0mtib.h:1493
static void drop(Page_extent *extent)
Release the page extent.
Definition: btr0mtib.h:1510
const bool m_is_leaf
Definition: btr0mtib.h:192
void set_cached()
Mark the extent as cached.
Definition: btr0mtib.h:172
size_t m_next_cached_page_load_index
Next cached page load index.
Definition: btr0mtib.h:200
std::atomic_bool m_is_free
true if the cached entry is free to be used.
Definition: btr0mtib.h:196
std::vector< Page_load * > m_page_loads
All the page loaders of the used pages.
Definition: btr0mtib.h:78
bool is_null() const
Definition: btr0mtib.h:104
bool is_valid() const
Check if the range is valid.
Definition: btr0mtib.h:212
dberr_t flush(fil_node_t *node, void *iov, size_t iov_size)
Flush the used pages to disk.
Definition: btr0mtib.cc:497
page_no_t alloc()
Allocate a page number.
Definition: btr0mtib.h:244
void init()
Initialize the next page number to be allocated.
Definition: btr0mtib.h:252
bool is_page_loads_full() const
Definition: btr0mtib.h:118
std::ostream & print(std::ostream &out) const
Definition: btr0mtib.h:223
dberr_t destroy()
Free all resources.
Definition: btr0mtib.cc:565
std::pair< page_no_t, page_no_t > Page_range_t
Definition: btr0mtib.h:59
std::vector< Page_load * > m_cached_page_loads
Cached page loads.
Definition: btr0mtib.h:198
size_t used_pages() const
Calculate the number of used pages.
Definition: btr0mtib.h:98
page_no_t page_count() const
Number of pages in this extent.
Definition: btr0mtib.h:260
dberr_t flush_one_by_one(fil_node_t *node)
Flush one page at a time.
Definition: btr0mtib.cc:381
dberr_t bulk_flush(fil_node_t *node, void *iov, size_t iov_size)
Flush 1 extent pages at a time.
Definition: btr0mtib.cc:482
page_no_t m_page_no
Next page number to be used.
Definition: btr0mtib.h:71
void reset_range(const Page_range_t &range)
Reset the range with the given value.
Definition: btr0mtib.h:235
Page_range_t m_range
Page numbers of the pages that has been allocated in this extent.
Definition: btr0mtib.h:75
bool is_fully_used() const
Check if no more pages are there to be used.
Definition: btr0mtib.h:117
bool is_free() const
Definition: btr0mtib.h:179
void destroy_cached()
Free any cached page load entries.
Definition: btr0mtib.cc:557
void append(Page_load *page_load)
Save a page_load.
Definition: btr0mtib.h:1470
Page_range_t pages_to_free() const
void set_state(bool free)
Set and unset free state of a cached extent.
Definition: btr0mtib.h:176
std::atomic_bool m_is_cached
true iff the the extent is cached.
Definition: btr0mtib.h:194
bool is_cached() const
Definition: btr0mtib.h:182
void reset_cached_page_loads()
Reaset page load cache to free all.
Definition: btr0mtib.h:185
space_id_t space() const
Definition: btr0mtib.h:1489
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:1499
~Page_extent()
Destructor.
Definition: btr0mtib.h:205
Btree_load * m_btree_load
Definition: btr0mtib.h:191
Information about a buffer page.
Definition: btr0mtib.h:1462
size_t m_n_recs
Number of user records in the page.
Definition: btr0mtib.h:1464
size_t m_data_size
Number of bytes of data.
Definition: btr0mtib.h:1467
Heap wrapper that destroys the heap instance when it goes out of scope.
Definition: mem0mem.h:439
Storage format for overflow data in a big record, that is, a clustered index record which needs exter...
Definition: data0data.h:855
The buffer control block structure.
Definition: buf0buf.h:1765
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:1771
bool is_memory() const noexcept
Definition: buf0buf.h:2012
Compare the keys of an index.
Definition: ddl0impl-compare.h:41
Data structure for an index.
Definition: dict0mem.h:1046
unsigned space
space where the index tree is placed
Definition: dict0mem.h:1063
dict_table_t * table
back pointer to table
Definition: dict0mem.h:1060
page_size_t get_page_size() const
Get the page size of the tablespace to which this index belongs.
Definition: dict0mem.cc:917
Data structure for a database table.
Definition: dict0mem.h:1918
table_name_t name
Table name.
Definition: dict0mem.h:1993
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:694
File node of a tablespace or the log data space.
Definition: fil0fil.h:179
Tablespace or log data space.
Definition: fil0fil.h:262
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:177
Definition: gen_lex_token.cc:149
char * m_name
The name in internal representation.
Definition: dict0mem.h:472
Definition: trx0trx.h:675
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:138
#define IF_DEBUG(...)
Definition: univ.i:674
unsigned long int ulint
Definition: univ.i:406
Utilities related to class lifecycle.
#define UT_LOCATION_HERE
Definition: ut0core.h:73
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93
Dynamic memory allocation routines and custom allocators specifically crafted to support memory instr...
#define UT_NEW_THIS_FILE_PSI_KEY
Definition: ut0new.h:565