I'm learning erlang and mnesia. I have a question: how to reconncet a "crashed" erlang mnesia node to cluster again?
Erlang/OTP 17 [erts-6.2]
What I did:
Two mnesia nodes: m11#deb83-11 and m12#deb83-12. They were connected
with each other well.
(m11#deb83-11)4> mnesia:system_info(running_db_nodes).
['m12#deb83-12','m11#deb83-11']
Then I teminated the erl shell of m12#deb83-12 by "Ctl-G" and "q"
without stopping mnesia.
After that, I restarted erl shell for m12#deb83-12 node with same
command line.
I found the restarted node m12#deb83-12 did not connect to
m11#deb83-11.
(m11#deb83-11)16> mnesia:system_info(running_db_nodes).
['m11#deb83-11']
Note 1. If i stopped mnesia in step#2, m12#deb83-12 would reconnect to m11#deb83-11 successfully after step#3)
Note 2. I did not create any table. There is only an empty schema in this cluster.
Thanks in advance!
Ming
Apparently all you need to do is connect to the other node (so that nodes(). returns the other node) and restart mnesia with mnesia:stop(). and mnesia:start()..
Related
I am writing data to Mnesia from one erlang VM, now I started another erlang VM on same machine, can second VM read the data written to mnesia by first VM.
To share Mnesia tables the nodes must be part of the same distributed Erlang system.
The schema defines which nodes contain the data base, cf. http://erlang.org/doc/apps/mnesia/Mnesia_chap3.html#define-a-schema
Mnesia database replication is described here: http://erlang.org/doc/apps/mnesia/Mnesia_chap5.html#distribution-and-fault-tolerance.
You can use mnesia:set_master_nodes() to define where to find a table.
Ofcourse you can, here is some basic way to do it:
Start the two nodes - iex --name nodeA#127.0.0.1 and iex --name nodeB#127.0.0.1
From the terminal of node A - Node.connect :"nodeB#127.0.0.1"
From the terminal of node A - :mnesia.create_schema [node(), :"nodeB#127.0.0.1"]
For node A and node B - :mnesia.start
From the terminal of node A - create_table(Person, [attributes: [:id, :name]])
From the terminal of node B - :mnesia.dirty_write({Person, 1, "John"})
Now you can get the information that node B has written from node A through doing basic selection - :mnesia.dirty_read({Person, 1})
References:
https://elixirschool.com/en/lessons/specifics/mnesia/#
http://erlang.org/doc/apps/mnesia/
I have setup ejabberd clustering, one is master and other is slave as described here.
I have copied .erlang.cookie and database files from master to slave.
Everything is working fine.
The issue is when I stop master node:
Then no request getting routed to slave.
When trying to restart slave node its not getting start once it down.
I get stuck here, please help me out.
Thanks
This is the standard behaviour of Mnesia. If the node you start was not the last one that was stopped in a cluster, then it does not have any way to know if it has the latest, most up to date data.
The process to start a Mnesia cluster is to start the node in reverse order in which they were shutdown.
In case the node that was last seen on Mnesia cluster cannot start or join the cluster, them you need to use a Mnesia command to force the cluster "master", that is tell it that you consider this node has the most up to date content. This is done by using Erlang command mnesia:set_master_nodes/1.
For example, from ejabberd Erlang command-line:
mnesia:set_master_nodes([node1#myhost]).
In most case, Mnesia clustering handles everything automatically. When a node goes down, the other nodes are aware and automatically keep on working transparently. The only case you need to set which node as the reference data (with set_master_nodes/1), is when this is ambiguous for Mnesia, that is either when starting only nodes that were down when there was still running nodes or when there is a netsplit.
Follow the step from below link:
http://chadillac.tumblr.com/post/35967173942/easy-ejabberd-clustering-guide-mnesia-mysql
and call the method join_as_master(NodeName) of the easy_cluster module.
I am trying to read the remote Mnesia node using an Erlang command. I am using Ubuntu 14.04 and I am running Erlang 17 OTP. I tried to start my local Mnesia node by issuing
mnesia:start().
And then I tried to connect to remote node with
mnesia.start([{extra_db_nodes, [:'abc#def.com']}]).
It returns true. Then I issue the mnesia:info(), however, it only returns the local Mnesia info. My question is how can I issue the Mnesia command to a remote node from my local node? I am wondering how I can get the Mnesia data of extra_db_nodes in my local node?
I follow this website link for ejabberd clustering http://chad.ill.ac/post/35967173942/easy-ejabberd-clustering-guide-mnesia-mysql
everything is fine its shows two nodes running db and web admin also two node master and slave but if i shtdown master or slave node other one node not continue the process what should i do for if one node is down otherone is continue the process.
Mnesia behaves as a multi-master database. But if you down the nodes, the restart process should be in reverse order. If you have node1 and node2 and you kill node 1 and after that, you kill node2, then you should restart node2 first and then node1. That's because Mnesia thinks that the last updated node is the last one.
Is it a bug or a feature that epmd process still exists after I exit from an erlang shell ?
It is quite normal: EPMD is a host daemon process. Its presence is required when one intends to use distributed nodes. It is also useful when just using many nodes on the same machine.