diff options
author | Yuval Lifshitz <ylifshit@redhat.com> | 2022-05-02 19:58:29 +0200 |
---|---|---|
committer | Yuval Lifshitz <ylifshit@redhat.com> | 2022-05-08 13:11:04 +0200 |
commit | 51c19337d844b784b098074b24b3d709622f34a2 (patch) | |
tree | ed4d8ac79a1ef649333ebb60164bd74f227fcb7a /src/rgw/rgw_lua_background.cc | |
parent | rgw: Lua scripting global map feature (diff) | |
download | ceph-51c19337d844b784b098074b24b3d709622f34a2.tar.xz ceph-51c19337d844b784b098074b24b3d709622f34a2.zip |
rgw: add unit tests to background lua context
Signed-off-by: Yuval Lifshitz <ylifshit@redhat.com>
Diffstat (limited to 'src/rgw/rgw_lua_background.cc')
-rw-r--r-- | src/rgw/rgw_lua_background.cc | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/rgw/rgw_lua_background.cc b/src/rgw/rgw_lua_background.cc index 2c85cabb23e..56000edff23 100644 --- a/src/rgw/rgw_lua_background.cc +++ b/src/rgw/rgw_lua_background.cc @@ -8,12 +8,31 @@ namespace rgw::lua { void Background::shutdown(){ this->stop(); - runner.join(); + if (runner.joinable()) { + runner.join(); + } } void Background::stop(){ stopped = true; } +void Background::start() { + if (started) { + // start the thread only once + return; + } + started = true; + runner = std::thread(&Background::run, this); + const auto rc = ceph_pthread_setname(runner.native_handle(), + "lua_background"); + ceph_assert(rc == 0); +} + +int Background::read_script() { + std::string tenant; + return rgw::lua::read_script(dpp, store, tenant, null_yield, rgw::lua::context::background, rgw_script); +} + //(1) Loads the script from the object //(2) Executes the script //(3) Sleep (configurable) @@ -22,13 +41,11 @@ void Background::run() { rgw::lua::lua_state_guard lguard(L); open_standard_libs(L); set_package_path(L, luarocks_path); - create_debug_action(L, cct->get()); + create_debug_action(L, cct); create_background_metatable(L); while (!stopped) { - - std::string tenant; - auto rc = rgw::lua::read_script(dpp, store, tenant, null_yield, rgw::lua::context::background, rgw_script); + const auto rc = read_script(); if (rc == -ENOENT) { // no script, nothing to do } else if (rc < 0) { |