mnesia

Mnesia: unexpectedly getting aborted, cyclic transactions

笑着哭i 提交于 2019-12-06 09:06:34
问题 I have a 5 processes that insert/update the same 3 records in a mnesia table. Each of these processes does its insert/updates within a single transaction. I have 5 other process that read these very same 3 records, also within a single transaction. Unless I lock the entire table as part of the multi-record transaction, I get an {aborted, {cyclic, node....}} error. My intuition is that my use-case is ordinary and should not, in of itself, result in in an aborted transaction. Can someone help

Pagination search in Erlang Mnesia

柔情痞子 提交于 2019-12-06 07:11:39
For example, given record -record(item, { id, time, status}). I want to search the 1000 to 1100 items, ordered by time and status =:= <<"finished">> Any suggestions? It depends on what your queries look like. If you need to order by lots of different columns, then I'd consider using SQL instead of Mnesia. But if you only need the kind of query you described, you should be able to use the ordered_set type of table to handle the ordering and mnesia:select/4 to handle pagination and the constraint. Here's some untested code to give you the gist: % time goes first because it's our primary sort key

How to stop ejabberd from using mnesia [closed]

故事扮演 提交于 2019-12-06 05:58:11
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I'm trying to establish a procedure for restoring my database from a crashed server to a new server. My server is running Ejabberd as an XMPP server, and I configured it to use postgresql instead of mnesia - or so I thought. My procedure goes something like "dump the contents of the original DB, run the new server, restore the contents of the DBs using psql, then run the system". However, when I try running

Erlang: Mnesia can not create schema while release with rebar

杀马特。学长 韩版系。学妹 提交于 2019-12-05 22:53:39
When I call mnesia:create_schema on startup, the program crashes. If I run my program in ebin without releasing it, it works find. The error log as follows: =INFO REPORT==== 3-Jul-2013::09:44:06 === application: eddy exited: {bad_return, {{eddy_app,start,[normal,[]]}, {'EXIT', {{badmatch, {error, {'EXIT', {undef, [{mnesia_backup,open_write, ["/home/cometeor/eddy/rel/eddy/Mnesia.eddy@127.0.0.1/eddy@127.0.0.1137284464686415846847780"], []}, {mnesia_bup,do_apply,4, [{file,"mnesia_bup.erl"},{line,387}]}, {mnesia_bup,make_initial_backup,3, [{file,"mnesia_bup.erl"},{line,378}]}, {mnesia_bup,create

erlang mnesia - illegal record info

随声附和 提交于 2019-12-05 10:29:02
I am trying to have a function that ensures the table I need is already created and if not to create it. Here's the sample: ensure_table_exists(Table, MnesiaTables, Nodes) -> case lists:member(Table, MnesiaTables) of true -> throw({error, db_might_have_already_been_created}); false -> mnesia:create_table(Table, [{disc_copies, Nodes}, {attributes, record_info(fields, Table)}]), ok end. The issue is that when compiling I get the error: illegal record info . It might have to do that record_info is resolved at compile time or that the second argument to record info should actually be a record that

How to read all the records of mnesia database in erlang?

耗尽温柔 提交于 2019-12-05 09:53:15
I ma new in erlang and I need to do some operations for all records I get from mnesia database. Result = mnesia:dirty_read(mydatabase, {key1, key2}), case Result of [] -> ?DEBUG("No such record found", []); [#mydatabase{key3 = Key3}] -> %% some operations end How can I add a loop to my code that execute some operations for all records? I am not even sure if the code above does it or not? You could use mnesia:foldl/3 for that. It iterates over all records in a table, passing along an "accumulator" value. It doesn't have an explicit "dirty" counterpart, so if you want to run it as a dirty

How Elixir can read remote node mnesia table

放肆的年华 提交于 2019-12-05 09:28:57
I am trying use Elixir to write program to access mnesia. I run iex shell in amazon linux. I tried to connect another node using Node.connect(:'hello@abc.com') which return true, then I want to run mnesia command on this remote node, I issue :mneisa.info However, it only returns local node mnesia info. How can I access the connected remote node's mnesia database? I have tried rpc_call, it works. But is it having more direct method to get the data from remote node mnesia. Did you try: Node.spawn :'hello@abc.com', fn -> :mneisa.info end 来源: https://stackoverflow.com/questions/29642263/how-elixir

how do we efficiently handle time related constraints on mnesia records?

℡╲_俬逩灬. 提交于 2019-12-05 06:49:12
问题 i am writing records into mnesia which should be kept there only for an allowed time (24 hours). after 24 hours, before a user modifies part of them, the system should remove them automatically. forexample, a user is given free airtime (for voice calls) which they should use in a given time. if they do not use it, after 24 hours, the system should remove these resource reservation from the users record. Now, this has brought in timers. an example of a record structure is: -record(free_airtime

Erlang : Mnesia : Updating a single field value in a row

一世执手 提交于 2019-12-05 05:47:07
I have an mnesia table with three fields, i, a and b, created using the record -record(rec, {i, a,b}). Now I insert a row into the table as: mnesia:transaction( fun() -> mnesia:write("T", #rec{i=1, a=2, b=3}, write) end ). Now what do I do if I want to update this row, and change only the value of a to 10, while leaving i and b with the same values? Is there any SQL equivalent like " UPDATE T SET a=10 WHERE i=1 "? If I do something like this: mnesia:transaction( fun() -> mnesia:write("T", #rec{i=1, a=10}, write) end ) The row is stored as: {rec,1,10,undefined} The value of this function will

question about mnesia distribution

霸气de小男生 提交于 2019-12-04 18:41:57
I have two nodes running mnesia. I created schema and some tables on node 1 , and used mnesia:add_table_copy on node 2 to copy the tables from node 1 to node 2 . Everything works well until I call q() on node 1 and then q() on node 2 . I found that when I start node 1 again, mnesia:wait_for_tables([sometable], infinity) won't return. It will only return when I start node 2 again. Is there a way to fix this? This is a problem because I won't be able to start node 1 again if node 2 is down. In this discussion a situation similar to the one you're facing is presented. Reading from that source: At