Skip to content

Commit

Permalink
feat(shannon): statically guided load
Browse files Browse the repository at this point in the history
  • Loading branch information
ShannonBase committed Dec 9, 2024
1 parent d28e7a9 commit 2d9f534
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
5 changes: 4 additions & 1 deletion sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4867,12 +4867,15 @@ class handler {
if we exhaust the max cap of number of
parallel read threads that can be
spawned at a time
@param[in] max_desired_threads Maximum number of desired scan threads;
passing 0 has no effect, it is ignored.
@return error code
@retval 0 on success
*/
virtual int parallel_scan_init(void *&scan_ctx [[maybe_unused]],
size_t *num_threads [[maybe_unused]],
bool use_reserved_threads [[maybe_unused]]) {
bool use_reserved_threads [[maybe_unused]],
size_t max_desired_threads [[maybe_unused]]) {
return 0;
}

Expand Down
4 changes: 4 additions & 0 deletions sql/sql_alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,9 @@ bool Sql_cmd_secondary_load_unload::execute(THD *thd) {
if (check_grant(thd, ALTER_ACL, table_list, false, UINT_MAX, false))
return true;

Table_ddl_hton_notification_guard notification_guard{
thd, &table_list->mdl_request.key, HA_ALTER_DDL};
if (notification_guard.notify()) return true;

return mysql_secondary_load_or_unload(thd, table_list);
}
8 changes: 7 additions & 1 deletion storage/innobase/handler/ha_innodb.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,21 @@ class ha_innobase : public handler {
@param[out] scan_ctx A scan context created by this method
that has to be used in
parallel_scan
that has to be used in parallel_scan
@param[out] num_threads Number of threads to be spawned
@param[in] use_reserved_threads true if reserved threads are to be used
if we exhaust the max cap of number of
parallel read threads that can be
spawned at a time
@param[in] max_desired_threads Maximum number of desired read threads;
passing 0 has no effect, it is ignored;
upper-limited by the current value of
innodb_parallel_read_threads.
@return error code
@retval 0 on success */
int parallel_scan_init(void *&scan_ctx, size_t *num_threads,
bool use_reserved_threads) override;
bool use_reserved_threads,
size_t max_desired_threads) override;

/** Start parallel read of InnoDB records.
@param[in] scan_ctx A scan context created by parallel_scan_init
Expand Down
7 changes: 6 additions & 1 deletion storage/innobase/handler/ha_innopart.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,15 @@ class ha_innopart : public ha_innobase,
if we exhaust the max cap of number of
parallel read threads that can be
spawned at a time
@param[in] max_desired_threads Maximum number of desired read threads;
passing 0 has no effect, it is ignored;
upper-limited by the current value of
innodb_parallel_read_threads.
@return error code
@return 0 on success */
int parallel_scan_init(void *&scan_ctx, size_t *num_threads,
bool use_reserved_threads) override;
bool use_reserved_threads,
size_t max_desired_threads) override;

using Reader = Parallel_reader_adapter;

Expand Down
17 changes: 14 additions & 3 deletions storage/innobase/handler/handler0alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Copyright (c) 2023, Shannon Data AI and/or its affiliates.
/** @file handler/handler0alter.cc
Smart ALTER TABLE
*******************************************************/
#include <algorithm>

/* Include necessary SQL headers */
#include <assert.h>
Expand Down Expand Up @@ -1472,7 +1473,8 @@ static inline int convert_error_code(dberr_t err, int flags, THD *thd,
}

int ha_innobase::parallel_scan_init(void *&scan_ctx, size_t *num_threads,
bool use_reserved_threads) {
bool use_reserved_threads,
size_t max_desired_threads) {
if (dict_table_is_discarded(m_prebuilt->table)) {
ib_senderrf(ha_thd(), IB_LOG_LEVEL_ERROR, ER_TABLESPACE_DISCARDED,
table->s->table_name.str);
Expand All @@ -1494,6 +1496,10 @@ int ha_innobase::parallel_scan_init(void *&scan_ctx, size_t *num_threads,

size_t max_threads = thd_parallel_read_threads(m_prebuilt->trx->mysql_thd);

if (max_desired_threads > 0) {
max_threads = std::min(max_threads, max_desired_threads);
}

max_threads =
Parallel_reader::available_threads(max_threads, use_reserved_threads);

Expand Down Expand Up @@ -10025,8 +10031,13 @@ static inline Instant_Type innopart_support_instant(
}

int ha_innopart::parallel_scan_init(void *&scan_ctx, size_t *num_threads,
bool use_reserved_threads) {
auto max_threads = thd_parallel_read_threads(m_prebuilt->trx->mysql_thd);
bool use_reserved_threads,
size_t max_desired_threads) {
size_t max_threads = thd_parallel_read_threads(m_prebuilt->trx->mysql_thd);
if (max_desired_threads > 0) {
max_threads = std::min(max_threads, max_desired_threads);
}

ut_a(max_threads <= Parallel_reader::MAX_THREADS);

max_threads = static_cast<ulong>(
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/ut0new.h
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,7 @@ struct allocator_base {
explicit allocator_base(PSI_memory_key /*key*/) {}

template <typename U>
allocator_base(const allocator_base<U> &other) {}
allocator_base(const allocator_base<U> & /*other*/) {}

void *allocate_impl(size_t n_bytes) { return ut::malloc(n_bytes); }
};
Expand Down

0 comments on commit 2d9f534

Please sign in to comment.