[erlang-questions] how to clear a hot mnesia table

Igor Ribeiro Sucupira igorrs@REDACTED
Wed May 12 19:26:48 CEST 2010


Hi, Brian.

It's been a long time since you asked that question. Did someone help
you with that?

I probably would do that using a "dirty cursor" to iterate through the
table keys and delete them one by one. Does that create any problems
for you?

Table = your_table,
Cursor = mnesia:activity(sync_dirty, fun() ->
qlc:cursor(qlc:q([element(2, R) || R <- mnesia:table(Table)])) end).

And then repeatedly:
- Call qlc:next_answers(Cursor) to get a list with the next keys.
- Call mnesia:activity(sync_transaction, fun mnesia:delete/1, [{Table,
Key}]) for each returned key.

You can also introduce some artificial delays to avoid interfering too
much with the normal operation of your system.

Igor.

On Thu, Apr 1, 2010 at 9:12 PM, Brian Acton <acton@REDACTED> wrote:
> Hi guys,
>
> I am running R13B04 SMP on FreeBSD 7.3
>
> I have a very large table (i.e. 5.98M records covering 1.66GB) in Mnesia
> that I need to clear out. Unfortunately, the transaction volume is
> reasonably high and the servers are 24/7 servers.
>
> I'd like to clear out the table without experiencing any downtime.
>
> I know about mnesia:clear_table. However, I am concerned that since this
> requires transactional semantics that mnesia will succeed on one node but
> basically bring down the rest of the nodes as transactions pile up waiting
> on some form of table lock.
>
> Is there a clean and simple way to empty out the table in a less risky
> fashion ?
>
> --b


More information about the erlang-questions mailing list