wasm: Add manager::precompile()

This is not to make query_processor export alien runner from the
wasm::manager

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
This commit is contained in:
Pavel Emelyanov
2023-08-02 21:19:02 +03:00
parent d58a2d65b5
commit 93cb73fddb
5 changed files with 8 additions and 5 deletions

View File

@@ -174,9 +174,7 @@ public:
return *_wasm._instance_cache;
}
wasm::alien_thread_runner& alien_runner() {
return *_wasm._alien_runner;
}
wasm::manager& wasm() { return _wasm; }
statements::prepared_statement::checked_weak_ptr get_prepared(const std::optional<auth::authenticated_user>& user, const prepared_cache_key_type& key) {
if (user) {

View File

@@ -51,7 +51,7 @@ seastar::future<shared_ptr<functions::function>> create_function_statement::crea
// FIXME: need better way to test wasm compilation without real_database()
wasm::context ctx{qp.wasm_engine(), _name.name, qp.wasm_instance_cache(), db.get_config().wasm_udf_yield_fuel(), db.get_config().wasm_udf_total_fuel()};
try {
co_await wasm::precompile(qp.alien_runner(), ctx, arg_names, _body);
co_await qp.wasm().precompile(ctx, arg_names, _body);
co_return ::make_shared<functions::user_function>(_name, _arg_types, std::move(arg_names), _body, _language,
std::move(return_type), _called_on_null_input, std::move(ctx));
} catch (const wasm::exception& we) {

View File

@@ -1913,7 +1913,7 @@ static seastar::future<shared_ptr<cql3::functions::user_function>> create_func(r
row.get_nonnull<bool>("called_on_null_input"), std::move(ctx));
} else if (language == "wasm") {
wasm::context ctx{qctx->qp().wasm_engine(), name.name, qctx->qp().wasm_instance_cache(), db.get_config().wasm_udf_yield_fuel(), db.get_config().wasm_udf_total_fuel()};
co_await wasm::precompile(qctx->qp().alien_runner(), ctx, arg_names, body);
co_await qctx->qp().wasm().precompile(ctx, arg_names, body);
co_return ::make_shared<cql3::functions::user_function>(std::move(name), std::move(arg_types), std::move(arg_names),
std::move(body), language, std::move(return_type),
row.get_nonnull<bool>("called_on_null_input"), std::move(ctx));

View File

@@ -239,6 +239,10 @@ struct from_val_visitor {
}
};
seastar::future<> manager::precompile(context& ctx, const std::vector<sstring>& arg_names, std::string script) {
return ::wasm::precompile(*_alien_runner, ctx, arg_names, std::move(script));
}
seastar::future<> precompile(alien_thread_runner& alien_runner, context& ctx, const std::vector<sstring>& arg_names, std::string script) {
seastar::promise<rust::Box<wasmtime::Module>> done;
alien_runner.submit(done, [&engine_ptr = ctx.engine_ptr, script = std::move(script)] {

View File

@@ -58,6 +58,7 @@ public:
manager(const std::optional<wasm::startup_context>&);
friend class cql3::query_processor;
future<> stop();
seastar::future<> precompile(context& ctx, const std::vector<sstring>& arg_names, std::string script);
};
struct context {