Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>According to my own research answer for the question is - it will choose <strong>the most recently connected node</strong>. I will be grateful for pointing out errors if found - mnesia is a really complex system!</p> <p>As <a href="http://www.nabble.com/In-a-mnesia-cluster,-which-node-is-queried--td22920996.html" rel="noreferrer">Dan Gudmundsson pointed out</a> on the mailing list algorithm of selection of the remote node to query is defined in <code>mnesia_lib:set_remote_where_to_read/2</code>. It is the following</p> <pre><code>set_remote_where_to_read(Tab, Ignore) -&gt; Active = val({Tab, active_replicas}), Valid = case mnesia_recover:get_master_nodes(Tab) of [] -&gt; Active; Masters -&gt; mnesia_lib:intersect(Masters, Active) end, Available = mnesia_lib:intersect(val({current, db_nodes}), Valid -- Ignore), DiscOnlyC = val({Tab, disc_only_copies}), Prefered = Available -- DiscOnlyC, if Prefered /= [] -&gt; set({Tab, where_to_read}, hd(Prefered)); Available /= [] -&gt; set({Tab, where_to_read}, hd(Available)); true -&gt; set({Tab, where_to_read}, nowhere) end. </code></pre> <p>So it gets the list of active_replicas (i.e. list of candidates), optionally shrinks the list to master nodes for the table, remove tables to be ignored (for any reason), shrinks the list to currently connected nodes and then selects in the following order:</p> <ol> <li>First non-<code>disc_only_copies</code></li> <li>Any available node</li> </ol> <p>The most important part is in fact the list of <code>active_replicas</code>, since it determines the order of nodes in the list of candidates.</p> <p>List of <code>active_replicas</code> is formed by remote calls of <code>mnesia_controller:add_active_replica/*</code> from newly connected nodes to old nodes (i.e. one which were in the cluster before), which boils down to the function <code>add/1</code> which adds the item as the head of the list.</p> <p>Hence <strong>answer for the question is</strong> - it will choose <strong>the most recently connected node</strong>.</p> <p>Notes: To check out the list of active replicas on the given node you can use this (dirty hack) code:</p> <pre><code>[ {T,X} || {{T,active_replicas}, X} &lt;- ets:tab2list(mnesia_gvar) ]. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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