Question

After lookup a nonexistent table(t3) in ets, all the user-created tables(t1 and t2) will be deleted. Is it a bug or just a wierd feature of ets?

Here is the code in Eshell.


Eshell V5.9.1  (abort with ^G)

1> ets:new(t1, [named_table]).

t1

2> ets:new(t2, [named_table]).

t2

3> ets:all().

[t2,t1,8207,4110,13,file_io_servers,inet_hosts_file_byaddr,
 inet_hosts_file_byname,inet_hosts_byaddr,inet_hosts_byname,
 inet_cache,inet_db,global_pid_ids,global_pid_names,
 global_names_ext,global_names,global_locks,ac_tab]

4> ets:insert(t1, {1,2}).

true

5> ets:lookup(t1, 1).

[{1,2}]

6> ets:lookup(t2, 1).

[]

7> ets:all().        

[t2,t1,8207,4110,13,file_io_servers,inet_hosts_file_byaddr,
 inet_hosts_file_byname,inet_hosts_byaddr,inet_hosts_byname,
 inet_cache,inet_db,global_pid_ids,global_pid_names,
 global_names_ext,global_names,global_locks,ac_tab]

8> ets:lookup(t3, 1).

** exception error: bad argument
     in function  ets:lookup/2
        called as ets:lookup(t3,1)

9> ets:all().        

[8207,4110,13,file_io_servers,inet_hosts_file_byaddr,
 inet_hosts_file_byname,inet_hosts_byaddr,inet_hosts_byname,
 inet_cache,inet_db,global_pid_ids,global_pid_names,
 global_names_ext,global_names,global_locks,ac_tab]

10> 

Anyone who can tell me what's the problem here?

Was it helpful?

Solution

You lookuup in a table that does not exist, so you get an error that "crash" your shell. A new shell is launch an it looks transparent, except that the ets that belonged to the first shell are deleted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top