Can we make built-in modules reloadable? #6071
Replies: 2 comments
-
I believe there is no any reasonable explanation why we could not implement reload for Tarantool builtin modules. Certainly, [Why not simply keep the list of unloaded builtin modules, where to look into first the next moment it will be |
Beta Was this translation helpful? Give feedback.
-
The case which I met two days ago is that sometimes I want monkey patch built-in module at runtime.
|
Beta Was this translation helpful? Give feedback.
-
The idea
If we unload a built-in module, we unable to require it again:
There is no reason why we can't load it second time. The Lua code is built into tarantool's executable and we can add a loader that reads it1.
Why one may need it? There is a typical application upgrade scenario: unload all modules, load it again and reinitialize the application (some applications also kill fibers, cleanup global variables and perform specific actions like http server routes removal). Such code should leave built-in modules loaded: either hardcode a list of them or collect the list early during startup. Moreover, there are modules that reloads modules:
The idea is to make built-in modules reloadable and simplify application reloading. Hopefully even eliminate the need in the modules that reloads modules.
There are two things that disquiets me:
os
), the next require will fail. But there is no practical reason to make tarantool's built-in modules reloadable and leave luajit's ones non-reloadable. Technically the change, which allows to reload luajit's built-in modules, is not backward compatible.So, maybe, it would be better to agree on some common reload API for modules (say,
package.loaded.foo.reload()
) and deprecatepackage.loaded.foo = nil require('foo')
way as inaccurate one? At least old captures will be available in the reload function without hacks with burying them inside _G.(NB: Think, how to better handle modules with several submodules:
foo
,foo.bar
,foo.baz
.)References
Those thoughts appear in my head during writting the relevant issue https://github.com/tarantool/conf/issues/2.
Footnotes
Footnotes
In theory we can use
package.preload
, but it is accessible for a user that may lead to some collision. Aside of this, the preload loader is the first one: a user may remove a built-in module frompackage.loaded
to load an external replacement module with the same name. ↩Beta Was this translation helpful? Give feedback.
All reactions