2
votes

So I'm getting {aborted,{bad_type,link,disc_copies, 'my_server@127.0.0.1'}} (it is returned by my init_db/0 function):

-record(link, {hash, original, timestamp}).
init_db() ->
    application:set_env(mnesia, dir, "/tmp/mnesia_db"),
    mnesia:create_schema([node()]),
    mnesia:start(),
    mnesia:create_table( link,[
        {index,[timestamp]},
        {attributes, record_info(fields, link)},
        {disc_copies, [node()]}]).

Without {disc_copies, [node()]} table is properly created.

2

2 Answers

3
votes

Verify write permissions on the parent directory of the mnesia dir you're specifying via application:set_env/3. If the mnesia dir parent directory doesn't allow you to write, you'll get this error. (Another way to get this error is to forget to set mnesia dir entirely, but your set_env call is clearly doing that.)

Update: looking more carefully at your reported error, I see the node mentioned in the error is not in a list:

{aborted,{bad_type,link,disc_copies, 'my_server@127.0.0.1'}}

This might mean that the code you show in your question doesn't match what's really running. Specifically, if you call mnesia:create_table/2 passing a node instead of a list of nodes in the disc_copies tuple, as shown below, you'll get the same exact error:

mnesia:create_table(link,[{index,[timestamp]},
                          {attributes, record_info(fields, link)},
                          {disc_copies, node()}]). % note no list here, should be [node()]
0
votes

You may need to change the schema table to disc_copies which seems to affect the entire node.

mnesia:change_table_copy_type(schema, node(), disc_copies)

From the mnesia docs:

This function can also be used to change the storage type of the table named schema. The schema table can only have ram_copies or disc_copies as the storage type. If the storage type of the schema is ram_copies, no other table can be disc-resident on that node.

After this, you should be able to create disc_copies tables on the node.