Erlang / ets:在获得“坏参数”后重置ets表 [英] Erlang/ets: reset ets table after getting a "bad argument"?

查看:241
本文介绍了Erlang / ets:在获得“坏参数”后重置ets表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习如何使用ets,但有一件事令我烦恼的是偶尔*, ets:match 抛出一个 ...而且,从他们开始,所有后续调用(甚至以前工作的调用)也抛出一个坏参数

 
> ets:match(Tid,{[$ r |'$ 1']},1)。
%此匹配工作...
%然后,在某些时候,这出现了:
**异常错误:错误参数
在函数ets:match / 3
被称为ets:match(24589,{[114 |'$ 1']},1)
%从那时起,匹配停止工作:
> ets:match(Tid,{[$ r |'$ 1']},1)。
**异常错误:错误参数
在函数ets:match / 3
调用为ets:match(24589,{[114 |'$ 1']},1)
有没有办法重置 ets 系统,以便我可以查询(即,从shell)再次?



*:我没有能够重现的问题...但它发生相当频繁,当我试图做其他事情

解决方案

虽然我不是100%肯定,这个线程似乎回答了你的问题。看来你正在shell中观察这个行为。如果是这样,两个事实是以令人困惑的方式相互作用的:


  1. 一旦ets表的所有进程死机,ets表就会被删除。 >
  2. 如果Erlang shell收到异常,并且无声重新启动,它就会死机。

所以,当你得到第一个例外,当前的shell进程死机导致ets表被删除,然后为您启动一个新的shell进程。现在,当您尝试另一个 ets:match 时,它会失败,因为表不再存在。


I've been learning how to use ets, but one thing that has bothered me is that, occasionally*, ets:match throws a bad argument… And, from them on, all subsequent calls (even calls which previously worked) also throw a bad argument:

> ets:match(Tid, { [$r | '$1'] }, 1).
% this match works...
% Then, at some point, this comes up:
** exception error: bad argument
     in function  ets:match/3
        called as ets:match(24589,{[114|'$1']},1)
% And from then on, matches stop working:
> ets:match(Tid, { [$r | '$1'] }, 1).
** exception error: bad argument
     in function  ets:match/3
        called as ets:match(24589,{[114|'$1']},1)

Is there any way to "reset" the ets system so that I can query it (ie, from the shell) again?

*: I haven't been able to reproduce the problem… But it happens fairly often while I'm trying to do "other things".

解决方案

Although I'm not 100% sure, this thread seems to answer your question. It appears that you're observing this behaviour in the shell. If so, two facts are interacting in a confusing way:

  1. An ets table is deleted as soon as its owning process dies.
  2. The erlang shell dies whenver it receives an exception and is silently restarted.

So, when you get the first exception, the current shell process dies causing the ets table to be deleted, and then a new shell process is started for you. Now, when you try another ets:match, it fails because the table no longer exists.

这篇关于Erlang / ets:在获得“坏参数”后重置ets表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆