[erlang-questions] Efficiently backing up a DETS files

Alexei Sholik alcosholik@REDACTED
Fri Jun 27 14:39:11 CEST 2014

Hi all,

I've been thinking about and googling for ways to back up a running dets
database (i.e. with no interruption to the main service using it) and
here's what I have come up with so far.

1. On the same node that currently has the dets file open, create an empty
ETS table and another empty dets file. Call dets:to_ets and then
ets:to_dets to write to the new dets file. After closing the latter file it
will be safe to move it to the backup location.

2. Open a new dets file and use dets:bchunk on the production file in
combination with dets:init_table. I wasn't sure if init_table would iterate
over the original dets file automatically (iow, handling all the
continuations before receiving '$end_of_table').

3. Use one of the traversal functions to copy elements from one dets file
to another one.

I first thought the 1st approach to be the most efficient one (provided
there is enough free RAM for the temporary ETS table). However, if bchunk()
works like this with init_table():

     TableSize = dets:info(my_table, size),
     dets:open_file(new_table, [{min_no_slots, TableSize}]),
     InitFun = dets:bchunk(my_table, start),
     dets:init_table(new_table, InitFun, [{min_no_slots, TableSize},
{format, bchunk}]),

then this 2nd approach looks like the best candidate. Here I could also use
'ram_file' option for new_table to speed up the subsequent init_table()
call provided there is enough free RAM. Is this correct?

I will appreciate anyone pointing out mistakes in my reasoning above.


Best regards
Alexei Sholik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140627/3522e805/attachment.htm>

More information about the erlang-questions mailing list