gen_server code_change

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

gen_server code_change

Tony Pedley-2
Hi,
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

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.

So the question is, in a gen_server does the code_change function have
to be called explicitly by some
release script or is it triggered by the actual process of loading a new
module?

If it is the latter is there any case when the function is not called?
(version numbers, identical code size etc)

Thanks

Tony



Reply | Threaded
Open this post in threaded view
|

gen_server code_change

Peter H|gfeldt

Of the high-level code replacement instructions, only *update* can
cause the code_change function to be called. It does that if and only
if the Change element of the instruction is equal to {advanced, Extra}.

/Peter  
-------------------------------------------------------------------------

Peter H?gfeldt e-mail  : peter
Open Telecom Platform Phone:  : +46 (8) 727 57 58
Ericsson Utvecklings AB Mobile : +46  070-519 57 51
S-126 25 STOCKHOLM Fax: : +46 (8) 727 5775
Office address: Armborstv?gen 1, ?lvsj?

On Tue, 10 Apr 2001, Tony Pedley wrote:

> Hi,
> 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
>
> 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.
>
> So the question is, in a gen_server does the code_change function have
> to be called explicitly by some
> release script or is it triggered by the actual process of loading a new
> module?
>
> If it is the latter is there any case when the function is not called?
> (version numbers, identical code size etc)
>
> Thanks
>
> Tony
>



Reply | Threaded
Open this post in threaded view
|

gen_server code_change

Ulf Wiger-4
In reply to this post by Tony Pedley-2
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



Reply | Threaded
Open this post in threaded view
|

gen_server code_change

Ulf Wiger-4
In reply to this post by Tony Pedley-2
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

Oh, to answer this specific question, the only thing that happens
when you call l(Module) in the shell is that the code is loaded.
To simulate an upgrade of Module, you'd have to do this:

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


/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