2 nodes, mnesia store gets cleared when one (specific one) goes down

I’m facing a puzzling behavior using mnesiac, the distributed store almost works.

I have 2 hosts connected via libcluster. I can :mnesia.write on one host, then :mnesia.read on another, all good. However, when I shut down one host, the store gets cleared on the other. And it only happens in one direction: if I shut down the other host, all works fine, as if there were a “master” host that should always stay on (I can’t trace such a possibility in the docs).

Does it ring a bell? I tried all sorts of experiments, but still can’t figure it out. Thanks for any pointers!

Some relevant console bits:

iex(ultramemory_prod@app2.local)7> PairsOne.GameStore.store_options
[
  record_name: :games,
  attributes: [:id, :cards],
  index: [],
  ram_copies: [:"ultramemory_prod@app2.local"]
]
iex(ultramemory_prod@app2.local)1> Mnesiac.running_nodes
[:"ultramemory_prod@app1.local", :"ultramemory_prod@app2.local"]

I got a tiny bit closer. My hosts are indeed asymmetric, in the following sense:

host 1:

iex(ultramemory_prod@app1.local)1> :mnesia.info

remote             = [games]
ram_copies         = [schema]

host 2:

iex(ultramemory_prod@app2.local)1> :mnesia.info

remote             = []
ram_copies         = [games,schema]

Probably I need “ram_copies” contain “games” (my table) on both hosts.

The solution was that ram_copies option should receive both nodes, while I only had one there. Here’s how the correct options might look:

def store_options do
  [
     # ...
     ram_copies: [node() | Node.list()]
  ]
end
2 Likes