MySQL 8.0.31
Source Code Documentation
ddl0impl-loader.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2020, 2022, 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 also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/ddl0impl-loader.h
28 DDL index loader interface.
29 Created 2020-11-01 by Sunny Bains. */
30
31#ifndef ddl0impl_loader_h
32#define ddl0impl_loader_h
33
34#include "ddl0fts.h"
35#include "ddl0impl-buffer.h"
36#include "ut0mpmcbq.h"
37
38namespace ddl {
39
40/** Build indexes on a table by reading a clustered index, creating a temporary
41file containing index entries, merge sorting these index entries and inserting
42sorted index entries to indexes. */
43class Loader {
44 public:
45 /** Builder task. */
46 struct Task {
47 /** Constructor. */
48 Task() = default;
49
50 /** Constructor.
51 @param[in,out] builder Builder that performs the operation. */
52 explicit Task(Builder *builder) : m_builder(builder) {}
53
54 /** Constructor.
55 @param[in,out] builder Builder that performs the operation.
56 @param[in] thread_id Index value of the thread_state to work on. */
57 explicit Task(Builder *builder, size_t thread_id)
58 : m_builder(builder), m_thread_id(thread_id) {}
59
60 /** Do the operation.
61 @return DB_SUCCESS or error code. */
62 [[nodiscard]] dberr_t operator()() noexcept;
63
64 private:
65 /** Builder instance. */
67
68 /** Thread state index. */
69 size_t m_thread_id{std::numeric_limits<size_t>::max()};
70
71 friend class Loader;
72 };
73
74 // Forward declaration
75 class Task_queue;
76
77 /** Constructor.
78 @param[in,out] ctx DDL context. */
79 explicit Loader(ddl::Context &ctx) noexcept;
80
81 /** Destructor. */
82 ~Loader() noexcept;
83
84 /** Build the read instance.
85 @return DB_SUCCESS or error code. */
86 [[nodiscard]] dberr_t build_all() noexcept;
87
88 /** Add a task to the task queue.
89 @param[in] task Task to add. */
90 void add_task(Task task) noexcept;
91
92 /** Validate the indexes (except FTS).
93 @return true on success. */
94 [[nodiscard]] bool validate_indexes() const noexcept;
95
96 private:
97 /** Prepare to build and load the indexes.
98 @return DB_SUCCESS or error code. */
99 [[nodiscard]] dberr_t prepare() noexcept;
100
101 /** Load the indexes.
102 @return DB_SUCCESS or error code. */
103 [[nodiscard]] dberr_t load() noexcept;
104
105 /** Scan and build the indexes.
106 @return DB_SUCCESS or error code. */
107 [[nodiscard]] dberr_t scan_and_build_indexes() noexcept;
108
109 private:
110 /** DDL context, shared by the loader threads. */
112
113 /** If true then use parallel scan and index build. */
115
116 /** Sort buffer size. */
118
119 /** IO buffer size. */
121
122 /** Index builders. */
124
125 /** Task queue. */
127};
128
129} // namespace ddl
130
131#endif /* !ddl0impl_loader_h */
Unbounded task queue.
Definition: ddl0loader.cc:45
Build indexes on a table by reading a clustered index, creating a temporary file containing index ent...
Definition: ddl0impl-loader.h:43
dberr_t build_all() noexcept
Build the read instance.
Definition: ddl0loader.cc:476
bool validate_indexes() const noexcept
Validate the indexes (except FTS).
Definition: ddl0loader.cc:508
Builders m_builders
Index builders.
Definition: ddl0impl-loader.h:123
dberr_t prepare() noexcept
Prepare to build and load the indexes.
Definition: ddl0loader.cc:365
~Loader() noexcept
Destructor.
Definition: ddl0loader.cc:266
size_t m_io_buffer_size
IO buffer size.
Definition: ddl0impl-loader.h:120
size_t m_sort_buffer_size
Sort buffer size.
Definition: ddl0impl-loader.h:117
Task_queue * m_taskq
Task queue.
Definition: ddl0impl-loader.h:126
void add_task(Task task) noexcept
Add a task to the task queue.
Definition: ddl0loader.cc:286
dberr_t load() noexcept
Load the indexes.
Definition: ddl0loader.cc:288
ddl::Context & m_ctx
DDL context, shared by the loader threads.
Definition: ddl0impl-loader.h:111
dberr_t scan_and_build_indexes() noexcept
Scan and build the indexes.
Definition: ddl0loader.cc:397
bool m_parallel
If true then use parallel scan and index build.
Definition: ddl0impl-loader.h:114
Loader(ddl::Context &ctx) noexcept
Constructor.
Definition: ddl0loader.cc:264
dberr_t
Definition: db0err.h:38
Create Full Text Index with (parallel) merge sort.
DDL buffer infrastrucure.
static my_thread_id thread_id
Definition: my_thr_init.cc:62
The general architecture is that the work is done in two phases, roughly the read and write phase.
Definition: btr0load.cc:41
std::vector< Builder *, ut::allocator< Builder * > > Builders
Definition: ddl0impl.h:60
For loading indexes.
Definition: ddl0impl-builder.h:47
DDL context/configuration.
Definition: ddl0ddl.h:320
Builder task.
Definition: ddl0impl-loader.h:46
size_t m_thread_id
Thread state index.
Definition: ddl0impl-loader.h:69
Task()=default
Constructor.
Builder * m_builder
Builder instance.
Definition: ddl0impl-loader.h:66
Task(Builder *builder)
Constructor.
Definition: ddl0impl-loader.h:52
dberr_t operator()() noexcept
Do the operation.
Definition: ddl0builder.cc:2085
Task(Builder *builder, size_t thread_id)
Constructor.
Definition: ddl0impl-loader.h:57