Reloading a module
You can reload any Tarantool application or module with zero downtime.
Here’s an example that illustrates the most typical case – “update and reload”.
Note
In this example, we use recommended administration practices based on instance files and tarantoolctl utility.
Update the application file.
For example, a module in
/usr/share/tarantool/app.lua
:local function start() -- initial version box.once("myapp:v1.0", function() box.schema.space.create("somedata") box.space.somedata:create_index("primary") ... end) -- migration code from 1.0 to 1.1 box.once("myapp:v1.1", function() box.space.somedata.index.primary:alter(...) ... end) -- migration code from 1.1 to 1.2 box.once("myapp:v1.2", function() box.space.somedata.index.primary:alter(...) box.space.somedata:insert(...) ... end) end -- start some background fibers if you need local function stop() -- stop all background fibers and clean up resources end local function api_for_call(xxx) -- do some business end return { start = start, stop = stop, api_for_call = api_for_call }
Update the instance file.
For example,
/etc/tarantool/instances.enabled/my_app.lua
:#!/usr/bin/env tarantool -- -- hot code reload example -- box.cfg({listen = 3302}) -- ATTENTION: unload it all properly! local app = package.loaded['app'] if app ~= nil then -- stop the old application version app.stop() -- unload the application package.loaded['app'] = nil -- unload all dependencies package.loaded['somedep'] = nil end -- load the application log.info('require app') app = require('app') -- start the application app.start({some app options controlled by sysadmins})
The important thing here is to properly unload the application and its dependencies.
Manually reload the application file.
For example, using
tarantoolctl
:$ tarantoolctl eval my_app /etc/tarantool/instances.enabled/my_app.lua
After you compiled a new version of a C module (*.so
shared library), call
box.schema.func.reload(‘module-name’)
from your Lua script to reload the module.