Skip to content

Commit 7b774c4

Browse files
authored
Merge pull request ceph#52326 from yuvalif/wip-yuval-lua-reload
rgw/lua: support reloading lua packages on all RGWs reviwed-by: dang, cbodle, anthonyeleven
2 parents 7d85410 + 7a11f1d commit 7b774c4

27 files changed

+541
-230
lines changed

doc/radosgw/lua-scripting.rst

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ To change this default value, use the ``rgw_lua_max_memory_per_state`` configura
2323

2424
By default, all Lua standard libraries are available in the script, however, in order to allow for other Lua modules to be used in the script, we support adding packages to an allowlist:
2525

26-
- All packages in the allowlist are being re-installed using the luarocks package manager on radosgw restart. Therefore a restart is needed for adding or removing of packages to take effect
26+
- Adding a Lua package to the allowlist, or removing a packge from it does not install or remove it. For the changes to take affect a "reload" command should be called.
27+
- In addition all packages in the allowlist are being re-installed using the luarocks package manager on radosgw restart.
2728
- To add a package that contains C source code that needs to be compiled, use the ``--allow-compilation`` flag. In this case a C compiler needs to be available on the host
2829
- Lua packages are installed in, and used from, a directory local to the radosgw. Meaning that Lua packages in the allowlist are separated from any Lua packages available on the host.
2930
By default, this directory would be ``/tmp/luarocks/<entity name>``. Its prefix part (``/tmp/luarocks/``) could be set to a different location via the ``rgw_luarocks_location`` configuration parameter.
@@ -116,6 +117,13 @@ To print the list of packages in the allowlist:
116117
# radosgw-admin script-package list
117118

118119

120+
To apply changes from the allowlist to all RGWs:
121+
122+
::
123+
124+
# radosgw-admin script-package reload
125+
126+
119127
Context Free Functions
120128
----------------------
121129
Debug Log
@@ -460,16 +468,23 @@ First we should add the following packages to the allowlist:
460468

461469
::
462470

463-
# radosgw-admin script-package add --package=luajson
471+
# radosgw-admin script-package add --package=lua-cjson --allow-compilation
464472
# radosgw-admin script-package add --package=luasocket --allow-compilation
465473

466474

467-
Then, do a restart for the radosgw and upload the following script to the ``postrequest`` context:
475+
Then, run a server to listen on the Unix socket. For example, use "netcat":
476+
477+
::
478+
479+
# rm -f /tmp/socket
480+
# nc -vklU /tmp/socket
481+
482+
And last, do a restart for the radosgw and upload the following script to the ``postrequest`` context:
468483

469484
.. code-block:: lua
470485
471486
if Request.RGWOp == "get_obj" then
472-
local json = require("json")
487+
local json = require("cjson")
473488
local socket = require("socket")
474489
local unix = require("socket.unix")
475490
local s = assert(unix())

src/common/options/rgw.yaml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3755,7 +3755,7 @@ options:
37553755
type: str
37563756
level: advanced
37573757
desc: Directory where luarocks install packages from allowlist
3758-
default: @rgw_luarocks_location@
3758+
default: /tmp/rgw_luarocks/$name
37593759
services:
37603760
- rgw
37613761
flags:

src/rgw/driver/daos/rgw_sal_daos.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,8 @@ const std::string& DaosZone::get_current_period_id() {
880880
return current_period->get_id();
881881
}
882882

883-
std::unique_ptr<LuaManager> DaosStore::get_lua_manager() {
884-
return std::make_unique<DaosLuaManager>(this);
883+
std::unique_ptr<LuaManager> DaosStore::get_lua_manager(const DoutPrefixProvider *dpp, const std::string& luarocks_path) {
884+
return std::make_unique<DaosLuaManager>(this, dpp, luarocks_path);
885885
}
886886

887887
int DaosObject::get_obj_state(const DoutPrefixProvider* dpp,

src/rgw/driver/daos/rgw_sal_daos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ class DaosStore : public StoreDriver {
997997
}
998998
virtual std::string get_host_id() { return ""; }
999999

1000-
virtual std::unique_ptr<LuaManager> get_lua_manager() override;
1000+
std::unique_ptr<LuaManager> get_lua_manager(const DoutPrefixProvider *dpp = nullptr, const std::string& luarocks_path = "") override;
10011001
virtual std::unique_ptr<RGWRole> get_role(
10021002
std::string name, std::string tenant, std::string path = "",
10031003
std::string trust_policy = "", std::string max_session_duration_str = "",

src/rgw/driver/motr/rgw_sal_motr.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,9 @@ const std::string& MotrZone::get_current_period_id()
11511151
return current_period->get_id();
11521152
}
11531153

1154-
std::unique_ptr<LuaManager> MotrStore::get_lua_manager()
1154+
std::unique_ptr<LuaManager> MotrStore::get_lua_manager(const DoutPrefixProvider *dpp, const std::string& luarocks_path)
11551155
{
1156-
return std::make_unique<MotrLuaManager>(this);
1156+
return std::make_unique<MotrLuaManager>(this, dpp, luarocks_path);
11571157
}
11581158

11591159
int MotrObject::get_obj_state(const DoutPrefixProvider* dpp, RGWObjState **_state, optional_yield y, bool follow_olh)
@@ -3901,6 +3901,11 @@ int MotrStore::init_metadata_cache(const DoutPrefixProvider *dpp,
39013901
{
39023902
return -ENOENT;
39033903
}
3904+
3905+
int MotrLuaManager::reload_packages(const DoutPrefixProvider* dpp, optional_yield y)
3906+
{
3907+
return -ENOENT;
3908+
}
39043909
} // namespace rgw::sal
39053910

39063911
extern "C" {

src/rgw/driver/motr/rgw_sal_motr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ class MotrLuaManager : public StoreLuaManager {
559559
virtual int remove_package(const DoutPrefixProvider* dpp, optional_yield y, const std::string& package_name) override;
560560
/** List lua packages */
561561
virtual int list_packages(const DoutPrefixProvider* dpp, optional_yield y, rgw::lua::packages_t& packages) override;
562+
/** Reload lua packages */
563+
virtual int reload_packages(const DoutPrefixProvider* dpp, optional_yield y) override;
562564
};
563565

564566
class MotrOIDCProvider : public RGWOIDCProvider {
@@ -1047,7 +1049,7 @@ class MotrStore : public StoreDriver {
10471049
virtual const RGWSyncModuleInstanceRef& get_sync_module() { return sync_module; }
10481050
virtual std::string get_host_id() { return ""; }
10491051

1050-
virtual std::unique_ptr<LuaManager> get_lua_manager() override;
1052+
std::unique_ptr<LuaManager> get_lua_manager(const DoutPrefixProvider *dpp = nullptr, const std::string& luarocks_path = "") override;
10511053
virtual std::unique_ptr<RGWRole> get_role(std::string name,
10521054
std::string tenant,
10531055
std::string path="",

0 commit comments

Comments
 (0)