[erlang-questions] Lightweight proper code update
Per Melin
per.melin@REDACTED
Sat Feb 4 13:05:46 CET 2012
OTP release management, if you need most of the benefits it offers, can undoubtedly be very useful.
But I believe that most of us don't need most of those benefits most of the time, and that all the careful administration it requires can be a hindrance and even a source of errors. Especially if you are running your code in-house and do frequent incremental releases.
Unfortunately the next best thing is to restart the node or simply reload the changed modules and hope for the best. I think there is room for something better than that.
I've toyed with different solutions and the best I've come up with is an application that does this:
1. Compare the loaded code with the beam files on disk to find modules that have been changed.
2. Use xref to figure out any dependencies between the changed modules (who calls whom).
3. Inspect the modules to separate supervisors, special processes like gen_server, and the rest.
4. Generate a script with appup instructions, based on the previous steps.
5. Use systools to compile this script to a lower level relup script.
6. Ask release handler to execute the low level script.
You can find the code here. It is only about 200 lines.
https://github.com/permelin/updo
With this you don't get named releases or a bundled ERTS, but you do get the same code upgrade process as with a proper release; suspension of special processes, optional update of their states, updated child specs for supervisors, modules are reloaded in a logical order, etc. And it does not require you to keep app and appup files perfectly maintained or jump through any of the hoops otherwise associated with releases.
There are however also some potential problems. At the top of my head:
- To accomplish steps 5 and 6 I am calling functions in systools and release handler that are exported, but were most likely never intended to be used outside those applications.
- xref will not always be able to find all cross-module calls, or do something about circular dependencies. Though I'm not sure it will do a worse job than a human manually writing appup instructions.
Any other problems I've missed? Ideas? Questions? Wouldn't something like this be nice to have in OTP?
More information about the erlang-questions
mailing list