I would like to refine my question a bit. The real problem that I am having is how to share an mnesia db between two nodes that already have their own databases:
I have 3 erlang nodes, 2 are emqtt brokers and 1 is a special node for setting up a key value store. The 2 emqtt brokers have instances of mnesia running that are disc copies, and they need to be able to get a copy of a table from the mnesia database running on the special node.
I have read through all of the questions on stack pertaining to this but have yet to find a way to share a database across nodes from one central node.
I have tried copying tables to my emqtt instances using add_table_copy(device, '
emq...@127.0.0.1', ram_copies), but I get the error that my device table already exists, when it does not: Special Node:
------------------------------------------------------------------------------------------------------------------------------------------------------------
(ry...@127.0.0.1)35> mnesia:add_table_copy(device, 'emq...@127.0.0.1', ram_copies).
{aborted
,{already_exists,device,'emq...@127.0.0.1'}}
Emqtt:
(emq...@127.0.0.1)2> mnesia:info().------------------------------------------------------------------------------------------------------------------------------------------------------------
--->
Processes holding locks <---
--->
Processes waiting for locks <---
--->
Participant transactions <---
--->
Coordinator transactions <---
--->
Uncertain transactions <---
--->
Active tables <---
mqtt_admin : with
1 records occupying 326 words of mem
mqtt_retained : with
3 records occupying 194 words of mem
mqtt_route : with
0 records occupying 304 words of mem
mqtt_topic : with
0 records occupying 304 words of mem
mqtt_session : with
0 records occupying 304 words of mem
mqtt_trie_node : with
0 records occupying 304 words of mem
mqtt_trie : with
0 records occupying 304 words of mem
schema : with
8 records occupying 1273 words of mem
===>
System info in version "4.14.2", debug level = none <===
opt_disc
. Directory "/Users/ryanauger/repos/emq-relx/_rel/emqttd/data/mnesia/emq...@127.0.0.1" is used.
use fallback at restart = false
running db nodes = [
'emq...@127.0.0.1']
stopped db nodes = []
master node tables = []
remote = []
ram_copies = [mqtt_retained
,mqtt_route,mqtt_session,mqtt_topic,
mqtt_trie
,mqtt_trie_node]
disc_copies = [mqtt_admin
,schema]
disc_only_copies = []
[{
'emq...@127.0.0.1',disc_copies}] = [schema,mqtt_admin]
[{
'emq...@127.0.0.1',ram_copies}] = [mqtt_trie,mqtt_trie_node,mqtt_session,
mqtt_topic
,mqtt_route,mqtt_retained]
10 transactions committed, 2 aborted, 0 restarted, 15 logged to disc
0 held locks, 0 in queue; 0 local transactions, 0 remote
0 transactions waits for other nodes: []
ok
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
How would I go about sharing the tables from this database? Based on my research, it seems like it may not be possible with mnesia. If so, please suggest another tool that can integrate with erlang!