Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mnesia:wait_for_tables/2 , do i really understand it?

Tags:

erlang

mnesia

I have used mnesia for a while now. I have to confess that i feel like i do not exactly understand the concept of mnesia:wait_for_tables/2. Quoting the documentation here below says this:

Some applications need to wait for certain tables to be accessible in order to do
useful work. mnesia:wait_for_tables/2 hangs until all tables in the Tab List are
accessible, or until timeout is reached.
Now, for all the applications i have developed, i have had to call this when starting my backend. In the documentation above, the context of "Some applications" was not expanded well and thats where my question is.

These are my thoughts:
1. Waiting in this method means that we are loading mnesia tables from say the Disc to RAM (case of Disc_copies)
2. I personally think that if my application is consisting of only RAM (ram_copies) tables, then i do not need this method in my code. Now, I'm i right to think that if i have only disc_only_copies, i also do not need this function.
3. Also, i need this function when am loading mnesia tables from the network,especially when my tables are replicated, so my apps need to wait for mnesia on start up to make these tables ready. But this still only applies for tables of type disc_copies as why would an application running entirely on Disc or entirely in RAM need to wait and load tables ?

questions:
Help and examine my thoughts 1, 2 and 3. In general is this function only needed when dealing with mnesia table type: disc_copies since this type has something to do with data copy on disc and RAM ?

If my tables are all fragmented, (i have always called this method for each fragment to ensure mnesia makes it ready for my apps), do i have to call the method per fragment? is the method ATOMIC or Transactional if i call it within a mnesia transaction (meaning that mnesia will automatically load all the tables fragments if i specify the base table alone) ? does the table type of my fragments also matter concerning this function ?

like image 639
Muzaaya Joshua Avatar asked Oct 10 '22 13:10

Muzaaya Joshua


1 Answers

When starting mnesia, mnesia just queues up all tables that should be loaded from disc or from the network.

mnesia:wait_for_tables/2 gives you a synchronization point so you don't have to poll if the table(s) are ready to be used.

If you don't use the disc and no replication, (i.e. the schema is always empty during start) you don't need to use wait_for_tables.

like image 171
dgud Avatar answered Oct 13 '22 11:10

dgud