This is an automated email from the ASF dual-hosted git repository. isapego pushed a commit to branch ignite-17607 in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit 72c529be8e77e27fc3f8234e23438eb878ea9bc7 Author: Igor Sapego <[email protected]> AuthorDate: Tue Mar 7 12:59:32 2023 +0300 IGNITE-17607 execute_async stub --- modules/platforms/cpp/ignite/client/CMakeLists.txt | 1 + .../cpp/ignite/client/compute/compute.cpp | 38 ++++++++++++++-- .../platforms/cpp/ignite/client/compute/compute.h | 30 +++++++------ .../compute/compute_impl.cpp} | 13 +++--- .../compute.h => detail/compute/compute_impl.h} | 50 +++++++--------------- 5 files changed, 74 insertions(+), 58 deletions(-) diff --git a/modules/platforms/cpp/ignite/client/CMakeLists.txt b/modules/platforms/cpp/ignite/client/CMakeLists.txt index e84687dce8..626b172a60 100644 --- a/modules/platforms/cpp/ignite/client/CMakeLists.txt +++ b/modules/platforms/cpp/ignite/client/CMakeLists.txt @@ -33,6 +33,7 @@ set(SOURCES detail/cluster_connection.cpp detail/utils.cpp detail/node_connection.cpp + detail/compute/compute_impl.cpp detail/sql/sql_impl.cpp detail/table/table_impl.cpp detail/table/tables_impl.cpp diff --git a/modules/platforms/cpp/ignite/client/compute/compute.cpp b/modules/platforms/cpp/ignite/client/compute/compute.cpp index 8476afbaab..1a4de991b7 100644 --- a/modules/platforms/cpp/ignite/client/compute/compute.cpp +++ b/modules/platforms/cpp/ignite/client/compute/compute.cpp @@ -16,13 +16,45 @@ */ #include "ignite/client/compute/compute.h" -//#include "ignite/client/detail/compute/compute_impl.h" +#include "ignite/client/detail/compute/compute_impl.h" + +#include <random> namespace ignite { -void compute::execute_async(std::vector<cluster_node> nodes, std::string_view job_class_name, +template<typename T> +typename T::value_type get_random_element(const T &cont) { + // TODO: Move to utils + static std::mutex randomMutex; + static std::random_device rd; + static std::mt19937 gen(rd()); + + assert(!cont.empty()); + + std::uniform_int_distribution<size_t> distrib(0, cont.size() - 1); + + std::lock_guard<std::mutex> lock(randomMutex); + + return cont[distrib(gen)]; +} + +/** + * Check value argument. + * + * @param value Value tuple. + */ +template<typename T> +void inline check_non_empty(const T &cont, const std::string& title) { + if (cont.empty()) + throw ignite_error(title + " can not be empty"); +} + +void compute::execute_async(const std::vector<cluster_node>& nodes, std::string_view job_class_name, std::vector<primitive> args, ignite_callback<std::optional<primitive>> callback) { - // TODO: Implement me + check_non_empty(nodes, "Nodes container"); + check_non_empty(job_class_name, "Job class name"); + + m_impl->execute_on_one_node(get_random_element(nodes), job_class_name, std::move(args), std::move(callback)); } } // namespace ignite diff --git a/modules/platforms/cpp/ignite/client/compute/compute.h b/modules/platforms/cpp/ignite/client/compute/compute.h index 8f142bb835..d4d5f511dd 100644 --- a/modules/platforms/cpp/ignite/client/compute/compute.h +++ b/modules/platforms/cpp/ignite/client/compute/compute.h @@ -43,26 +43,28 @@ public: compute() = delete; /** - * Executes single SQL statement asynchronously and returns rows. + * Executes a compute job represented by the given class on one of the specified nodes asynchronously. * - * @param tx Optional transaction. If nullptr implicit transaction for this single operation is used. - * @param statement Statement to execute. - * @param args Arguments for the statement. - * @param callback A callback called on operation completion with SQL result set. + * @param nodes Nodes to use for the job execution. + * @param job_class_name Java class name of the job to execute. + * @param args Job arguments. + * @param callback A callback called on operation completion with job execution result. */ - IGNITE_API void execute_async(std::vector<cluster_node> nodes, std::string_view job_class_name, std::vector<primitive> args, - ignite_callback<std::optional<primitive>> callback); + IGNITE_API void execute_async(const std::vector<cluster_node>& nodes, std::string_view job_class_name, + std::vector<primitive> args, ignite_callback<std::optional<primitive>> callback); /** - * Executes single SQL statement and returns rows. + * Executes a compute job represented by the given class on one of the specified nodes. * - * @param tx Optional transaction. If nullptr implicit transaction for this single operation is used. - * @param statement Statement to execute. - * @param args Arguments for the statement. - * @return SQL result set. + * @param nodes Nodes to use for the job execution. + * @param job_class_name Java class name of the job to execute. + * @param args Job arguments. + * @return Job execution result. */ - IGNITE_API std::optional<primitive> execute(std::vector<cluster_node> nodes, std::string_view job_class_name, std::vector<primitive> args) { - return sync<std::optional<primitive>>([this, nodes = std::move(nodes), job_class_name, args = std::move(args)](auto callback) mutable { + IGNITE_API std::optional<primitive> execute(std::vector<cluster_node> nodes, std::string_view job_class_name, + std::vector<primitive> args) { + return sync<std::optional<primitive>>( + [this, nodes = std::move(nodes), job_class_name, args = std::move(args)](auto callback) mutable { execute_async(std::move(nodes), job_class_name, std::move(args), std::move(callback)); }); } diff --git a/modules/platforms/cpp/ignite/client/compute/compute.cpp b/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.cpp similarity index 69% copy from modules/platforms/cpp/ignite/client/compute/compute.cpp copy to modules/platforms/cpp/ignite/client/detail/compute/compute_impl.cpp index 8476afbaab..fa719a66a3 100644 --- a/modules/platforms/cpp/ignite/client/compute/compute.cpp +++ b/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.cpp @@ -15,14 +15,13 @@ * limitations under the License. */ -#include "ignite/client/compute/compute.h" -//#include "ignite/client/detail/compute/compute_impl.h" +#include "ignite/client/detail/compute/compute_impl.h" -namespace ignite { +namespace ignite::detail { -void compute::execute_async(std::vector<cluster_node> nodes, std::string_view job_class_name, - std::vector<primitive> args, ignite_callback<std::optional<primitive>> callback) { - // TODO: Implement me +void compute_impl::execute_on_one_node(cluster_node nodes, std::string_view job_class_name, std::vector<primitive> args, + ignite_callback<std::optional<primitive>> callback) { + // TODO: Implement me. } -} // namespace ignite +} // namespace ignite::detail diff --git a/modules/platforms/cpp/ignite/client/compute/compute.h b/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.h similarity index 55% copy from modules/platforms/cpp/ignite/client/compute/compute.h copy to modules/platforms/cpp/ignite/client/detail/compute/compute_impl.h index 8f142bb835..a43167fa3c 100644 --- a/modules/platforms/cpp/ignite/client/compute/compute.h +++ b/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.h @@ -26,21 +26,17 @@ #include <memory> #include <utility> -namespace ignite { - -namespace detail { -class compute_impl; -} +namespace ignite::detail { /** - * Ignite Compute facade. + * Ignite Compute implementation. */ -class compute { +class compute_impl { friend class ignite_client; public: // Delete - compute() = delete; + compute_impl() = delete; /** * Executes single SQL statement asynchronously and returns rows. @@ -50,34 +46,20 @@ public: * @param args Arguments for the statement. * @param callback A callback called on operation completion with SQL result set. */ - IGNITE_API void execute_async(std::vector<cluster_node> nodes, std::string_view job_class_name, std::vector<primitive> args, + void execute_on_one_node(cluster_node nodes, std::string_view job_class_name, std::vector<primitive> args, ignite_callback<std::optional<primitive>> callback); - /** - * Executes single SQL statement and returns rows. - * - * @param tx Optional transaction. If nullptr implicit transaction for this single operation is used. - * @param statement Statement to execute. - * @param args Arguments for the statement. - * @return SQL result set. - */ - IGNITE_API std::optional<primitive> execute(std::vector<cluster_node> nodes, std::string_view job_class_name, std::vector<primitive> args) { - return sync<std::optional<primitive>>([this, nodes = std::move(nodes), job_class_name, args = std::move(args)](auto callback) mutable { - execute_async(std::move(nodes), job_class_name, std::move(args), std::move(callback)); - }); - } - private: - /** - * Constructor - * - * @param impl Implementation - */ - explicit compute(std::shared_ptr<detail::compute_impl> impl) - : m_impl(std::move(impl)) {} - - /** Implementation. */ - std::shared_ptr<detail::compute_impl> m_impl; +// /** +// * Constructor +// * +// * @param impl Implementation +// */ +// explicit compute(std::shared_ptr<detail::compute_impl> impl) +// : m_impl(std::move(impl)) {} +// +// /** Implementation. */ +// std::shared_ptr<detail::compute_impl> m_impl; }; -} // namespace ignite +} // namespace ignite::detail
