The compilation of wasm UDFs is performed by a call to a foreign function, which cannot be divided with yielding points and, as a result, causes long reactor stalls for big UDFs. We avoid them by submitting the compilation task to a non-seastar std::thread, and retrieving the result using seastar::alien. The thread is created at the start of the program. It executes tasks from a queue in an infinite loop. All seastar shards reference the thread through a std::shared_ptr to a `alien_thread_runner`. Considering that the compilation takes a long time anyway, the alien_thread_runner is implemented with focus on simplicity more than on performance. The tasks are stored in an std::queue, reading and writing to it is synchronized using an std::mutex for reading/ writing to the queue, and an std::condition_variable waiting until the queue has elements. When the destructor of the alien runner is called, an std::nullopt sentinel is pushed to the queue, and after all remaining tasks are finished and the sentinel is read, the thread finishes. Fixes #12904 Closes #13051 * github.com:scylladb/scylladb: wasm: move compilation to an alien thread wasm: convert compilation to a future
75 lines
2.7 KiB
C++
75 lines
2.7 KiB
C++
/*
|
|
* Copyright (C) 2019-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "cql3/statements/schema_altering_statement.hh"
|
|
#include "cql3/functions/function_name.hh"
|
|
#include "cql3/cql3_type.hh"
|
|
|
|
namespace db {
|
|
namespace functions {
|
|
class function;
|
|
}
|
|
}
|
|
|
|
namespace cql3 {
|
|
|
|
namespace statements {
|
|
|
|
class function_statement : public schema_altering_statement {
|
|
protected:
|
|
virtual future<> check_access(query_processor& qp, const service::client_state& state) const override;
|
|
virtual void prepare_keyspace(const service::client_state& state) override;
|
|
db::functions::function_name _name;
|
|
std::vector<shared_ptr<cql3_type::raw>> _raw_arg_types;
|
|
mutable std::vector<data_type> _arg_types;
|
|
static shared_ptr<cql_transport::event::schema_change> create_schema_change(
|
|
const db::functions::function& func, bool created);
|
|
function_statement(functions::function_name name, std::vector<shared_ptr<cql3_type::raw>> raw_arg_types);
|
|
void create_arg_types(query_processor& qp) const;
|
|
data_type prepare_type(query_processor& qp, cql3_type::raw &t) const;
|
|
virtual seastar::future<shared_ptr<db::functions::function>> validate_while_executing(query_processor&) const = 0;
|
|
};
|
|
|
|
// common logic for creating UDF and UDA
|
|
class create_function_statement_base : public function_statement {
|
|
protected:
|
|
virtual void validate(query_processor& qp, const service::client_state& state) const override;
|
|
virtual seastar::future<shared_ptr<db::functions::function>> create(query_processor& qp, db::functions::function* old) const = 0;
|
|
virtual seastar::future<shared_ptr<db::functions::function>> validate_while_executing(query_processor&) const override;
|
|
|
|
bool _or_replace;
|
|
bool _if_not_exists;
|
|
|
|
create_function_statement_base(functions::function_name name, std::vector<shared_ptr<cql3_type::raw>> raw_arg_types,
|
|
bool or_replace, bool if_not_exists);
|
|
|
|
public:
|
|
virtual future<> check_access(query_processor& qp, const service::client_state& state) const override;
|
|
};
|
|
|
|
// common logic for dropping UDF and UDA
|
|
class drop_function_statement_base : public function_statement {
|
|
protected:
|
|
virtual void validate(query_processor&, const service::client_state& state) const override;
|
|
virtual seastar::future<shared_ptr<db::functions::function>> validate_while_executing(query_processor&) const override;
|
|
|
|
bool _args_present;
|
|
bool _if_exists;
|
|
|
|
drop_function_statement_base(functions::function_name name, std::vector<shared_ptr<cql3_type::raw>> arg_types,
|
|
bool args_present, bool if_exists);
|
|
|
|
public:
|
|
virtual future<> check_access(query_processor& qp, const service::client_state& state) const override;
|
|
};
|
|
|
|
}
|
|
}
|