mnesia

Unique constraint in Mnesia

I am developing an Erlang application which requires a LOT of DB writes. My schema has, in addition to the primary key, another attribute with a unique constraint enforced. Say I have an ID, an unique_constraint_field, and some other fields. I need to now update a row in the DB corresponding to the unique ID, given that no other row sh...

erlang - how can I match tuple contents with qlc and mnesia ?

Hi. I have a mnesia table for this record. -record(peer, { peer_key, %% key is the tuple {FileId, PeerId} last_seen, last_event, uploaded = 0, downloaded = 0, left = 0, ip_port, key }). Peer_key is a tuple {FileId, ClientId}, now I need to extract the ip_port field from all peers that have a specific...

In Erlang, what is the best way to upgrade a distributed system?

If I have multiple web server written in Erlang running (load balanced) and Mnesia is used for the backend database, what is the best way to upgrade the whole system to a newer version? ...

How to define a foreign key in Mnesia

Is there an equivalent to this SQL statement in Mnesia? alter table TABLE add foreign key (FIELD) references TABLE2 (FIELD2) ...

Eventually consistent mnesia database with erlang. Best practices anyone?

Hi. I'm writing a bittorrent tracker in erlang. Given the nature of the service, I won't need absolute consistency (ie. a client can be perfectly happy with a slightly outdated list of peers or torrent status). My strategy so far has been to create mnesia tables in RAM with disc_copies enabled, so to have mnesia automatically dump the ...

Records in Erl (Erlang question)

Is there a way to use records directly in erl? No matter what I try, it always says it canno find the record. I am trying to do mnesia transactions and I cannot go too far without my records. Any help is greatly appreciated - thank you! ...

How do I properly snapshot an EBS volume with a RabbitMQ instance running?

I'm using RabbitMQ on an EC2 instance and I have the Mnesia tables on an EBS volume, so when I snapshot it and try to launch another instance with the same data, it appears that the table is in use by another RabbitMQ instance. Is the only way to get around this to shut RabbitMQ down for the flush/snapshot and then start it back up once...

Using gen_server to encapsulate an mnesia table?

I have a server application made in Erlang. In it I have an mnesia table that store some information on photos. In the spirit of "everything is a process" I decided to wrap that table in a gen_server module, so that the gen_server module is the only one that directly accesses the table. Querying and adding information to that table is ...

Mochiweb mnesia requests

I'm trying to link Mochiweb with my ejabberd mnesia db and am unable to do any mnesia transactions in my controllers. I test my controllers without the mnesia transactions and they work fine. I am using application:start(mnesia) inside the start function. On the browser, I see "Internal server error" and on Mochiweb's log I see, "=ERR...

How far should I take referential transparency?

I am building a website using erlang, mnesia, and webmachine. Most of the documentation I have read praises the virtues of having referentially transparent functions. The problem is, all database access is external state. This means that any method that hits the database is no longer referentially transparent. Lets say I have a user ob...

Erlang Ets tables between Nodes

I've got an ejabberd server with a good amount of custom modules running. I have several mnesia tables and I know these can be easily copied between nodes without any change to the code at all. I was wondering if there's a similar way with ets tables? Ideally it'd be nice to be able to have several machines running with exactly the sa...

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

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 wit...

Erlang : Mnesia : Lookup and update based on fields other than the key

I have a table in mnesia and I need to update individual fields in the records in it. According to http://stackoverflow.com/questions/1820996/erlang-mnesia-updating-a-single-field-value-in-a-row if I do something like: update_a(Tab, Key, Value) -> fun() -> [P] = mnesia:wread({Tab, Key}), mnesia:write(Tab, P#rec{a=Value}, write...

Erlang: specifying a working directory for mnesia?

How do I specify a working directory for mnesia without resorting to passing the "dir" parameter on the command-line? In other words, can I specify a "working directory" for mnesia just before calling `mnesia:start()' ? ...

Erlang: side effect(s) to calling mnesia:create_schema more than once?

Is there a side effect to calling mnesia:create_schema() on each application start? From what I keep reading, this function should only be called once per database instance. Is it a big issue to call it more than once on an existing database? ...

Profiling Mnesia Queries

Our Mnesia DB is running slowly and we think it should be somewhat faster. So we need to profile it and work out what is happening. There are a number of options that suggest themselves: run fprof and see where the time is going run cprof and see which functions are called a lot However these are both fairly standard performance ...

Ejabberd Memory Consumption (or Leak?)

I'm using ejabberd + mochiweb on our server. The longer I keep ejabberd and mochiweb running, the more memory is consumed (last night it was consuming 35% of memory. right now it's a bit above 50%). I thought this was just a mnesia garbage collection issue - so I installed Erlang R13B3 and restarted ejabberd. This didn't fix it thoug...

Mnesia asynchronous transaction

I would like to have a master-slave setup of Erlang nodes, where read and write operations happen on the master node only. Slave nodes are only kept as hot-standbys. As I understand the default behavior of Mnesia is to acquire the lock synchronously on all nodes before executing the write operation. This would result in high latency esp...

ejabberd : replace mnesia with mysql

Hello All, Is there any way to setup mysql in place of mnesia. any help on this is much appreciated. Everything for me went on fine. Also I need to archive the history text. Thanks in advance Abraham ...

ejabberd supervisor module

I need to keep a gen_mod process running as it loops every minute and does some cleanup. However once every few days it will crash and I'll have to manually start it back up again. I could use a basic example of implementing a supervisor into ejabberd_sup so it can keep going. I am struggling to understand the examples that use gen_se...