lang: Move wasm::manager to its .cc/.hh files
It's going to become a facade in front of both -- wasm and lua, so keep it in files with language independent names. Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
add_library(lang STATIC)
|
||||
target_sources(lang
|
||||
PRIVATE
|
||||
manager.cc
|
||||
lua.cc
|
||||
wasm.cc
|
||||
wasm_alien_thread_runner.cc
|
||||
|
||||
26
lang/manager.cc
Normal file
26
lang/manager.cc
Normal file
@@ -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<wasm::startup_context>& ctx)
|
||||
: _engine(ctx ? ctx->engine : nullptr)
|
||||
, _instance_cache(ctx ? std::make_optional<wasm::instance_cache>(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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
34
lang/manager.hh
Normal file
34
lang/manager.hh
Normal file
@@ -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<rust::Box<wasmtime::Engine>> _engine;
|
||||
std::optional<wasm::instance_cache> _instance_cache;
|
||||
std::shared_ptr<wasm::alien_thread_runner> _alien_runner;
|
||||
|
||||
public:
|
||||
manager(const std::optional<wasm::startup_context>&);
|
||||
friend context;
|
||||
future<> stop();
|
||||
seastar::future<> precompile(context& ctx, const std::vector<sstring>& arg_names, std::string script);
|
||||
void remove(const db::functions::function_name& name, const std::vector<data_type>& arg_types) noexcept {
|
||||
_instance_cache->remove(name, arg_types);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
13
lang/wasm.cc
13
lang/wasm.cc
@@ -19,6 +19,7 @@
|
||||
#include <seastar/coroutine/exception.hh>
|
||||
#include <seastar/coroutine/maybe_yield.hh>
|
||||
#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<wasm::startup_context>& ctx)
|
||||
: _engine(ctx ? ctx->engine : nullptr)
|
||||
, _instance_cache(ctx ? std::make_optional<wasm::instance_cache>(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)
|
||||
|
||||
15
lang/wasm.hh
15
lang/wasm.hh
@@ -45,21 +45,6 @@ struct startup_context {
|
||||
startup_context(db::config& cfg, replica::database_config& dbcfg);
|
||||
};
|
||||
|
||||
class manager {
|
||||
std::shared_ptr<rust::Box<wasmtime::Engine>> _engine;
|
||||
std::optional<wasm::instance_cache> _instance_cache;
|
||||
std::shared_ptr<wasm::alien_thread_runner> _alien_runner;
|
||||
|
||||
public:
|
||||
manager(const std::optional<wasm::startup_context>&);
|
||||
friend context;
|
||||
future<> stop();
|
||||
seastar::future<> precompile(context& ctx, const std::vector<sstring>& arg_names, std::string script);
|
||||
void remove(const db::functions::function_name& name, const std::vector<data_type>& arg_types) noexcept {
|
||||
_instance_cache->remove(name, arg_types);
|
||||
}
|
||||
};
|
||||
|
||||
struct context {
|
||||
wasmtime::Engine& engine_ptr;
|
||||
std::optional<rust::Box<wasmtime::Module>> module;
|
||||
|
||||
1
main.cc
1
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"
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
#include "service/raft/raft_group0.hh"
|
||||
#include "sstables/sstables_manager.hh"
|
||||
#include "init.hh"
|
||||
#include "lang/manager.hh"
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
Reference in New Issue
Block a user