[erlang-questions] Issues with ets:match_delete

Code Wiget codewiget95@REDACTED
Fri Jul 13 17:05:27 CEST 2018


Here is a full run of it. I am working on the open source project cqerl:

(NODE)19> [Test] = ets:match_object(cqerl_clusters, {'_', '_', {Node, '$1'}}).
[{cluster_table,'$primary_cluster',
                {{{192,168,1,104},9042},
                 [{cassandra_nodes,[{<<"192.168.1.107">>,9042},
                                    {<<"192.168.1.104">>,9042}]},
                  {keyspace,devices},
                  {included_applications,[]},
                  {reconnect_interval,12}]}}]
(NODE)20> ets:delete_object(cqerl_clusters, Test).
** exception error: bad argument
     in function  ets:delete_object/2
        called as ets:delete_object(cqerl_clusters,
                                    {cluster_table,'$primary_cluster',
                                                   {{{192,168,1,104},9042},
                                                    [{cassandra_nodes,[{<<"192.168.1.107">>,9042},
                                                                       {<<"192.168.1.104">>,9042}]},
                                                     {keyspace,devices},
                                                     {included_applications,[]},
                                                     {reconnect_interval,12}]}})
(NODE)21> ets:delete_object(cqerl_clusters, [Test]).
** exception error: bad argument
     in function  ets:delete_object/2
        called as ets:delete_object(cqerl_clusters,
                                    [{cluster_table,'$primary_cluster',
                                                    {{{192,168,1,104},9042},
                                                     [{cassandra_nodes,[{<<"192.168.1.107">>,9042},
                                                                        {<<"192.168.1.104">>,9042}]},
                                                      {keyspace,devices},
                                                      {included_applications,[]},
                                                      {reconnect_interval,12}]}}])

Cant figure why the match is working but not the delete..

On Jul 13, 2018, 11:01 AM -0400, Code Wiget <codewiget95@REDACTED>, wrote:
> Here, it seems alive
>
> (NODE13> ets:info(table_name).
> [{read_concurrency,true},
>  {write_concurrency,false},
>  {compressed,false},
>  {memory,422},
>  {owner,<0.1064.0>},
>  {heir,none},
>  {name,cqerl_clusters},
>  {size,2},
>  {node,’NODE'},
>  {named_table,true},
>  {type,bag},
>  {keypos,2},
>  {protection,protected}]
>
>
> On Jul 13, 2018, 7:24 AM -0400, Sverker Eriksson <sverker.eriksson@REDACTED>, wrote:
> > Your ets:match_delete looks fine.
> > Are you sure the table is still alive? Try ets:info(table_name).
> >
> > When you get an exception in the Erlang shell, the shell process will terminate and be restarted
> > losing all process specific resources such as ets tables.
> >
> >
> > /Sverker, Erlang/OTP
> >
> >
> > On tor, 2018-07-12 at 16:35 -0400, Code Wiget wrote:
> > > Hey everyone,
> > >
> > > Lets say you have an ets table with entries as shown below:
> > >
> > > {table_name, key, {A, [B]}.
> > >
> > > I am trying to delete all table entries matching A. I can create a match like so:
> > >
> > > ets:match(table_name, {'_', '_', {Node, '$1'}})
> > >
> > > and it returns the values for B. But when I run match_delete or select_delete, I get a badarg error…:
> > >
> > > > ets:match_delete(table_name, {'_', '_', {Node, '$1'}}).
> > > > ** exception error: bad argument
> > > >      in function  ets:select_delete/2
> > > >         called as ets:select_delete(table_name,
> > > >                                     [{{'_','_',{{{192,168,1,104},9042},'$1'}},[],[true]}])
> > > >      in call from ets:match_delete/2 (ets.erl, line 726)
> > > > (NODE)16> ets:select_delete(table_name, {'_', '_', {Node, '$1'}}).
> > > > ** exception error: bad argument
> > > >      in function  ets:select_delete/2
> > > >         called as ets:select_delete(table_name,{'_','_',{{{192,168,1,104},9042},'$1'}})
> > >
> > > So I tried to match and object and delete it...
> > >
> > > > (NODE)17> ets:match_object(table_name, {'_', '_', {Node, '$1'}}).
> > > > [{table_name,'$primary_cluster',
> > > >                 Info…]
> > > >
> > > >
> > > > (NODE)25> ets:delete_object(table_name, Info).
> > > > ** exception error: bad argument
> > > >      in function  ets:delete_object/2
> > > >         called as ets:delete_object(table_name, …. )
> > > >
> > > I would like to avoid re-creating the table structure, as it is not from a project that I created and would take some time to fix all the code. How do I delete something from this table?
> > >
> > > Thanks!
> > >
> > >
> > > _______________________________________________
> > > erlang-questions mailing list
> > > erlang-questions@REDACTED
> > > http://erlang.org/mailman/listinfo/erlang-questions
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180713/f757c2bb/attachment.htm>


More information about the erlang-questions mailing list