Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

erlang ets select strange behaviour

Tags:

erlang

ets

I have a strange behaviour in erlang with ets:select.

I achieve a correct select statement (4 and 5 below), then I make an error in my statement (6 below), and then I try again the same statement as in 4 and 5, and it does not work any longer.

What is happening ? any idea ?

Erlang R14B01 (erts-5.8.2) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

Eshell V5.8.2  (abort with ^G)
1> Tab = ets:new(x, [private]).
16400
2> ets:insert(Tab, {c, "rhino"}).
true
3> ets:insert(Tab, {a, "lion"}). 
true
4> ets:select(Tab,[{{'$1','$2'},[],['$1', '$2']}]).      
["rhino","lion"]    
5> ets:select(Tab,[{{'$1','$2'},[],['$1', '$2']}]).      
["rhino","lion"]
6> ets:select(Tab,[{{'$1','$2'},[],['$1', '$2', '$3']}]).
** exception error: bad argument
 in function  ets:select/2
    called as ets:select(16400,[{{'$1','$2'},[],['$1','$2','$3']}])
7> ets:select(Tab,[{{'$1','$2'},[],['$1', '$2']}]).      
** exception error: bad argument
 in function  ets:select/2
    called as ets:select(16400,[{{'$1','$2'},[],['$1','$2']}])

Has my ets table been destroyed ? Would it be a bug of ets ?

Thank you.

like image 515
user803422 Avatar asked Jan 15 '23 05:01

user803422


1 Answers

The shell process has created the ETS table and is the owner of it. When the owner process dies the ETS table is automatically deleted.

So when you get an exception at 6, the shell process dies so the ETS table is deleted.

Making it private also means that no other process can access it (so even if the table was persisted the new shell wouldn't be able to access it), but in this case it is even worse as the table has been deleted.

like image 98
4 revs, 2 users 55% Avatar answered Jan 22 '23 04:01

4 revs, 2 users 55%