mnesia

Pagination search in Erlang Mnesia

送分小仙女□ 提交于 2019-12-23 01:28:19
问题 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? 回答1: 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

Erlang: Mnesia can not create schema while release with rebar

笑着哭i 提交于 2019-12-22 10:12:08
问题 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

erlang mnesia - illegal record info

不问归期 提交于 2019-12-22 07:05:01
问题 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

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

你。 提交于 2019-12-22 05:03:43
问题 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",

Creating mnesia disk_copies of existing ram table

梦想的初衷 提交于 2019-12-21 22:02:48
问题 I have a complete mnesia ram_copies-only database but I am experiencing problems adding a disk_copy table to a node. At the moment I do: Create all my ram_copy tables/nodes Start mnesia on the disk_copy-to-be node. Create a new schema (I didnt create a schema for the ram_copy tables) using mnesia:create_schema([Node]) Copy the table I wish to be a disk_copy, using mnesia:add_table_copy(table, Node, disk_copy) I then wait for the tables to be created Everything seems to go according to plan

Erlang and JavaScript MD5 Digest match

£可爱£侵袭症+ 提交于 2019-12-21 15:39:23
问题 Testing the Javascript Implementation of MD5 here: http://www.webtoolkit.info/javascript-md5.html gives the following output: MD5("muzaaya") = "00e081abefbbbf72b2d5258196a9b6d0" Going to my erlang shell, and calculating the MD5 of the same value i get this: Eshell V5.8.4 (abort with ^G) 1> erlang:md5("muzaaya"). <<0,224,129,171,239,187,191,114,178,213,37,129,150,169, 182,208>> 2> How can i compare the two? If the MD5 result from the JavaScript front end app comes to my Erlang backend, i would

what is the proper way to backup/restore a mnesia database?

旧城冷巷雨未停 提交于 2019-12-20 12:34:14
问题 WARNING: the background info is pretty long. Skip to the bottom if you think you need the question before the background info. Appreciate the time this is gonna take! I've been all over the web (read google) and I have not found a good answer. YES, there are plenty of links and references to the Mnesia documentation on the erlang.org site but even those links suffer from version-itis. So in the simplest case where the node() you are currently connected to is the same as the owner of the table

how do I remove an extra node

☆樱花仙子☆ 提交于 2019-12-20 10:40:20
问题 I have a group of erlang nodes that are replicating their data through Mnesia's "extra_db_nodes"... I need to upgrade hardware and software so I have to detach some nodes as I make my way from node to node. How does one remove a node and still preserve the data that was inserted? [update] removing nodes is as important as adding them. Over time as your cluster grows it must also contract. If not then Mnesia is going to be busy trying to send data to nonexistent nodes filling up queues and

call an undefined function in erlang

▼魔方 西西 提交于 2019-12-14 03:38:16
问题 I want to export DATA fom table mnesia to the txt file I try with this code : exporttxt()-> F = fun(T) -> mensia:foldl(fun(X,Acc) -> [X|Acc] end, [],T) end, {atomic,L} = mnesia:transaction(F(user)), file:write_file("test.txt",[io_lib:format("~p\t~p\t~p~n",[F1,F2,F3]) || #user{id = F1,adress = F2,birthday = F3} <- L]). but when I test this function I have this error : Erlang R13B03 (erts-5.7.4) [source] [rq:1] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.7.4 (abort with ^G) 1> model

Mnesia: How to lock multiple rows simultaneously so that I can write/read a “consistent” set of of records

与世无争的帅哥 提交于 2019-12-13 12:07:26
问题 HOW I WISH I HAD PHRASED MY QUESTION TO BEGIN WITH Take a table with 26 keys, a-z and let them have integer values. Create a process, Ouch, that does two things over and over again In one transaction, write random values for a , b , and c such that those values always sum to 10 In another transaction, read the values for a , b and c and complain if their values do not sum to 10 If you spin-up even a few of these processes you will see that very quickly a , b and c are in a state where their