Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As I already mentioned the normal way of upgrading is creating the proper .appup and .relup files, and let release_handler do what needs to be done. However you can manually execute the steps involved, as described here. Sorry for the long answer.</p> <p>The following dummy gen_server implements a counter. The old version ("0") simply stores an integer as state, while the new version ("1") stores {tschak, Int} as state. As I said, this is a dummy example.</p> <p>z.erl (old):</p> <pre><code>-module(z). -version("0"). -export([start_link/0, boing/0]). -behavior(gen_server). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). start_link() -&gt; gen_server:start_link({local, ?MODULE}, ?MODULE, [], [{debug, [trace]}]). boing() -&gt; gen_server:call(?MODULE, boom). init([]) -&gt; {ok, 0}. handle_call(boom, _From, Num) -&gt; {reply, Num, Num+1}; handle_call(_Call, _From, State) -&gt; {noreply, State}. handle_cast(_Cast, State) -&gt; {noreply, State}. handle_info(_Info, State) -&gt; {noreply, State}. terminate(_Reason, _State) -&gt; ok. code_change(_OldVsn, State, _Extra) -&gt; {ok, State}. </code></pre> <p>z.erl (new):</p> <pre><code>-module(z). -version("1"). -export([start_link/0, boing/0]). -behavior(gen_server). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). start_link() -&gt; gen_server:start_link({local, ?MODULE}, ?MODULE, [], [{debug, [trace]}]). boing() -&gt; gen_server:call(?MODULE, boom). init([]) -&gt; {ok, {tschak, 0}}. handle_call(boom, _From, {tschak, Num}) -&gt; {reply, Num, {tschak, Num+1}}; handle_call(_Call, _From, State) -&gt; {noreply, State}. handle_cast(_Cast, State) -&gt; {noreply, State}. handle_info(_Info, State) -&gt; {noreply, State}. terminate(_Reason, _State) -&gt; ok. code_change("0", Num, _Extra) -&gt; {ok, {tschak, Num}}. </code></pre> <p>Start the shell, and compile the old code. Notice the gen_server is started with debug trace.</p> <pre><code>1&gt; c(z). {ok,z} 2&gt; z:start_link(). {ok,&lt;0.38.0&gt;} 3&gt; z:boing(). *DBG* z got call boom from &lt;0.31.0&gt; *DBG* z sent 0 to &lt;0.31.0&gt;, new state 1 0 4&gt; z:boing(). *DBG* z got call boom from &lt;0.31.0&gt; *DBG* z sent 1 to &lt;0.31.0&gt;, new state 2 1 </code></pre> <p>Works as expected: returns the Int, and new state is Int+1.</p> <p>Now replace z.erl with the new one, and execute the following steps.</p> <pre><code>5&gt; compile:file(z). {ok,z} 6&gt; sys:suspend(z). ok 7&gt; code:purge(z). false 8&gt; code:load_file(z). {module,z} 9&gt; sys:change_code(z,z,"0",[]). ok 10&gt; sys:resume(z). ok </code></pre> <p>What you just did: 5: compiled the new code. 6: suspended the server. 7: purged older code (just in case). 8: loaded the new code. 9: invoked code change in process 'z' for module 'z' from version "0" with [] passed as "Extra" to code_change. 10: resumed the server.</p> <p>Now if you run some more tests, you can see, that the server works with the new state format:</p> <pre><code>11&gt; z:boing(). *DBG* z got call boom from &lt;0.31.0&gt; *DBG* z sent 2 to &lt;0.31.0&gt;, new state {tschak,3} 2 12&gt; z:boing(). *DBG* z got call boom from &lt;0.31.0&gt; *DBG* z sent 3 to &lt;0.31.0&gt;, new state {tschak,4} 3 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload