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