无需重启服务器即可重新加载模块

时间:2018-06-26 08:37:45

标签: c tarantool

美好的一天! 我对在tarantool中重新加载c模块有一个小问题 例如:我有一个公开方法的c模块:

extern "C"
{    
    LUA_API int luaopen_cuendemodule(lua_State *L);
}

此外,我声明了入口点:

require('testmodule')
box.schema.func.create('testmodule.calculate')
box.schema.user.grant('user', 'execute', 'function', 'testmodule.calculate')

现在,我将这个模块(“ testmodule.so”)加载到tarantool中:

await tarantoolClient.Call<TarantoolTuple<CalculateParameters>, CalculationResults>("testmodule.calculate", TarantoolTuple.Create(....));

现在我从c#客户端调用此方法:

box.schema.func.create('testmodule.calculate', {language = 'C'})

它按预期工作-执行方法计算并返回结果

但是,如果我要更新模块而不是问题开始:在替换了so文件并调用计算方法后,我的tarantool重新启动,并且在dmesg中可以看到类似“ testmodule.so中的Tarntool无效操作码”的内容

阅读文档后,我在函数定义中看到了如下附加参数:

<tal:root define="lt string:&lt;;gt string:&gt;;
                  member python:options['member'];
                  portal_state context/@@plone_portal_state;
                  view context/@@passwordreset_view;
                  isAnon context/@@plone_portal_state/anonymous;
                  reset python:options['reset']"
>From: <span tal:replace="structure view/encoded_mail_sender" />
To: <span tal:replace="python:member.getProperty('email')" />
Subject: Request to reset your password
Content-Type: text/plain
Precedence: bulk

Hello

Some text

More text

Kind regards
Organization Name
</tal:root>

但是在此之后,如果我从c#调用它,则会收到消息“无法动态加载函数未定义的符号计算失败”的异常

我在ubuntu上使用tarantool 1.7 我这样用gcc 8.1.0编译了

2 个答案:

答案 0 :(得分:2)

没有一个好的方法可以做到这一点(意味着-一种可移植的方法)。我认为,最好的方法是使用诸如dlopen()[1]之类的函数,该函数允许打开(一般管理共享对象)共享对象,但是您必须对此非常谨慎,它也可能使代码失败甚至您也可以进行sigfault。

一个很好的例子是:https://github.com/tarantool/mqtt,该模块不使用这些功能(func.create等),但也可以对其进行扩展。

因此,重点是:如果开发C模块,则必须考虑重新加载策略。 例如,类似* -unix的系统具有很多功能,可以重新加载某些共享库,而tarantool也具有一些功能。

而且,我建议您开始考虑像Lua的C模块一样的模块,实际上是一样的。

PS

还提供了一些重新加载模块:https://github.com/Mons/tnt-package-reload(我没有测试模块),https://github.com/tarantool/reload(我没有测试模块)

[1] http://man7.org/linux/man-pages/man3/dlopen.3.html

答案 1 :(得分:0)

我认为,您可以尝试使用此模块重新加载应用程序-https://github.com/moonlibs/package-reload

相关问题