MySQL 8.4.1
Source Code Documentation
btr0mtib.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2023, 2024, 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:
688 using Page_loaders = std::vector<Page_load *, ut::allocator<Page_load *>>;
689 using Level_ctxs = std::vector<Level_ctx *, ut::allocator<Level_ctx *>>;
690
691 /** Helper to set wait callbacks for the current scope. */
693 public:
694 using Function = std::function<void()>;
695 friend class Btree_load;
696
698 : m_btree_load(btree_load) {
701 }
702
704 m_btree_load->m_fn_wait_begin = nullptr;
705 m_btree_load->m_fn_wait_end = nullptr;
706 }
707
708 private:
709 /** Btree Load for the wait callbacks. */
711 };
712
713 /** Constructor
714 @param[in] index B-tree index.
715 @param[in] trx Transaction object.
716 @param[in] loader_num loader index
717 @param[in] flush_queue_size bulk flusher queue size
718 @param[in] allocator extent allocator */
719 Btree_load(dict_index_t *index, trx_t *trx, size_t loader_num,
720 size_t flush_queue_size,
721 Bulk_extent_allocator &allocator) noexcept;
722
723 /** Destructor */
724 ~Btree_load() noexcept;
725
726 /** Initialize. Allocates the m_heap_order memory heap.
727 @return DB_SUCCESS on success or an error code on failure. */
728 dberr_t init();
729
730#ifdef UNIV_DEBUG
731 /** Save flushed page numbers for debugging purposes.
732 @param[in] page_no page number of the page that is flushed. */
734 m_bulk_flusher.m_flushed_page_nos.push_back(page_no);
735 }
736#endif /* UNIV_DEBUG */
737
738 /** Check if the index build operation has been interrupted.
739 @return true if the index build operation is interrupted, false otherwise.*/
740 bool is_interrupted() const;
741
742 /** Trigger flusher thread and check for error.
743 @return Innodb error code. */
745
746 /** Get the index object.
747 @return index object. */
748 dict_index_t *index() const { return m_index; }
749
750 const char *get_table_name() const { return m_index->table->name.m_name; }
751
752 /** Get the root page number of this tree/subtree.
753 @return the root page number of this tree/subtree. */
754 page_no_t get_subtree_root() const { return m_first_page_nos.back(); }
755
756 /** Get the level of the root page.
757 @return the level of the root page. */
758 size_t get_root_level() const { return m_root_level; }
759
760 /** Get information about root page. */
761 void get_root_page_stat(Page_stat &stat);
762
763 /** Get the transaction id.
764 @return the transaction id. */
765 trx_id_t get_trx_id() const;
766
767 /** Btree bulk load finish. We commit the last page in each level
768 and copy the last page in top level to the root page of the index
769 if no error occurs.
770 @param[in] is_err Whether bulk load was successful until now
771 @param[in] subtree true if a subtree is being built, false otherwise.
772 @return error code */
773 [[nodiscard]] dberr_t finish(bool is_err, const bool subtree) noexcept;
774
775 /** Insert a tuple to a page in a level
776 @param[in] dtuple Tuple to insert
777 @param[in] level B-tree level
778 @return error code */
779 [[nodiscard]] dberr_t insert(dtuple_t *dtuple, size_t level) noexcept;
780
781 /** Split the right most block of the tree at the given level.
782 @param[in,out] block the right most block at the given level.
783 @param[in] level level of the given block.
784 @param[in] node_ptr node pointer to be inserted in the block after
785 splitting.
786 @param[in] mtr mini transaction context.
787 @param[in,out] highest_level highest level among all the subtrees.*/
788 void split_rightmost(buf_block_t *block, size_t level, dtuple_t *node_ptr,
789 mtr_t *mtr, size_t &highest_level);
790
791 /** Split the left most block of the tree at the given level.
792 @param[in,out] block the left most block at the given level. it will be
793 updated with the new left most block.
794 @param[in] level level of the given block.
795 @param[in] node_ptr node pointer to be inserted in the block after
796 splitting.
797 @param[in] mtr mini transaction context.
798 @param[in,out] highest_level highest level among all the subtrees.*/
799 void split_leftmost(buf_block_t *&block, size_t level, dtuple_t *node_ptr,
800 mtr_t *mtr, size_t &highest_level);
801
802 private:
803 /** Set the root page on completion.
804 @param[in] last_page_no Last page number (the new root).
805 @return DB_SUCCESS or error code. */
806 [[nodiscard]] dberr_t load_root_page(page_no_t last_page_no) noexcept;
807
808 public:
809 /** Commit(finish) a page. We set next/prev page no, insert a node pointer to
810 father page if needed, and commit mini-transaction.
811 @param[in] page_load Page to commit
812 @param[in] next_page_load Next page
813 @param[in] insert_father Flag whether need to insert node ptr
814 @return error code */
815 [[nodiscard]] dberr_t page_commit(Page_load *page_load,
816 Page_load *next_page_load,
817 bool insert_father) noexcept;
818
819 /** Prepare space to insert a tuple.
820 @param[in,out] page_load Page bulk that will be used to store the record.
821 It may be replaced if there is not enough space
822 to hold the record.
823 @param[in] level B-tree level
824 @param[in] rec_size Record size
825 @return error code */
826 [[nodiscard]] dberr_t prepare_space(Page_load *&page_load, size_t level,
827 size_t rec_size) noexcept;
828
829 /** Insert a tuple to a page.
830 @param[in] page_load Page bulk object
831 @param[in] tuple Tuple to insert
832 @param[in] big_rec Big record vector, maybe NULL if there is no
833 Data to be stored externally.
834 @param[in] rec_size Record size
835 @return error code */
836 [[nodiscard]] dberr_t insert(Page_load *page_load, dtuple_t *tuple,
837 big_rec_t *big_rec, size_t rec_size) noexcept;
838
839 /** Btree page bulk load finish. Commits the last page in each level
840 if no error occurs. Also releases all page bulks.
841 @param[in] is_err Whether bulk load was successful until now
842 @param[out] last_page_no Last page number
843 @return error code */
844 [[nodiscard]] dberr_t finalize_page_loads(bool is_err,
845 page_no_t &last_page_no) noexcept;
846
847 public:
848 /** Allocate an extent.
849 @param[in,out] page_range the range of pages allocated.
850 @param[in] level btree level for which pages are allocated.
851 @return status code. */
852 dberr_t alloc_extent(Page_range_t &page_range, size_t level);
853
854 /** Initiate a direct file write operation.
855 @param[in] block block to be written to disk.
856 @return error code. */
857 [[nodiscard]] dberr_t fil_io(buf_block_t *block) noexcept;
858
859 /** Flush the blob pages.
860 @return status code. */
861 [[nodiscard]] dberr_t flush_blobs() noexcept;
862
863 /** Add the given block the internal cache of blocks.
864 @param[in] block the block to be cached. */
865 inline void block_put(buf_block_t *block);
866
867 /** Remove the given block from the internal cache of blocks.
868 @param[in] page_no the page number of block to be removed from cache. */
869 inline void block_remove(const page_no_t page_no);
870
871 /** Search for a BUF_BLOCK_MEMORY block with given page number in the local
872 cache.
873 @param[in] page_no the page number of block to be fetched.
874 @return buffer block with given page number. */
875 [[nodiscard]] inline buf_block_t *block_get(page_no_t page_no) const noexcept;
876
877 /** Evict all the pages in the given range from the buffer pool.
878 @param[in] range range of page numbers.
879 @param[in] dirty_is_ok it is OK for a page to be dirty. */
880 void force_evict(const Page_range_t &range, const bool dirty_is_ok = true);
881
882 public:
883 /** Check if a new level is needed. */
884 bool is_new_level(size_t level) const { return level >= m_level_ctxs.size(); }
885
886 /** Last page numbers of each level. */
887 std::vector<page_no_t, ut::allocator<page_no_t>> m_last_page_nos{};
888
889 /** First page numbers of each level. */
890 std::vector<page_no_t, ut::allocator<page_no_t>> m_first_page_nos{};
891
892 /** Get the level context object.
893 @param[in] level the level number. level 0 is leaf level.
894 @return the level context object. */
895 Level_ctx *get_level(size_t level) const;
896
897 /** Page numbers of the pages that has been allocated in the leaf level.
898 The page range is [p1, p2), where p2 is not included. */
900
901 /** Page numbers of the pages that has been allocated in the non-leaf level.
902 The page range is [p1, p2), where p2 is not included. */
904
907
908 /** State of the index. Used for asserting at the end of a
909 bulk load operation to ensure that the online status of the
910 index does not change */
912
913 /** Number of extents allocated for this B-tree. */
915
916 /** Number of pages allocated for this B-tree. */
917 size_t m_stat_n_pages{0};
918
919 public:
920 std::ostream &print_left_pages(std::ostream &out) const;
921 std::ostream &print_right_pages(std::ostream &out) const;
922
923 dberr_t check_key_overlap(const Btree_load *r_btree) const;
924
925#ifdef UNIV_DEBUG
926 void print_tree_pages() const;
927 std::string print_pages_in_level(const size_t level) const;
928 /** Check size and validate index of limited size.
929 @param[in] index Index to validate
930 @return true if successful. */
931 static bool validate_index(dict_index_t *index);
932#endif /* UNIV_DEBUG */
933
934 /** All allocated extents registers with Btree_load. */
935 void track_extent(Page_extent *page_extent);
936
937 /** Add fully used extents to the bulk flusher. Call this whenever a new
938 Page_load is allocated, with finish set to false. Only in
939 Btree_load::finish(), the finish argument will be true.
940 @param[in] finish if true, add all the tracked extents to the bulk flusher,
941 irrespective of whether it is fully used or not. */
942 void add_to_bulk_flusher(bool finish = false);
943
944 /** Add the given page extent object to the bulk flusher.
945 @param[in] page_extent the extent to be flushed. */
946 void add_to_bulk_flusher(Page_extent *page_extent);
947
948 /** Check if transparent page compression (TPC) is enabled.
949 @return true if TPC is enabled. */
950 bool is_tpc_enabled() const;
951
952 /** Check if transparent page encryption (TPE) is enabled.
953 @return true if TPE is enabled. */
954 bool is_tpe_enabled() const;
955
956 /** @return get flush queue size limit. */
959 }
960
961 /** If the data is already sorted and checked for duplicates, then we can
962 disable doing it again. */
964
965 private:
966 /** Page allocation type. We allocate in extents by default. */
969
970 /** Number of records inserted. */
971 uint64_t m_n_recs{};
972
973 /** B-tree index */
975
977
978 /** Transaction id */
980
981 /** Root page level */
982 size_t m_root_level{};
983
984 private:
985 /** Context information for each level of the B-tree. The leaf level is at
986 m_level_ctxs[0]. */
988
989 /* Dedicated thread to flush pages. */
991
992 /** Reference to global extent allocator. */
994
995 /** Extents that are being tracked. */
996 std::list<Page_extent *> m_extents_tracked;
997
998 /** If true, check if data is inserted in sorted order. */
999 bool m_check_order{true};
1000
1001 /** Memory heap to be used for sort order checks. */
1003
1004 /** Function object to compare two tuples. */
1006
1007 /** The previous tuple that has been inserted. */
1009
1010 bool is_extent_tracked(const Page_extent *page_extent) const;
1011
1012 /** Loader number. */
1014
1016
1017 /* Begin wait callback function. */
1019
1020 /* End wait callback function. */
1022};
1023
1025 public:
1026 using Btree_loads = std::vector<Btree_load *, ut::allocator<Btree_load *>>;
1027
1029 : m_btree_loads(loads),
1030 m_index(index),
1031 m_trx(trx),
1033
1034 dberr_t merge(bool sort);
1035
1036 private:
1037 /** Get the maximum free space available in an empty page in bytes.
1038 @return the maximum free space available in an empty page. */
1039 size_t get_max_free() const {
1041 }
1042
1043 /** Remove any empty sub-trees with no records. */
1044 void remove_empty_subtrees();
1045
1046#ifdef UNIV_DEBUG
1047 /** Validate sub-tree boundaries. */
1048 void validate_boundaries();
1049
1050#endif /* UNIV_DEBUG */
1051
1052 /** Stich sub-trees together to form a tree with one or multiple
1053 nodes at highest leve.
1054 @param[out] highest_level highest level of the merged tree.
1055 @return innodb error code. */
1056 dberr_t subtree_link_levels(size_t &highest_level);
1057
1058 /** Create root node for the stiched sub-trees by combining the nodes
1059 at highest level creating another level if required.
1060 @param[in] highest_level highest level of the merged tree.
1061 @return innodb error code. */
1062 dberr_t add_root_for_subtrees(const size_t highest_level);
1063
1064 /** Insert the given list of node pointers into pages at the given level.
1065 @param[in,out] all_node_ptrs list of node pointers
1066 @param[in,out] total_node_ptrs_size total space in bytes needed to insert
1067 all the node pointers.
1068 @param[in] level the level at which the node pointers are inserted.
1069 @return DB_SUCCESS if successful.
1070 @return error code on failure. */
1071 dberr_t insert_node_ptrs(std::vector<dtuple_t *> &all_node_ptrs,
1072 size_t &total_node_ptrs_size, size_t level);
1073
1074 /** Load the left page and update its FIL_PAGE_NEXT.
1075 @param[in] l_page_no left page number
1076 @param[in] r_page_no right page number. */
1077 void link_right_sibling(const page_no_t l_page_no, const page_no_t r_page_no);
1078
1079 private:
1080 /** Refernce to the subtrees to be merged. */
1082
1083 /** Index which is being built. */
1085
1086 /** Transaction making the changes. */
1088
1089 /** Memory heap to store node pointers. */
1091};
1092
1094 const Page_extent *page_extent) const {
1095 for (auto e : m_extents_tracked) {
1096 if (page_extent == e) {
1097 return true;
1098 }
1099 }
1100 return false;
1101}
1102
1103/** The proper function call sequence of Page_load is as below:
1104-- Page_load::init
1105-- Page_load::insert
1106-- Page_load::finish
1107-- Page_load::commit */
1109 public:
1111
1112 /** Ctor.
1113 @param[in] index B-tree index
1114 @param[in] btree_load btree object to which this page belongs. */
1115 Page_load(dict_index_t *index, Btree_load *btree_load);
1116
1117 /** Destructor. */
1118 ~Page_load() noexcept;
1119
1120 /** Check if page is corrupted.
1121 @return true if corrupted, false otherwise. */
1122 bool is_corrupted() const;
1123
1124 /** Print the child page numbers. */
1125 void print_child_page_nos() noexcept;
1126
1127 /** Check if state of this page is BUF_BLOCK_MEMORY.
1128 @return true if page state is BUF_BLOCK_MEMORY, false otherwise.*/
1129 bool is_memory() const { return m_block->is_memory(); }
1130
1131 /** A static member function to create this object.
1132 @param[in] btree_load the bulk load object to which this Page_load belongs.
1133 @param[in] page_extent page extent to which this page belongs. */
1134 static Page_load *create(Btree_load *btree_load, Page_extent *page_extent);
1135
1136 /** Release the page loader. Delete if not cached.
1137 @param[in] page_load page loader to delete. */
1138 static void drop(Page_load *page_load);
1139
1140 /** Constructor
1141 @param[in] index B-tree index
1142 @param[in] trx_id Transaction id
1143 @param[in] page_no Page number
1144 @param[in] level Page level
1145 @param[in] observer Flush observer
1146 @param[in] btree_load btree object to which this page belongs. */
1148 size_t level, Flush_observer *observer,
1149 Btree_load *btree_load = nullptr) noexcept
1150 : m_index(index),
1151 m_trx_id(trx_id),
1152 m_page_no(page_no),
1153 m_level(level),
1155 m_flush_observer(observer),
1156 m_btree_load(btree_load) {
1158 }
1159
1160 /** Set the transaction id.
1161 @param[in] trx_id the transaction id to used. */
1162 void set_trx_id(const trx_id_t trx_id) { m_trx_id = trx_id; }
1163
1164 /** Set the flush observer.
1165 @param[in] observer the flush observer object to use. */
1167 m_flush_observer = observer;
1168 }
1169
1170 bool is_leaf() const { return m_level == 0; }
1171
1172 /** Set the page number of this object. */
1173 void set_page_no(const page_no_t page_no);
1174
1175 void set_leaf_seg(const fseg_header_t *hdr) {
1177 }
1178 void set_top_seg(const fseg_header_t *hdr) {
1180 }
1181
1182 /** Initialize members and allocate page if needed and start mtr.
1183 @note Must be called and only once right after constructor.
1184 @return error code */
1185 [[nodiscard]] dberr_t init() noexcept;
1186 [[nodiscard]] dberr_t init_mem(const page_no_t new_page_no,
1187 Page_extent *page_extent) noexcept;
1188
1189 /** Allocate a page for this Page_load object.
1190 @return DB_SUCCESS on success, error code on failure. */
1191 dberr_t alloc() noexcept;
1192
1193 /** Re-initialize this page. */
1194 [[nodiscard]] dberr_t reinit() noexcept;
1195
1196 /** Reset this object so that Page_load::init() can be called again on this
1197 object. */
1198 void reset() noexcept;
1199
1200 /** Insert a tuple in the page.
1201 @param[in] tuple Tuple to insert
1202 @param[in] big_rec External record
1203 @param[in] rec_size Record size
1204 @return error code */
1205 [[nodiscard]] dberr_t insert(const dtuple_t *tuple, const big_rec_t *big_rec,
1206 size_t rec_size) noexcept;
1207
1208 /** Mark end of insertion to the page. Scan records to set page dirs,
1209 and set page header members. The scan is incremental (slots and records
1210 which assignment could be "finalized" are not checked again. Check the
1211 m_slotted_rec_no usage, note it could be reset in some cases like
1212 during split.
1213 Note: we refer to page_copy_rec_list_end_to_created_page.*/
1214 void finish() noexcept;
1215
1216 /** Commit mtr for a page
1217 @return DB_SUCCESS on success, error code on failure. */
1218 dberr_t commit() noexcept;
1219
1220 /** Commit mtr for a page */
1221 void rollback() noexcept;
1222
1223 /** Check whether the record needs to be stored externally.
1224 @return false if the entire record can be stored locally on the page */
1225 [[nodiscard]] bool need_ext(const dtuple_t *tuple,
1226 size_t rec_size) const noexcept;
1227
1228 /** Get node pointer
1229 @return node pointer */
1230 [[nodiscard]] dtuple_t *get_node_ptr() noexcept;
1231
1232 /** Get node pointer
1233 @param[in] heap allocate node pointer in the given heap.
1234 @return node pointer */
1235 [[nodiscard]] dtuple_t *get_node_ptr(mem_heap_t *heap) noexcept;
1236
1237 /** Copy all records from page.
1238 @param[in] src_page Page with records to copy. */
1239 size_t copy_all(const page_t *src_page) noexcept;
1240
1241 /** Distribute all records from this page to the given pages.
1242 @param[in,out] to_pages array of Page_load objects.
1243 return total number of records processed. */
1244 size_t copy_to(std::vector<Page_load *> &to_pages);
1245
1246 /** Set next page
1247 @param[in] next_page_no Next page no */
1248 void set_next(page_no_t next_page_no) noexcept;
1249
1250 /** Set previous page
1251 @param[in] prev_page_no Previous page no */
1252 void set_prev(page_no_t prev_page_no) noexcept;
1253
1254 /** Get previous page (FIL_PAGE_PREV). */
1255 page_no_t get_prev() noexcept;
1256
1257 /** Start mtr and latch block */
1258 void latch() noexcept;
1259
1260 /** Check if required space is available in the page for the rec
1261 to be inserted. We check fill factor & padding here.
1262 @param[in] rec_size Required space
1263 @return true if space is available */
1264 [[nodiscard]] inline bool is_space_available(size_t rec_size) const noexcept;
1265
1266 /** Get page no */
1267 [[nodiscard]] page_no_t get_page_no() const noexcept { return m_page_no; }
1268 [[nodiscard]] page_id_t get_page_id() const noexcept {
1269 return m_block->page.id;
1270 }
1271
1272 /** Get the physical page size of the underlying tablespace.
1273 @return the physical page size of the tablespace. */
1274 size_t get_page_size() const noexcept;
1275
1276 /** Get the table space ID.
1277 @return the table space ID. */
1278 space_id_t space() const noexcept;
1279
1280#ifdef UNIV_DEBUG
1281 /** Obtain tablespace id from the frame and the buffer block and ensure that
1282 they are the same.
1283 @return true if space id is same in both places. */
1284 bool verify_space_id() const;
1285#endif /* UNIV_DEBUG */
1286
1287 /** Get page level */
1288 [[nodiscard]] size_t get_level() const noexcept { return m_level; }
1289
1290 /** Set the level of this page. */
1291 void set_level(size_t level) noexcept { m_level = level; }
1292
1293 /** Get record no */
1294 [[nodiscard]] size_t get_rec_no() const { return m_rec_no; }
1295
1296 /** Get page */
1297 [[nodiscard]] const page_t *get_page() const noexcept {
1299 }
1300
1301 [[nodiscard]] page_t *get_page() noexcept {
1303 }
1304
1305 public:
1306 void init_for_writing();
1307 size_t get_data_size() const { return page_get_data_size(m_page); }
1308
1309#ifdef UNIV_DEBUG
1310 /** Check if index is X locked
1311 @return true if index is locked. */
1312 bool is_index_locked() noexcept;
1313#endif /* UNIV_DEBUG */
1314
1315 /** Copy given and all following records.
1316 @param[in] first_rec First record to copy */
1317 size_t copy_records(const rec_t *first_rec) noexcept;
1318
1319 /** Insert a record in the page, check for duplicates too.
1320 @param[in] rec Record
1321 @param[in] offsets Record offsets
1322 @return DB_SUCCESS or error code. */
1323 dberr_t insert(const rec_t *rec, Rec_offsets offsets) noexcept;
1324
1325 public:
1326 /** Store external record
1327 Since the record is not logged yet, so we don't log update to the record.
1328 the blob data is logged first, then the record is logged in bulk mode.
1329 @param[in] big_rec External record
1330 @param[in] offsets Record offsets
1331 @return error code */
1332 [[nodiscard]] dberr_t store_ext(const big_rec_t *big_rec,
1333 Rec_offsets offsets) noexcept;
1334
1335 /** Set the REC_INFO_MIN_REC_FLAG on the first user record in this page.
1336 @param[in] mtr mini transaction context. */
1337 void set_min_rec_flag(mtr_t *mtr);
1338
1339 /** Set the REC_INFO_MIN_REC_FLAG on the first user record in this page. */
1340 void set_min_rec_flag();
1341 bool is_min_rec_flag() const;
1342
1343 /** Set the level context object for this page load
1344 @param[in] level_ctx the level context object. */
1345 void set_level_ctx(Level_ctx *level_ctx) { m_level_ctx = level_ctx; }
1346
1347 /** Check if this page load object contains a level context object.
1348 @return true if the page load contains a level context object.
1349 @return false if the page load does NOT contain a level context object.*/
1350 bool has_level_ctx() const { return m_level_ctx != nullptr; }
1351
1352 /** Free the memory block. */
1353 void free();
1354
1356
1358
1359 void set_page_extent(Page_extent *page_extent) {
1360 m_page_extent = page_extent;
1361 }
1362
1363 /** Mark the Page load as cached. Flush thread should not free this Page. */
1364 void set_cached() { m_is_cached.store(true); }
1365
1366 /** @return true iff it is a cached Page Load. */
1367 bool is_cached() const { return m_is_cached.load(); }
1368
1369 private:
1370 /** Memory heap for internal allocation */
1372
1373 /** The index B-tree */
1375
1376 /** The min-transaction */
1378
1379 /** The transaction id */
1381
1382 /** The buffer block */
1384
1385 /** The page */
1387
1388 /** The current rec, just before the next insert rec */
1390
1391 /** The page no */
1393
1394 /** The page level in B-tree */
1395 size_t m_level{};
1396
1397 /** Flag: is page in compact format */
1398 const bool m_is_comp{};
1399
1400 /** The heap top in page for next insert */
1401 byte *m_heap_top{};
1402
1403 /** User record no */
1404 size_t m_rec_no{};
1405
1406 /** The free space left in the page */
1408
1409 /** The reserved space for fill factor */
1411
1412 /** Total data in the page */
1414
1415 /** The modify clock value of the buffer block
1416 when the block is re-pinned */
1417 uint64_t m_modify_clock{};
1418
1419 /** Flush observer */
1421
1422 /** Last record assigned to a slot. */
1424
1425 /** Number of records assigned to slots. */
1427
1428 /** Page modified flag. */
1430
1432
1434
1436
1437 /** true iff the the Page load is cached. */
1438 std::atomic_bool m_is_cached{false};
1439
1440 friend class Btree_load;
1441};
1442
1444 return get_node_ptr(m_heap);
1445}
1446
1447inline space_id_t Page_load::space() const noexcept { return m_index->space; }
1448
1449inline size_t Page_load::get_page_size() const noexcept {
1450 const page_size_t page_size = m_index->get_page_size();
1451 return page_size.physical();
1452}
1453
1454inline Level_ctx *Btree_load::get_level(size_t level) const {
1455 ut_a(m_level_ctxs.size() > level);
1456 return m_level_ctxs[level];
1457}
1458
1459/** Information about a buffer page. */
1461 /** Number of user records in the page. */
1462 size_t m_n_recs;
1463
1464 /** Number of bytes of data. */
1466};
1467
1468inline void Page_extent::append(Page_load *page_load) {
1469 ut_ad(page_load->get_block() != nullptr);
1470 ut_ad(page_load->is_memory());
1471 ut_ad(page_load->get_page_no() >= m_range.first);
1472 ut_ad(page_load->get_page_no() < m_range.second);
1474 for (auto &iter : m_page_loads) {
1475 if (iter->get_page_no() == page_load->get_page_no()) {
1476 /* Page already appended. Don't append again. */
1477 return;
1478 }
1479 }
1480 m_page_loads.push_back(page_load);
1481}
1482
1484 return m_btree_load->get_trx_id();
1485}
1486
1488 return m_btree_load->index()->space;
1489}
1490
1491inline Page_extent::Page_extent(Btree_load *btree_load, const bool is_leaf)
1492 : m_page_no(FIL_NULL),
1493 m_range(FIL_NULL, FIL_NULL),
1494 m_btree_load(btree_load),
1495 m_is_leaf(is_leaf) {}
1496
1498 const bool is_leaf, bool skip_track) {
1499 Page_extent *p = ut::new_withkey<Page_extent>(UT_NEW_THIS_FILE_PSI_KEY,
1500 btree_load, is_leaf);
1501 if (!skip_track) {
1502 btree_load->track_extent(p);
1503 }
1504 p->m_is_cached.store(false);
1505 return p;
1506}
1507
1508inline void Page_extent::drop(Page_extent *extent) {
1509 if (extent == nullptr) {
1510 return;
1511 }
1512 if (extent->is_cached()) {
1513 ut_a(!extent->is_free());
1514 bool free = true;
1515 extent->set_state(free);
1516 return;
1517 }
1518 ut::delete_(extent);
1519}
1520
1521/** Function object to compare two Btree_load objects. */
1524 bool operator()(const Btree_load *l_btree, const Btree_load *r_btree);
1526};
1527
1528#ifdef UNIV_DEBUG
1531#endif /* UNIV_DEBUG */
1532
1533} /* namespace Btree_multi */
1534
1535#endif /* btr0mtib_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:47
uint32_t page_no_t
Page number.
Definition: api0api.h:45
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:1024
Btree_loads & m_btree_loads
Refernce to the subtrees to be merged.
Definition: btr0mtib.h:1081
std::vector< Btree_load *, ut::allocator< Btree_load * > > Btree_loads
Definition: btr0mtib.h:1026
dict_index_t * m_index
Index which is being built.
Definition: btr0mtib.h:1084
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:1039
Merger(Btree_loads &loads, dict_index_t *index, trx_t *trx)
Definition: btr0mtib.h:1028
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:1090
dberr_t merge(bool sort)
Definition: btr0mtib.cc:2482
trx_t * m_trx
Transaction making the changes.
Definition: btr0mtib.h:1087
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:692
~Wait_callbacks()
Definition: btr0mtib.h:703
Wait_callbacks(Btree_load *btree_load, Function &begin, Function &end)
Definition: btr0mtib.h:697
Btree_load * m_btree_load
Btree Load for the wait callbacks.
Definition: btr0mtib.h:710
std::function< void()> Function
Definition: btr0mtib.h:694
Definition: btr0mtib.h:682
~Btree_load() noexcept
Destructor.
Definition: btr0mtib.cc:1504
dict_index_t * m_index
B-tree index.
Definition: btr0mtib.h:974
Bulk_flusher m_bulk_flusher
Definition: btr0mtib.h:990
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:744
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:993
bool is_new_level(size_t level) const
Check if a new level is needed.
Definition: btr0mtib.h:884
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:748
size_t get_max_flush_queue_size() const
Definition: btr0mtib.h:957
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:1008
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:982
std::vector< page_no_t, ut::allocator< page_no_t > > m_first_page_nos
First page numbers of each level.
Definition: btr0mtib.h:890
byte m_fseg_hdr_leaf[FSEG_HEADER_SIZE]
Definition: btr0mtib.h:905
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:967
Page_range_t m_page_range_leaf
Page numbers of the pages that has been allocated in the leaf level.
Definition: btr0mtib.h:899
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:1013
Level_ctxs m_level_ctxs
Context information for each level of the B-tree.
Definition: btr0mtib.h:987
page_no_t get_subtree_root() const
Get the root page number of this tree/subtree.
Definition: btr0mtib.h:754
size_t m_stat_n_pages
Number of pages allocated for this B-tree.
Definition: btr0mtib.h:917
trx_t * m_trx
Transaction id.
Definition: btr0mtib.h:979
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:1002
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:996
void track_page_flush(page_no_t page_no)
Save flushed page numbers for debugging purposes.
Definition: btr0mtib.h:733
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:1005
size_t get_root_level() const
Get the level of the root page.
Definition: btr0mtib.h:758
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:1093
bool m_check_order
If true, check if data is inserted in sorted order.
Definition: btr0mtib.h:999
bool is_tpc_enabled() const
Check if transparent page compression (TPC) is enabled.
Definition: btr0mtib.cc:2464
std::vector< Page_load *, ut::allocator< Page_load * > > Page_loaders
Definition: btr0mtib.h:688
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:963
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:971
Wait_callbacks::Function m_fn_wait_begin
Definition: btr0mtib.h:1018
const char * get_table_name() const
Definition: btr0mtib.h:750
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:976
Page_range_t m_page_range_top
Page numbers of the pages that has been allocated in the non-leaf level.
Definition: btr0mtib.h:903
Wait_callbacks::Function m_fn_wait_end
Definition: btr0mtib.h:1021
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:911
byte m_fseg_hdr_top[FSEG_HEADER_SIZE]
Definition: btr0mtib.h:906
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:1454
const page_size_t m_page_size
Definition: btr0mtib.h:1015
std::vector< Level_ctx *, ut::allocator< Level_ctx * > > Level_ctxs
Definition: btr0mtib.h:689
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:887
size_t m_stat_n_extents
Number of extents allocated for this B-tree.
Definition: btr0mtib.h:914
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:1108
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:1291
buf_block_t * get_block()
Definition: btr0mtib.h:1357
space_id_t space() const noexcept
Get the table space ID.
Definition: btr0mtib.h:1447
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:1380
byte * m_heap_top
The heap top in page for next insert.
Definition: btr0mtib.h:1401
size_t get_level() const noexcept
Get page level.
Definition: btr0mtib.h:1288
rec_t * m_last_slotted_rec
Last record assigned to a slot.
Definition: btr0mtib.h:1423
dict_index_t * index()
Definition: btr0mtib.h:1355
void set_level_ctx(Level_ctx *level_ctx)
Set the level context object for this page load.
Definition: btr0mtib.h:1345
void set_trx_id(const trx_id_t trx_id)
Set the transaction id.
Definition: btr0mtib.h:1162
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:1166
void set_page_extent(Page_extent *page_extent)
Definition: btr0mtib.h:1359
size_t get_rec_no() const
Get record no.
Definition: btr0mtib.h:1294
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:1267
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:1449
dict_index_t * m_index
The index B-tree.
Definition: btr0mtib.h:1374
size_t m_slotted_rec_no
Number of records assigned to slots.
Definition: btr0mtib.h:1426
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:1420
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:1417
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:1350
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:1404
std::atomic_bool m_is_cached
true iff the the Page load is cached.
Definition: btr0mtib.h:1438
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:1129
bool is_leaf() const
Definition: btr0mtib.h:1170
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:1307
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:1395
rec_t * m_cur_rec
The current rec, just before the next insert rec.
Definition: btr0mtib.h:1389
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:1410
mem_heap_t * m_heap
Memory heap for internal allocation.
Definition: btr0mtib.h:1371
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:1268
void latch() noexcept
Start mtr and latch block.
Page_extent * m_page_extent
Definition: btr0mtib.h:1435
bool is_cached() const
Definition: btr0mtib.h:1367
page_t * get_page() noexcept
Definition: btr0mtib.h:1301
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:1147
void set_top_seg(const fseg_header_t *hdr)
Definition: btr0mtib.h:1178
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:1175
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:1407
void set_cached()
Mark the Page load as cached.
Definition: btr0mtib.h:1364
const bool m_is_comp
Flag: is page in compact format.
Definition: btr0mtib.h:1398
Btree_load * m_btree_load
Definition: btr0mtib.h:1431
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:1377
const page_t * get_page() const noexcept
Get page.
Definition: btr0mtib.h:1297
bool m_modified
Page modified flag.
Definition: btr0mtib.h:1429
buf_block_t * m_block
The buffer block.
Definition: btr0mtib.h:1383
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:1392
Level_ctx * m_level_ctx
Definition: btr0mtib.h:1433
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:1413
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:1386
dtuple_t * get_node_ptr() noexcept
Get node pointer.
Definition: btr0mtib.h:1443
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:304
page_id_t id
Page id.
Definition: buf0buf.h:1376
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:4766
constexpr page_no_t FIL_NULL
'null' (undefined) page offset in the context of file spaces
Definition: fil0fil.h:1159
#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:2874
void delete_(T *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::new*() variants.
Definition: ut0new.h:809
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:1522
dict_index_t * m_index
Definition: btr0mtib.h:1525
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:1523
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:1483
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:1491
static void drop(Page_extent *extent)
Release the page extent.
Definition: btr0mtib.h:1508
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:1468
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:1487
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:1497
~Page_extent()
Destructor.
Definition: btr0mtib.h:205
Btree_load * m_btree_load
Definition: btr0mtib.h:191
Information about a buffer page.
Definition: btr0mtib.h:1460
size_t m_n_recs
Number of user records in the page.
Definition: btr0mtib.h:1462
size_t m_data_size
Number of bytes of data.
Definition: btr0mtib.h:1465
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:838
The buffer control block structure.
Definition: buf0buf.h:1747
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:1753
bool is_memory() const noexcept
Definition: buf0buf.h:1993
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:895
Data structure for a database table.
Definition: dict0mem.h:1909
table_name_t name
Table name.
Definition: dict0mem.h:1984
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:682
File node of a tablespace or the log data space.
Definition: fil0fil.h:155
Tablespace or log data space.
Definition: fil0fil.h:238
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:684
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:564