gen_server code_change

Ulf Wiger <>
Tue Apr 10 13:25:54 CEST 2001


On Tue, 10 Apr 2001, Tony Pedley wrote:

>I had always assumed up to now that the gen_server callback function
>code_change was called automatically when a new gen_server module
>was loaded into the Erlang shell(i.e l(Module)) This was partly due
>to my reading of the Erlang Reference Manual

You need to read the SASL User's Guide:
http://www.erlang.org/doc/r7b/lib/sasl-1.9/doc/html/part_frame.html

(but that's pretty hard reading, so read this whole message first.)


Specifically, there's an example on upgrading a gen_server at

http://www.erlang.org/doc/r7b/lib/sasl-1.9/doc/html/release_handling.html#4.7


>However in pursuit of a ongoing bug, I have begun to doubt that
>notion, even to the point of writing a simple gen_server and trying
>it. I have so far been unable to generate a code_change event.

Try this:

sys:suspend(MyProc).
sys:change_code(MyProc, OldVsn, Module, Extra).
sys:resume(MyProc).


These functions are called by the release_handler during upgrade,
triggered by instructions in the release handling script,
like:

[{suspend, [Module]},
 {code_change, [{Module, []}]}
 {resume,  [Module]}]

In the script, one specifies the module names, and the 
release_handler finds out at runtime which processes are related
to the modules being upgraded. This relation is specified in the
supervisor child specification.

OldVsn corresponds to the -vsn attribute in the code, according to
the manual. I haven't checked if this is still true, but I know
that OTP has removed the -vsn attribute from all their source files.
The reason was that it made automatic merge between development
branches difficult.

At AXD301, we ignore the OldVsn argument and put interesting
information in Extra instead. In our system, Extra is {OldAppVsn,
NewAppVsn}, where these versions correspond to the 'vsn' attribute in
the .app files.


/Uffe
-- 
Ulf Wiger                                    tfn: +46  8 719 81 95
Senior System Architect                      mob: +46 70 519 81 95
Strategic Product & System Management    ATM Multiservice Networks
Data Backbone & Optical Services Division      Ericsson Telecom AB




More information about the erlang-questions mailing list