1

我遇到了 dets 文件大小的问题。

> {ok,D1} = dets:open_file(sample_dets_file, [{type, set},{auto_save,3}]).
{ok,sample_dets_file}

> [dets:insert(D1,{{fid,X},"this is sample data"}) || X <- lists:seq(1,10000)].
> dets:info(D1).

[{type,set},
 {keypos,1},
 {size,10000},
 {file_size,769748},
 {filename,"sample_dets_file"}]

> [dets:delete(D1,{fid,X}) || X <- lists:seq(1,10000)].
> dets:info(D1).

[{type,set},
 {keypos,1},
 {size,0},
 {file_size,770092},
 {filename,"sample_dets_file"}]

插入后-{size,10000}, {file_size,769748}
删除 后- {size,0}, {file_size,770092}
即使表为空,文件大小也没有减少。但是,当我执行时delete_all_objects,文件大小恢复正常。

> dets:delete_all_objects(D1).
> dets:info(D1).

 [{type,set},
 {keypos,1},
 {size,0},
 {file_size,5464},
 {filename,"sample_dets_file"}]

我不明白我还需要做什么以及删除操作以减少文件大小。问题是,由于dets file_size 限制为4gb,即使删除了对象,我也达到了dets 文件的大小限制。

4

2 回答 2

1

删除条目时,dets 实现不会尝试缩小文件,除非您执行 delete_all_objects。要手动收缩文件,您必须创建一个新的临时 dets 文件,将所有条目复制到新文件,删除旧文件,然后重命名临时文件以替换旧文件。

于 2014-05-29T11:30:36.567 回答
0

There is another option how to reduce size of the DETS table (after deletion).

Close this DETS table (dets:close) and open it whit an option {repair, force}.

See the documentation: http://www.erlang.org/doc/man/dets.htm

The only way to defragment a table is to close it and then open it again with the repair option set to force.

When there is no another process which have open this file, the file is compacted.

It works for me.

于 2014-11-24T09:06:02.907 回答