diff --git a/configure.py b/configure.py index 8892b794aa..c612a8bd87 100755 --- a/configure.py +++ b/configure.py @@ -1180,6 +1180,7 @@ scylla_core = (['message/messaging_service.cc', 'mutation_writer/partition_based_splitting_writer.cc', 'mutation_writer/token_group_based_splitting_writer.cc', 'mutation_writer/feed_writers.cc', + 'lang/manager.cc', 'lang/lua.cc', 'lang/wasm.cc', 'lang/wasm_alien_thread_runner.cc', diff --git a/cql3/statements/create_function_statement.cc b/cql3/statements/create_function_statement.cc index 14326eb6c7..3614df4046 100644 --- a/cql3/statements/create_function_statement.cc +++ b/cql3/statements/create_function_statement.cc @@ -16,6 +16,7 @@ #include "lang/lua.hh" #include "data_dictionary/data_dictionary.hh" #include "replica/database.hh" // for wasm +#include "lang/manager.hh" #include "cql3/query_processor.hh" #include "db/config.hh" diff --git a/db/schema_tables.cc b/db/schema_tables.cc index 746355c0c9..266ed845fa 100644 --- a/db/schema_tables.cc +++ b/db/schema_tables.cc @@ -69,6 +69,7 @@ #include "index/target_parser.hh" #include "lang/lua.hh" +#include "lang/manager.hh" #include "idl/mutation.dist.hh" #include "idl/mutation.dist.impl.hh" diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt index 060796150c..2cd8092971 100644 --- a/lang/CMakeLists.txt +++ b/lang/CMakeLists.txt @@ -1,6 +1,7 @@ add_library(lang STATIC) target_sources(lang PRIVATE + manager.cc lua.cc wasm.cc wasm_alien_thread_runner.cc diff --git a/lang/manager.cc b/lang/manager.cc new file mode 100644 index 0000000000..ad06a09f54 --- /dev/null +++ b/lang/manager.cc @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2024-present ScyllaDB + */ + +/* + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include "lang/wasm.hh" +#include "lang/manager.hh" + +namespace wasm { + +manager::manager(const std::optional& ctx) + : _engine(ctx ? ctx->engine : nullptr) + , _instance_cache(ctx ? std::make_optional(ctx->cache_size, ctx->instance_size, ctx->timer_period) : std::nullopt) + , _alien_runner(ctx ? ctx->alien_runner : nullptr) +{} + +future<> manager::stop() { + if (_instance_cache) { + co_await _instance_cache->stop(); + } +} + +} diff --git a/lang/manager.hh b/lang/manager.hh new file mode 100644 index 0000000000..ca89f0be55 --- /dev/null +++ b/lang/manager.hh @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024-present ScyllaDB + */ + +/* + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#pragma once + +#include "rust/wasmtime_bindings.hh" +#include "lang/wasm_instance_cache.hh" +#include "lang/wasm_alien_thread_runner.hh" + +namespace wasm { + +struct startup_context; + +class manager { + std::shared_ptr> _engine; + std::optional _instance_cache; + std::shared_ptr _alien_runner; + +public: + manager(const std::optional&); + friend context; + future<> stop(); + seastar::future<> precompile(context& ctx, const std::vector& arg_names, std::string script); + void remove(const db::functions::function_name& name, const std::vector& arg_types) noexcept { + _instance_cache->remove(name, arg_types); + } +}; + +} diff --git a/lang/wasm.cc b/lang/wasm.cc index 60a0d0e70c..21ec31aefa 100644 --- a/lang/wasm.cc +++ b/lang/wasm.cc @@ -19,6 +19,7 @@ #include #include #include "lang/wasm_alien_thread_runner.hh" +#include "lang/manager.hh" logging::logger wasm_logger("wasm"); @@ -32,18 +33,6 @@ startup_context::startup_context(db::config& cfg, replica::database_config& dbcf , timer_period(std::chrono::milliseconds(cfg.wasm_cache_timeout_in_ms())) { } -manager::manager(const std::optional& ctx) - : _engine(ctx ? ctx->engine : nullptr) - , _instance_cache(ctx ? std::make_optional(ctx->cache_size, ctx->instance_size, ctx->timer_period) : std::nullopt) - , _alien_runner(ctx ? ctx->alien_runner : nullptr) -{} - -future<> manager::stop() { - if (_instance_cache) { - co_await _instance_cache->stop(); - } -} - context::context(wasmtime::Engine& engine_ptr, std::string name, instance_cache& cache, uint64_t yield_fuel, uint64_t total_fuel) : engine_ptr(engine_ptr) , function_name(name) diff --git a/lang/wasm.hh b/lang/wasm.hh index ed5d14e29d..9a014e3d27 100644 --- a/lang/wasm.hh +++ b/lang/wasm.hh @@ -45,21 +45,6 @@ struct startup_context { startup_context(db::config& cfg, replica::database_config& dbcfg); }; -class manager { - std::shared_ptr> _engine; - std::optional _instance_cache; - std::shared_ptr _alien_runner; - -public: - manager(const std::optional&); - friend context; - future<> stop(); - seastar::future<> precompile(context& ctx, const std::vector& arg_names, std::string script); - void remove(const db::functions::function_name& name, const std::vector& arg_types) noexcept { - _instance_cache->remove(name, arg_types); - } -}; - struct context { wasmtime::Engine& engine_ptr; std::optional> module; diff --git a/main.cc b/main.cc index a330956e81..fa978e4f3b 100644 --- a/main.cc +++ b/main.cc @@ -104,6 +104,7 @@ #include "db/per_partition_rate_limit_extension.hh" #include "lang/wasm_instance_cache.hh" #include "lang/wasm_alien_thread_runner.hh" +#include "lang/manager.hh" #include "sstables/sstables_manager.hh" #include "db/virtual_tables.hh" diff --git a/test/lib/cql_test_env.cc b/test/lib/cql_test_env.cc index cc974f090c..2d5c692f46 100644 --- a/test/lib/cql_test_env.cc +++ b/test/lib/cql_test_env.cc @@ -67,6 +67,7 @@ #include "service/raft/raft_group0.hh" #include "sstables/sstables_manager.hh" #include "init.hh" +#include "lang/manager.hh" #include #include