commit c55a1080c76a1a9cee69d5da4be722f911c19b26 Author: Laurynas Biveinis Date: Mon May 27 17:08:05 2024 +0300 Fix bug 109920 (SEs cannot add to clone data size estimates) Implement clone plugin API for storage engines to add to clone data size estimate. diff --git a/plugin/clone/include/clone_client.h b/plugin/clone/include/clone_client.h index f218c5fdd87..5d4f5c34212 100644 --- a/plugin/clone/include/clone_client.h +++ b/plugin/clone/include/clone_client.h @@ -553,6 +553,10 @@ class Client { /** Change stage in PFS progress table. */ void pfs_change_stage(uint64_t estimate); + /** Add to the data size estimate. + @param[in] estimate_delta how many bytes to add to the estimate */ + void add_to_data_size_estimate(uint64_t estimate_delta); + /** End state in PFS table. @param[in] err_num error number @param[in] err_mesg error message */ @@ -824,6 +828,10 @@ class Client_Cbk : public Ha_clone_cbk { @return error code */ int apply_buffer_cbk(uchar *&to_buffer, uint &len) override; + /** Add to the data size estimate. + @param[in] estimate_delta how many bytes to add to the estimate */ + void add_to_data_size_estimate(uint64_t estimate_delta) override; + private: /** Apply data to local file or buffer. @param[in,out] to_file destination file diff --git a/plugin/clone/include/clone_local.h b/plugin/clone/include/clone_local.h index 7d7bd0fe33b..00290817db9 100644 --- a/plugin/clone/include/clone_local.h +++ b/plugin/clone/include/clone_local.h @@ -130,6 +130,10 @@ class Local_Callback : public Ha_clone_cbk { @return error code */ int apply_buffer_cbk(uchar *&to_buffer, uint &len) override; + /** Add to the data size estimate. + @param[in] estimate_delta how many bytes to add to the estimate */ + void add_to_data_size_estimate(std::uint64_t estimate_delta) override; + private: /** Apply data using storage engine apply interface. @return error code */ diff --git a/plugin/clone/include/clone_server.h b/plugin/clone/include/clone_server.h index f34af2b8d89..0a6b5df7625 100644 --- a/plugin/clone/include/clone_server.h +++ b/plugin/clone/include/clone_server.h @@ -281,6 +281,12 @@ class Server_Cbk : public Ha_clone_cbk { @return error code */ int apply_buffer_cbk(uchar *&to_buffer, uint &len) override; + /** Callback to update data size estimate for the current SE: not used for + server. */ + void add_to_data_size_estimate(std::uint64_t) override { + assert(0); + } + private: /** Clone server object */ Server *m_clone_server; diff --git a/plugin/clone/include/clone_status.h b/plugin/clone/include/clone_status.h index 9941c2b5897..cd662d7b5d5 100644 --- a/plugin/clone/include/clone_status.h +++ b/plugin/clone/include/clone_status.h @@ -420,6 +420,13 @@ class Progress_pfs : public Table_pfs { write(data_dir); } + /** Add to the data size estimate. + @param[in] estimate_delta how many bytes to add to the estimate */ + void add_to_data_size_estimate(uint64_t estimate_delta) { + assert(m_current_stage != STAGE_NONE); + m_estimate[m_current_stage] += estimate_delta; + } + /** Set PFS table data while ending a Clone stage. @@param[in] data_dir data directory for write. */ void end_stage(bool failed, const char *data_dir) { diff --git a/plugin/clone/src/clone_client.cc b/plugin/clone/src/clone_client.cc index 1cf7f22501b..91a13db819f 100644 --- a/plugin/clone/src/clone_client.cc +++ b/plugin/clone/src/clone_client.cc @@ -599,6 +599,13 @@ void Client::pfs_change_stage(uint64_t estimate) { mysql_mutex_unlock(&s_table_mutex); } +void Client::add_to_data_size_estimate(uint64_t estimate_delta) { + mysql_mutex_lock(&s_table_mutex); + s_progress_data.add_to_data_size_estimate(estimate_delta); + s_status_data.write(false); + mysql_mutex_unlock(&s_table_mutex); +} + void Client::pfs_end_state(uint32_t err_num, const char *err_mesg) { if (!is_master()) { return; @@ -1866,6 +1873,11 @@ int Client_Cbk::buffer_cbk(uchar *from_buffer [[maybe_unused]], uint buf_len) { return (err); } +void Client_Cbk::add_to_data_size_estimate(std::uint64_t estimate_delta) { + auto *const client = get_clone_client(); + client->add_to_data_size_estimate(estimate_delta); +} + int Client_Cbk::apply_buffer_cbk(uchar *&to_buffer, uint &len) { Ha_clone_file dummy_file; dummy_file.o_direct_uneven_file_size = false; diff --git a/plugin/clone/src/clone_local.cc b/plugin/clone/src/clone_local.cc index 734c5261587..21de7867000 100644 --- a/plugin/clone/src/clone_local.cc +++ b/plugin/clone/src/clone_local.cc @@ -253,6 +253,11 @@ int Local_Callback::apply_ack() { return (error); } +void Local_Callback::add_to_data_size_estimate(std::uint64_t estimate_delta) { + auto *const client = get_clone_client(); + client->add_to_data_size_estimate(estimate_delta); +} + int Local_Callback::apply_data() { uint loc_len = 0; diff --git a/sql/handler.h b/sql/handler.h index 19e7b18d09d..0c4d3a0eaa0 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1060,6 +1060,10 @@ class Ha_clone_cbk { @return error code */ virtual int apply_buffer_cbk(uchar *&to_buffer, uint &len) = 0; + /** Callback to update clone data size estimate for the current SE. + @param[in] estimate_delta how many bytes to add to the clone size estimate */ + virtual void add_to_data_size_estimate(std::uint64_t estimate_delta) = 0; + /** virtual destructor. */ virtual ~Ha_clone_cbk() = default;