Mnesia database from RabbitMQ plugin

257 views
Skip to first unread message

Urmik Shah

unread,
Jan 19, 2015, 2:30:18 AM1/19/15
to rabbitm...@googlegroups.com
Hello,

I am trying to create Mnesia database table from RabbitMQ plugin. 
By default, Mnesia schema and table has been created inside "\Users\AppData\Roaming\RabbitMQ\db\rabbit@xxx-mnesia" .
I have used below code to create schema and table inside plugin.

init() ->
    mnesia:create_schema([node()]),
    mnesia:start(),
    mnesia:create_table(mytable,
        [ {disc_copies, [node()] },
             {attributes,      
                record_info(fields,mytable)}
]).

I have couple of question

1) How can I change Mnesia database directory for this plugin only?
   I have tried with  "application:set_env(mnesia, dir, "D:/MnesiaDB")" before creating schema but didn't get success.
 
2) Also How can I view my tables using erlan command from "\Users\AppData\Roaming\RabbitMQ\db\rabbit@xxx-mnesia" . ?
    
    I have tried with following
    
    erl.exe -mnesia dir "Users/AppData/Roaming/RabbitMQ/db/rabbit@xxx-mnesia
    mnesia:start().
    tv:start().

   Here i can view all tables but all tables have 0 table size.(I have already interested records successfully inside table).  

   
   Regards,
   Urmik

Urmik Shah

unread,
Jan 19, 2015, 3:55:53 AM1/19/15
to rabbitm...@googlegroups.com
Does any one know, how can I view my mnesia table data from  "\Users\AppData\Roaming\RabbitMQ\db\rabbit@xxx-mnesia"? 
Tables are empty when I looked in mnesia tables with table viewer (tv) 

Regards,
Urmik

Jean-Sébastien Pédron

unread,
Jan 19, 2015, 4:19:39 AM1/19/15
to rabbitm...@googlegroups.com
On 19.01.2015 08:30, Urmik Shah wrote:
> Hello,

Hi!

> init() ->
> mnesia:create_schema([node()]),
> mnesia:start(),
> mnesia:create_table(mytable,
> [ {disc_copies, [node()] },
> {attributes,
> record_info(fields,mytable)}
> ]).

You can't change Mnesia directory and create another schema, it would
break RabbitMQ.

Just create your table(s). Make sure to prefix each table name to avoid
any conflict with other tables.

> 2) Also How can I view my tables using erlan command from
> "\Users\AppData\Roaming\RabbitMQ\db\rabbit@xxx-mnesia" . ?
>
> I have tried with following
>
> erl.exe -mnesia dir "Users/AppData/Roaming/RabbitMQ/db/rabbit@xxx-mnesia
> mnesia:start().
> tv:start().

I never used this application and don't have it installed currently, so
can't really help here.

--
Jean-Sébastien Pédron
Pivotal / RabbitMQ

Jean-Sébastien Pédron

unread,
Jan 19, 2015, 4:49:20 AM1/19/15
to rabbitm...@googlegroups.com
On 19.01.2015 08:30, Urmik Shah wrote:
> 2) Also How can I view my tables using erlan command from
> "\Users\AppData\Roaming\RabbitMQ\db\rabbit@xxx-mnesia" . ?
>
> I have tried with following
>
> erl.exe -mnesia dir "Users/AppData/Roaming/RabbitMQ/db/rabbit@xxx-mnesia
> mnesia:start().
> tv:start().

I tried the "observer" application and I could see the tables content:

erl -sname remote -remsh rabbit@myhostname

(rabbit@myhostname)1> observer:start().

Urmik Shah

unread,
Jan 19, 2015, 8:23:31 AM1/19/15
to rabbitm...@googlegroups.com, jean-se...@rabbitmq.com
Hello Jean-Sébastien Pédron,

Many thanks for your reply. 
It works for me also. I could also see my table contents.
Thanks again.

Also as per your suggestion, I shall only create table like
init() ->
    mnesia:start(),
    mnesia:create_table(mytable,
        [ {disc_copies, [node()] },
             {attributes,      
                record_info(fields,mytable)}
 ]). 

Just couple of questions I want to ask you,

1) Should I need to check if table is already exist or not before creating it?Is there any disadvantage if I call above function each time?
2) Also how reliable to store/retrieve data into Mnesia database?

Regards,
Urmik  

Jean-Sébastien Pédron

unread,
Jan 19, 2015, 9:00:30 AM1/19/15
to rabbitm...@googlegroups.com
On 19.01.2015 14:23, Urmik Shah wrote:
> 1) Should I need to check if table is already exist or not before
> creating it?Is there any disadvantage if I call above function each time?

mnesia:create_table/2 returns an error if the table already exists (not
an exception), so you can call it each time. However, if you change the
parameters, it won't "upgrade" the existing table.

Furthermore, you may want to use rabbit_mnesia:cluster_nodes/1 to
populate {ram_copies, ...} and/or {disc_copies, ...}.

> 2) Also how reliable to store/retrieve data into Mnesia database?

Mnesia is reliable as a local storage. It works quite well when
clustered too, but it is sensitive to network partitioning.
Reply all
Reply to author
Forward
0 new messages