-record(my_data, {a, b, c}).<br><br>-record(sys_state, {key, value}).<br><br>mnesia:create_table(my_data_1, [{record_info(fields, my_data), {record_name, my_data}, blah, blah]).<br><br>mnesia:create_table(my_data_2, [{record_info(fields, my_data), {record_name, my_data}, blah, blah]).<br>

<br>mnesia:create_table(sys_state, [{record_info(fields, sys_state), blah, blah}]).<br><br>mnesia:dirty_write(#sys_state{key = active_table, value = my_data_1}).<br><br>active_table() -><br>    case mnesia:dirty_read(sys_state, active_table) of<br>

       [] -> my_data_1;<br>       [#sys_state{value= V}] -> V<br>     end.<br><br>standby_table() -><br>     case active_table() of<br>          my_data_1 -> my_data_2;<br>          my_data_2 -> my_data_1<br>

     end.<br><br>swap_tables() -><br>      mnesia:dirty_write(#sys_state{key = active_table, value = standby_table()}).<br><br>upload_new_data() -><br>      write_data_to_standby_table(),<br>      swap_tables().<br>

<br>read_data_from_table() -><br>     mnesia:dirty_read(active_table(), blah).<br><br>cheers<br>Chandru<br><br><div class="gmail_quote">On 28 November 2012 14:06, Philip Clarke <span dir="ltr"><<a href="mailto:send2philip@gmail.com" target="_blank">send2philip@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<div><br></div><div>Is it possible to swap or replace tables in mnesia ?</div><div><br></div><div>For example, say I have a file which is read and parsed by some erlang process and then stored in a mnesia table.  When it is ready, the table data is used by some other processes.</div>


<div><br></div><div>Then at some later time, I get a new version of the file.  I don't want to delete the existing table and load it up from the new file (the system would not be able to function during the load time).</div>


<div><br></div><div>I would like for example to load up to a table called e.g. temp and when that has finished, replace my existing table with the temp table.</div><div><br></div><div>One option I considered is to just keep loading up to new tables e.g. version1, version2, version3 etc. and then have another table which keeps the name of the table to use.  I'm interested to hear if anyone has a better solution.</div>


<div><br></div><div>Thanks</div><span class="HOEnZb"><font color="#888888"><div>Philip</div>
</font></span><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br>