Search code examples
ctarantool

reload module without restart server


good day! i have small question about reload c module in tarantool for example: i have c module which expose a method:

int calculate(lua_State* L);

in addition i declared entry point:

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

now, i load this module ("testmodule.so") in tarantool:

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

and now i call this method from my c# client:

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

and it is work as expected - method calculate executed and results was returned

but if i want ещ update my module than the problems begin: after i replace so file and call calculate method my tarantool restart and i can see something like "tarntool invalid opcode in testmodule.so" in dmesg

after reading documentation i see additional parameters in function definition like this:

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

but after this if i call it from c# i receive exception with message "failed to dynamically load function undefined symbol calculate"

i use tarantool 1.7 on ubuntu my so compiled with gcc 8.1.0


Solution

  • There is no a good way to do this (means - a portable way). I think, the best way is using something like dlopen()[1], the function allows to open (manage shared objects in general) a shared object, but you have to be very cautious about this, it may fail your code as well or even you can have sigfault.

    A good example is: https://github.com/tarantool/mqtt, the module does not use these functions (func.create and so on), but it could be extended as well.

    So the point is: if you develop a C-module, you have to think about reloading policy. For instance, *-unix like systems have alot of features which allows to reload some shared objects and also tarantool has some features too.

    And also, I suggest to you, start think about modules as like about Lua's C-modules, it is actually the same.

    PS

    Some reload modules also available: https://github.com/Mons/tnt-package-reload (I didn't test the module), https://github.com/tarantool/reload (I didn't test the module)

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