问题描述
我的失忆症有一个很奇怪的错误。我有大约10张记忆卡正在记录的桌子,通常它可以正常工作。但是,在代码的某个位置,每当我尝试从特定表中读取(尝试从其他表中读取都可以)时,都会收到DETS错误。
我将代码缩减为
{atomic,ok} = mnesia:transaction(fun()->
[ Entry] = mnesia:read(table_name,Key),
ok
end)
我在交易周围有一个 try
/ catch
块,我得到的错误是:
错误:{badmatch,
{已终止,
{{badmatch,
{错误,
{bad_object_header,
/path/to/table_name.DAT}}},
[{callback,
'-handle / 2-fun-0-',
1,
[{file,
src / src.erl},
{line,
234}]},
{mnes ia_tm,
apply_fun,
3,
[{file,
mnesia_tm.erl},
{line,
830}]},
{mnesia_tm,
execute_transaction,
5,
[{文件,
mnesia_tm.erl},
{行,
810} ]},
]}}}
不幸的是,我无法用一个简短的例子重现该错误。即使我从REPL调用了该函数,也不会出错。当它发生在我的实际代码中时,它只会出错。
如果我删除 mnesia:read
行,一切正常。我尝试过重新制作架构和表格,但这没有帮助。真的很奇怪,因为我的代码稍后继续成功使用该表。只有在此位置使用它时,它才会失败。
出什么问题了?
更新
我做了更多的实验,似乎错误仅在其中两个事务(在不同的过程中)几乎同时发生时才发生。
Update 2
原来,问题出在通过将我在Arch Linux上的erlang安装从R16B-6降级到R16B-3进行了修复。希望这个错误会很快得到解决。文件用完了内存,或者您正尝试从文件中不存在的位置读取数据。因此,如果您没有用完内存(应该注意),那么DETS在处理该文件时可能会出现竞争状态。
I am having a very weird error with mnesia. I have about 10 tables that mnesia is recording, and usually it works fine. However, in a certain place in my code, whenever I try to read from a particular table (trying to read from other tables is fine) I get a DETS error.
I reduced my code to
{atomic, ok} = mnesia:transaction(fun() ->
[Entry] = mnesia:read(table_name, Key),
ok
end)
I have a try
/catch
block around the transaction, and the error I get is this:
error:{badmatch,
{aborted,
{{badmatch,
{error,
{bad_object_header,
"/path/to/table_name.DAT"}}},
[{callback,
'-handle/2-fun-0-',
1,
[{file,
"src/src.erl"},
{line,
234}]},
{mnesia_tm,
apply_fun,
3,
[{file,
"mnesia_tm.erl"},
{line,
830}]},
{mnesia_tm,
execute_transaction,
5,
[{file,
"mnesia_tm.erl"},
{line,
810}]},
]}}}
Unfortunately I cannot reproduce the error with a short example. Even if I call the function from the REPL, it doesn't error. It only errors when it happens in my actual code. But it does happen reliably every time.
If I take out the mnesia:read
line, everything works fine. I have tried remaking the schema and the tables, and that didn't help. It's really weird because my code goes on later to use the table successfully. It is only if it's used from this one place that it fails.
What could be going wrong?
Update
I experimented some more and it seems that the error only happens when two of these transactions happen (in different processes) nearly simultaneously. Isn't mnesia meant to be used in this way?
Update 2
Turned out that the problem was fixed by downgrading my erlang installation on Arch Linux to R16B-3 from R16B-6. Hopefully this bug will be ironed out soon.
The symptoms means that either that the file operation to read at a specific part of the file runs out of memory or you are trying to read from an non existing position in the file. So if you do not run out of memory (which you should have noticed), it is likely that there is a race condition in the handling of that file by DETS.
这篇关于随机bad_object_header遗忘/错失错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!